1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.ipc;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.hbase.client.HConnection;
24 import org.apache.hadoop.hbase.client.ServerCallable;
25 import org.apache.hadoop.hbase.client.coprocessor.Exec;
26 import org.apache.hadoop.hbase.client.coprocessor.ExecResult;
27 import org.apache.hadoop.hbase.util.Bytes;
28
29 import java.lang.reflect.InvocationHandler;
30 import java.lang.reflect.Method;
31
32
33
34
35
36
37 public class MasterExecRPCInvoker implements InvocationHandler {
38
39
40 private static final Log LOG = LogFactory.getLog("org.apache.hadoop.ipc.MasterExecRPCInvoker");
41
42 private Configuration conf;
43 private final HConnection connection;
44 private Class<? extends CoprocessorProtocol> protocol;
45
46 public MasterExecRPCInvoker(Configuration conf,
47 HConnection connection,
48 Class<? extends CoprocessorProtocol> protocol) {
49 this.conf = conf;
50 this.connection = connection;
51 this.protocol = protocol;
52 }
53
54 @Override
55 public Object invoke(Object instance, final Method method, final Object[] args)
56 throws Throwable {
57 if (LOG.isDebugEnabled()) {
58 LOG.debug("Call: "+method.getName()+", "+(args != null ? args.length : 0));
59 }
60 Exec exec = new Exec(conf, protocol, method, args);
61 ExecResult result = connection.getMaster().execCoprocessor(exec);
62 LOG.debug("Master Result is value="+result.getValue());
63 return result.getValue();
64 }
65 }