View Javadoc

1   /*
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.apache.hadoop.hbase.coprocessor;
17  
18  import java.io.IOException;
19  
20  import org.apache.hadoop.classification.InterfaceAudience;
21  import org.apache.hadoop.classification.InterfaceStability;
22  import org.apache.hadoop.hbase.Coprocessor;
23  import org.apache.hadoop.hbase.CoprocessorEnvironment;
24  import org.apache.hadoop.hbase.ipc.CoprocessorProtocol;
25  import org.apache.hadoop.hbase.ipc.ProtocolSignature;
26  import org.apache.hadoop.hbase.ipc.VersionedProtocol;
27  
28  /**
29   * This abstract class provides default implementation of an Endpoint.
30   * It also maintains a CoprocessorEnvironment object which can be
31   * used to access region resource.
32   *
33   * It's recommended to use this abstract class to implement your Endpoint.
34   * However you still can just implement the interface CoprocessorProtocol
35   * and Coprocessor to develop an Endpoint. But you won't be able to access
36   * the region related resource, i.e., CoprocessorEnvironment.
37   */
38  @InterfaceAudience.Public
39  @InterfaceStability.Evolving
40  public abstract class BaseEndpointCoprocessor implements Coprocessor,
41      CoprocessorProtocol, VersionedProtocol {
42    /**
43     * This Interfaces' version. Version changes when the Interface changes.
44     */
45    // All HBase Interfaces used derive from HBaseRPCProtocolVersion.  It
46    // maintained a single global version number on all HBase Interfaces.  This
47    // meant all HBase RPC was broke though only one of the three RPC Interfaces
48    // had changed.  This has since been undone.
49    public static final long VERSION = 28L;
50  
51    private CoprocessorEnvironment env;
52  
53    /**
54     * @return env Coprocessor environment.
55     */
56    public CoprocessorEnvironment getEnvironment() {
57      return env;
58    }
59  
60    @Override
61    public void start(CoprocessorEnvironment env) {
62      this.env = env;
63    }
64  
65    @Override
66    public void stop(CoprocessorEnvironment env) { }
67  
68    @Override
69    public ProtocolSignature getProtocolSignature(
70        String protocol, long version, int clientMethodsHashCode)
71    throws IOException {
72      return new ProtocolSignature(VERSION, null);
73    }
74  
75    @Override
76    public long getProtocolVersion(String protocol, long clientVersion)
77    throws IOException {
78      return VERSION;
79    }
80  }