1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.ipc;
20
21 import com.google.protobuf.BlockingRpcChannel;
22 import com.google.protobuf.Descriptors;
23 import com.google.protobuf.Message;
24 import com.google.protobuf.RpcCallback;
25 import com.google.protobuf.RpcChannel;
26 import com.google.protobuf.RpcController;
27 import com.google.protobuf.Service;
28 import com.google.protobuf.ServiceException;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.hadoop.classification.InterfaceAudience;
32 import org.apache.hadoop.hbase.protobuf.ResponseConverter;
33
34 import java.io.IOException;
35
36
37
38
39
40 @InterfaceAudience.Private
41 public abstract class CoprocessorRpcChannel implements RpcChannel, BlockingRpcChannel {
42 private static Log LOG = LogFactory.getLog(CoprocessorRpcChannel.class);
43
44 @Override
45 public void callMethod(Descriptors.MethodDescriptor method,
46 RpcController controller,
47 Message request, Message responsePrototype,
48 RpcCallback<Message> callback) {
49 Message response = null;
50 try {
51 response = callExecService(method, request, responsePrototype);
52 } catch (IOException ioe) {
53 LOG.warn("Call failed on IOException", ioe);
54 ResponseConverter.setControllerException(controller, ioe);
55 }
56 if (callback != null) {
57 callback.run(response);
58 }
59 }
60
61 @Override
62 public Message callBlockingMethod(Descriptors.MethodDescriptor method,
63 RpcController controller,
64 Message request, Message responsePrototype)
65 throws ServiceException {
66 try {
67 return callExecService(method, request, responsePrototype);
68 } catch (IOException ioe) {
69 throw new ServiceException("Error calling method "+method.getFullName(), ioe);
70 }
71 }
72
73 protected abstract Message callExecService(Descriptors.MethodDescriptor method,
74 Message request, Message responsePrototype) throws IOException;
75 }