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 /** 30 * Optionally carries Cells across the proxy/service interface down into ipc. On its 31 * way out it optionally carries a set of result Cell data. We stick the Cells here when we want 32 * to avoid having to protobuf them. This class is used ferrying data across the proxy/protobuf 33 * service chasm. Used by client and server ipc'ing. 34 */ 35 @InterfaceAudience.Private 36 public class PayloadCarryingRpcController 37 extends TimeLimitedRpcController implements CellScannable { 38 39 public static final int PRIORITY_UNSET = -1; 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 private int priority = PRIORITY_UNSET; 46 47 /** 48 * They are optionally set on construction, cleared after we make the call, and then optionally 49 * set on response with the result. We use this lowest common denominator access to Cells because 50 * sometimes the scanner is backed by a List of Cells and other times, it is backed by an 51 * encoded block that implements CellScanner. 52 */ 53 private CellScanner cellScanner; 54 55 public PayloadCarryingRpcController() { 56 this((CellScanner)null); 57 } 58 59 public PayloadCarryingRpcController(final CellScanner cellScanner) { 60 this.cellScanner = cellScanner; 61 } 62 63 public PayloadCarryingRpcController(final List<CellScannable> cellIterables) { 64 this.cellScanner = cellIterables == null? null: CellUtil.createCellScanner(cellIterables); 65 } 66 67 /** 68 * @return One-shot cell scanner (you cannot back it up and restart) 69 */ 70 @Override 71 public CellScanner cellScanner() { 72 return cellScanner; 73 } 74 75 public void setCellScanner(final CellScanner cellScanner) { 76 this.cellScanner = cellScanner; 77 } 78 79 /** 80 * @param priority Priority for this request; should fall roughly in the range 81 * {@link HConstants#NORMAL_QOS} to {@link HConstants#HIGH_QOS} 82 */ 83 public void setPriority(int priority) { 84 this.priority = priority; 85 } 86 87 /** 88 * @param tn Set priority based off the table we are going against. 89 */ 90 public void setPriority(final TableName tn) { 91 this.priority = 92 (tn != null && tn.isSystemTable())? HConstants.SYSTEMTABLE_QOS: HConstants.NORMAL_QOS; 93 } 94 95 /** 96 * @return The priority of this request 97 */ 98 public int getPriority() { 99 return priority; 100 } 101 102 @Override public void reset() { 103 super.reset(); 104 priority = 0; 105 cellScanner = null; 106 } 107 }