1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel;
17
18 import io.netty.buffer.ByteBufAllocator;
19 import io.netty.util.UniqueName;
20 import io.netty.util.internal.PlatformDependent;
21
22 import java.net.InetAddress;
23 import java.net.NetworkInterface;
24 import java.util.concurrent.ConcurrentMap;
25
26 import static io.netty.util.internal.ObjectUtil.checkNotNull;
27
28
29
30
31
32
33
34
35
36 @SuppressWarnings("deprecation")
37 public class ChannelOption<T> extends UniqueName {
38
39 @SuppressWarnings("rawtypes")
40 private static final ConcurrentMap<String, ChannelOption> names = PlatformDependent.newConcurrentHashMap();
41
42 public static final ChannelOption<ByteBufAllocator> ALLOCATOR = valueOf("ALLOCATOR");
43 public static final ChannelOption<RecvByteBufAllocator> RCVBUF_ALLOCATOR = valueOf("RCVBUF_ALLOCATOR");
44 public static final ChannelOption<MessageSizeEstimator> MESSAGE_SIZE_ESTIMATOR = valueOf("MESSAGE_SIZE_ESTIMATOR");
45
46 public static final ChannelOption<Integer> CONNECT_TIMEOUT_MILLIS = valueOf("CONNECT_TIMEOUT_MILLIS");
47 public static final ChannelOption<Integer> MAX_MESSAGES_PER_READ = valueOf("MAX_MESSAGES_PER_READ");
48 public static final ChannelOption<Integer> WRITE_SPIN_COUNT = valueOf("WRITE_SPIN_COUNT");
49 public static final ChannelOption<Integer> WRITE_BUFFER_HIGH_WATER_MARK = valueOf("WRITE_BUFFER_HIGH_WATER_MARK");
50 public static final ChannelOption<Integer> WRITE_BUFFER_LOW_WATER_MARK = valueOf("WRITE_BUFFER_LOW_WATER_MARK");
51
52 public static final ChannelOption<Boolean> ALLOW_HALF_CLOSURE = valueOf("ALLOW_HALF_CLOSURE");
53 public static final ChannelOption<Boolean> AUTO_READ = valueOf("AUTO_READ");
54
55
56
57
58
59
60
61 @Deprecated
62 public static final ChannelOption<Boolean> AUTO_CLOSE = valueOf("AUTO_CLOSE");
63
64 public static final ChannelOption<Boolean> SO_BROADCAST = valueOf("SO_BROADCAST");
65 public static final ChannelOption<Boolean> SO_KEEPALIVE = valueOf("SO_KEEPALIVE");
66 public static final ChannelOption<Integer> SO_SNDBUF = valueOf("SO_SNDBUF");
67 public static final ChannelOption<Integer> SO_RCVBUF = valueOf("SO_RCVBUF");
68 public static final ChannelOption<Boolean> SO_REUSEADDR = valueOf("SO_REUSEADDR");
69 public static final ChannelOption<Integer> SO_LINGER = valueOf("SO_LINGER");
70 public static final ChannelOption<Integer> SO_BACKLOG = valueOf("SO_BACKLOG");
71 public static final ChannelOption<Integer> SO_TIMEOUT = valueOf("SO_TIMEOUT");
72
73 public static final ChannelOption<Integer> IP_TOS = valueOf("IP_TOS");
74 public static final ChannelOption<InetAddress> IP_MULTICAST_ADDR = valueOf("IP_MULTICAST_ADDR");
75 public static final ChannelOption<NetworkInterface> IP_MULTICAST_IF = valueOf("IP_MULTICAST_IF");
76 public static final ChannelOption<Integer> IP_MULTICAST_TTL = valueOf("IP_MULTICAST_TTL");
77 public static final ChannelOption<Boolean> IP_MULTICAST_LOOP_DISABLED = valueOf("IP_MULTICAST_LOOP_DISABLED");
78
79 public static final ChannelOption<Boolean> TCP_NODELAY = valueOf("TCP_NODELAY");
80
81 @Deprecated
82 public static final ChannelOption<Long> AIO_READ_TIMEOUT = valueOf("AIO_READ_TIMEOUT");
83 @Deprecated
84 public static final ChannelOption<Long> AIO_WRITE_TIMEOUT = valueOf("AIO_WRITE_TIMEOUT");
85
86 @Deprecated
87 public static final ChannelOption<Boolean> DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION =
88 valueOf("DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION");
89
90 public static final ChannelOption<Boolean> SINGLE_EVENTEXECUTOR_PER_GROUP =
91 valueOf("SINGLE_EVENTEXECUTOR_PER_GROUP");
92
93
94
95
96
97 @SuppressWarnings("unchecked")
98 public static <T> ChannelOption<T> valueOf(String name) {
99 checkNotNull(name, "name");
100 ChannelOption<T> option = names.get(name);
101 if (option == null) {
102 option = new ChannelOption<T>(name);
103 ChannelOption<T> old = names.putIfAbsent(name, option);
104 if (old != null) {
105 option = old;
106 }
107 }
108 return option;
109 }
110
111
112
113
114 public static boolean exists(String name) {
115 checkNotNull(name, "name");
116 return names.containsKey(name);
117 }
118
119
120
121
122
123 @SuppressWarnings("unchecked")
124 public static <T> ChannelOption<T> newInstance(String name) {
125 checkNotNull(name, "name");
126 ChannelOption<T> option = new ChannelOption<T>(name);
127 ChannelOption<T> old = names.putIfAbsent(name, option);
128 if (old != null) {
129 throw new IllegalArgumentException(String.format("'%s' is already in use", name));
130 }
131 return option;
132 }
133
134
135
136
137 @Deprecated
138 protected ChannelOption(String name) {
139 super(name);
140 }
141
142
143
144
145
146 public void validate(T value) {
147 if (value == null) {
148 throw new NullPointerException("value");
149 }
150 }
151 }