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 19 package org.apache.hadoop.hbase.coprocessor; 20 21 import com.google.protobuf.RpcCallback; 22 import com.google.protobuf.RpcController; 23 import com.google.protobuf.Service; 24 import org.apache.hadoop.hbase.Coprocessor; 25 import org.apache.hadoop.hbase.CoprocessorEnvironment; 26 import org.apache.hadoop.hbase.ipc.protobuf.generated.TestProtos; 27 import org.apache.hadoop.hbase.ipc.protobuf.generated.TestRpcServiceProtos; 28 import org.apache.hadoop.hbase.protobuf.ResponseConverter; 29 30 import java.io.IOException; 31 32 /** 33 * Test implementation of a coprocessor endpoint exposing the 34 * {@link TestRpcServiceProtos.TestProtobufRpcProto} service methods. For internal use by 35 * unit tests only. 36 */ 37 public class ProtobufCoprocessorService 38 extends TestRpcServiceProtos.TestProtobufRpcProto 39 implements CoprocessorService, Coprocessor { ProtobufCoprocessorService()40 public ProtobufCoprocessorService() { 41 } 42 43 @Override getService()44 public Service getService() { 45 return this; 46 } 47 48 @Override ping(RpcController controller, TestProtos.EmptyRequestProto request, RpcCallback<TestProtos.EmptyResponseProto> done)49 public void ping(RpcController controller, TestProtos.EmptyRequestProto request, 50 RpcCallback<TestProtos.EmptyResponseProto> done) { 51 done.run(TestProtos.EmptyResponseProto.getDefaultInstance()); 52 } 53 54 @Override echo(RpcController controller, TestProtos.EchoRequestProto request, RpcCallback<TestProtos.EchoResponseProto> done)55 public void echo(RpcController controller, TestProtos.EchoRequestProto request, 56 RpcCallback<TestProtos.EchoResponseProto> done) { 57 String message = request.getMessage(); 58 done.run(TestProtos.EchoResponseProto.newBuilder().setMessage(message).build()); 59 } 60 61 @Override error(RpcController controller, TestProtos.EmptyRequestProto request, RpcCallback<TestProtos.EmptyResponseProto> done)62 public void error(RpcController controller, TestProtos.EmptyRequestProto request, 63 RpcCallback<TestProtos.EmptyResponseProto> done) { 64 ResponseConverter.setControllerException(controller, new IOException("Test exception")); 65 done.run(null); 66 } 67 68 @Override start(CoprocessorEnvironment env)69 public void start(CoprocessorEnvironment env) throws IOException { 70 //To change body of implemented methods use File | Settings | File Templates. 71 } 72 73 @Override stop(CoprocessorEnvironment env)74 public void stop(CoprocessorEnvironment env) throws IOException { 75 //To change body of implemented methods use File | Settings | File Templates. 76 } 77 } 78