1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.client;
20
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25 import java.util.TreeMap;
26
27 import org.apache.hadoop.classification.InterfaceAudience;
28 import org.apache.hadoop.hbase.HConstants;
29 import org.apache.hadoop.hbase.util.Bytes;
30
31
32
33
34
35 @InterfaceAudience.Private
36 public final class MultiAction<R> {
37
38
39
40 public Map<byte[], List<Action<R>>> actions =
41 new TreeMap<byte[], List<Action<R>>>(Bytes.BYTES_COMPARATOR);
42
43 private long nonceGroup = HConstants.NO_NONCE;
44
45 public MultiAction() {
46 super();
47 }
48
49
50
51
52
53
54 public int size() {
55 int size = 0;
56 for (List<?> l : actions.values()) {
57 size += l.size();
58 }
59 return size;
60 }
61
62
63
64
65
66
67
68
69
70 public void add(byte[] regionName, Action<R> a) {
71 List<Action<R>> rsActions = actions.get(regionName);
72 if (rsActions == null) {
73 rsActions = new ArrayList<Action<R>>();
74 actions.put(regionName, rsActions);
75 }
76 rsActions.add(a);
77 }
78
79 public void setNonceGroup(long nonceGroup) {
80 this.nonceGroup = nonceGroup;
81 }
82
83 public Set<byte[]> getRegions() {
84 return actions.keySet();
85 }
86
87
88
89
90 public List<Action<R>> allActions() {
91 List<Action<R>> res = new ArrayList<Action<R>>();
92 for (List<Action<R>> lst : actions.values()) {
93 res.addAll(lst);
94 }
95 return res;
96 }
97
98 public boolean hasNonceGroup() {
99 return nonceGroup != HConstants.NO_NONCE;
100 }
101
102 public long getNonceGroup() {
103 return this.nonceGroup;
104 }
105 }