HBASE-18420 Some methods of Admin don't use ColumnFamilyDescriptor
[hbase.git] / hbase-client / src / main / java / org / apache / hadoop / hbase / client / MultiAction.java
bloba4aa71d8208543c3010627e8224dbc362446f9b1
1 /*
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org.apache.hadoop.hbase.client;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.TreeMap;
28 import org.apache.hadoop.hbase.HConstants;
29 import org.apache.hadoop.hbase.classification.InterfaceAudience;
30 import org.apache.hadoop.hbase.util.Bytes;
32 /**
33 * Container for Actions (i.e. Get, Delete, or Put), which are grouped by
34 * regionName. Intended to be used with {@link AsyncProcess}.
36 @InterfaceAudience.Private
37 public final class MultiAction {
38 // TODO: This class should not be visible outside of the client package.
40 // map of regions to lists of puts/gets/deletes for that region.
41 protected Map<byte[], List<Action>> actions = new TreeMap<>(Bytes.BYTES_COMPARATOR);
43 private long nonceGroup = HConstants.NO_NONCE;
45 public MultiAction() {
46 super();
49 /**
50 * Get the total number of Actions
52 * @return total number of Actions for all groups in this container.
54 public int size() {
55 int size = 0;
56 for (List<?> l : actions.values()) {
57 size += l.size();
59 return size;
62 /**
63 * Add an Action to this container based on it's regionName. If the regionName
64 * is wrong, the initial execution will fail, but will be automatically
65 * retried after looking up the correct region.
67 * @param regionName
68 * @param a
70 public void add(byte[] regionName, Action a) {
71 add(regionName, Collections.singletonList(a));
74 /**
75 * Add an Action to this container based on it's regionName. If the regionName
76 * is wrong, the initial execution will fail, but will be automatically
77 * retried after looking up the correct region.
79 * @param regionName
80 * @param actionList list of actions to add for the region
82 public void add(byte[] regionName, List<Action> actionList){
83 List<Action> rsActions = actions.get(regionName);
84 if (rsActions == null) {
85 rsActions = new ArrayList<>(actionList.size());
86 actions.put(regionName, rsActions);
88 rsActions.addAll(actionList);
91 public void setNonceGroup(long nonceGroup) {
92 this.nonceGroup = nonceGroup;
95 public Set<byte[]> getRegions() {
96 return actions.keySet();
99 public boolean hasNonceGroup() {
100 return nonceGroup != HConstants.NO_NONCE;
103 public long getNonceGroup() {
104 return this.nonceGroup;