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.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.TreeMap;
28
29 import org.apache.hadoop.hbase.classification.InterfaceAudience;
30 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
31 import org.apache.hadoop.hbase.util.Bytes;
32 import org.apache.hadoop.hbase.util.Pair;
33
34
35
36
37 @InterfaceAudience.Private
38 public class MultiResponse {
39
40
41
42 private Map<byte[], RegionResult> results =
43 new TreeMap<byte[], RegionResult>(Bytes.BYTES_COMPARATOR);
44
45
46
47
48
49 private Map<byte[], Throwable> exceptions =
50 new TreeMap<byte[], Throwable>(Bytes.BYTES_COMPARATOR);
51
52 public MultiResponse() {
53 super();
54 }
55
56
57
58
59 public int size() {
60 int size = 0;
61 for (RegionResult result: results.values()) {
62 size += result.size();
63 }
64 return size;
65 }
66
67
68
69
70
71
72
73
74
75 public void add(byte[] regionName, int originalIndex, Object resOrEx) {
76 getResult(regionName).addResult(originalIndex, resOrEx);
77 }
78
79 public void addException(byte []regionName, Throwable ie){
80 exceptions.put(regionName, ie);
81 }
82
83
84
85
86 public Throwable getException(byte []regionName){
87 return exceptions.get(regionName);
88 }
89
90 public Map<byte[], Throwable> getExceptions() {
91 return exceptions;
92 }
93
94 public void addStatistic(byte[] regionName, ClientProtos.RegionLoadStats stat) {
95 getResult(regionName).setStat(stat);
96 }
97
98 private RegionResult getResult(byte[] region){
99 RegionResult rs = results.get(region);
100 if (rs == null) {
101 rs = new RegionResult();
102 results.put(region, rs);
103 }
104 return rs;
105 }
106
107 public Map<byte[], RegionResult> getResults(){
108 return this.results;
109 }
110
111 static class RegionResult{
112 Map<Integer, Object> result = new HashMap<Integer, Object>();
113 ClientProtos.RegionLoadStats stat;
114
115 public void addResult(int index, Object result){
116 this.result.put(index, result);
117 }
118
119 public void setStat(ClientProtos.RegionLoadStats stat){
120 this.stat = stat;
121 }
122
123 public int size() {
124 return this.result.size();
125 }
126
127 public ClientProtos.RegionLoadStats getStat() {
128 return this.stat;
129 }
130 }
131 }