1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.client;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.TreeMap;
27
28 import org.apache.hadoop.hbase.classification.InterfaceAudience;
29 import org.apache.hadoop.hbase.util.Bytes;
30 import org.apache.hadoop.hbase.util.Pair;
31
32
33
34
35 @InterfaceAudience.Private
36 public class MultiResponse {
37
38
39
40 private Map<byte[], List<Pair<Integer, Object>>> results =
41 new TreeMap<byte[], List<Pair<Integer, Object>>>(Bytes.BYTES_COMPARATOR);
42
43
44
45
46
47 private Map<byte[], Throwable> exceptions =
48 new TreeMap<byte[], Throwable>(Bytes.BYTES_COMPARATOR);
49
50 public MultiResponse() {
51 super();
52 }
53
54
55
56
57 public int size() {
58 int size = 0;
59 for (Collection<?> c : results.values()) {
60 size += c.size();
61 }
62 return size;
63 }
64
65
66
67
68
69
70
71
72
73
74 public void add(byte[] regionName, Pair<Integer, Object> r) {
75 List<Pair<Integer, Object>> rs = results.get(regionName);
76 if (rs == null) {
77 rs = new ArrayList<Pair<Integer, Object>>();
78 results.put(regionName, rs);
79 }
80 rs.add(r);
81 }
82
83 public void add(byte []regionName, int originalIndex, Object resOrEx) {
84 add(regionName, new Pair<Integer,Object>(originalIndex, resOrEx));
85 }
86
87 public Map<byte[], List<Pair<Integer, Object>>> getResults() {
88 return results;
89 }
90
91 public void addException(byte []regionName, Throwable ie){
92 exceptions.put(regionName, ie);
93 }
94
95
96
97
98 public Throwable getException(byte []regionName){
99 return exceptions.get(regionName);
100 }
101
102 public Map<byte[], Throwable> getExceptions() {
103 return exceptions;
104 }
105 }