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