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 com.google.common.collect.ImmutableMap;
21
22 import java.net.SocketAddress;
23
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.hbase.client.MetricsConnection;
27 import org.apache.hadoop.hbase.util.ReflectionUtils;
28
29
30
31
32 @InterfaceAudience.Private
33 public final class RpcClientFactory {
34
35 public static final String CUSTOM_RPC_CLIENT_IMPL_CONF_KEY = "hbase.rpc.client.impl";
36
37 private static final ImmutableMap<String, String> DEPRECATED_NAME_MAPPING = ImmutableMap.of(
38 "org.apache.hadoop.hbase.ipc.RpcClientImpl", BlockingRpcClient.class.getName(),
39 "org.apache.hadoop.hbase.ipc.AsyncRpcClient", NettyRpcClient.class.getName());
40
41
42
43
44 private RpcClientFactory() {
45 }
46
47
48 public static RpcClient createClient(Configuration conf, String clusterId) {
49 return createClient(conf, clusterId, null);
50 }
51
52
53
54
55
56
57
58
59
60 public static RpcClient createClient(Configuration conf, String clusterId,
61 MetricsConnection metrics) {
62 return createClient(conf, clusterId, null, metrics);
63 }
64
65 private static String getRpcClientClass(Configuration conf) {
66 String rpcClientClass = conf.get(CUSTOM_RPC_CLIENT_IMPL_CONF_KEY);
67 if (rpcClientClass == null) {
68 return BlockingRpcClient.class.getName();
69 }
70 String mappedName = DEPRECATED_NAME_MAPPING.get(rpcClientClass);
71 return mappedName == null ? rpcClientClass : mappedName;
72 }
73
74
75
76
77
78
79
80
81
82
83 public static RpcClient createClient(Configuration conf, String clusterId,
84 SocketAddress localAddr, MetricsConnection metrics) {
85 String rpcClientClass = getRpcClientClass(conf);
86 return ReflectionUtils.instantiateWithCustomCtor(rpcClientClass, new Class[] {
87 Configuration.class, String.class, SocketAddress.class, MetricsConnection.class },
88 new Object[] { conf, clusterId, localAddr, metrics });
89 }
90 }