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.IoHandlerFactory;
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
32 import java.util.Iterator;
33 import java.util.Queue;
34 import java.util.concurrent.Executor;
35 import java.util.concurrent.ThreadFactory;
36
37
38
39
40
41 @Deprecated
42 public final class KQueueEventLoopGroup extends MultiThreadIoEventLoopGroup {
43
44
45
46 {
47
48 KQueue.ensureAvailability();
49 }
50
51
52
53
54 public KQueueEventLoopGroup() {
55 this(0);
56 }
57
58
59
60
61 public KQueueEventLoopGroup(int nThreads) {
62 this(nThreads, (ThreadFactory) null);
63 }
64
65
66
67
68 @SuppressWarnings("deprecation")
69 public KQueueEventLoopGroup(ThreadFactory threadFactory) {
70 this(0, threadFactory, 0);
71 }
72
73
74
75
76 @SuppressWarnings("deprecation")
77 public KQueueEventLoopGroup(int nThreads, SelectStrategyFactory selectStrategyFactory) {
78 this(nThreads, (ThreadFactory) null, selectStrategyFactory);
79 }
80
81
82
83
84 @SuppressWarnings("deprecation")
85 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
86 this(nThreads, threadFactory, 0);
87 }
88
89 public KQueueEventLoopGroup(int nThreads, Executor executor) {
90 this(nThreads, executor, DefaultSelectStrategyFactory.INSTANCE);
91 }
92
93
94
95
96 @SuppressWarnings("deprecation")
97 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory,
98 SelectStrategyFactory selectStrategyFactory) {
99 this(nThreads, threadFactory, 0, selectStrategyFactory);
100 }
101
102
103
104
105
106
107
108 @Deprecated
109 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce) {
110 this(nThreads, threadFactory, maxEventsAtOnce, DefaultSelectStrategyFactory.INSTANCE);
111 }
112
113
114
115
116
117
118
119
120 @Deprecated
121 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce,
122 SelectStrategyFactory selectStrategyFactory) {
123 super(nThreads, threadFactory, KQueueIoHandler.newFactory(maxEventsAtOnce, selectStrategyFactory),
124 RejectedExecutionHandlers.reject());
125 }
126
127 public KQueueEventLoopGroup(int nThreads, Executor executor, SelectStrategyFactory selectStrategyFactory) {
128 super(nThreads, executor, KQueueIoHandler.newFactory(0, selectStrategyFactory),
129 RejectedExecutionHandlers.reject());
130 }
131
132 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
133 SelectStrategyFactory selectStrategyFactory) {
134 super(nThreads, executor, KQueueIoHandler.newFactory(0, selectStrategyFactory),
135 chooserFactory, RejectedExecutionHandlers.reject());
136 }
137
138 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
139 SelectStrategyFactory selectStrategyFactory,
140 RejectedExecutionHandler rejectedExecutionHandler) {
141 super(nThreads, executor, KQueueIoHandler.newFactory(0, selectStrategyFactory), chooserFactory,
142 rejectedExecutionHandler);
143 }
144
145 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
146 SelectStrategyFactory selectStrategyFactory,
147 RejectedExecutionHandler rejectedExecutionHandler,
148 EventLoopTaskQueueFactory queueFactory) {
149 super(nThreads, executor, KQueueIoHandler.newFactory(0, selectStrategyFactory), chooserFactory,
150 rejectedExecutionHandler, queueFactory);
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
167 SelectStrategyFactory selectStrategyFactory,
168 RejectedExecutionHandler rejectedExecutionHandler,
169 EventLoopTaskQueueFactory taskQueueFactory,
170 EventLoopTaskQueueFactory tailTaskQueueFactory) {
171 super(nThreads, executor, KQueueIoHandler.newFactory(0, selectStrategyFactory), chooserFactory,
172 rejectedExecutionHandler, taskQueueFactory, tailTaskQueueFactory);
173 }
174
175 @Override
176 protected IoEventLoop newChild(Executor executor, IoHandlerFactory ioHandlerFactory, Object... args) {
177 RejectedExecutionHandler rejectedExecutionHandler = null;
178 EventLoopTaskQueueFactory taskQueueFactory = null;
179 EventLoopTaskQueueFactory tailTaskQueueFactory = null;
180 int argsLength = args.length;
181 if (argsLength > 0) {
182 rejectedExecutionHandler = (RejectedExecutionHandler) args[0];
183 }
184 if (argsLength > 1) {
185 taskQueueFactory = (EventLoopTaskQueueFactory) args[2];
186 }
187 if (argsLength > 2) {
188 tailTaskQueueFactory = (EventLoopTaskQueueFactory) args[1];
189 }
190 return new KQueueEventLoop(this, executor, ioHandlerFactory,
191 KQueueEventLoop.newTaskQueue(taskQueueFactory),
192 KQueueEventLoop.newTaskQueue(tailTaskQueueFactory),
193 rejectedExecutionHandler);
194 }
195
196 private static final class KQueueEventLoop extends SingleThreadIoEventLoop {
197 KQueueEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory,
198 Queue<Runnable> taskQueue, Queue<Runnable> tailTaskQueue,
199 RejectedExecutionHandler rejectedExecutionHandler) {
200 super(parent, executor, ioHandlerFactory, taskQueue, tailTaskQueue, rejectedExecutionHandler);
201 }
202
203 static Queue<Runnable> newTaskQueue(
204 EventLoopTaskQueueFactory queueFactory) {
205 if (queueFactory == null) {
206 return newTaskQueue0(DEFAULT_MAX_PENDING_TASKS);
207 }
208 return queueFactory.newTaskQueue(DEFAULT_MAX_PENDING_TASKS);
209 }
210
211 @Override
212 public int registeredChannels() {
213 assert inEventLoop();
214 return ((KQueueIoHandler) ioHandler()).numRegisteredChannels();
215 }
216
217 @Override
218 public Iterator<Channel> registeredChannelsIterator() {
219 assert inEventLoop();
220 return ((KQueueIoHandler) ioHandler()).registeredChannelsList().iterator();
221 }
222 }
223 }