1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.ipc;
19
20 import java.util.List;
21
22 import org.apache.hadoop.hbase.classification.InterfaceAudience;
23 import org.apache.hadoop.hbase.CellScannable;
24 import org.apache.hadoop.hbase.CellScanner;
25 import org.apache.hadoop.hbase.CellUtil;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.TableName;
28
29 import com.google.protobuf.RpcCallback;
30 import com.google.protobuf.RpcController;
31
32 /**
33 * Optionally carries Cells across the proxy/service interface down into ipc. On its
34 * way out it optionally carries a set of result Cell data. We stick the Cells here when we want
35 * to avoid having to protobuf them. This class is used ferrying data across the proxy/protobuf
36 * service chasm. Used by client and server ipc'ing.
37 */
38 @InterfaceAudience.Private
39 public class PayloadCarryingRpcController implements RpcController, CellScannable {
40 /**
41 * Priority to set on this request. Set it here in controller so available composing the
42 * request. This is the ordained way of setting priorities going forward. We will be
43 * undoing the old annotation-based mechanism.
44 */
45 // Currently only multi call makes use of this. Eventually this should be only way to set
46 // priority.
47 private int priority = 0;
48
49 // TODO: Fill out the rest of this class methods rather than return UnsupportedOperationException
50
51 /**
52 * They are optionally set on construction, cleared after we make the call, and then optionally
53 * set on response with the result. We use this lowest common denominator access to Cells because
54 * sometimes the scanner is backed by a List of Cells and other times, it is backed by an
55 * encoded block that implements CellScanner.
56 */
57 private CellScanner cellScanner;
58
59 public PayloadCarryingRpcController() {
60 this((CellScanner)null);
61 }
62
63 public PayloadCarryingRpcController(final CellScanner cellScanner) {
64 this.cellScanner = cellScanner;
65 }
66
67 public PayloadCarryingRpcController(final List<CellScannable> cellIterables) {
68 this.cellScanner = cellIterables == null? null: CellUtil.createCellScanner(cellIterables);
69 }
70
71 /**
72 * @return One-shot cell scanner (you cannot back it up and restart)
73 */
74 public CellScanner cellScanner() {
75 return cellScanner;
76 }
77
78 public void setCellScanner(final CellScanner cellScanner) {
79 this.cellScanner = cellScanner;
80 }
81
82 @Override
83 public String errorText() {
84 throw new UnsupportedOperationException();
85 }
86
87 @Override
88 public boolean failed() {
89 throw new UnsupportedOperationException();
90 }
91
92 @Override
93 public boolean isCanceled() {
94 throw new UnsupportedOperationException();
95 }
96
97 @Override
98 public void notifyOnCancel(RpcCallback<Object> arg0) {
99 throw new UnsupportedOperationException();
100 }
101
102 @Override
103 public void reset() {
104 throw new UnsupportedOperationException();
105 }
106
107 @Override
108 public void setFailed(String arg0) {
109 throw new UnsupportedOperationException();
110 }
111
112 @Override
113 public void startCancel() {
114 throw new UnsupportedOperationException();
115 }
116
117 /**
118 * @param priority Priority for this request; should fall roughly in the range
119 * {@link HConstants#NORMAL_QOS} to {@link HConstants#HIGH_QOS}
120 */
121 public void setPriority(int priority) {
122 this.priority = priority;
123 }
124
125 /**
126 * @param tn Set priority based off the table we are going against.
127 */
128 public void setPriority(final TableName tn) {
129 this.priority = tn != null && tn.isSystemTable()? HConstants.HIGH_QOS: HConstants.NORMAL_QOS;
130 }
131
132 /**
133 * @return The priority of this request
134 */
135 public int getPriority() {
136 return priority;
137 }
138 }