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.DefaultSelectStrategyFactory;
19 import io.netty.channel.EventLoop;
20 import io.netty.channel.EventLoopTaskQueueFactory;
21 import io.netty.channel.MultithreadEventLoopGroup;
22 import io.netty.channel.SelectStrategyFactory;
23 import io.netty.channel.SingleThreadEventLoop;
24 import io.netty.util.concurrent.EventExecutor;
25 import io.netty.util.concurrent.EventExecutorChooserFactory;
26 import io.netty.util.concurrent.RejectedExecutionHandler;
27 import io.netty.util.concurrent.RejectedExecutionHandlers;
28 import io.netty.util.internal.UnstableApi;
29
30 import java.util.concurrent.Executor;
31 import java.util.concurrent.ThreadFactory;
32
33 @UnstableApi
34 public final class KQueueEventLoopGroup extends MultithreadEventLoopGroup {
35
36
37
38 {
39
40 KQueue.ensureAvailability();
41 }
42
43
44
45 public KQueueEventLoopGroup() {
46 this(0);
47 }
48
49
50
51
52 public KQueueEventLoopGroup(int nThreads) {
53 this(nThreads, (ThreadFactory) null);
54 }
55
56
57
58
59 @SuppressWarnings("deprecation")
60 public KQueueEventLoopGroup(ThreadFactory threadFactory) {
61 this(0, threadFactory, 0);
62 }
63
64
65
66
67 @SuppressWarnings("deprecation")
68 public KQueueEventLoopGroup(int nThreads, SelectStrategyFactory selectStrategyFactory) {
69 this(nThreads, (ThreadFactory) null, selectStrategyFactory);
70 }
71
72
73
74
75 @SuppressWarnings("deprecation")
76 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
77 this(nThreads, threadFactory, 0);
78 }
79
80 public KQueueEventLoopGroup(int nThreads, Executor executor) {
81 this(nThreads, executor, DefaultSelectStrategyFactory.INSTANCE);
82 }
83
84
85
86
87 @SuppressWarnings("deprecation")
88 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory,
89 SelectStrategyFactory selectStrategyFactory) {
90 this(nThreads, threadFactory, 0, selectStrategyFactory);
91 }
92
93
94
95
96
97
98
99 @Deprecated
100 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce) {
101 this(nThreads, threadFactory, maxEventsAtOnce, DefaultSelectStrategyFactory.INSTANCE);
102 }
103
104
105
106
107
108
109
110
111 @Deprecated
112 public KQueueEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce,
113 SelectStrategyFactory selectStrategyFactory) {
114 super(nThreads, threadFactory, maxEventsAtOnce, selectStrategyFactory, RejectedExecutionHandlers.reject());
115 }
116
117 public KQueueEventLoopGroup(int nThreads, Executor executor, SelectStrategyFactory selectStrategyFactory) {
118 super(nThreads, executor, 0, selectStrategyFactory, RejectedExecutionHandlers.reject());
119 }
120
121 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
122 SelectStrategyFactory selectStrategyFactory) {
123 super(nThreads, executor, chooserFactory, 0, selectStrategyFactory, RejectedExecutionHandlers.reject());
124 }
125
126 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
127 SelectStrategyFactory selectStrategyFactory,
128 RejectedExecutionHandler rejectedExecutionHandler) {
129 super(nThreads, executor, chooserFactory, 0, selectStrategyFactory, rejectedExecutionHandler);
130 }
131
132 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
133 SelectStrategyFactory selectStrategyFactory,
134 RejectedExecutionHandler rejectedExecutionHandler,
135 EventLoopTaskQueueFactory queueFactory) {
136 super(nThreads, executor, chooserFactory, 0, selectStrategyFactory,
137 rejectedExecutionHandler, queueFactory);
138 }
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 public KQueueEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
154 SelectStrategyFactory selectStrategyFactory,
155 RejectedExecutionHandler rejectedExecutionHandler,
156 EventLoopTaskQueueFactory taskQueueFactory,
157 EventLoopTaskQueueFactory tailTaskQueueFactory) {
158 super(nThreads, executor, chooserFactory, 0, selectStrategyFactory, rejectedExecutionHandler, taskQueueFactory,
159 tailTaskQueueFactory);
160 }
161
162
163
164
165
166 public void setIoRatio(int ioRatio) {
167 for (EventExecutor e: this) {
168 ((KQueueEventLoop) e).setIoRatio(ioRatio);
169 }
170 }
171
172 @Override
173 protected EventLoop newChild(Executor executor, Object... args) throws Exception {
174 Integer maxEvents = (Integer) args[0];
175 SelectStrategyFactory selectStrategyFactory = (SelectStrategyFactory) args[1];
176 RejectedExecutionHandler rejectedExecutionHandler = (RejectedExecutionHandler) args[2];
177 EventLoopTaskQueueFactory taskQueueFactory = null;
178 EventLoopTaskQueueFactory tailTaskQueueFactory = null;
179
180 int argsLength = args.length;
181 if (argsLength > 3) {
182 taskQueueFactory = (EventLoopTaskQueueFactory) args[3];
183 }
184 if (argsLength > 4) {
185 tailTaskQueueFactory = (EventLoopTaskQueueFactory) args[4];
186 }
187 return new KQueueEventLoop(this, executor, maxEvents,
188 selectStrategyFactory.newSelectStrategy(),
189 rejectedExecutionHandler, taskQueueFactory, tailTaskQueueFactory);
190 }
191 }