1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.kqueue;
17
18 import io.netty.channel.Channel;
19 import io.netty.channel.DefaultSelectStrategyFactory;
20 import io.netty.channel.EventLoopTaskQueueFactory;
21 import io.netty.channel.IoEventLoopGroup;
22 import io.netty.channel.IoEventLoop;
23 import io.netty.channel.IoHandler;
24 import io.netty.channel.MultiThreadIoEventLoopGroup;
25 import io.netty.channel.SelectStrategyFactory;
26 import io.netty.channel.SingleThreadEventLoop;
27 import io.netty.channel.SingleThreadIoEventLoop;
28 import io.netty.util.concurrent.EventExecutorChooserFactory;
29 import io.netty.util.concurrent.RejectedExecutionHandler;
30 import io.netty.util.concurrent.RejectedExecutionHandlers;
31 import io.netty.util.internal.PlatformDependent;
32 import io.netty.util.internal.logging.InternalLogger;
33 import io.netty.util.internal.logging.InternalLoggerFactory;
34
35 import java.util.Iterator;
36 import java.util.Queue;
37 import java.util.concurrent.Executor;
38 import java.util.concurrent.ThreadFactory;
39
40
41
42
43
44 @Deprecated
45 public final class KQueueEventLoopGroup extends MultiThreadIoEventLoopGroup {
46
47
48
49 {
50
51 KQueue.ensureAvailability();
52 }
53
54 private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(KQueueEventLoopGroup.class);
55
56
57
58
59 public KQueueEventLoopGroup() {
60 this(0);
61 }
62
63
64
65
66 public KQueueEventLoopGroup(int nThreads) {
67 this(nThreads, (ThreadFactory) null);
68 }
69
70
71
72
73 @SuppressWarnings("deprecation")
74 public KQueueEventLoopGroup(ThreadFactory threadFactory) {
75 this(0, threadFactory, 0);
76 }
77
78
79
80
81 @SuppressWarnings("deprecation")
82 public KQueueEventLoopGroup(int nThreads, SelectStrategyFactory selectStrategyFactory) {
83 this(nThreads, (ThreadFactory) null, selectStrategyFactory);
84 }
85
86
87
88
89 @SuppressWarnings("deprecation")
90 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
91 this(nThreads, threadFactory, 0);
92 }
93
94 public KQueueEventLoopGroup(int nThreads, Executor executor) {
95 this(nThreads, executor, DefaultSelectStrategyFactory.INSTANCE);
96 }
97
98
99
100
101 @SuppressWarnings("deprecation")
102 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory,
103 SelectStrategyFactory selectStrategyFactory) {
104 this(nThreads, threadFactory, 0, selectStrategyFactory);
105 }
106
107
108
109
110
111
112
113 @Deprecated
114 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce) {
115 this(nThreads, threadFactory, maxEventsAtOnce, DefaultSelectStrategyFactory.INSTANCE);
116 }
117
118
119
120
121
122
123
124
125 @Deprecated
126 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce,
127 SelectStrategyFactory selectStrategyFactory) {
128 super(nThreads, threadFactory, KQueueIoHandler.newFactory(maxEventsAtOnce, selectStrategyFactory),
129 RejectedExecutionHandlers.reject());
130 }
131
132 public KQueueEventLoopGroup(int nThreads, Executor executor, SelectStrategyFactory selectStrategyFactory) {
133 super(nThreads, executor, KQueueIoHandler.newFactory(0, selectStrategyFactory),
134 RejectedExecutionHandlers.reject());
135 }
136
137 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
138 SelectStrategyFactory selectStrategyFactory) {
139 super(nThreads, executor, KQueueIoHandler.newFactory(0, selectStrategyFactory),
140 chooserFactory, RejectedExecutionHandlers.reject());
141 }
142
143 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
144 SelectStrategyFactory selectStrategyFactory,
145 RejectedExecutionHandler rejectedExecutionHandler) {
146 super(nThreads, executor, KQueueIoHandler.newFactory(0, selectStrategyFactory), chooserFactory,
147 rejectedExecutionHandler);
148 }
149
150 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
151 SelectStrategyFactory selectStrategyFactory,
152 RejectedExecutionHandler rejectedExecutionHandler,
153 EventLoopTaskQueueFactory queueFactory) {
154 super(nThreads, executor, KQueueIoHandler.newFactory(0, selectStrategyFactory), chooserFactory,
155 rejectedExecutionHandler, queueFactory);
156 }
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
172 SelectStrategyFactory selectStrategyFactory,
173 RejectedExecutionHandler rejectedExecutionHandler,
174 EventLoopTaskQueueFactory taskQueueFactory,
175 EventLoopTaskQueueFactory tailTaskQueueFactory) {
176 super(nThreads, executor, KQueueIoHandler.newFactory(0, selectStrategyFactory), chooserFactory,
177 rejectedExecutionHandler, taskQueueFactory, tailTaskQueueFactory);
178 }
179
180
181
182
183
184
185 @Deprecated
186 public void setIoRatio(int ioRatio) {
187 LOGGER.debug("EpollEventLoopGroup.setIoRatio(int) logic was removed, this is a no-op");
188 }
189
190 @Override
191 protected IoEventLoop newChild(Executor executor, IoHandler handler, Object... args) {
192 RejectedExecutionHandler rejectedExecutionHandler = null;
193 EventLoopTaskQueueFactory taskQueueFactory = null;
194 EventLoopTaskQueueFactory tailTaskQueueFactory = null;
195 int argsLength = args.length;
196 if (argsLength > 0) {
197 rejectedExecutionHandler = (RejectedExecutionHandler) args[0];
198 }
199 if (argsLength > 1) {
200 taskQueueFactory = (EventLoopTaskQueueFactory) args[2];
201 }
202 if (argsLength > 2) {
203 tailTaskQueueFactory = (EventLoopTaskQueueFactory) args[1];
204 }
205 return new KQueueEventLoop(this, executor, handler,
206 KQueueEventLoop.newTaskQueue(taskQueueFactory),
207 KQueueEventLoop.newTaskQueue(tailTaskQueueFactory),
208 rejectedExecutionHandler);
209 }
210
211 private static final class KQueueEventLoop extends SingleThreadIoEventLoop {
212 KQueueEventLoop(IoEventLoopGroup parent, Executor executor, IoHandler ioHandler,
213 Queue<Runnable> taskQueue, Queue<Runnable> tailTaskQueue,
214 RejectedExecutionHandler rejectedExecutionHandler) {
215 super(parent, executor, ioHandler, taskQueue, tailTaskQueue, rejectedExecutionHandler);
216 }
217
218 static Queue<Runnable> newTaskQueue(
219 EventLoopTaskQueueFactory queueFactory) {
220 if (queueFactory == null) {
221 return newTaskQueue0(DEFAULT_MAX_PENDING_TASKS);
222 }
223 return queueFactory.newTaskQueue(DEFAULT_MAX_PENDING_TASKS);
224 }
225
226 private static Queue<Runnable> newTaskQueue0(int maxPendingTasks) {
227
228 return maxPendingTasks == Integer.MAX_VALUE ? PlatformDependent.<Runnable>newMpscQueue()
229 : PlatformDependent.<Runnable>newMpscQueue(maxPendingTasks);
230 }
231
232 @Override
233 public int registeredChannels() {
234 assert inEventLoop();
235 return ((KQueueIoHandler) ioHandler()).numRegisteredChannels();
236 }
237
238 @Override
239 public Iterator<Channel> registeredChannelsIterator() {
240 assert inEventLoop();
241 return ((KQueueIoHandler) ioHandler()).registeredChannelsList().iterator();
242 }
243 }
244 }