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 org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.hbase.classification.InterfaceStability;
23 import org.apache.hadoop.hbase.protobuf.ResponseConverter;
24
25 import com.google.protobuf.BlockingRpcChannel;
26 import com.google.protobuf.Descriptors;
27 import com.google.protobuf.Message;
28 import com.google.protobuf.RpcCallback;
29 import com.google.protobuf.RpcChannel;
30 import com.google.protobuf.RpcController;
31 import com.google.protobuf.ServiceException;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35 import java.io.IOException;
36
37
38
39
40
41
42
43 @InterfaceAudience.Public
44 @InterfaceStability.Evolving
45 public abstract class CoprocessorRpcChannel implements RpcChannel, BlockingRpcChannel {
46 private static final Log LOG = LogFactory.getLog(CoprocessorRpcChannel.class);
47
48 @Override
49 @InterfaceAudience.Private
50 public void callMethod(Descriptors.MethodDescriptor method,
51 RpcController controller,
52 Message request, Message responsePrototype,
53 RpcCallback<Message> callback) {
54 Message response = null;
55 try {
56 response = callExecService(controller, method, request, responsePrototype);
57 } catch (IOException ioe) {
58 LOG.warn("Call failed on IOException", ioe);
59 ResponseConverter.setControllerException(controller, ioe);
60 }
61 if (callback != null) {
62 callback.run(response);
63 }
64 }
65
66 @Override
67 @InterfaceAudience.Private
68 public Message callBlockingMethod(Descriptors.MethodDescriptor method,
69 RpcController controller,
70 Message request, Message responsePrototype)
71 throws ServiceException {
72 try {
73 return callExecService(controller, method, request, responsePrototype);
74 } catch (IOException ioe) {
75 throw new ServiceException("Error calling method "+method.getFullName(), ioe);
76 }
77 }
78
79 protected abstract Message callExecService(RpcController controller,
80 Descriptors.MethodDescriptor method, Message request, Message responsePrototype)
81 throws IOException;
82 }