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.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.CellScannable;
24  import org.apache.hadoop.hbase.CellScanner;
25  import org.apache.hadoop.hbase.CellUtil;
26  
27  
28  import com.google.protobuf.RpcCallback;
29  import com.google.protobuf.RpcController;
30  
31  /**
32   * Optionally carries Cells across the proxy/service interface down into ipc. On its
33   * way out it optionally carries a set of result Cell data.  We stick the Cells here when we want
34   * to avoid having to protobuf them.  This class is used ferrying data across the proxy/protobuf
35   * service chasm.  Used by client and server ipc'ing.
36   */
37  @InterfaceAudience.Private
38  public class PayloadCarryingRpcController implements RpcController, CellScannable {
39    // TODO: Fill out the rest of this class methods rather than return UnsupportedOperationException
40  
41    /**
42     * They are optionally set on construction, cleared after we make the call, and then optionally
43     * set on response with the result. We use this lowest common denominator access to Cells because
44     * sometimes the scanner is backed by a List of Cells and other times, it is backed by an
45     * encoded block that implements CellScanner.
46     */
47    private CellScanner cellScanner;
48  
49    public PayloadCarryingRpcController() {
50      this((CellScanner)null);
51    }
52  
53    public PayloadCarryingRpcController(final CellScanner cellScanner) {
54      this.cellScanner = cellScanner;
55    }
56  
57    public PayloadCarryingRpcController(final List<CellScannable> cellIterables) {
58      this.cellScanner = CellUtil.createCellScanner(cellIterables);
59    }
60  
61    /**
62     * @return One-shot cell scanner (you cannot back it up and restart)
63     */
64    public CellScanner cellScanner() {
65      return cellScanner;
66    }
67  
68    public void setCellScanner(final CellScanner cellScanner) {
69      this.cellScanner = cellScanner;
70    }
71  
72    @Override
73    public String errorText() {
74      throw new UnsupportedOperationException();
75    }
76  
77    @Override
78    public boolean failed() {
79      throw new UnsupportedOperationException();
80    }
81  
82    @Override
83    public boolean isCanceled() {
84      throw new UnsupportedOperationException();
85    }
86  
87    @Override
88    public void notifyOnCancel(RpcCallback<Object> arg0) {
89      throw new UnsupportedOperationException();
90    }
91  
92    @Override
93    public void reset() {
94      throw new UnsupportedOperationException();
95    }
96  
97    @Override
98    public void setFailed(String arg0) {
99      throw new UnsupportedOperationException();
100   }
101 
102   @Override
103   public void startCancel() {
104     throw new UnsupportedOperationException();
105   }
106 }