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