1
2
3
4
5
6
7
8
9
10
11
12 package org.apache.hadoop.hbase.ipc;
13
14 import java.io.IOException;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.apache.hadoop.hbase.classification.InterfaceAudience;
19 import org.apache.hadoop.hbase.HConstants;
20 import org.apache.hadoop.hbase.ServerName;
21 import org.apache.hadoop.hbase.client.ClusterConnection;
22 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
23 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
24 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CoprocessorServiceResponse;
25
26
27 import com.google.protobuf.Descriptors;
28 import com.google.protobuf.Message;
29 import com.google.protobuf.RpcController;
30
31
32
33
34
35
36
37
38
39 @InterfaceAudience.Private
40 public class RegionServerCoprocessorRpcChannel extends CoprocessorRpcChannel {
41 private static Log LOG = LogFactory.getLog(RegionServerCoprocessorRpcChannel.class);
42 private final ClusterConnection connection;
43 private final ServerName serverName;
44
45 public RegionServerCoprocessorRpcChannel(ClusterConnection conn, ServerName serverName) {
46 this.connection = conn;
47 this.serverName = serverName;
48 }
49
50 @Override
51 protected Message callExecService(RpcController controller,
52 Descriptors.MethodDescriptor method, Message request, Message responsePrototype)
53 throws IOException {
54 if (LOG.isTraceEnabled()) {
55 LOG.trace("Call: " + method.getName() + ", " + request.toString());
56 }
57 final ClientProtos.CoprocessorServiceCall call =
58 CoprocessorRpcUtils.buildServiceCall(HConstants.EMPTY_BYTE_ARRAY, method, request);
59
60
61 CoprocessorServiceResponse result =
62 ProtobufUtil.execRegionServerService(controller, connection.getClient(serverName), call);
63 Message response = null;
64 if (result.getValue().hasValue()) {
65 Message.Builder builder = responsePrototype.newBuilderForType();
66 ProtobufUtil.mergeFrom(builder, result.getValue().getValue());
67 response = builder.build();
68 } else {
69 response = responsePrototype.getDefaultInstanceForType();
70 }
71 if (LOG.isTraceEnabled()) {
72 LOG.trace("Result is value=" + response);
73 }
74 return response;
75 }
76 }