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