1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.channel;
17
18 import io.netty5.buffer.api.BufferAllocator;
19 import io.netty5.util.AbstractConstant;
20 import io.netty5.util.ConstantPool;
21
22 import java.net.InetAddress;
23 import java.net.NetworkInterface;
24
25 import static java.util.Objects.requireNonNull;
26
27
28
29
30
31
32
33
34
35 public class ChannelOption<T> extends AbstractConstant<ChannelOption<T>> {
36
37 private static final ConstantPool<ChannelOption<Object>> pool = new ConstantPool<>() {
38 @Override
39 protected ChannelOption<Object> newConstant(int id, String name) {
40 return new ChannelOption<>(id, name);
41 }
42 };
43
44
45
46
47 @SuppressWarnings("unchecked")
48 public static <T> ChannelOption<T> valueOf(String name) {
49 return (ChannelOption<T>) pool.valueOf(name);
50 }
51
52
53
54
55 @SuppressWarnings("unchecked")
56 public static <T> ChannelOption<T> valueOf(Class<?> firstNameComponent, String secondNameComponent) {
57 return (ChannelOption<T>) pool.valueOf(firstNameComponent, secondNameComponent);
58 }
59
60
61
62
63 public static boolean exists(String name) {
64 return pool.exists(name);
65 }
66
67
68
69
70
71
72
73 @Deprecated
74 @SuppressWarnings("unchecked")
75 public static <T> ChannelOption<T> newInstance(String name) {
76 return (ChannelOption<T>) pool.newInstance(name);
77 }
78
79 public static final ChannelOption<BufferAllocator> BUFFER_ALLOCATOR = valueOf("BUFFER_ALLOCATOR");
80 public static final ChannelOption<RecvBufferAllocator> RCVBUFFER_ALLOCATOR = valueOf("RCVBUFFER_ALLOCATOR");
81 public static final ChannelOption<MessageSizeEstimator> MESSAGE_SIZE_ESTIMATOR = valueOf("MESSAGE_SIZE_ESTIMATOR");
82
83 public static final ChannelOption<Integer> CONNECT_TIMEOUT_MILLIS = valueOf("CONNECT_TIMEOUT_MILLIS");
84
85
86
87
88 @Deprecated
89 public static final ChannelOption<Integer> MAX_MESSAGES_PER_READ = valueOf("MAX_MESSAGES_PER_READ");
90 public static final ChannelOption<Integer> MAX_MESSAGES_PER_WRITE = valueOf("MAX_MESSAGES_PER_WRITE");
91
92 public static final ChannelOption<Integer> WRITE_SPIN_COUNT = valueOf("WRITE_SPIN_COUNT");
93
94 public static final ChannelOption<WriteBufferWaterMark> WRITE_BUFFER_WATER_MARK =
95 valueOf("WRITE_BUFFER_WATER_MARK");
96
97 public static final ChannelOption<Boolean> ALLOW_HALF_CLOSURE = valueOf("ALLOW_HALF_CLOSURE");
98 public static final ChannelOption<Boolean> AUTO_READ = valueOf("AUTO_READ");
99
100
101
102
103
104 public static final ChannelOption<Boolean> AUTO_CLOSE = valueOf("AUTO_CLOSE");
105
106 public static final ChannelOption<Boolean> SO_BROADCAST = valueOf("SO_BROADCAST");
107 public static final ChannelOption<Boolean> SO_KEEPALIVE = valueOf("SO_KEEPALIVE");
108 public static final ChannelOption<Integer> SO_SNDBUF = valueOf("SO_SNDBUF");
109 public static final ChannelOption<Integer> SO_RCVBUF = valueOf("SO_RCVBUF");
110 public static final ChannelOption<Boolean> SO_REUSEADDR = valueOf("SO_REUSEADDR");
111 public static final ChannelOption<Integer> SO_LINGER = valueOf("SO_LINGER");
112 public static final ChannelOption<Integer> SO_BACKLOG = valueOf("SO_BACKLOG");
113 public static final ChannelOption<Integer> SO_TIMEOUT = valueOf("SO_TIMEOUT");
114
115 public static final ChannelOption<Integer> IP_TOS = valueOf("IP_TOS");
116 public static final ChannelOption<NetworkInterface> IP_MULTICAST_IF = valueOf("IP_MULTICAST_IF");
117 public static final ChannelOption<Integer> IP_MULTICAST_TTL = valueOf("IP_MULTICAST_TTL");
118 public static final ChannelOption<Boolean> IP_MULTICAST_LOOP_DISABLED = valueOf("IP_MULTICAST_LOOP_DISABLED");
119
120 public static final ChannelOption<Boolean> TCP_NODELAY = valueOf("TCP_NODELAY");
121
122
123
124 public static final ChannelOption<Boolean> TCP_FASTOPEN_CONNECT = valueOf("TCP_FASTOPEN_CONNECT");
125
126
127
128
129 public static final ChannelOption<Integer> TCP_FASTOPEN = valueOf(ChannelOption.class, "TCP_FASTOPEN");
130
131 public static final ChannelOption<Boolean> DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION =
132 valueOf("DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION");
133
134
135
136
137 private ChannelOption(int id, String name) {
138 super(id, name);
139 }
140
141 @Deprecated
142 protected ChannelOption(String name) {
143 this(pool.nextId(), name);
144 }
145
146
147
148
149
150 public void validate(T value) {
151 requireNonNull(value, "value");
152 }
153 }