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.base.Preconditions;
21
22 import io.netty.channel.Channel;
23 import io.netty.channel.EventLoopGroup;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.apache.commons.lang.StringUtils;
29 import org.apache.hadoop.conf.Configuration;
30 import org.apache.hadoop.hbase.classification.InterfaceAudience;
31 import org.apache.hadoop.hbase.classification.InterfaceStability;
32 import org.apache.hadoop.hbase.util.Pair;
33
34
35
36
37
38
39
40
41 @InterfaceAudience.Public
42 @InterfaceStability.Evolving
43 public class NettyRpcClientConfigHelper {
44
45 public static final String EVENT_LOOP_CONFIG = "hbase.rpc.client.event-loop.config";
46
47 private static final String CONFIG_NAME = "global-event-loop";
48
49 private static final Map<String, Pair<EventLoopGroup, Class<? extends Channel>>>
50 EVENT_LOOP_CONFIG_MAP = new HashMap<>();
51
52
53
54
55 public static void setEventLoopConfig(Configuration conf, EventLoopGroup group,
56 Class<? extends Channel> channelClass) {
57 Preconditions.checkNotNull(group, "group is null");
58 Preconditions.checkNotNull(channelClass, "channel class is null");
59 conf.set(EVENT_LOOP_CONFIG, CONFIG_NAME);
60 EVENT_LOOP_CONFIG_MAP.put(CONFIG_NAME,
61 Pair.<EventLoopGroup, Class<? extends Channel>> newPair(group, channelClass));
62 }
63
64
65
66
67 public static void createEventLoopPerClient(Configuration conf) {
68 conf.set(EVENT_LOOP_CONFIG, "");
69 EVENT_LOOP_CONFIG_MAP.clear();
70 }
71
72 static Pair<EventLoopGroup, Class<? extends Channel>> getEventLoopConfig(Configuration conf) {
73 String name = conf.get(EVENT_LOOP_CONFIG);
74 if (name == null) {
75 return DefaultNettyEventLoopConfig.GROUP_AND_CHANNEL_CLASS;
76 }
77 if (StringUtils.isBlank(name)) {
78 return null;
79 }
80 return EVENT_LOOP_CONFIG_MAP.get(name);
81 }
82
83 }