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