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.
20 package org
.apache
.hadoop
.hbase
.client
;
22 import java
.util
.HashMap
;
24 import java
.util
.TreeMap
;
26 import org
.apache
.yetus
.audience
.InterfaceAudience
;
27 import org
.apache
.hadoop
.hbase
.shaded
.protobuf
.generated
.ClientProtos
;
28 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
31 * A container for Result objects, grouped by regionName.
33 @InterfaceAudience.Private
34 public class MultiResponse
extends AbstractResponse
{
36 // map of regionName to map of Results by the original index for that Result
37 private Map
<byte[], RegionResult
> results
= new TreeMap
<>(Bytes
.BYTES_COMPARATOR
);
40 * The server can send us a failure for the region itself, instead of individual failure.
41 * It's a part of the protobuf definition.
43 private Map
<byte[], Throwable
> exceptions
=
44 new TreeMap
<>(Bytes
.BYTES_COMPARATOR
);
46 public MultiResponse() {
51 * @return Number of pairs in this container
55 for (RegionResult result
: results
.values()) {
56 size
+= result
.size();
62 * Add the pair to the container, grouped by the regionName
65 * @param originalIndex the original index of the Action (request).
66 * @param resOrEx the result or error; will be empty for successful Put and Delete actions.
68 public void add(byte[] regionName
, int originalIndex
, Object resOrEx
) {
69 getResult(regionName
).addResult(originalIndex
, resOrEx
);
72 public void addException(byte []regionName
, Throwable ie
){
73 exceptions
.put(regionName
, ie
);
77 * @return the exception for the region, if any. Null otherwise.
79 public Throwable
getException(byte []regionName
){
80 return exceptions
.get(regionName
);
83 public Map
<byte[], Throwable
> getExceptions() {
87 public void addStatistic(byte[] regionName
, ClientProtos
.RegionLoadStats stat
) {
88 getResult(regionName
).setStat(stat
);
91 private RegionResult
getResult(byte[] region
){
92 RegionResult rs
= results
.get(region
);
94 rs
= new RegionResult();
95 results
.put(region
, rs
);
100 public Map
<byte[], RegionResult
> getResults(){
105 public ResponseType
type() {
106 return ResponseType
.MULTI
;
109 static class RegionResult
{
110 Map
<Integer
, Object
> result
= new HashMap
<>();
111 ClientProtos
.RegionLoadStats stat
;
113 public void addResult(int index
, Object result
){
114 this.result
.put(index
, result
);
117 public void setStat(ClientProtos
.RegionLoadStats stat
){
122 return this.result
.size();
125 public ClientProtos
.RegionLoadStats
getStat() {