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.lang.reflect.InvocationHandler;
22 import java.lang.reflect.Method;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.classification.InterfaceAudience;
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.hbase.client.HConnection;
29 import org.apache.hadoop.hbase.client.ServerCallable;
30 import org.apache.hadoop.hbase.client.coprocessor.Exec;
31 import org.apache.hadoop.hbase.client.coprocessor.ExecResult;
32 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
33 import org.apache.hadoop.hbase.util.Bytes;
34
35
36
37
38
39
40
41 @InterfaceAudience.Private
42 @Deprecated
43 public class ExecRPCInvoker implements InvocationHandler {
44
45
46 private static final Log LOG = LogFactory.getLog("org.apache.hadoop.ipc.ExecRPCInvoker");
47
48 private Configuration conf;
49 private final HConnection connection;
50 private Class<? extends CoprocessorProtocol> protocol;
51 private final byte[] table;
52 private final byte[] row;
53 private byte[] regionName;
54
55 public ExecRPCInvoker(Configuration conf,
56 HConnection connection,
57 Class<? extends CoprocessorProtocol> protocol,
58 byte[] table,
59 byte[] row) {
60 this.conf = conf;
61 this.connection = connection;
62 this.protocol = protocol;
63 this.table = table;
64 this.row = row;
65 }
66
67 @Override
68 public Object invoke(Object instance, final Method method, final Object[] args)
69 throws Throwable {
70 if (LOG.isDebugEnabled()) {
71 LOG.debug("Call: "+method.getName()+", "+(args != null ? args.length : 0));
72 }
73
74 if (row != null) {
75 final Exec exec = new Exec(conf, row, protocol, method, args);
76 ServerCallable<ExecResult> callable =
77 new ServerCallable<ExecResult>(connection, table, row) {
78 public ExecResult call() throws Exception {
79 byte[] regionName = location.getRegionInfo().getRegionName();
80 return ProtobufUtil.execCoprocessor(server, exec, regionName);
81 }
82 };
83 ExecResult result = callable.withRetries();
84 this.regionName = result.getRegionName();
85 LOG.debug("Result is region="+ Bytes.toStringBinary(regionName) +
86 ", value="+result.getValue());
87 return result.getValue();
88 } else if (LOG.isDebugEnabled()) {
89 LOG.debug("Null row passed for call");
90 }
91
92 return null;
93 }
94
95 public byte[] getRegionName() {
96 return regionName;
97 }
98 }