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 java.io.IOException;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.hadoop.classification.InterfaceAudience;
29 import org.apache.hadoop.conf.Configuration;
30 import org.apache.hadoop.hbase.IpcProtocol;
31 import org.apache.hadoop.util.ReflectionUtils;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 @InterfaceAudience.Private
51 public class HBaseServerRPC {
52
53
54
55 protected static final Log LOG =
56 LogFactory.getLog("org.apache.hadoop.ipc.HBaseServerRPC");
57
58
59 private static final Map<Class<? extends IpcProtocol>, RpcServerEngine> PROTOCOL_ENGINES =
60 new HashMap<Class<? extends IpcProtocol>, RpcServerEngine>();
61
62
63
64
65
66
67 public static final String RPC_ENGINE_PROP = "hbase.rpc.server.engine";
68
69 private HBaseServerRPC() {
70 super();
71 }
72
73
74 static void setProtocolEngine(Configuration conf,
75 Class<? extends IpcProtocol> protocol, Class<? extends RpcServerEngine> engine) {
76 conf.setClass(RPC_ENGINE_PROP + "." + protocol.getName(), engine, RpcServerEngine.class);
77 }
78
79
80 static synchronized RpcServerEngine getProtocolEngine(Class<? extends IpcProtocol> protocol,
81 Configuration conf) {
82 RpcServerEngine engine = PROTOCOL_ENGINES.get(protocol);
83 if (engine == null) {
84
85 Class<?> defaultEngine =
86 conf.getClass(RPC_ENGINE_PROP, ProtobufRpcServerEngine.class);
87
88
89 Class<?> impl = conf.getClass(RPC_ENGINE_PROP + "." + protocol.getName(),
90 defaultEngine);
91 LOG.debug("Using " + impl.getName() + " for " + protocol.getName());
92 engine = (RpcServerEngine) ReflectionUtils.newInstance(impl, conf);
93 PROTOCOL_ENGINES.put(protocol, engine);
94 }
95 return engine;
96 }
97
98
99
100
101 public static RpcServer getServer(Class<? extends IpcProtocol> protocol,
102 final Object instance,
103 final Class<?>[] ifaces,
104 String bindAddress,
105 int port,
106 final int numHandlers,
107 int metaHandlerCount,
108 final boolean verbose,
109 Configuration conf,
110 int highPriorityLevel)
111 throws IOException {
112 return getProtocolEngine(protocol, conf).
113 getServer(instance,
114 ifaces,
115 bindAddress,
116 port,
117 numHandlers,
118 metaHandlerCount,
119 verbose,
120 conf,
121 highPriorityLevel);
122 }
123 }