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