1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.epoll;
17
18 import io.netty.channel.DefaultSelectStrategyFactory;
19 import io.netty.channel.EventLoop;
20 import io.netty.channel.EventLoopGroup;
21 import io.netty.channel.EventLoopTaskQueueFactory;
22 import io.netty.channel.MultithreadEventLoopGroup;
23 import io.netty.channel.SelectStrategyFactory;
24 import io.netty.channel.SingleThreadEventLoop;
25 import io.netty.util.concurrent.EventExecutor;
26 import io.netty.util.concurrent.EventExecutorChooserFactory;
27 import io.netty.util.concurrent.RejectedExecutionHandler;
28 import io.netty.util.concurrent.RejectedExecutionHandlers;
29
30 import java.util.concurrent.Executor;
31 import java.util.concurrent.ThreadFactory;
32
33
34
35
36
37 public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
38 {
39
40 Epoll.ensureAvailability();
41 }
42
43
44
45
46 public EpollEventLoopGroup() {
47 this(0);
48 }
49
50
51
52
53 public EpollEventLoopGroup(int nThreads) {
54 this(nThreads, (ThreadFactory) null);
55 }
56
57
58
59
60 @SuppressWarnings("deprecation")
61 public EpollEventLoopGroup(ThreadFactory threadFactory) {
62 this(0, threadFactory, 0);
63 }
64
65
66
67
68 @SuppressWarnings("deprecation")
69 public EpollEventLoopGroup(int nThreads, SelectStrategyFactory selectStrategyFactory) {
70 this(nThreads, (ThreadFactory) null, selectStrategyFactory);
71 }
72
73
74
75
76 @SuppressWarnings("deprecation")
77 public EpollEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
78 this(nThreads, threadFactory, 0);
79 }
80
81 public EpollEventLoopGroup(int nThreads, Executor executor) {
82 this(nThreads, executor, DefaultSelectStrategyFactory.INSTANCE);
83 }
84
85
86
87
88 @SuppressWarnings("deprecation")
89 public EpollEventLoopGroup(int nThreads, ThreadFactory threadFactory, SelectStrategyFactory selectStrategyFactory) {
90 this(nThreads, threadFactory, 0, selectStrategyFactory);
91 }
92
93
94
95
96
97
98
99 @Deprecated
100 public EpollEventLoopGroup(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 EpollEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce,
113 SelectStrategyFactory selectStrategyFactory) {
114 super(nThreads, threadFactory, maxEventsAtOnce, selectStrategyFactory, RejectedExecutionHandlers.reject());
115 }
116
117 public EpollEventLoopGroup(int nThreads, Executor executor, SelectStrategyFactory selectStrategyFactory) {
118 super(nThreads, executor, 0, selectStrategyFactory, RejectedExecutionHandlers.reject());
119 }
120
121 public EpollEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
122 SelectStrategyFactory selectStrategyFactory) {
123 super(nThreads, executor, chooserFactory, 0, selectStrategyFactory, RejectedExecutionHandlers.reject());
124 }
125
126 public EpollEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
127 SelectStrategyFactory selectStrategyFactory,
128 RejectedExecutionHandler rejectedExecutionHandler) {
129 super(nThreads, executor, chooserFactory, 0, selectStrategyFactory, rejectedExecutionHandler);
130 }
131
132 public EpollEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
133 SelectStrategyFactory selectStrategyFactory,
134 RejectedExecutionHandler rejectedExecutionHandler,
135 EventLoopTaskQueueFactory queueFactory) {
136 super(nThreads, executor, chooserFactory, 0, selectStrategyFactory, rejectedExecutionHandler, queueFactory);
137 }
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 public EpollEventLoopGroup(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 ((EpollEventLoop) 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 EpollEventLoop(this, executor, maxEvents,
187 selectStrategyFactory.newSelectStrategy(),
188 rejectedExecutionHandler, taskQueueFactory, tailTaskQueueFactory);
189 }
190 }