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 com.google.protobuf.RpcCallback;
21  import com.google.protobuf.RpcController;
22  
23  import java.io.IOException;
24  
25  import org.apache.hadoop.hbase.CellScannable;
26  import org.apache.hadoop.hbase.CellScanner;
27  import org.apache.hadoop.hbase.HConstants;
28  import org.apache.hadoop.hbase.TableName;
29  import org.apache.hadoop.hbase.classification.InterfaceAudience;
30  
31  /**
32   * Optionally carries Cells across the proxy/service interface down into ipc. On its way out it
33   * optionally carries a set of result Cell data. We stick the Cells here when we want to avoid
34   * having to protobuf them (for performance reasons). This class is used ferrying data across the
35   * proxy/protobuf service chasm. Also does call timeout. Used by client and server ipc'ing.
36   */
37  @InterfaceAudience.Private
38  public interface HBaseRpcController extends RpcController, CellScannable {
39  
40    /**
41     * Only used to send cells to rpc server, the returned cells should be set by
42     * {@link #setDone(CellScanner)}.
43     */
44    void setCellScanner(CellScanner cellScanner);
45  
46    /**
47     * @param priority Priority for this request; should fall roughly in the range
48     *          {@link HConstants#NORMAL_QOS} to {@link HConstants#HIGH_QOS}
49     */
50    void setPriority(int priority);
51  
52    /**
53     * @param tn Set priority based off the table we are going against.
54     */
55    void setPriority(final TableName tn);
56  
57    /**
58     * @return The priority of this request
59     */
60    int getPriority();
61  
62    int getCallTimeout();
63  
64    void setCallTimeout(int callTimeout);
65  
66    boolean hasCallTimeout();
67  
68    /**
69     * Set failed with an exception to pass on. For use in async rpc clients
70     * @param e exception to set with
71     */
72    void setFailed(IOException e);
73  
74    /**
75     * Return the failed exception, null if not failed.
76     */
77    IOException getFailed();
78  
79    /**
80     * <b>IMPORTANT:</b> always call this method if the call finished without any exception to tell
81     * the {@code HBaseRpcController} that we are done.
82     */
83    void setDone(CellScanner cellScanner);
84  
85    /**
86     * A little different from the basic RpcController:
87     * <ol>
88     * <li>You can register multiple callbacks to an {@code HBaseRpcController}.</li>
89     * <li>The callback will not be called if the rpc call is finished without any cancellation.</li>
90     * <li>You can call me at client side also.</li>
91     * </ol>
92     */
93    @Override
94    void notifyOnCancel(RpcCallback<Object> callback);
95  
96    interface CancellationCallback {
97      void run(boolean cancelled) throws IOException;
98    }
99  
100   /**
101    * If not cancelled, add the callback to cancellation callback list. And then execute the action
102    * with the cancellation state as a parameter. The implementation should guarantee that the
103    * cancellation state does not change during this call.
104    */
105   void notifyOnCancel(RpcCallback<Object> callback, CancellationCallback action) throws IOException;
106 }