View Javadoc

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.CellScannable;
23  import org.apache.hadoop.hbase.CellScanner;
24  import org.apache.hadoop.hbase.CellUtil;
25  import org.apache.hadoop.hbase.HConstants;
26  import org.apache.hadoop.hbase.TableName;
27  import org.apache.hadoop.hbase.classification.InterfaceAudience;
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     * Priority to set on this request.  Set it here in controller so available composing the
40     * request.  This is the ordained way of setting priorities going forward.  We will be
41     * undoing the old annotation-based mechanism.
42     */
43    // Currently only multi call makes use of this.  Eventually this should be only way to set
44    // priority.
45    private int priority = 0;
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    public CellScanner cellScanner() {
71      return cellScanner;
72    }
73  
74    public void setCellScanner(final CellScanner cellScanner) {
75      this.cellScanner = cellScanner;
76    }
77  
78    /**
79     * @param priority Priority for this request; should fall roughly in the range
80     * {@link HConstants#NORMAL_QOS} to {@link HConstants#HIGH_QOS}
81     */
82    public void setPriority(int priority) {
83      this.priority = priority;
84    }
85  
86    /**
87     * @param tn Set priority based off the table we are going against.
88     */
89    public void setPriority(final TableName tn) {
90      this.priority = tn != null && tn.isSystemTable()? HConstants.HIGH_QOS: HConstants.NORMAL_QOS;
91    }
92  
93    /**
94     * @return The priority of this request
95     */
96    public int getPriority() {
97      return priority;
98    }
99  
100   @Override public void reset() {
101     super.reset();
102     priority = 0;
103     cellScanner = null;
104   }
105 }