1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.nio;
17
18 import io.netty.channel.Channel;
19 import io.netty.channel.DefaultSelectStrategyFactory;
20 import io.netty.channel.EventLoopTaskQueueFactory;
21 import io.netty.channel.IoEventLoop;
22 import io.netty.channel.IoEventLoopGroup;
23 import io.netty.channel.IoHandler;
24 import io.netty.channel.MultiThreadIoEventLoopGroup;
25 import io.netty.channel.SelectStrategyFactory;
26 import io.netty.channel.SingleThreadEventLoop;
27 import io.netty.util.concurrent.EventExecutor;
28 import io.netty.util.concurrent.EventExecutorChooserFactory;
29 import io.netty.util.concurrent.RejectedExecutionHandler;
30 import io.netty.util.concurrent.RejectedExecutionHandlers;
31 import io.netty.util.internal.logging.InternalLogger;
32 import io.netty.util.internal.logging.InternalLoggerFactory;
33
34 import java.nio.channels.Selector;
35 import java.nio.channels.spi.SelectorProvider;
36 import java.util.concurrent.Executor;
37 import java.util.concurrent.ThreadFactory;
38
39
40
41
42
43
44 @Deprecated
45 public class NioEventLoopGroup extends MultiThreadIoEventLoopGroup implements IoEventLoopGroup {
46
47 private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(NioEventLoopGroup.class);
48
49
50
51
52
53 public NioEventLoopGroup() {
54 this(0);
55 }
56
57
58
59
60
61 public NioEventLoopGroup(int nThreads) {
62 this(nThreads, (Executor) null);
63 }
64
65
66
67
68
69 public NioEventLoopGroup(ThreadFactory threadFactory) {
70 this(0, threadFactory, SelectorProvider.provider());
71 }
72
73
74
75
76
77 public NioEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
78 this(nThreads, threadFactory, SelectorProvider.provider());
79 }
80
81 public NioEventLoopGroup(int nThreads, Executor executor) {
82 this(nThreads, executor, SelectorProvider.provider());
83 }
84
85
86
87
88
89 public NioEventLoopGroup(
90 int nThreads, ThreadFactory threadFactory, final SelectorProvider selectorProvider) {
91 this(nThreads, threadFactory, selectorProvider, DefaultSelectStrategyFactory.INSTANCE);
92 }
93
94 public NioEventLoopGroup(int nThreads, ThreadFactory threadFactory,
95 final SelectorProvider selectorProvider, final SelectStrategyFactory selectStrategyFactory) {
96 super(nThreads, threadFactory, NioIoHandler.newFactory(selectorProvider, selectStrategyFactory),
97 RejectedExecutionHandlers.reject());
98 }
99
100 public NioEventLoopGroup(
101 int nThreads, Executor executor, final SelectorProvider selectorProvider) {
102 this(nThreads, executor, selectorProvider, DefaultSelectStrategyFactory.INSTANCE);
103 }
104
105 public NioEventLoopGroup(int nThreads, Executor executor, final SelectorProvider selectorProvider,
106 final SelectStrategyFactory selectStrategyFactory) {
107 super(nThreads, executor, NioIoHandler.newFactory(selectorProvider, selectStrategyFactory),
108 RejectedExecutionHandlers.reject());
109 }
110
111 public NioEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
112 final SelectorProvider selectorProvider,
113 final SelectStrategyFactory selectStrategyFactory) {
114 super(nThreads, executor, NioIoHandler.newFactory(selectorProvider, selectStrategyFactory), chooserFactory,
115 RejectedExecutionHandlers.reject());
116 }
117
118 public NioEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
119 final SelectorProvider selectorProvider,
120 final SelectStrategyFactory selectStrategyFactory,
121 final RejectedExecutionHandler rejectedExecutionHandler) {
122 super(nThreads, executor, NioIoHandler.newFactory(selectorProvider, selectStrategyFactory), chooserFactory,
123 rejectedExecutionHandler);
124 }
125
126 public NioEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
127 final SelectorProvider selectorProvider,
128 final SelectStrategyFactory selectStrategyFactory,
129 final RejectedExecutionHandler rejectedExecutionHandler,
130 final EventLoopTaskQueueFactory taskQueueFactory) {
131 super(nThreads, executor, NioIoHandler.newFactory(selectorProvider, selectStrategyFactory), chooserFactory,
132 rejectedExecutionHandler, taskQueueFactory);
133 }
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 public NioEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
150 SelectorProvider selectorProvider,
151 SelectStrategyFactory selectStrategyFactory,
152 RejectedExecutionHandler rejectedExecutionHandler,
153 EventLoopTaskQueueFactory taskQueueFactory,
154 EventLoopTaskQueueFactory tailTaskQueueFactory) {
155 super(nThreads, executor, NioIoHandler.newFactory(selectorProvider, selectStrategyFactory), chooserFactory,
156 rejectedExecutionHandler, taskQueueFactory, tailTaskQueueFactory);
157 }
158
159
160
161
162
163
164 @Deprecated
165 public void setIoRatio(int ioRatio) {
166 LOGGER.debug("NioEventLoopGroup.setIoRatio(int) logic was removed, this is a no-op");
167 }
168
169
170
171
172
173 public void rebuildSelectors() {
174 for (EventExecutor e: this) {
175 ((NioEventLoop) e).rebuildSelector();
176 }
177 }
178
179 @Override
180 protected IoEventLoop newChild(Executor executor, IoHandler ioHandler, Object... args) {
181 RejectedExecutionHandler rejectedExecutionHandler = (RejectedExecutionHandler) args[0];
182 EventLoopTaskQueueFactory taskQueueFactory = null;
183 EventLoopTaskQueueFactory tailTaskQueueFactory = null;
184
185 int argsLength = args.length;
186 if (argsLength > 1) {
187 taskQueueFactory = (EventLoopTaskQueueFactory) args[1];
188 }
189 if (argsLength > 2) {
190 tailTaskQueueFactory = (EventLoopTaskQueueFactory) args[2];
191 }
192 return new NioEventLoop(
193 this, executor, ioHandler, taskQueueFactory, tailTaskQueueFactory, rejectedExecutionHandler);
194 }
195 }