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