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