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