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 java.util.List;
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.CellScannable;
26 import org.apache.hadoop.hbase.CellScanner;
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28 import org.apache.hadoop.hbase.util.ReflectionUtils;
29
30
31
32
33 @InterfaceAudience.Private
34 public class RpcControllerFactory {
35 private static final Log LOG = LogFactory.getLog(RpcControllerFactory.class);
36
37
38
39
40
41
42 public static final String CUSTOM_CONTROLLER_CONF_KEY = "hbase.rpc.controllerfactory.class";
43 protected final Configuration conf;
44
45 public RpcControllerFactory(Configuration conf) {
46 this.conf = conf;
47 }
48
49 public PayloadCarryingRpcController newController() {
50 return new PayloadCarryingRpcController();
51 }
52
53 public PayloadCarryingRpcController newController(final CellScanner cellScanner) {
54 return new PayloadCarryingRpcController(cellScanner);
55 }
56
57 public PayloadCarryingRpcController newController(final List<CellScannable> cellIterables) {
58 return new PayloadCarryingRpcController(cellIterables);
59 }
60
61
62 public static RpcControllerFactory instantiate(Configuration configuration) {
63 String rpcControllerFactoryClazz =
64 configuration.get(CUSTOM_CONTROLLER_CONF_KEY,
65 RpcControllerFactory.class.getName());
66 try {
67 return ReflectionUtils.instantiateWithCustomCtor(rpcControllerFactoryClazz,
68 new Class[] { Configuration.class }, new Object[] { configuration });
69 } catch (UnsupportedOperationException | NoClassDefFoundError ex) {
70
71
72 String msg = "Cannot load configured \"" + CUSTOM_CONTROLLER_CONF_KEY + "\" ("
73 + rpcControllerFactoryClazz + ") from hbase-site.xml, falling back to use "
74 + "default RpcControllerFactory";
75 if (LOG.isDebugEnabled()) {
76 LOG.warn(msg, ex);
77 } else {
78 LOG.warn(msg);
79 }
80 return new RpcControllerFactory(configuration);
81 }
82 }
83 }