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 import org.apache.hadoop.hbase.util.ByteStringer;
26
27
28 import com.google.protobuf.Descriptors;
29 import com.google.protobuf.Message;
30 import com.google.protobuf.RpcController;
31
32
33
34
35
36
37
38
39
40 @InterfaceAudience.Private
41 public class RegionServerCoprocessorRpcChannel extends CoprocessorRpcChannel {
42 private static final Log LOG = LogFactory.getLog(RegionServerCoprocessorRpcChannel.class);
43 private final ClusterConnection connection;
44 private final ServerName serverName;
45
46 public RegionServerCoprocessorRpcChannel(ClusterConnection conn, ServerName serverName) {
47 this.connection = conn;
48 this.serverName = serverName;
49 }
50
51 @Override
52 protected Message callExecService(RpcController controller,
53 Descriptors.MethodDescriptor method, Message request, Message responsePrototype)
54 throws IOException {
55 if (LOG.isTraceEnabled()) {
56 LOG.trace("Call: " + method.getName() + ", " + request.toString());
57 }
58 final ClientProtos.CoprocessorServiceCall call =
59 ClientProtos.CoprocessorServiceCall.newBuilder()
60 .setRow(ByteStringer.wrap(HConstants.EMPTY_BYTE_ARRAY))
61 .setServiceName(method.getService().getFullName()).setMethodName(method.getName())
62 .setRequest(request.toByteString()).build();
63
64
65 CoprocessorServiceResponse result =
66 ProtobufUtil.execRegionServerService(controller, connection.getClient(serverName), call);
67 Message response = null;
68 if (result.getValue().hasValue()) {
69 Message.Builder builder = responsePrototype.newBuilderForType();
70 ProtobufUtil.mergeFrom(builder, result.getValue().getValue());
71 response = builder.build();
72 } else {
73 response = responsePrototype.getDefaultInstanceForType();
74 }
75 if (LOG.isTraceEnabled()) {
76 LOG.trace("Result is value=" + response);
77 }
78 return response;
79 }
80 }