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