diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java index d2faab828e6..5650a614588 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpClientCodecTest.java @@ -25,9 +25,10 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.embedded.EmbeddedChannel; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; @@ -129,7 +130,7 @@ public void testServerCloseSocketInputProvidesData() throws InterruptedException final CountDownLatch serverChannelLatch = new CountDownLatch(1); final CountDownLatch responseReceivedLatch = new CountDownLatch(1); try { - sb.group(new NioEventLoopGroup(2)); + sb.group(new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory())); sb.channel(NioServerSocketChannel.class); sb.childHandler(new ChannelInitializer() { @Override @@ -173,7 +174,7 @@ public void operationComplete(ChannelFuture future) throws Exception { } }); - cb.group(new NioEventLoopGroup(1)); + cb.group(new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory())); cb.channel(NioSocketChannel.class); cb.option(ChannelOption.ALLOW_HALF_CLOSURE, true); cb.handler(new ChannelInitializer() { diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java index 04014497b62..283b655baad 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java @@ -25,7 +25,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPromise; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.compression.Brotli; @@ -449,7 +450,8 @@ public Integer answer(InvocationOnMock in) throws Throwable { any(ByteBuf.class), anyInt(), anyBoolean()); final CountDownLatch serverChannelLatch = new CountDownLatch(1); - sb.group(new NioEventLoopGroup(), new NioEventLoopGroup()); + sb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()), + new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); sb.channel(NioServerSocketChannel.class); sb.childHandler(new ChannelInitializer() { @Override @@ -473,7 +475,7 @@ protected void initChannel(Channel ch) throws Exception { } }); - cb.group(new NioEventLoopGroup()); + cb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); cb.channel(NioSocketChannel.class); cb.handler(new ChannelInitializer() { @Override diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionTest.java index 1574d16828d..65457c17ff7 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionTest.java @@ -17,7 +17,9 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import io.netty.channel.DefaultEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.local.LocalIoHandler; import io.netty.handler.codec.http2.Http2Connection.Endpoint; import io.netty.handler.codec.http2.Http2Stream.State; import io.netty.util.concurrent.Future; @@ -59,7 +61,7 @@ public class DefaultHttp2ConnectionTest { private DefaultHttp2Connection server; private DefaultHttp2Connection client; - private static DefaultEventLoopGroup group; + private static EventLoopGroup group; @Mock private Http2Connection.Listener clientListener; @@ -69,7 +71,7 @@ public class DefaultHttp2ConnectionTest { @BeforeAll public static void beforeClass() { - group = new DefaultEventLoopGroup(2); + group = new MultiThreadIoEventLoopGroup(2, LocalIoHandler.newFactory()); } @AfterAll diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2PushPromiseFrameTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2PushPromiseFrameTest.java index 04acf60d55f..8cae6ec8667 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2PushPromiseFrameTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2PushPromiseFrameTest.java @@ -24,7 +24,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; @@ -42,7 +43,7 @@ public class DefaultHttp2PushPromiseFrameTest { - private final EventLoopGroup eventLoopGroup = new NioEventLoopGroup(2); + private final EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory()); private final ClientHandler clientHandler = new ClientHandler(); private final Map contentMap = new ConcurrentHashMap(); diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTransportTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTransportTest.java index c3709102b06..848a15fc791 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTransportTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTransportTest.java @@ -30,11 +30,12 @@ import io.netty.channel.ChannelPipeline; import io.netty.channel.DefaultEventLoop; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; import io.netty.channel.local.LocalServerChannel; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.DefaultFullHttpRequest; @@ -163,7 +164,7 @@ private static String generateLargeString(int sizeInBytes) { @BeforeEach public void setup() { - eventLoopGroup = new NioEventLoopGroup(); + eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); } @AfterEach @@ -668,19 +669,19 @@ public void streamHandlerInactivatedResponseFlushed() throws InterruptedExceptio EventLoopGroup clientEventLoopGroup = null; try { - serverEventLoopGroup = new NioEventLoopGroup(1, new ThreadFactory() { + serverEventLoopGroup = new MultiThreadIoEventLoopGroup(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, "serverloop"); } - }); + }, NioIoHandler.newFactory()); - clientEventLoopGroup = new NioEventLoopGroup(1, new ThreadFactory() { + clientEventLoopGroup = new MultiThreadIoEventLoopGroup(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, "clientloop"); } - }); + }, NioIoHandler.newFactory()); final int streams = 10; final CountDownLatch latchClientResponses = new CountDownLatch(streams); diff --git a/codec/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java b/codec/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java index 483e75297e4..6ce490feadb 100644 --- a/codec/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java +++ b/codec/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java @@ -27,8 +27,9 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.embedded.EmbeddedChannel; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.EncoderException; @@ -255,7 +256,7 @@ public void testAllocatingAroundBlockSize() { @Test @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void writingAfterClosedChannelDoesNotNPE() throws InterruptedException { - EventLoopGroup group = new NioEventLoopGroup(2); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory()); Channel serverChannel = null; Channel clientChannel = null; final CountDownLatch latch = new CountDownLatch(1); diff --git a/example/src/main/java/io/netty/example/discard/DiscardClient.java b/example/src/main/java/io/netty/example/discard/DiscardClient.java index 32562f89ae5..cdfb37cdc98 100644 --- a/example/src/main/java/io/netty/example/discard/DiscardClient.java +++ b/example/src/main/java/io/netty/example/discard/DiscardClient.java @@ -20,7 +20,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.example.util.ServerUtil; @@ -39,7 +40,7 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/discard/DiscardServer.java b/example/src/main/java/io/netty/example/discard/DiscardServer.java index 33c7ff19920..1607235b1c5 100644 --- a/example/src/main/java/io/netty/example/discard/DiscardServer.java +++ b/example/src/main/java/io/netty/example/discard/DiscardServer.java @@ -20,7 +20,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; @@ -39,8 +40,8 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/dns/dot/DoTClient.java b/example/src/main/java/io/netty/example/dns/dot/DoTClient.java index 7224d90d9c1..0a04e5996d9 100644 --- a/example/src/main/java/io/netty/example/dns/dot/DoTClient.java +++ b/example/src/main/java/io/netty/example/dns/dot/DoTClient.java @@ -23,7 +23,8 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.SimpleChannelInboundHandler; @@ -71,7 +72,7 @@ private static void handleQueryResp(DefaultDnsResponse msg) { } public static void main(String[] args) throws Exception { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { final SslContext sslContext = SslContextBuilder.forClient() .protocols("TLSv1.3", "TLSv1.2") diff --git a/example/src/main/java/io/netty/example/dns/tcp/TcpDnsClient.java b/example/src/main/java/io/netty/example/dns/tcp/TcpDnsClient.java index e91ca25059c..20510c1ef4e 100644 --- a/example/src/main/java/io/netty/example/dns/tcp/TcpDnsClient.java +++ b/example/src/main/java/io/netty/example/dns/tcp/TcpDnsClient.java @@ -23,7 +23,8 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.SimpleChannelInboundHandler; @@ -69,7 +70,7 @@ private static void handleQueryResp(DefaultDnsResponse msg) { } public static void main(String[] args) throws Exception { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/dns/tcp/TcpDnsServer.java b/example/src/main/java/io/netty/example/dns/tcp/TcpDnsServer.java index d72070b0ba6..a1b41a85582 100644 --- a/example/src/main/java/io/netty/example/dns/tcp/TcpDnsServer.java +++ b/example/src/main/java/io/netty/example/dns/tcp/TcpDnsServer.java @@ -22,8 +22,10 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; @@ -57,8 +59,9 @@ public final class TcpDnsServer { private static final byte[] QUERY_RESULT = new byte[]{(byte) 192, (byte) 168, 1, 1}; public static void main(String[] args) throws Exception { - ServerBootstrap bootstrap = new ServerBootstrap().group(new NioEventLoopGroup(1), - new NioEventLoopGroup()) + ServerBootstrap bootstrap = new ServerBootstrap().group( + new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()), + new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())) .channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer() { @@ -110,7 +113,7 @@ public void run() { // copy from TcpDnsClient.java private static void clientQuery() throws Exception { - NioEventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/dns/udp/DnsClient.java b/example/src/main/java/io/netty/example/dns/udp/DnsClient.java index 396d9abdd6c..da869366236 100644 --- a/example/src/main/java/io/netty/example/dns/udp/DnsClient.java +++ b/example/src/main/java/io/netty/example/dns/udp/DnsClient.java @@ -25,8 +25,9 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.handler.codec.dns.DatagramDnsQuery; @@ -67,7 +68,7 @@ private static void handleQueryResp(DatagramDnsResponse msg) { public static void main(String[] args) throws Exception { InetSocketAddress addr = new InetSocketAddress(DNS_SERVER_HOST, DNS_SERVER_PORT); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/echo/EchoClient.java b/example/src/main/java/io/netty/example/echo/EchoClient.java index c7ccc484ad7..987649a0ce5 100644 --- a/example/src/main/java/io/netty/example/echo/EchoClient.java +++ b/example/src/main/java/io/netty/example/echo/EchoClient.java @@ -21,7 +21,8 @@ import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.example.util.ServerUtil; @@ -44,7 +45,7 @@ public static void main(String[] args) throws Exception { final SslContext sslCtx = ServerUtil.buildSslContext(); // Configure the client. - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/echo/EchoServer.java b/example/src/main/java/io/netty/example/echo/EchoServer.java index 69625458be0..db113f96bf0 100644 --- a/example/src/main/java/io/netty/example/echo/EchoServer.java +++ b/example/src/main/java/io/netty/example/echo/EchoServer.java @@ -21,7 +21,8 @@ import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; @@ -41,8 +42,8 @@ public static void main(String[] args) throws Exception { final SslContext sslCtx = ServerUtil.buildSslContext(); // Configure the server. - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); final EchoServerHandler serverHandler = new EchoServerHandler(); try { ServerBootstrap b = new ServerBootstrap(); diff --git a/example/src/main/java/io/netty/example/factorial/FactorialClient.java b/example/src/main/java/io/netty/example/factorial/FactorialClient.java index 85123d4fc51..e6cd9858d37 100644 --- a/example/src/main/java/io/netty/example/factorial/FactorialClient.java +++ b/example/src/main/java/io/netty/example/factorial/FactorialClient.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.ssl.SslContext; @@ -37,7 +38,7 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/factorial/FactorialServer.java b/example/src/main/java/io/netty/example/factorial/FactorialServer.java index 3ac93e53acf..877f77abc2c 100644 --- a/example/src/main/java/io/netty/example/factorial/FactorialServer.java +++ b/example/src/main/java/io/netty/example/factorial/FactorialServer.java @@ -17,7 +17,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.logging.LogLevel; @@ -36,8 +37,8 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/file/FileServer.java b/example/src/main/java/io/netty/example/file/FileServer.java index 8b2eb7c319d..9969725a2cc 100644 --- a/example/src/main/java/io/netty/example/file/FileServer.java +++ b/example/src/main/java/io/netty/example/file/FileServer.java @@ -21,7 +21,8 @@ import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; @@ -48,8 +49,8 @@ public static void main(String[] args) throws Exception { final SslContext sslCtx = ServerUtil.buildSslContext(); // Configure the server. - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/haproxy/HAProxyClient.java b/example/src/main/java/io/netty/example/haproxy/HAProxyClient.java index fdd9e219b15..bd4efd42b4a 100644 --- a/example/src/main/java/io/netty/example/haproxy/HAProxyClient.java +++ b/example/src/main/java/io/netty/example/haproxy/HAProxyClient.java @@ -20,7 +20,8 @@ import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.haproxy.HAProxyCommand; import io.netty.handler.codec.haproxy.HAProxyMessage; @@ -35,7 +36,7 @@ public final class HAProxyClient { private static final String HOST = System.getProperty("host", "127.0.0.1"); public static void main(String[] args) throws Exception { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/haproxy/HAProxyServer.java b/example/src/main/java/io/netty/example/haproxy/HAProxyServer.java index dfb66f42d32..f9e4cede704 100644 --- a/example/src/main/java/io/netty/example/haproxy/HAProxyServer.java +++ b/example/src/main/java/io/netty/example/haproxy/HAProxyServer.java @@ -22,8 +22,9 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.haproxy.HAProxyMessage; @@ -36,8 +37,8 @@ public final class HAProxyServer { static final int PORT = Integer.parseInt(System.getProperty("port", "8080")); public static void main(String[] args) throws Exception { - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/http/cors/HttpCorsServer.java b/example/src/main/java/io/netty/example/http/cors/HttpCorsServer.java index f9908ea2a99..e1c83535a1c 100644 --- a/example/src/main/java/io/netty/example/http/cors/HttpCorsServer.java +++ b/example/src/main/java/io/netty/example/http/cors/HttpCorsServer.java @@ -17,7 +17,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.logging.LogLevel; @@ -79,8 +80,8 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/http/file/HttpStaticFileServer.java b/example/src/main/java/io/netty/example/http/file/HttpStaticFileServer.java index adeca2ada59..dbec3dae149 100644 --- a/example/src/main/java/io/netty/example/http/file/HttpStaticFileServer.java +++ b/example/src/main/java/io/netty/example/http/file/HttpStaticFileServer.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.logging.LogLevel; @@ -34,8 +35,8 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServer.java b/example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServer.java index 23ce5a747d7..ab6708b5caf 100644 --- a/example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServer.java +++ b/example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServer.java @@ -19,7 +19,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.logging.LogLevel; @@ -40,8 +41,8 @@ public static void main(String[] args) throws Exception { final SslContext sslCtx = ServerUtil.buildSslContext(); // Configure the server. - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); diff --git a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java index 32aef98c171..7c56850ff73 100644 --- a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java +++ b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java @@ -19,7 +19,8 @@ import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.HttpHeaderNames; @@ -72,7 +73,7 @@ public static void main(String[] args) throws Exception { } // Configure the client. - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServer.java b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServer.java index b6f6a239724..e7ed3f1e170 100644 --- a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServer.java +++ b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServer.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.logging.LogLevel; @@ -39,8 +40,8 @@ public static void main(String[] args) throws Exception { final SslContext sslCtx = ServerUtil.buildSslContext(); // Configure the server. - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java index 712d4c646ba..0cd9411ea8a 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java @@ -19,7 +19,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.LastHttpContent; @@ -102,7 +103,7 @@ public static void main(String[] args) throws Exception { } // Configure the client. - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); // setup the factory: here using a mixed memory/disk based on size threshold HttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE); // Disk if MINSIZE exceed diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java index 1c1abaa1e53..9570a8a7c16 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.logging.LogLevel; @@ -37,8 +38,8 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup); diff --git a/example/src/main/java/io/netty/example/http/websocketx/benchmarkserver/WebSocketServer.java b/example/src/main/java/io/netty/example/http/websocketx/benchmarkserver/WebSocketServer.java index a344df8aa6a..a5df452cf31 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/benchmarkserver/WebSocketServer.java +++ b/example/src/main/java/io/netty/example/http/websocketx/benchmarkserver/WebSocketServer.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.ssl.SslContext; @@ -40,8 +41,8 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java b/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java index 5cfc62cba23..c1f7f2496bf 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java +++ b/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java @@ -21,7 +21,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.DefaultHttpHeaders; @@ -90,7 +91,7 @@ public static void main(String[] args) throws Exception { sslCtx = null; } - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { // Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00. // If you change it to V00, ping is not supported and remember to change diff --git a/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServer.java b/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServer.java index ad1e8efab4f..38cbdcb0996 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServer.java +++ b/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServer.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.logging.LogLevel; @@ -53,8 +54,8 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/http2/file/Http2StaticFileServer.java b/example/src/main/java/io/netty/example/http2/file/Http2StaticFileServer.java index 03a04b60a6a..9cc2cf4186d 100644 --- a/example/src/main/java/io/netty/example/http2/file/Http2StaticFileServer.java +++ b/example/src/main/java/io/netty/example/http2/file/Http2StaticFileServer.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.http2.Http2SecurityUtil; import io.netty.handler.logging.LogLevel; @@ -50,8 +51,8 @@ public static void main(String[] args) throws Exception { ApplicationProtocolNames.HTTP_1_1)) .build(); - EventLoopGroup bossGroup = new NioEventLoopGroup(2); - EventLoopGroup workerGroup = new NioEventLoopGroup(4); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(4, NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/http2/helloworld/client/Http2Client.java b/example/src/main/java/io/netty/example/http2/helloworld/client/Http2Client.java index a987e7423c4..f8199481147 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/client/Http2Client.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/client/Http2Client.java @@ -19,7 +19,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.FullHttpRequest; @@ -91,13 +92,13 @@ public static void main(String[] args) throws Exception { sslCtx = null; } - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Http2ClientInitializer initializer = new Http2ClientInitializer(sslCtx, Integer.MAX_VALUE); try { // Configure the client. Bootstrap b = new Bootstrap(); - b.group(workerGroup); + b.group(group); b.channel(NioSocketChannel.class); b.option(ChannelOption.SO_KEEPALIVE, true); b.remoteAddress(HOST, PORT); @@ -143,7 +144,7 @@ public static void main(String[] args) throws Exception { // Wait until the connection is closed. channel.close().syncUninterruptibly(); } finally { - workerGroup.shutdownGracefully(); + group.shutdownGracefully(); } } } diff --git a/example/src/main/java/io/netty/example/http2/helloworld/frame/client/Http2FrameClient.java b/example/src/main/java/io/netty/example/http2/helloworld/frame/client/Http2FrameClient.java index 8f87c986e1e..9d7508b65ea 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/frame/client/Http2FrameClient.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/frame/client/Http2FrameClient.java @@ -18,7 +18,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http2.DefaultHttp2Headers; import io.netty.handler.codec.http2.DefaultHttp2HeadersFrame; @@ -56,7 +57,7 @@ private Http2FrameClient() { } public static void main(String[] args) throws Exception { - final EventLoopGroup clientWorkerGroup = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); // Configure SSL. final SslContext sslCtx; @@ -81,7 +82,7 @@ public static void main(String[] args) throws Exception { try { final Bootstrap b = new Bootstrap(); - b.group(clientWorkerGroup); + b.group(group); b.channel(NioSocketChannel.class); b.option(ChannelOption.SO_KEEPALIVE, true); b.remoteAddress(HOST, PORT); @@ -117,7 +118,7 @@ public static void main(String[] args) throws Exception { // Wait until the connection is closed. channel.close().syncUninterruptibly(); } finally { - clientWorkerGroup.shutdownGracefully(); + group.shutdownGracefully(); } } diff --git a/example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2Server.java b/example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2Server.java index 2ba58748e69..05711c9ed80 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2Server.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2Server.java @@ -20,7 +20,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.http2.Http2SecurityUtil; import io.netty.handler.logging.LogLevel; @@ -74,7 +75,7 @@ public static void main(String[] args) throws Exception { sslCtx = null; } // Configure the server. - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); diff --git a/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2Server.java b/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2Server.java index 52ad4785e11..e099393f186 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2Server.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2Server.java @@ -20,7 +20,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.http2.Http2SecurityUtil; import io.netty.handler.logging.LogLevel; @@ -74,7 +75,7 @@ public static void main(String[] args) throws Exception { sslCtx = null; } // Configure the server. - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); diff --git a/example/src/main/java/io/netty/example/http2/helloworld/server/Http2Server.java b/example/src/main/java/io/netty/example/http2/helloworld/server/Http2Server.java index 05a41c6491f..219bd5dd3f1 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/server/Http2Server.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/server/Http2Server.java @@ -20,7 +20,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.http2.Http2SecurityUtil; import io.netty.handler.logging.LogLevel; @@ -71,7 +72,7 @@ public static void main(String[] args) throws Exception { sslCtx = null; } // Configure the server. - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); diff --git a/example/src/main/java/io/netty/example/http2/tiles/Launcher.java b/example/src/main/java/io/netty/example/http2/tiles/Launcher.java index a375a4fa359..15904528ba4 100644 --- a/example/src/main/java/io/netty/example/http2/tiles/Launcher.java +++ b/example/src/main/java/io/netty/example/http2/tiles/Launcher.java @@ -17,7 +17,8 @@ package io.netty.example.http2.tiles; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; /** *

@@ -38,7 +39,7 @@ public final class Launcher { public static void main(String[] args) { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Http2Server http2 = new Http2Server(group); HttpServer http = new HttpServer(group); try { diff --git a/example/src/main/java/io/netty/example/ipfilter/IpSubnetFilterExample.java b/example/src/main/java/io/netty/example/ipfilter/IpSubnetFilterExample.java index 5d69e8724fd..56341321d38 100644 --- a/example/src/main/java/io/netty/example/ipfilter/IpSubnetFilterExample.java +++ b/example/src/main/java/io/netty/example/ipfilter/IpSubnetFilterExample.java @@ -22,8 +22,9 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.ipfilter.IpFilterRuleType; @@ -43,8 +44,8 @@ public final class IpSubnetFilterExample { static final int PORT = Integer.parseInt(System.getProperty("port", "8009")); public static void main(String[] args) throws Exception { - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(1); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { List rules = new ArrayList(); diff --git a/example/src/main/java/io/netty/example/localecho/LocalEcho.java b/example/src/main/java/io/netty/example/localecho/LocalEcho.java index a567a744051..4f4fcf27958 100644 --- a/example/src/main/java/io/netty/example/localecho/LocalEcho.java +++ b/example/src/main/java/io/netty/example/localecho/LocalEcho.java @@ -20,12 +20,12 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; -import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; +import io.netty.channel.local.LocalIoHandler; import io.netty.channel.local.LocalServerChannel; -import io.netty.channel.nio.NioEventLoopGroup; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; @@ -40,8 +40,8 @@ public static void main(String[] args) throws Exception { // Address to bind on / connect to. final LocalAddress addr = new LocalAddress(PORT); - EventLoopGroup serverGroup = new DefaultEventLoopGroup(); - EventLoopGroup clientGroup = new NioEventLoopGroup(); // NIO event loops are also OK + EventLoopGroup serverGroup = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()); + EventLoopGroup clientGroup = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()); try { // Note that we can use any event loop to ensure certain local channels // are handled by the same event loop thread which drives a certain socket channel diff --git a/example/src/main/java/io/netty/example/memcache/binary/MemcacheClient.java b/example/src/main/java/io/netty/example/memcache/binary/MemcacheClient.java index 1b01fb57c59..b434c7dea55 100644 --- a/example/src/main/java/io/netty/example/memcache/binary/MemcacheClient.java +++ b/example/src/main/java/io/netty/example/memcache/binary/MemcacheClient.java @@ -21,7 +21,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.memcache.binary.BinaryMemcacheClientCodec; @@ -52,7 +53,7 @@ public static void main(String[] args) throws Exception { sslCtx = null; } - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/mqtt/heartBeat/MqttHeartBeatBroker.java b/example/src/main/java/io/netty/example/mqtt/heartBeat/MqttHeartBeatBroker.java index 66777f9da70..4de602a0538 100644 --- a/example/src/main/java/io/netty/example/mqtt/heartBeat/MqttHeartBeatBroker.java +++ b/example/src/main/java/io/netty/example/mqtt/heartBeat/MqttHeartBeatBroker.java @@ -20,7 +20,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.mqtt.MqttDecoder; @@ -35,8 +36,8 @@ private MqttHeartBeatBroker() { } public static void main(String[] args) throws Exception { - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); diff --git a/example/src/main/java/io/netty/example/mqtt/heartBeat/MqttHeartBeatClient.java b/example/src/main/java/io/netty/example/mqtt/heartBeat/MqttHeartBeatClient.java index 3d64523ff7c..e799a0da95a 100644 --- a/example/src/main/java/io/netty/example/mqtt/heartBeat/MqttHeartBeatClient.java +++ b/example/src/main/java/io/netty/example/mqtt/heartBeat/MqttHeartBeatClient.java @@ -19,7 +19,8 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.mqtt.MqttDecoder; @@ -39,11 +40,11 @@ private MqttHeartBeatClient() { private static final String PASSWORD = System.getProperty("password", "guest"); public static void main(String[] args) throws Exception { - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); - b.group(workerGroup); + b.group(group); b.channel(NioSocketChannel.class); b.handler(new ChannelInitializer() { @Override @@ -59,7 +60,7 @@ protected void initChannel(SocketChannel ch) throws Exception { System.out.println("Client connected"); f.channel().closeFuture().sync(); } finally { - workerGroup.shutdownGracefully(); + group.shutdownGracefully(); } } } diff --git a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java index 2d6985cd86d..37929de9b11 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java @@ -19,7 +19,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.example.echo.EchoClient; @@ -50,7 +51,7 @@ public static void main(String[] args) throws Exception { sslCtx = null; } - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java b/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java index b8778696bcc..25b40f243ec 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java @@ -19,7 +19,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.echo.EchoServer; @@ -43,8 +44,8 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/ocsp/OcspClientExample.java b/example/src/main/java/io/netty/example/ocsp/OcspClientExample.java index c5b11edca7a..854de0bdd67 100644 --- a/example/src/main/java/io/netty/example/ocsp/OcspClientExample.java +++ b/example/src/main/java/io/netty/example/ocsp/OcspClientExample.java @@ -22,6 +22,8 @@ import javax.security.cert.X509Certificate; import io.netty.buffer.Unpooled; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import org.bouncycastle.asn1.ocsp.OCSPResponseStatus; import org.bouncycastle.cert.ocsp.BasicOCSPResp; import org.bouncycastle.cert.ocsp.CertificateStatus; @@ -37,7 +39,6 @@ import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.FullHttpRequest; @@ -88,7 +89,7 @@ public static void main(String[] args) throws Exception { .build(); try { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Promise promise = group.next().newPromise(); diff --git a/example/src/main/java/io/netty/example/portunification/PortUnificationServer.java b/example/src/main/java/io/netty/example/portunification/PortUnificationServer.java index eae62892257..02f92113f4a 100644 --- a/example/src/main/java/io/netty/example/portunification/PortUnificationServer.java +++ b/example/src/main/java/io/netty/example/portunification/PortUnificationServer.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; @@ -44,8 +45,8 @@ public static void main(String[] args) throws Exception { final SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) .build(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/proxy/HexDumpProxy.java b/example/src/main/java/io/netty/example/proxy/HexDumpProxy.java index c57515ea8f1..e33e29ba85a 100644 --- a/example/src/main/java/io/netty/example/proxy/HexDumpProxy.java +++ b/example/src/main/java/io/netty/example/proxy/HexDumpProxy.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; @@ -33,8 +34,8 @@ public static void main(String[] args) throws Exception { System.err.println("Proxying *:" + LOCAL_PORT + " to " + REMOTE_HOST + ':' + REMOTE_PORT + " ..."); // Configure the bootstrap. - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java index 68594a82893..f00747b289b 100644 --- a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java +++ b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java @@ -20,7 +20,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.util.CharsetUtil; @@ -38,7 +39,7 @@ public final class QuoteOfTheMomentClient { public static void main(String[] args) throws Exception { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java index 46ef1932585..ee44ab2a442 100644 --- a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java +++ b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioDatagramChannel; /** @@ -32,7 +33,7 @@ public final class QuoteOfTheMomentServer { private static final int PORT = Integer.parseInt(System.getProperty("port", "7686")); public static void main(String[] args) throws Exception { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/redis/RedisClient.java b/example/src/main/java/io/netty/example/redis/RedisClient.java index 50718b11243..c8b211da9bb 100644 --- a/example/src/main/java/io/netty/example/redis/RedisClient.java +++ b/example/src/main/java/io/netty/example/redis/RedisClient.java @@ -21,7 +21,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.redis.RedisArrayAggregator; @@ -41,7 +42,7 @@ public class RedisClient { private static final int PORT = Integer.parseInt(System.getProperty("port", "6379")); public static void main(String[] args) throws Exception { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/sctp/SctpEchoClient.java b/example/src/main/java/io/netty/example/sctp/SctpEchoClient.java index 1b5eca6cca7..202ebfb2044 100644 --- a/example/src/main/java/io/netty/example/sctp/SctpEchoClient.java +++ b/example/src/main/java/io/netty/example/sctp/SctpEchoClient.java @@ -19,7 +19,8 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.sctp.SctpChannel; import io.netty.channel.sctp.SctpChannelOption; import io.netty.channel.sctp.nio.NioSctpChannel; @@ -40,7 +41,7 @@ public final class SctpEchoClient { public static void main(String[] args) throws Exception { // Configure the client. - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/sctp/SctpEchoServer.java b/example/src/main/java/io/netty/example/sctp/SctpEchoServer.java index c3273c64d08..70ec1a24e7e 100644 --- a/example/src/main/java/io/netty/example/sctp/SctpEchoServer.java +++ b/example/src/main/java/io/netty/example/sctp/SctpEchoServer.java @@ -20,7 +20,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.sctp.SctpChannel; import io.netty.channel.sctp.nio.NioSctpServerChannel; import io.netty.handler.logging.LogLevel; @@ -35,8 +36,8 @@ public final class SctpEchoServer { public static void main(String[] args) throws Exception { // Configure the server. - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); final SctpEchoServerHandler serverHandler = new SctpEchoServerHandler(); try { ServerBootstrap b = new ServerBootstrap(); diff --git a/example/src/main/java/io/netty/example/sctp/multihoming/SctpMultiHomingEchoClient.java b/example/src/main/java/io/netty/example/sctp/multihoming/SctpMultiHomingEchoClient.java index 9b6dff684af..1d2260a1786 100644 --- a/example/src/main/java/io/netty/example/sctp/multihoming/SctpMultiHomingEchoClient.java +++ b/example/src/main/java/io/netty/example/sctp/multihoming/SctpMultiHomingEchoClient.java @@ -19,7 +19,8 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.sctp.SctpChannel; import io.netty.channel.sctp.SctpChannelOption; import io.netty.channel.sctp.nio.NioSctpChannel; @@ -44,7 +45,7 @@ public final class SctpMultiHomingEchoClient { public static void main(String[] args) throws Exception { // Configure the client. - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/sctp/multihoming/SctpMultiHomingEchoServer.java b/example/src/main/java/io/netty/example/sctp/multihoming/SctpMultiHomingEchoServer.java index c11cb09324b..6c64f945244 100644 --- a/example/src/main/java/io/netty/example/sctp/multihoming/SctpMultiHomingEchoServer.java +++ b/example/src/main/java/io/netty/example/sctp/multihoming/SctpMultiHomingEchoServer.java @@ -20,7 +20,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.sctp.SctpChannel; import io.netty.channel.sctp.SctpServerChannel; import io.netty.channel.sctp.nio.NioSctpServerChannel; @@ -44,8 +45,8 @@ public final class SctpMultiHomingEchoServer { public static void main(String[] args) throws Exception { // Configure the server. - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/securechat/SecureChatClient.java b/example/src/main/java/io/netty/example/securechat/SecureChatClient.java index 2404c409547..e05dda6e645 100644 --- a/example/src/main/java/io/netty/example/securechat/SecureChatClient.java +++ b/example/src/main/java/io/netty/example/securechat/SecureChatClient.java @@ -19,7 +19,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.example.telnet.TelnetClient; import io.netty.handler.ssl.SslContext; @@ -42,7 +43,7 @@ public static void main(String[] args) throws Exception { final SslContext sslCtx = SslContextBuilder.forClient() .trustManager(InsecureTrustManagerFactory.INSTANCE).build(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/securechat/SecureChatServer.java b/example/src/main/java/io/netty/example/securechat/SecureChatServer.java index 5e5b7cfd2ed..a67d72042c8 100644 --- a/example/src/main/java/io/netty/example/securechat/SecureChatServer.java +++ b/example/src/main/java/io/netty/example/securechat/SecureChatServer.java @@ -17,7 +17,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.telnet.TelnetServer; import io.netty.handler.logging.LogLevel; @@ -38,8 +39,8 @@ public static void main(String[] args) throws Exception { SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) .build(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/socksproxy/SocksServer.java b/example/src/main/java/io/netty/example/socksproxy/SocksServer.java index 6c284f8831e..b226a0e3d8c 100644 --- a/example/src/main/java/io/netty/example/socksproxy/SocksServer.java +++ b/example/src/main/java/io/netty/example/socksproxy/SocksServer.java @@ -17,7 +17,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; @@ -27,8 +28,8 @@ public final class SocksServer { static final int PORT = Integer.parseInt(System.getProperty("port", "1080")); public static void main(String[] args) throws Exception { - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/spdy/client/SpdyClient.java b/example/src/main/java/io/netty/example/spdy/client/SpdyClient.java index cb477a108d3..56077187d3c 100644 --- a/example/src/main/java/io/netty/example/spdy/client/SpdyClient.java +++ b/example/src/main/java/io/netty/example/spdy/client/SpdyClient.java @@ -20,7 +20,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.HttpHeaderNames; @@ -70,11 +71,11 @@ public static void main(String[] args) throws Exception { .build(); HttpResponseClientHandler httpResponseHandler = new HttpResponseClientHandler(); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); - b.group(workerGroup); + b.group(group); b.channel(NioSocketChannel.class); b.option(ChannelOption.SO_KEEPALIVE, true); b.remoteAddress(HOST, PORT); @@ -100,7 +101,7 @@ public static void main(String[] args) throws Exception { // Wait until the connection is closed. channel.close().syncUninterruptibly(); } finally { - workerGroup.shutdownGracefully(); + group.shutdownGracefully(); } } } diff --git a/example/src/main/java/io/netty/example/spdy/server/SpdyServer.java b/example/src/main/java/io/netty/example/spdy/server/SpdyServer.java index 40adeeb4f84..a2b090aa03b 100644 --- a/example/src/main/java/io/netty/example/spdy/server/SpdyServer.java +++ b/example/src/main/java/io/netty/example/spdy/server/SpdyServer.java @@ -19,7 +19,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; @@ -69,8 +70,8 @@ public static void main(String[] args) throws Exception { .build(); // Configure the server. - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); diff --git a/example/src/main/java/io/netty/example/stomp/StompClient.java b/example/src/main/java/io/netty/example/stomp/StompClient.java index 9606027ee7c..f8320a50cea 100644 --- a/example/src/main/java/io/netty/example/stomp/StompClient.java +++ b/example/src/main/java/io/netty/example/stomp/StompClient.java @@ -19,7 +19,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.stomp.StompSubframeAggregator; @@ -41,7 +42,7 @@ public final class StompClient { static final String TOPIC = System.getProperty("topic", "jms.topic.exampleTopic"); public static void main(String[] args) throws Exception { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class); diff --git a/example/src/main/java/io/netty/example/stomp/websocket/StompWebSocketChatServer.java b/example/src/main/java/io/netty/example/stomp/websocket/StompWebSocketChatServer.java index a67edfbe53b..3b5e5cd10c3 100644 --- a/example/src/main/java/io/netty/example/stomp/websocket/StompWebSocketChatServer.java +++ b/example/src/main/java/io/netty/example/stomp/websocket/StompWebSocketChatServer.java @@ -18,7 +18,9 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; public class StompWebSocketChatServer { @@ -26,11 +28,11 @@ public class StompWebSocketChatServer { static final int PORT = Integer.parseInt(System.getProperty("port", "8080")); public void start(final int port) throws Exception { - NioEventLoopGroup boosGroup = new NioEventLoopGroup(1); - NioEventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap bootstrap = new ServerBootstrap() - .group(boosGroup, workerGroup) + .group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new StompWebSocketChatServerInitializer("/chat")); bootstrap.bind(port).addListener(new ChannelFutureListener() { @@ -44,7 +46,7 @@ public void operationComplete(ChannelFuture future) { } }).channel().closeFuture().sync(); } finally { - boosGroup.shutdownGracefully(); + bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } } diff --git a/example/src/main/java/io/netty/example/telnet/TelnetClient.java b/example/src/main/java/io/netty/example/telnet/TelnetClient.java index f75354cfc0b..3aba7e2059e 100644 --- a/example/src/main/java/io/netty/example/telnet/TelnetClient.java +++ b/example/src/main/java/io/netty/example/telnet/TelnetClient.java @@ -19,7 +19,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.ssl.SslContext; @@ -40,7 +41,7 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/telnet/TelnetServer.java b/example/src/main/java/io/netty/example/telnet/TelnetServer.java index 5d0674542ad..f72ac161b45 100644 --- a/example/src/main/java/io/netty/example/telnet/TelnetServer.java +++ b/example/src/main/java/io/netty/example/telnet/TelnetServer.java @@ -17,7 +17,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.logging.LogLevel; @@ -36,8 +37,8 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClient.java b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClient.java index 73381e98815..eba4a1e5862 100644 --- a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClient.java +++ b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClient.java @@ -18,7 +18,9 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.udt.UdtChannel; import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.handler.logging.LogLevel; @@ -44,8 +46,8 @@ public final class ByteEchoClient { public static void main(String[] args) throws Exception { // Configure the client. final ThreadFactory connectFactory = new DefaultThreadFactory("connect"); - final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, - connectFactory, NioUdtProvider.BYTE_PROVIDER); + final EventLoopGroup connectGroup = new MultiThreadIoEventLoopGroup(1, + connectFactory, NioIoHandler.newFactory(NioUdtProvider.BYTE_PROVIDER)); try { final Bootstrap boot = new Bootstrap(); boot.group(connectGroup) diff --git a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServer.java b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServer.java index 750ec663f33..92173e99899 100644 --- a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServer.java +++ b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServer.java @@ -19,7 +19,9 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.udt.UdtChannel; import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.handler.logging.LogLevel; @@ -40,8 +42,10 @@ public final class ByteEchoServer { public static void main(String[] args) throws Exception { final ThreadFactory acceptFactory = new DefaultThreadFactory("accept"); final ThreadFactory connectFactory = new DefaultThreadFactory("connect"); - final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1, acceptFactory, NioUdtProvider.BYTE_PROVIDER); - final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory, NioUdtProvider.BYTE_PROVIDER); + final EventLoopGroup acceptGroup = new MultiThreadIoEventLoopGroup( + 1, acceptFactory, NioIoHandler.newFactory(NioUdtProvider.BYTE_PROVIDER)); + final EventLoopGroup connectGroup = new MultiThreadIoEventLoopGroup( + 1, connectFactory, NioIoHandler.newFactory(NioUdtProvider.BYTE_PROVIDER)); // Configure the server. try { diff --git a/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClient.java b/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClient.java index b2664ee421b..e2e4f7da75b 100644 --- a/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClient.java +++ b/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClient.java @@ -18,7 +18,9 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.udt.UdtChannel; import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.handler.logging.LogLevel; @@ -48,8 +50,8 @@ public static void main(String[] args) throws Exception { // Configure the client. final ThreadFactory connectFactory = new DefaultThreadFactory("connect"); - final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, - connectFactory, NioUdtProvider.MESSAGE_PROVIDER); + final EventLoopGroup connectGroup = new MultiThreadIoEventLoopGroup(1, + connectFactory, NioIoHandler.newFactory(NioUdtProvider.MESSAGE_PROVIDER)); try { final Bootstrap boot = new Bootstrap(); boot.group(connectGroup) diff --git a/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoServer.java b/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoServer.java index 14c56e19ac8..765f2a07f14 100644 --- a/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoServer.java +++ b/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoServer.java @@ -19,7 +19,9 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.udt.UdtChannel; import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.handler.logging.LogLevel; @@ -40,10 +42,12 @@ public final class MsgEchoServer { public static void main(String[] args) throws Exception { final ThreadFactory acceptFactory = new DefaultThreadFactory("accept"); final ThreadFactory connectFactory = new DefaultThreadFactory("connect"); - final NioEventLoopGroup acceptGroup = - new NioEventLoopGroup(1, acceptFactory, NioUdtProvider.MESSAGE_PROVIDER); - final NioEventLoopGroup connectGroup = - new NioEventLoopGroup(1, connectFactory, NioUdtProvider.MESSAGE_PROVIDER); + final EventLoopGroup acceptGroup = + new MultiThreadIoEventLoopGroup( + 1, acceptFactory, NioIoHandler.newFactory(NioUdtProvider.MESSAGE_PROVIDER)); + final EventLoopGroup connectGroup = + new MultiThreadIoEventLoopGroup( + 1, connectFactory, NioIoHandler.newFactory(NioUdtProvider.MESSAGE_PROVIDER)); // Configure the server. try { diff --git a/example/src/main/java/io/netty/example/udt/echo/rendezvous/MsgEchoPeerBase.java b/example/src/main/java/io/netty/example/udt/echo/rendezvous/MsgEchoPeerBase.java index f48de0e7fe2..bba53deea85 100644 --- a/example/src/main/java/io/netty/example/udt/echo/rendezvous/MsgEchoPeerBase.java +++ b/example/src/main/java/io/netty/example/udt/echo/rendezvous/MsgEchoPeerBase.java @@ -18,7 +18,9 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.udt.UdtChannel; import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.handler.logging.LogLevel; @@ -49,8 +51,8 @@ protected MsgEchoPeerBase(final InetSocketAddress self, final InetSocketAddress public void run() throws Exception { // Configure the peer. final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous"); - final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, - connectFactory, NioUdtProvider.MESSAGE_PROVIDER); + final EventLoopGroup connectGroup = new MultiThreadIoEventLoopGroup(1, + connectFactory, NioIoHandler.newFactory(NioUdtProvider.MESSAGE_PROVIDER)); try { final Bootstrap boot = new Bootstrap(); boot.group(connectGroup) diff --git a/example/src/main/java/io/netty/example/udt/echo/rendezvousBytes/ByteEchoPeerBase.java b/example/src/main/java/io/netty/example/udt/echo/rendezvousBytes/ByteEchoPeerBase.java index 8a93b4ced5d..b02b5f36173 100644 --- a/example/src/main/java/io/netty/example/udt/echo/rendezvousBytes/ByteEchoPeerBase.java +++ b/example/src/main/java/io/netty/example/udt/echo/rendezvousBytes/ByteEchoPeerBase.java @@ -18,7 +18,9 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.udt.UdtChannel; import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.handler.logging.LogLevel; @@ -51,8 +53,8 @@ public ByteEchoPeerBase(int messageSize, SocketAddress myAddress, SocketAddress public void run() throws Exception { final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous"); - final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, - connectFactory, NioUdtProvider.BYTE_PROVIDER); + final EventLoopGroup connectGroup = new MultiThreadIoEventLoopGroup(1, + connectFactory, NioIoHandler.newFactory(NioUdtProvider.BYTE_PROVIDER)); try { final Bootstrap bootstrap = new Bootstrap(); bootstrap.group(connectGroup) diff --git a/example/src/main/java/io/netty/example/uptime/UptimeClient.java b/example/src/main/java/io/netty/example/uptime/UptimeClient.java index 4b55dd9da7d..c362ffad4db 100644 --- a/example/src/main/java/io/netty/example/uptime/UptimeClient.java +++ b/example/src/main/java/io/netty/example/uptime/UptimeClient.java @@ -20,7 +20,8 @@ import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.timeout.IdleStateHandler; @@ -44,7 +45,7 @@ public final class UptimeClient { private static final Bootstrap bs = new Bootstrap(); public static void main(String[] args) throws Exception { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); bs.group(group) .channel(NioSocketChannel.class) .remoteAddress(HOST, PORT) diff --git a/example/src/main/java/io/netty/example/uptime/UptimeServer.java b/example/src/main/java/io/netty/example/uptime/UptimeServer.java index 919aa6f50d4..21b070700a1 100644 --- a/example/src/main/java/io/netty/example/uptime/UptimeServer.java +++ b/example/src/main/java/io/netty/example/uptime/UptimeServer.java @@ -19,7 +19,8 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; @@ -38,8 +39,8 @@ private UptimeServer() { public static void main(String[] args) throws Exception { - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/example/src/main/java/io/netty/example/worldclock/WorldClockClient.java b/example/src/main/java/io/netty/example/worldclock/WorldClockClient.java index c1b977f8282..dd0a27aeb26 100644 --- a/example/src/main/java/io/netty/example/worldclock/WorldClockClient.java +++ b/example/src/main/java/io/netty/example/worldclock/WorldClockClient.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.ssl.SslContext; @@ -41,7 +42,7 @@ public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx = ServerUtil.buildSslContext(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Bootstrap b = new Bootstrap(); b.group(group) diff --git a/example/src/main/java/io/netty/example/worldclock/WorldClockServer.java b/example/src/main/java/io/netty/example/worldclock/WorldClockServer.java index 9ac24a5002c..a35a4971a10 100644 --- a/example/src/main/java/io/netty/example/worldclock/WorldClockServer.java +++ b/example/src/main/java/io/netty/example/worldclock/WorldClockServer.java @@ -17,7 +17,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.example.util.ServerUtil; import io.netty.handler.logging.LogLevel; @@ -33,8 +34,8 @@ public final class WorldClockServer { public static void main(String[] args) throws Exception { - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java b/handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java index 9d7d695b407..ab7d540f600 100644 --- a/handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java +++ b/handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java @@ -29,8 +29,9 @@ import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.LineBasedFrameDecoder; @@ -80,7 +81,8 @@ public class ProxyHandlerTest { private static final String BAD_USERNAME = "badUser"; private static final String BAD_PASSWORD = "badPassword"; - static final EventLoopGroup group = new NioEventLoopGroup(3, new DefaultThreadFactory("proxy", true)); + static final EventLoopGroup group = new MultiThreadIoEventLoopGroup( + 3, new DefaultThreadFactory("proxy", true), NioIoHandler.newFactory()); static final SslContext serverSslCtx; static final SslContext clientSslCtx; diff --git a/handler-ssl-ocsp/src/main/java/io/netty/handler/ssl/ocsp/IoTransport.java b/handler-ssl-ocsp/src/main/java/io/netty/handler/ssl/ocsp/IoTransport.java index 85ded8a3a3d..2045154708b 100644 --- a/handler-ssl-ocsp/src/main/java/io/netty/handler/ssl/ocsp/IoTransport.java +++ b/handler-ssl-ocsp/src/main/java/io/netty/handler/ssl/ocsp/IoTransport.java @@ -17,8 +17,8 @@ import io.netty.channel.ChannelFactory; import io.netty.channel.EventLoop; -import io.netty.channel.nio.NioEventLoop; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioDatagramChannel; @@ -36,10 +36,11 @@ public final class IoTransport { private final ChannelFactory datagramChannel; /** - * Default {@link IoTransport} which uses {@link NioEventLoop}, {@link NioSocketChannel} + * Default {@link IoTransport} which uses {@link NioIoHandler}, {@link NioSocketChannel} * and {@link NioDatagramChannel}. */ - public static final IoTransport DEFAULT = new IoTransport(new NioEventLoopGroup(1).next(), + public static final IoTransport DEFAULT = new IoTransport( + new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()).next(), new ChannelFactory() { @Override public SocketChannel newChannel() { diff --git a/handler-ssl-ocsp/src/test/java/io/netty/handler/ssl/ocsp/OcspServerCertificateValidatorTest.java b/handler-ssl-ocsp/src/test/java/io/netty/handler/ssl/ocsp/OcspServerCertificateValidatorTest.java index 0be194159ce..a30779134ca 100644 --- a/handler-ssl-ocsp/src/test/java/io/netty/handler/ssl/ocsp/OcspServerCertificateValidatorTest.java +++ b/handler-ssl-ocsp/src/test/java/io/netty/handler/ssl/ocsp/OcspServerCertificateValidatorTest.java @@ -22,8 +22,9 @@ import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.ssl.SslContext; @@ -42,7 +43,7 @@ class OcspServerCertificateValidatorTest { @Test void connectUsingHttpAndValidateCertificateUsingOcspTest() throws Exception { final AtomicBoolean ocspStatus = new AtomicBoolean(); - EventLoopGroup eventLoopGroup = new NioEventLoopGroup(); + EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { final CountDownLatch latch = new CountDownLatch(1); diff --git a/handler/src/test/java/io/netty/handler/flow/FlowControlHandlerTest.java b/handler/src/test/java/io/netty/handler/flow/FlowControlHandlerTest.java index dd45e640174..6caa9d41e4c 100644 --- a/handler/src/test/java/io/netty/handler/flow/FlowControlHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/flow/FlowControlHandlerTest.java @@ -29,8 +29,9 @@ import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.embedded.EmbeddedChannel; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.ByteToMessageDecoder; @@ -62,7 +63,7 @@ public class FlowControlHandlerTest { @BeforeAll public static void init() { - GROUP = new NioEventLoopGroup(); + GROUP = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); } @AfterAll diff --git a/handler/src/test/java/io/netty/handler/pcap/PcapWriteHandlerTest.java b/handler/src/test/java/io/netty/handler/pcap/PcapWriteHandlerTest.java index b8f1bff98e7..2173bc9faf9 100644 --- a/handler/src/test/java/io/netty/handler/pcap/PcapWriteHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/pcap/PcapWriteHandlerTest.java @@ -31,9 +31,10 @@ import io.netty.channel.ChannelPromise; import io.netty.channel.DefaultChannelId; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.embedded.EmbeddedChannel; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.DatagramChannelConfig; import io.netty.channel.socket.DatagramPacket; @@ -82,7 +83,7 @@ private static void udpV4(boolean sharedOutputStream) throws InterruptedExceptio InetSocketAddress serverAddr = new InetSocketAddress("127.0.0.1", 0); InetSocketAddress clientAddr = new InetSocketAddress("127.0.0.1", 0); - NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(2); + EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory()); // We'll bootstrap a UDP Server to avoid "Network Unreachable errors" when sending UDP Packet. Bootstrap server = new Bootstrap() @@ -187,8 +188,8 @@ public void tcpV4NonOutputStream() throws Exception { private static void tcpV4(final boolean sharedOutputStream) throws Exception { final ByteBuf byteBuf = Unpooled.buffer(); - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup clientGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup clientGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); // Configure the echo server ServerBootstrap sb = new ServerBootstrap(); diff --git a/handler/src/test/java/io/netty/handler/ssl/OpenSslCertificateCompressionTest.java b/handler/src/test/java/io/netty/handler/ssl/OpenSslCertificateCompressionTest.java index 9882c722aad..45bd06cf34b 100644 --- a/handler/src/test/java/io/netty/handler/ssl/OpenSslCertificateCompressionTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/OpenSslCertificateCompressionTest.java @@ -22,10 +22,11 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; -import io.netty.channel.local.LocalEventLoopGroup; +import io.netty.channel.local.LocalIoHandler; import io.netty.channel.local.LocalServerChannel; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import io.netty.handler.ssl.util.SelfSignedCertificate; @@ -310,7 +311,7 @@ public void execute() throws Throwable { } public void runCertCompressionTest(SslContext clientSslContext, SslContext serverSslContext) throws Throwable { - EventLoopGroup group = new LocalEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()); Promise clientPromise = group.next().newPromise(); Promise serverPromise = group.next().newPromise(); try { diff --git a/handler/src/test/java/io/netty/handler/ssl/ParameterizedSslHandlerTest.java b/handler/src/test/java/io/netty/handler/ssl/ParameterizedSslHandlerTest.java index c3da0dc1baa..d0e6fb05d17 100644 --- a/handler/src/test/java/io/netty/handler/ssl/ParameterizedSslHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/ParameterizedSslHandlerTest.java @@ -26,14 +26,15 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; -import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; +import io.netty.channel.local.LocalIoHandler; import io.netty.channel.local.LocalServerChannel; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; @@ -46,6 +47,7 @@ import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.PromiseNotifier; import io.netty.util.internal.EmptyArrays; +import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.ResourcesUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -75,7 +77,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import static io.netty.buffer.ByteBufUtil.writeAscii; -import static io.netty.util.internal.ThreadLocalRandom.current; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -141,7 +142,7 @@ private static void compositeBufSizeEstimationGuaranteesSynchronousWrite( .trustManager(InsecureTrustManagerFactory.INSTANCE) .sslProvider(clientProvider).build(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; try { @@ -323,7 +324,7 @@ public X509Certificate[] getAcceptedIssuers() { ResourcesUtil.getFile(getClass(), "test_unencrypted.pem")) .sslProvider(clientProvider).build(); - NioEventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; try { @@ -423,7 +424,7 @@ private void testCloseNotify(SslProvider clientProvider, SslProvider serverProvi .protocols(SslProtocols.TLS_v1_2) .build(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; try { @@ -524,7 +525,7 @@ public void operationComplete(Future future) { @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS) public void reentryOnHandshakeCompleteNioChannel(SslProvider clientProvider, SslProvider serverProvider) throws Exception { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { Class serverClass = NioServerSocketChannel.class; Class clientClass = NioSocketChannel.class; @@ -547,11 +548,12 @@ public void reentryOnHandshakeCompleteNioChannel(SslProvider clientProvider, Ssl @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS) public void reentryOnHandshakeCompleteLocalChannel(SslProvider clientProvider, SslProvider serverProvider) throws Exception { - EventLoopGroup group = new DefaultEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()); try { Class serverClass = LocalServerChannel.class; Class clientClass = LocalChannel.class; - SocketAddress bindAddress = new LocalAddress(String.valueOf(current().nextLong())); + SocketAddress bindAddress = new LocalAddress(String.valueOf( + PlatformDependent.threadLocalRandom().nextLong())); reentryOnHandshakeComplete(clientProvider, serverProvider, group, bindAddress, serverClass, clientClass, false, false); reentryOnHandshakeComplete(clientProvider, serverProvider, group, bindAddress, diff --git a/handler/src/test/java/io/netty/handler/ssl/RenegotiateTest.java b/handler/src/test/java/io/netty/handler/ssl/RenegotiateTest.java index 210ff4b6bb2..43007059531 100644 --- a/handler/src/test/java/io/netty/handler/ssl/RenegotiateTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/RenegotiateTest.java @@ -22,9 +22,10 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; -import io.netty.channel.local.LocalEventLoopGroup; +import io.netty.channel.local.LocalIoHandler; import io.netty.channel.local.LocalServerChannel; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import io.netty.handler.ssl.util.SelfSignedCertificate; @@ -46,7 +47,7 @@ public void testRenegotiateServer() throws Throwable { final AtomicReference error = new AtomicReference(); final CountDownLatch latch = new CountDownLatch(2); SelfSignedCertificate cert = new SelfSignedCertificate(); - EventLoopGroup group = new LocalEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()); try { final SslContext context = SslContextBuilder.forServer(cert.key(), cert.cert()) .sslProvider(serverSslProvider()) diff --git a/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java b/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java index bdc1351625e..3423d5c5de6 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java @@ -28,8 +28,9 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; @@ -827,7 +828,8 @@ protected void mySetupMutualAuth(final SSLEngineTestParam param, KeyManagerFacto sb = new ServerBootstrap(); cb = new Bootstrap(); - sb.group(new NioEventLoopGroup(), new NioEventLoopGroup()); + sb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()), + new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); sb.channel(NioServerSocketChannel.class); sb.childHandler(new ChannelInitializer() { @Override @@ -872,7 +874,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E } }); - cb.group(new NioEventLoopGroup()); + cb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); cb.channel(NioSocketChannel.class); cb.handler(new ChannelInitializer() { @Override @@ -994,7 +996,8 @@ private Future mySetupClientHostnameValidation(final SSLEngineTestParam pa sb = new ServerBootstrap(); cb = new Bootstrap(); - sb.group(new NioEventLoopGroup(), new NioEventLoopGroup()); + sb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()), + new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); sb.channel(NioServerSocketChannel.class); sb.childHandler(new ChannelInitializer() { @Override @@ -1037,7 +1040,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E }); final Promise clientWritePromise = ImmediateEventExecutor.INSTANCE.newPromise(); - cb.group(new NioEventLoopGroup()); + cb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); cb.channel(NioSocketChannel.class); cb.handler(new ChannelInitializer() { @Override @@ -1182,7 +1185,8 @@ private void mySetupMutualAuth(final SSLEngineTestParam param, sb = new ServerBootstrap(); cb = new Bootstrap(); - sb.group(new NioEventLoopGroup(), new NioEventLoopGroup()); + sb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()), + new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); sb.channel(NioServerSocketChannel.class); sb.childHandler(new ChannelInitializer() { @Override @@ -1224,7 +1228,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc } }); - cb.group(new NioEventLoopGroup()); + cb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); cb.channel(NioSocketChannel.class); cb.handler(new ChannelInitializer() { @Override @@ -1469,7 +1473,7 @@ public void clientInitiatedRenegotiationWithFatalAlertDoesNotInfiniteLoopServer( .ciphers(param.ciphers()) .build()); sb = new ServerBootstrap() - .group(new NioEventLoopGroup(1)) + .group(new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory())) .channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer() { @Override @@ -1530,7 +1534,7 @@ public void channelInactive(ChannelHandlerContext ctx) { .build()); cb = new Bootstrap(); - cb.group(new NioEventLoopGroup(1)) + cb.group(new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory())) .channel(NioSocketChannel.class) .handler(new ChannelInitializer() { @Override @@ -1878,7 +1882,8 @@ protected void setupHandlers(final BufferType type, final boolean delegate, sb = new ServerBootstrap(); cb = new Bootstrap(); - sb.group(new NioEventLoopGroup(), new NioEventLoopGroup()); + sb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()), + new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); sb.channel(NioServerSocketChannel.class); sb.childHandler(new ChannelInitializer() { @Override @@ -1908,7 +1913,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E } }); - cb.group(new NioEventLoopGroup()); + cb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); cb.channel(NioSocketChannel.class); cb.handler(new ChannelInitializer() { @Override @@ -1964,7 +1969,8 @@ public void testMutualAuthSameCertChain(final SSLEngineTestParam param) throws E .ciphers(param.ciphers()).build()); sb = new ServerBootstrap(); - sb.group(new NioEventLoopGroup(), new NioEventLoopGroup()); + sb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()), + new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); sb.channel(NioServerSocketChannel.class); final Promise promise = sb.config().group().next().newPromise(); @@ -2046,7 +2052,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc .sslContextProvider(clientSslContextProvider()) .protocols(param.protocols()).ciphers(param.ciphers()).build()); cb = new Bootstrap(); - cb.group(new NioEventLoopGroup()); + cb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); cb.channel(NioSocketChannel.class); clientChannel = cb.handler(new ChannelInitializer() { @Override @@ -4184,7 +4190,8 @@ public void testMasterKeyLogging(final SSLEngineTestParam param) throws Exceptio try { sb = new ServerBootstrap(); - sb.group(new NioEventLoopGroup(), new NioEventLoopGroup()); + sb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()), + new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); sb.channel(NioServerSocketChannel.class); final Promise promise = sb.config().group().next().newPromise(); diff --git a/handler/src/test/java/io/netty/handler/ssl/SniHandlerTest.java b/handler/src/test/java/io/netty/handler/ssl/SniHandlerTest.java index 25de5476228..1db6e1f807e 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SniHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SniHandlerTest.java @@ -28,6 +28,9 @@ import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.local.LocalIoHandler; +import io.netty.channel.nio.NioIoHandler; import io.netty.handler.codec.TooLongFrameException; import io.netty.util.concurrent.Future; @@ -42,13 +45,11 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; -import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.EventLoopGroup; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; import io.netty.channel.local.LocalServerChannel; -import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.DecoderException; @@ -411,7 +412,7 @@ public void testSniWithApnHandler(SslProvider provider) throws Exception { .add("*.netty.io", nettyContext) .add("sni.fake.site", sniContext).build(); final SniHandler handler = new SniHandler(mapping); - EventLoopGroup group = new NioEventLoopGroup(2); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory()); Channel serverChannel = null; Channel clientChannel = null; try { @@ -491,7 +492,7 @@ public void testReplaceHandler(SslProvider provider) throws Exception { case OPENSSL_REFCNT: final String sniHost = "sni.netty.io"; LocalAddress address = new LocalAddress("testReplaceHandler-" + Math.random()); - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); Channel sc = null; Channel cc = null; SslContext sslContext = null; diff --git a/handler/src/test/java/io/netty/handler/ssl/SslErrorTest.java b/handler/src/test/java/io/netty/handler/ssl/SslErrorTest.java index be73753025e..700b9b0690c 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SslErrorTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SslErrorTest.java @@ -22,7 +22,8 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.logging.LogLevel; @@ -140,7 +141,7 @@ public void testCorrectAlert(SslProvider serverProvider, final SslProvider clien Channel serverChannel = null; Channel clientChannel = null; - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); final Promise promise = group.next().newPromise(); try { serverChannel = new ServerBootstrap().group(group) diff --git a/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java b/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java index 0025e14a130..93b9e38bd66 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java @@ -35,13 +35,14 @@ import io.netty.channel.DefaultChannelId; import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; -import io.netty.channel.local.LocalEventLoopGroup; +import io.netty.channel.local.LocalIoHandler; import io.netty.channel.local.LocalServerChannel; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.ByteToMessageDecoder; @@ -476,7 +477,7 @@ public void testIssueReadAfterWriteFlushActive() throws Exception { @Test @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS) public void testRemoval() throws Exception { - NioEventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; try { @@ -700,7 +701,7 @@ public void writingReadOnlyBufferDoesNotBreakAggregation() throws Exception { final SslContext sslClientCtx = SslContextBuilder.forClient() .trustManager(InsecureTrustManagerFactory.INSTANCE).build(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; final CountDownLatch serverReceiveLatch = new CountDownLatch(1); @@ -771,7 +772,7 @@ public void testCloseOnHandshakeFailure() throws Exception { .trustManager(new SelfSignedCertificate().cert()) .build(); - EventLoopGroup group = new LocalEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); Channel sc = null; Channel cc = null; try { @@ -845,7 +846,7 @@ public void testHandshakeFailedByWriteBeforeChannelActive() throws Exception { .trustManager(InsecureTrustManagerFactory.INSTANCE) .sslProvider(SslProvider.JDK).build(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; final CountDownLatch activeLatch = new CountDownLatch(1); @@ -929,7 +930,7 @@ private static void testHandshakeTimeout0(final boolean startTls) throws Excepti .trustManager(InsecureTrustManagerFactory.INSTANCE) .sslProvider(SslProvider.JDK).build(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; final SslHandler sslHandler = sslClientCtx.newHandler(UnpooledByteBufAllocator.DEFAULT); @@ -1116,7 +1117,7 @@ private static void testHandshakeWithExecutor(Executor executor, SslProvider pro .sslProvider(provider).build(); } - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; final SslHandler clientSslHandler = new SslHandler( @@ -1196,7 +1197,7 @@ private static void testHandshakeTimeoutBecauseExecutorNotExecute(final boolean final SslContext sslServerCtx = SslContextBuilder.forServer(cert.key(), cert.cert()) .sslProvider(SslProvider.JDK).build(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; final SslHandler clientSslHandler = sslClientCtx.newHandler(UnpooledByteBufAllocator.DEFAULT, new Executor() { @@ -1316,7 +1317,7 @@ private static void testSessionTickets(SslProvider provider, String protocol, bo ((OpenSslSessionContext) sslServerCtx.sessionContext()).setTicketKeys(); } - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; final byte[] bytes = new byte[96]; PlatformDependent.threadLocalRandom().nextBytes(bytes); @@ -1496,7 +1497,7 @@ private void failVerification() throws CertificateException { final SslContext sslServerCtx = SslContextBuilder.forServer(cert.key(), cert.cert()) .sslProvider(SslProvider.JDK).build(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; final SslHandler clientSslHandler = sslClientCtx.newHandler(UnpooledByteBufAllocator.DEFAULT); final SslHandler serverSslHandler = sslServerCtx.newHandler(UnpooledByteBufAllocator.DEFAULT); @@ -1610,7 +1611,7 @@ private static void testHandshakeFailureCipherMissmatch(SslProvider provider, bo .ciphers(Collections.singleton(serverCipher)) .sslProvider(provider).build(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; final SslHandler clientSslHandler = sslClientCtx.newHandler(UnpooledByteBufAllocator.DEFAULT); @@ -1724,7 +1725,7 @@ private void testSslCompletionEvents(SslProvider provider, final String protocol .protocols(protocol) .sslProvider(provider).build(); - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); final LinkedBlockingQueue acceptedChannels = new LinkedBlockingQueue(); diff --git a/handler/src/test/java/io/netty/handler/traffic/FileRegionThrottleTest.java b/handler/src/test/java/io/netty/handler/traffic/FileRegionThrottleTest.java index 58481e7d555..8d4ed5c9de5 100644 --- a/handler/src/test/java/io/netty/handler/traffic/FileRegionThrottleTest.java +++ b/handler/src/test/java/io/netty/handler/traffic/FileRegionThrottleTest.java @@ -26,7 +26,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.DefaultFileRegion; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; @@ -85,7 +86,7 @@ public static void beforeClass() throws IOException { @BeforeEach public void setUp() { - group = new NioEventLoopGroup(); + group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); } @AfterEach diff --git a/handler/src/test/java/io/netty/handler/traffic/TrafficShapingHandlerTest.java b/handler/src/test/java/io/netty/handler/traffic/TrafficShapingHandlerTest.java index f95ad8b43e2..53de7630de7 100644 --- a/handler/src/test/java/io/netty/handler/traffic/TrafficShapingHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/traffic/TrafficShapingHandlerTest.java @@ -26,9 +26,11 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; -import io.netty.channel.DefaultEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; +import io.netty.channel.local.LocalIoHandler; import io.netty.channel.local.LocalServerChannel; import io.netty.util.Attribute; import io.netty.util.CharsetUtil; @@ -42,7 +44,7 @@ public class TrafficShapingHandlerTest { private static final long READ_LIMIT_BYTES_PER_SECOND = 1; private static final ScheduledExecutorService SES = Executors.newSingleThreadScheduledExecutor(); - private static final DefaultEventLoopGroup GROUP = new DefaultEventLoopGroup(1); + private static final EventLoopGroup GROUP = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); @AfterAll public static void destroy() { diff --git a/microbench/src/main/java/io/netty/microbench/channel/epoll/EpollSocketChannelBenchmark.java b/microbench/src/main/java/io/netty/microbench/channel/epoll/EpollSocketChannelBenchmark.java index 268c08ed531..343f21bd5c5 100644 --- a/microbench/src/main/java/io/netty/microbench/channel/epoll/EpollSocketChannelBenchmark.java +++ b/microbench/src/main/java/io/netty/microbench/channel/epoll/EpollSocketChannelBenchmark.java @@ -23,7 +23,9 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPromise; -import io.netty.channel.epoll.EpollEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.epoll.EpollIoHandler; import io.netty.channel.epoll.EpollServerSocketChannel; import io.netty.channel.epoll.EpollSocketChannel; import io.netty.microbench.util.AbstractMicrobenchmark; @@ -41,7 +43,7 @@ public class EpollSocketChannelBenchmark extends AbstractMicrobenchmark { public void run() { } }; - private EpollEventLoopGroup group; + private EventLoopGroup group; private Channel serverChan; private Channel chan; private ByteBuf abyte; @@ -49,7 +51,7 @@ public void run() { } @Setup public void setup() throws Exception { - group = new EpollEventLoopGroup(1); + group = new MultiThreadIoEventLoopGroup(1, EpollIoHandler.newFactory()); // add an arbitrary timeout to make the timer reschedule future = group.schedule(new Runnable() { diff --git a/microbench/src/main/java/io/netty/util/concurrent/ScheduleFutureTaskBenchmark.java b/microbench/src/main/java/io/netty/util/concurrent/ScheduleFutureTaskBenchmark.java index 2b0e7b22ca6..0d0a2684cb0 100644 --- a/microbench/src/main/java/io/netty/util/concurrent/ScheduleFutureTaskBenchmark.java +++ b/microbench/src/main/java/io/netty/util/concurrent/ScheduleFutureTaskBenchmark.java @@ -18,6 +18,8 @@ import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; @@ -29,7 +31,6 @@ import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; -import io.netty.channel.nio.NioEventLoopGroup; import io.netty.microbench.util.AbstractMicrobenchmark; @Warmup(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS) @@ -54,7 +55,8 @@ public static class ThreadState { @Setup(Level.Trial) public void reset() { - eventLoop = (AbstractScheduledEventExecutor) new NioEventLoopGroup(1).next(); + eventLoop = (AbstractScheduledEventExecutor) new MultiThreadIoEventLoopGroup( + 1, NioIoHandler.newFactory()).next(); } @Setup(Level.Invocation) diff --git a/microbench/src/main/java/io/netty/util/concurrent/ScheduledFutureTaskDeadlineBenchmark.java b/microbench/src/main/java/io/netty/util/concurrent/ScheduledFutureTaskDeadlineBenchmark.java index bcb8ae67896..152990a4c3b 100644 --- a/microbench/src/main/java/io/netty/util/concurrent/ScheduledFutureTaskDeadlineBenchmark.java +++ b/microbench/src/main/java/io/netty/util/concurrent/ScheduledFutureTaskDeadlineBenchmark.java @@ -15,7 +15,8 @@ */ package io.netty.util.concurrent; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.microbench.util.AbstractMicrobenchmark; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; @@ -41,7 +42,8 @@ public static class ThreadState { @Setup(Level.Trial) public void reset() { - eventLoop = (AbstractScheduledEventExecutor) new NioEventLoopGroup(1).next(); + eventLoop = (AbstractScheduledEventExecutor) new MultiThreadIoEventLoopGroup( + 1, NioIoHandler.newFactory()).next(); future = (ScheduledFutureTask) eventLoop.schedule(new Runnable() { @Override public void run() { diff --git a/resolver-dns/src/test/java/io/netty/resolver/dns/DefaultAuthoritativeDnsServerCacheTest.java b/resolver-dns/src/test/java/io/netty/resolver/dns/DefaultAuthoritativeDnsServerCacheTest.java index 3bc95342d1a..dff90d7b0c1 100644 --- a/resolver-dns/src/test/java/io/netty/resolver/dns/DefaultAuthoritativeDnsServerCacheTest.java +++ b/resolver-dns/src/test/java/io/netty/resolver/dns/DefaultAuthoritativeDnsServerCacheTest.java @@ -18,7 +18,8 @@ import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.EventLoop; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.local.LocalIoHandler; import io.netty.util.NetUtil; import org.junit.jupiter.api.Test; @@ -74,7 +75,7 @@ public void testExpireWithDifferentTTLs() { } private static void testExpireWithTTL0(int days) { - EventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); try { EventLoop loop = group.next(); @@ -91,7 +92,7 @@ public void testAddMultipleDnsServerForSameHostname() throws Exception { InetAddress.getByAddress("ns1", new byte[] { 10, 0, 0, 1 }), 53); InetSocketAddress resolved2 = new InetSocketAddress( InetAddress.getByAddress("ns2", new byte[] { 10, 0, 0, 2 }), 53); - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); try { EventLoop loop = group.next(); @@ -115,7 +116,7 @@ public void testUnresolvedReplacedByResolved() throws Exception { InetAddress.getByAddress("ns2", new byte[] { 10, 0, 0, 2 }), 53); InetSocketAddress resolved2 = new InetSocketAddress( InetAddress.getByAddress("ns1", new byte[] { 10, 0, 0, 1 }), 53); - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); try { EventLoop loop = group.next(); diff --git a/resolver-dns/src/test/java/io/netty/resolver/dns/DefaultDnsCacheTest.java b/resolver-dns/src/test/java/io/netty/resolver/dns/DefaultDnsCacheTest.java index 71f5328a3f2..39e54781ddb 100644 --- a/resolver-dns/src/test/java/io/netty/resolver/dns/DefaultDnsCacheTest.java +++ b/resolver-dns/src/test/java/io/netty/resolver/dns/DefaultDnsCacheTest.java @@ -15,11 +15,10 @@ */ package io.netty.resolver.dns; -import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.EventLoop; import io.netty.channel.EventLoopGroup; - -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.util.NetUtil; import org.junit.jupiter.api.Test; @@ -46,7 +45,7 @@ public class DefaultDnsCacheTest { public void testExpire() throws Throwable { InetAddress addr1 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 1 }); InetAddress addr2 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 2 }); - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); try { EventLoop loop = group.next(); @@ -81,7 +80,7 @@ public void testExpireWithDifferentTTLs() { } private static void testExpireWithTTL0(int days) { - EventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); try { EventLoop loop = group.next(); @@ -94,7 +93,7 @@ private static void testExpireWithTTL0(int days) { @Test public void testExpireWithToBigMinTTL() { - EventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); try { EventLoop loop = group.next(); @@ -109,7 +108,7 @@ public void testExpireWithToBigMinTTL() { public void testAddMultipleAddressesForSameHostname() throws Exception { InetAddress addr1 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 1 }); InetAddress addr2 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 2 }); - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); try { EventLoop loop = group.next(); @@ -129,7 +128,7 @@ public void testAddMultipleAddressesForSameHostname() throws Exception { @Test public void testAddSameAddressForSameHostname() throws Exception { InetAddress addr1 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 1 }); - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); try { EventLoop loop = group.next(); @@ -154,7 +153,7 @@ private static void assertEntry(DnsCacheEntry entry, InetAddress address) { public void testCacheFailed() throws Exception { InetAddress addr1 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 1 }); InetAddress addr2 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 2 }); - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); try { EventLoop loop = group.next(); @@ -183,7 +182,7 @@ public void testCacheFailed() throws Exception { public void testDotHandling() throws Exception { InetAddress addr1 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 1 }); InetAddress addr2 = InetAddress.getByAddress(new byte[] { 10, 0, 0, 2 }); - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); try { EventLoop loop = group.next(); @@ -207,7 +206,7 @@ public void testDotHandling() throws Exception { @Test public void testCacheExceptionIsSafe() throws Exception { - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); try { EventLoop loop = group.next(); diff --git a/resolver-dns/src/test/java/io/netty/resolver/dns/DnsAddressResolverGroupTest.java b/resolver-dns/src/test/java/io/netty/resolver/dns/DnsAddressResolverGroupTest.java index 758bfcc7f77..ec7da5b4a53 100644 --- a/resolver-dns/src/test/java/io/netty/resolver/dns/DnsAddressResolverGroupTest.java +++ b/resolver-dns/src/test/java/io/netty/resolver/dns/DnsAddressResolverGroupTest.java @@ -17,7 +17,9 @@ import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.EventLoop; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.resolver.AddressResolver; import io.netty.util.concurrent.Future; @@ -35,7 +37,7 @@ public class DnsAddressResolverGroupTest { @Test public void testUseConfiguredEventLoop() throws InterruptedException { - NioEventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); final EventLoop loop = group.next(); DefaultEventLoopGroup defaultEventLoopGroup = new DefaultEventLoopGroup(1); DnsNameResolverBuilder builder = new DnsNameResolverBuilder() diff --git a/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverBuilderTest.java b/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverBuilderTest.java index e62c69767ec..f8c90e3a364 100644 --- a/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverBuilderTest.java +++ b/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverBuilderTest.java @@ -17,7 +17,8 @@ import io.netty.channel.EventLoop; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.handler.codec.dns.DnsRecord; import org.junit.jupiter.api.AfterAll; @@ -33,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; class DnsNameResolverBuilderTest { - private static final EventLoopGroup GROUP = new NioEventLoopGroup(1); + private static final EventLoopGroup GROUP = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); private DnsNameResolverBuilder builder; private DnsNameResolver resolver; diff --git a/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverClientSubnetTest.java b/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverClientSubnetTest.java index f707e6fcbb7..3353139be00 100644 --- a/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverClientSubnetTest.java +++ b/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverClientSubnetTest.java @@ -16,7 +16,8 @@ package io.netty.resolver.dns; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.handler.codec.dns.DefaultDnsOptEcsRecord; import io.netty.handler.codec.dns.DnsRecord; @@ -37,7 +38,7 @@ public class DnsNameResolverClientSubnetTest { @Disabled @Test public void testSubnetQuery() throws Exception { - EventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); DnsNameResolver resolver = newResolver(group).build(); try { // Same as: diff --git a/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverTest.java b/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverTest.java index d2eb64b80b8..21825f2e2c2 100644 --- a/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverTest.java +++ b/resolver-dns/src/test/java/io/netty/resolver/dns/DnsNameResolverTest.java @@ -24,8 +24,9 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.EventLoop; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.ReflectiveChannelFactory; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.InternetProtocolFamily; @@ -378,7 +379,7 @@ public class DnsNameResolverTest { } private static final TestDnsServer dnsServer = new TestDnsServer(DOMAINS_ALL); - private static final EventLoopGroup group = new NioEventLoopGroup(1); + private static final EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); private static DnsNameResolverBuilder newResolver(boolean decodeToUnicode) { return newResolver(decodeToUnicode, null); @@ -1408,7 +1409,7 @@ private static void testRecursiveResolveCache(boolean cache) cache ? new DefaultAuthoritativeDnsServerCache() : NoopAuthoritativeDnsServerCache.INSTANCE); TestRecursiveCacheDnsQueryLifecycleObserverFactory lifecycleObserverFactory = new TestRecursiveCacheDnsQueryLifecycleObserverFactory(); - EventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); final DnsNameResolver resolver = new DnsNameResolver( group.next(), new ReflectiveChannelFactory(NioDatagramChannel.class), NoopDnsCache.INSTANCE, nsCache, lifecycleObserverFactory, 3000, ResolvedAddressTypes.IPV4_ONLY, true, @@ -1566,7 +1567,7 @@ protected DnsMessage filterMessage(DnsMessage message) { } }; redirectServer.start(); - EventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); final DnsNameResolver resolver = new DnsNameResolver( group.next(), new ReflectiveChannelFactory(NioDatagramChannel.class), cache, authoritativeDnsServerCache, NoopDnsQueryLifecycleObserverFactory.INSTANCE, 2000, @@ -1702,7 +1703,7 @@ private ResourceRecord newARecord(InetSocketAddress address) { } }; redirectServer.start(); - EventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); final List cached = new CopyOnWriteArrayList(); final AuthoritativeDnsServerCache authoritativeDnsServerCache = new AuthoritativeDnsServerCache() { @@ -1832,7 +1833,7 @@ private ResourceRecord newARecord(InetSocketAddress address) { } }; redirectServer.start(); - EventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); final List cached = new CopyOnWriteArrayList(); final AuthoritativeDnsServerCache authoritativeDnsServerCache = new AuthoritativeDnsServerCache() { @@ -4222,7 +4223,7 @@ protected DnsMessage filterMessage(DnsMessage message) { } }; server.start(); - EventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); final DnsNameResolver resolver = new DnsNameResolver( group.next(), new ReflectiveChannelFactory(NioDatagramChannel.class), diff --git a/resolver-dns/src/test/java/io/netty/resolver/dns/SearchDomainTest.java b/resolver-dns/src/test/java/io/netty/resolver/dns/SearchDomainTest.java index 98b0a689ec6..f87a7252498 100644 --- a/resolver-dns/src/test/java/io/netty/resolver/dns/SearchDomainTest.java +++ b/resolver-dns/src/test/java/io/netty/resolver/dns/SearchDomainTest.java @@ -16,7 +16,8 @@ package io.netty.resolver.dns; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.util.concurrent.Future; import org.junit.jupiter.api.AfterEach; @@ -58,7 +59,7 @@ private DnsNameResolverBuilder newResolver() { @BeforeEach public void before() { - group = new NioEventLoopGroup(1); + group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); } @AfterEach diff --git a/testsuite-autobahn/src/main/java/io/netty/testsuite/autobahn/AutobahnServer.java b/testsuite-autobahn/src/main/java/io/netty/testsuite/autobahn/AutobahnServer.java index 02fbc9b7ea8..52ae74ac10e 100644 --- a/testsuite-autobahn/src/main/java/io/netty/testsuite/autobahn/AutobahnServer.java +++ b/testsuite-autobahn/src/main/java/io/netty/testsuite/autobahn/AutobahnServer.java @@ -20,7 +20,8 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; /** @@ -36,8 +37,8 @@ public AutobahnServer(int port) { } public void run() throws Exception { - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) diff --git a/testsuite-http2/src/main/java/io/netty/testsuite/http2/Http2Server.java b/testsuite-http2/src/main/java/io/netty/testsuite/http2/Http2Server.java index eb8b3b27d23..89da3fbf909 100644 --- a/testsuite-http2/src/main/java/io/netty/testsuite/http2/Http2Server.java +++ b/testsuite-http2/src/main/java/io/netty/testsuite/http2/Http2Server.java @@ -20,7 +20,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; @@ -39,7 +40,7 @@ public final class Http2Server { void run() throws Exception { // Configure the server. - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); diff --git a/testsuite-native-image-client/src/main/java/io/netty/testsuite/svm/client/DnsNativeClient.java b/testsuite-native-image-client/src/main/java/io/netty/testsuite/svm/client/DnsNativeClient.java index afbbd61eb14..a1d7a4a4205 100644 --- a/testsuite-native-image-client/src/main/java/io/netty/testsuite/svm/client/DnsNativeClient.java +++ b/testsuite-native-image-client/src/main/java/io/netty/testsuite/svm/client/DnsNativeClient.java @@ -15,7 +15,9 @@ */ package io.netty.testsuite.svm.client; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.resolver.AddressResolver; import io.netty.resolver.dns.DnsAddressResolverGroup; @@ -35,7 +37,8 @@ private DnsNativeClient() { } public static void main(String[] args) throws Exception { - NioEventLoopGroup group = new NioEventLoopGroup(1, new DefaultThreadFactory("netty")); + EventLoopGroup group = new MultiThreadIoEventLoopGroup( + 1, new DefaultThreadFactory("netty"), NioIoHandler.newFactory()); DnsAddressResolverGroup resolverGroup = new DnsAddressResolverGroup(NioDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault()); diff --git a/testsuite-native-image/src/main/java/io/netty/testsuite/svm/HttpNativeServer.java b/testsuite-native-image/src/main/java/io/netty/testsuite/svm/HttpNativeServer.java index 8b3b16eec21..9a1c412aebb 100644 --- a/testsuite-native-image/src/main/java/io/netty/testsuite/svm/HttpNativeServer.java +++ b/testsuite-native-image/src/main/java/io/netty/testsuite/svm/HttpNativeServer.java @@ -19,7 +19,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; @@ -38,8 +39,8 @@ private HttpNativeServer() { public static void main(String[] args) throws Exception { // Configure the server. - EventLoopGroup bossGroup = new NioEventLoopGroup(1); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); // Control status. boolean serverStartSucess = false; try { diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/sctp/SctpTestPermutation.java b/testsuite/src/main/java/io/netty/testsuite/transport/sctp/SctpTestPermutation.java index 7fb3508eddb..189e981c90a 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/sctp/SctpTestPermutation.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/sctp/SctpTestPermutation.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.oio.OioEventLoopGroup; import io.netty.channel.sctp.nio.NioSctpChannel; import io.netty.channel.sctp.nio.NioSctpServerChannel; @@ -37,10 +38,10 @@ public final class SctpTestPermutation { private static final int BOSSES = 2; private static final int WORKERS = 3; - private static final EventLoopGroup nioBossGroup = - new NioEventLoopGroup(BOSSES, new DefaultThreadFactory("testsuite-sctp-nio-boss", true)); - private static final EventLoopGroup nioWorkerGroup = - new NioEventLoopGroup(WORKERS, new DefaultThreadFactory("testsuite-sctp-nio-worker", true)); + private static final EventLoopGroup nioBossGroup = new MultiThreadIoEventLoopGroup( + BOSSES, new DefaultThreadFactory("testsuite-sctp-nio-boss", true), NioIoHandler.newFactory()); + private static final EventLoopGroup nioWorkerGroup = new MultiThreadIoEventLoopGroup( + WORKERS, new DefaultThreadFactory("testsuite-sctp-nio-worker", true), NioIoHandler.newFactory()); private static final EventLoopGroup oioBossGroup = new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-sctp-oio-boss", true)); private static final EventLoopGroup oioWorkerGroup = diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketChannelNotYetConnectedTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketChannelNotYetConnectedTest.java index 13171a83dfb..7eeeee434e6 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketChannelNotYetConnectedTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketChannelNotYetConnectedTest.java @@ -22,7 +22,9 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.ByteToMessageDecoder; @@ -86,7 +88,7 @@ public void readMustBePendingUntilChannelIsActive(TestInfo info) throws Throwabl run(info, new Runner() { @Override public void run(Bootstrap bootstrap) throws Throwable { - NioEventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); ServerBootstrap sb = new ServerBootstrap().group(group); Channel serverChannel = sb.childHandler(new ChannelInboundHandlerAdapter() { @Override diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketMultipleConnectTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketMultipleConnectTest.java index 3019e6bca14..2224a259b46 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketMultipleConnectTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketMultipleConnectTest.java @@ -20,7 +20,9 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.IoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.util.NetUtil; import org.junit.jupiter.api.Test; @@ -75,7 +77,8 @@ protected List>(); for (TestsuitePermutation.BootstrapComboFactory comboFactory : SocketTestPermutation.INSTANCE.socketWithFastOpen()) { - if (comboFactory.newClientInstance().config().group() instanceof NioEventLoopGroup) { + EventLoopGroup group = comboFactory.newClientInstance().config().group(); + if (group instanceof IoEventLoopGroup && ((IoEventLoopGroup) group).isIoType(NioIoHandler.class)) { factories.add(comboFactory); } } diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java index cace51b2ec5..4050608fdd2 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java @@ -22,7 +22,8 @@ import io.netty.channel.ChannelFactory; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.oio.OioEventLoopGroup; import io.netty.channel.socket.InternetProtocolFamily; import io.netty.channel.socket.nio.NioDatagramChannel; @@ -60,10 +61,10 @@ public class SocketTestPermutation { protected static final int OIO_SO_TIMEOUT = 10; // Use short timeout for faster runs. - protected final EventLoopGroup nioBossGroup = - new NioEventLoopGroup(BOSSES, new DefaultThreadFactory("testsuite-nio-boss", true)); - protected final EventLoopGroup nioWorkerGroup = - new NioEventLoopGroup(WORKERS, new DefaultThreadFactory("testsuite-nio-worker", true)); + protected final EventLoopGroup nioBossGroup = new MultiThreadIoEventLoopGroup( + BOSSES, new DefaultThreadFactory("testsuite-nio-boss", true), NioIoHandler.newFactory()); + protected final EventLoopGroup nioWorkerGroup = new MultiThreadIoEventLoopGroup( + WORKERS, new DefaultThreadFactory("testsuite-nio-worker", true), NioIoHandler.newFactory()); protected final EventLoopGroup oioBossGroup = new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-oio-boss", true)); protected final EventLoopGroup oioWorkerGroup = diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java index 75e34213bf4..598257ee2d0 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java @@ -21,10 +21,12 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.DefaultChannelGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.udt.UdtChannel; import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.handler.codec.DelimiterBasedFrameDecoder; @@ -72,8 +74,8 @@ static class Client implements Runnable { public void run() { final Bootstrap boot = new Bootstrap(); final ThreadFactory clientFactory = new DefaultThreadFactory("client"); - final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, - clientFactory, NioUdtProvider.BYTE_PROVIDER); + final EventLoopGroup connectGroup = new MultiThreadIoEventLoopGroup(1, + clientFactory, NioIoHandler.newFactory(NioUdtProvider.BYTE_PROVIDER)); try { boot.group(connectGroup) .channelFactory(NioUdtProvider.BYTE_CONNECTOR) @@ -198,10 +200,10 @@ public void run() { final ServerBootstrap boot = new ServerBootstrap(); final ThreadFactory acceptFactory = new DefaultThreadFactory("accept"); final ThreadFactory serverFactory = new DefaultThreadFactory("server"); - final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1, - acceptFactory, NioUdtProvider.BYTE_PROVIDER); - final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, - serverFactory, NioUdtProvider.BYTE_PROVIDER); + final EventLoopGroup acceptGroup = new MultiThreadIoEventLoopGroup(1, + acceptFactory, NioIoHandler.newFactory(NioUdtProvider.BYTE_PROVIDER)); + final EventLoopGroup connectGroup = new MultiThreadIoEventLoopGroup(1, + serverFactory, NioIoHandler.newFactory(NioUdtProvider.BYTE_PROVIDER)); try { boot.group(acceptGroup, connectGroup) .channelFactory(NioUdtProvider.BYTE_ACCEPTOR) diff --git a/transport-blockhound-tests/src/test/java/io/netty/util/internal/NettyBlockHoundIntegrationTest.java b/transport-blockhound-tests/src/test/java/io/netty/util/internal/NettyBlockHoundIntegrationTest.java index a005095d821..e51864e1409 100644 --- a/transport-blockhound-tests/src/test/java/io/netty/util/internal/NettyBlockHoundIntegrationTest.java +++ b/transport-blockhound-tests/src/test/java/io/netty/util/internal/NettyBlockHoundIntegrationTest.java @@ -27,7 +27,8 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; @@ -301,7 +302,7 @@ public void testSslHandlerWrapAllowsBlockingCalls() throws Exception { .sslProvider(SslProvider.JDK) .build(); final SslHandler sslHandler = sslClientCtx.newHandler(UnpooledByteBufAllocator.DEFAULT); - final EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); final CountDownLatch activeLatch = new CountDownLatch(1); final AtomicReference error = new AtomicReference<>(); @@ -410,7 +411,7 @@ public void testHostsFileParser_Parse() throws InterruptedException { @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testUnixResolverDnsServerAddressStreamProvider_ParseEtcResolverSearchDomainsAndOptions() throws InterruptedException { - NioEventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); try { DnsNameResolverBuilder builder = new DnsNameResolverBuilder(group.next()) .channelFactory(NioDatagramChannel::new); @@ -496,7 +497,7 @@ private static void testHandshakeWithExecutor(Executor executor, String tlsVersi private static void testHandshake(SslContext sslClientCtx, SslHandler clientSslHandler, SslHandler serverSslHandler) throws Exception { - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); Channel sc = null; Channel cc = null; try { diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramUnicastTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramUnicastTest.java index ba1970f9512..f10bc5226ef 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramUnicastTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramUnicastTest.java @@ -23,6 +23,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOption; import io.netty.channel.FixedRecvByteBufAllocator; +import io.netty.channel.IoEventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.InternetProtocolFamily; @@ -112,11 +113,14 @@ public void testSendAndReceiveSegmentedDatagramPacketComposite(Bootstrap sb, Boo private void testSegmentedDatagramPacket(Bootstrap sb, Bootstrap cb, boolean composite, boolean gro) throws Throwable { - if (!(cb.group() instanceof EpollEventLoopGroup)) { + if (!(cb.group() instanceof IoEventLoopGroup && + ((IoEventLoopGroup) cb.group()).isIoType(EpollIoHandler.class))) { // Only supported for the native epoll transport. return; } - if (gro && !(sb.group() instanceof EpollEventLoopGroup)) { + + if (gro && !(sb.group() instanceof IoEventLoopGroup) && + ((IoEventLoopGroup) sb.group()).isIoType(EpollIoHandler.class)) { // Only supported for the native epoll transport. return; } diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketMultipleConnectTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketMultipleConnectTest.java index b70313545ed..bdc9ae4e4c0 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketMultipleConnectTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketMultipleConnectTest.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.IoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.socket.SocketMultipleConnectTest; @@ -34,9 +35,15 @@ protected List comboFactory : EpollSocketTestPermutation.INSTANCE.socketWithFastOpen()) { EventLoopGroup group = comboFactory.newClientInstance().config().group(); - if (group instanceof NioEventLoopGroup || group instanceof EpollEventLoopGroup) { + if (group instanceof IoEventLoopGroup && ((IoEventLoopGroup) group).isIoType(NioIoHandler.class)) { factories.add(comboFactory); } + if (group instanceof IoEventLoopGroup) { + IoEventLoopGroup ioGroup = (IoEventLoopGroup) group; + if (ioGroup.isIoType(NioIoHandler.class) || ioGroup.isIoType(EpollIoHandler.class)) { + factories.add(comboFactory); + } + } } return factories; } diff --git a/transport-native-kqueue/src/test/java/io/netty/channel/kqueue/KQueueSocketMultipleConnectTest.java b/transport-native-kqueue/src/test/java/io/netty/channel/kqueue/KQueueSocketMultipleConnectTest.java index dfad86ba862..f4397fc5aac 100644 --- a/transport-native-kqueue/src/test/java/io/netty/channel/kqueue/KQueueSocketMultipleConnectTest.java +++ b/transport-native-kqueue/src/test/java/io/netty/channel/kqueue/KQueueSocketMultipleConnectTest.java @@ -18,7 +18,8 @@ import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.IoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.testsuite.transport.socket.SocketMultipleConnectTest; @@ -33,8 +34,11 @@ protected List comboFactory : KQueueSocketTestPermutation.INSTANCE.socket()) { EventLoopGroup group = comboFactory.newClientInstance().config().group(); - if (group instanceof NioEventLoopGroup || group instanceof KQueueEventLoopGroup) { - factories.add(comboFactory); + if (group instanceof IoEventLoopGroup) { + IoEventLoopGroup ioGroup = (IoEventLoopGroup) group; + if (ioGroup.isIoType(NioIoHandler.class) || ioGroup.isIoType(KQueueIoHandler.class)) { + factories.add(comboFactory); + } } } return factories; diff --git a/transport-sctp/src/test/java/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java b/transport-sctp/src/test/java/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java index 2eb1892a543..7b60eda6f58 100644 --- a/transport-sctp/src/test/java/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java +++ b/transport-sctp/src/test/java/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java @@ -16,7 +16,8 @@ package io.netty.channel.sctp.nio; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.sctp.SctpChannel; import io.netty.channel.sctp.SctpLimitStreamsTest; import io.netty.channel.sctp.SctpServerChannel; @@ -24,7 +25,7 @@ public class NioSctpLimitStreamsTest extends SctpLimitStreamsTest { @Override protected EventLoopGroup newEventLoopGroup() { - return new NioEventLoopGroup(); + return new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); } @Override diff --git a/transport-udt/src/test/java/io/netty/test/udt/bench/xfer/UdtNetty.java b/transport-udt/src/test/java/io/netty/test/udt/bench/xfer/UdtNetty.java index 36cdbd68906..69889562061 100644 --- a/transport-udt/src/test/java/io/netty/test/udt/bench/xfer/UdtNetty.java +++ b/transport-udt/src/test/java/io/netty/test/udt/bench/xfer/UdtNetty.java @@ -22,7 +22,9 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.test.udt.util.CustomReporter; import io.netty.test.udt.util.EchoMessageHandler; @@ -92,10 +94,10 @@ public static void main(final String[] args) throws Exception { final ChannelHandler handler1 = new EchoMessageHandler(rate, size); final ChannelHandler handler2 = new EchoMessageHandler(null, size); - final NioEventLoopGroup group1 = new NioEventLoopGroup( - 1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER); - final NioEventLoopGroup group2 = new NioEventLoopGroup( - 1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER); + final EventLoopGroup group1 = new MultiThreadIoEventLoopGroup( + 1, Executors.defaultThreadFactory(), NioIoHandler.newFactory(NioUdtProvider.MESSAGE_PROVIDER)); + final EventLoopGroup group2 = new MultiThreadIoEventLoopGroup( + 1, Executors.defaultThreadFactory(), NioIoHandler.newFactory(NioUdtProvider.MESSAGE_PROVIDER)); final Bootstrap peerBoot1 = new Bootstrap(); peerBoot1.group(group1) diff --git a/transport-udt/src/test/java/io/netty/test/udt/nio/NioUdtByteRendezvousChannelTest.java b/transport-udt/src/test/java/io/netty/test/udt/nio/NioUdtByteRendezvousChannelTest.java index 4ab18a08b30..2b6c2a607ba 100644 --- a/transport-udt/src/test/java/io/netty/test/udt/nio/NioUdtByteRendezvousChannelTest.java +++ b/transport-udt/src/test/java/io/netty/test/udt/nio/NioUdtByteRendezvousChannelTest.java @@ -20,7 +20,9 @@ import com.yammer.metrics.core.Meter; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.udt.nio.NioUdtByteRendezvousChannel; import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.test.udt.util.EchoByteHandler; @@ -74,10 +76,10 @@ public void basicEcho() throws Exception { final EchoByteHandler handler1 = new EchoByteHandler(rate1, messageSize); final EchoByteHandler handler2 = new EchoByteHandler(rate2, messageSize); - final NioEventLoopGroup group1 = new NioEventLoopGroup( - 1, Executors.defaultThreadFactory(), NioUdtProvider.BYTE_PROVIDER); - final NioEventLoopGroup group2 = new NioEventLoopGroup( - 1, Executors.defaultThreadFactory(), NioUdtProvider.BYTE_PROVIDER); + final EventLoopGroup group1 = new MultiThreadIoEventLoopGroup( + 1, Executors.defaultThreadFactory(), NioIoHandler.newFactory(NioUdtProvider.BYTE_PROVIDER)); + final EventLoopGroup group2 = new MultiThreadIoEventLoopGroup( + 1, Executors.defaultThreadFactory(), NioIoHandler.newFactory(NioUdtProvider.BYTE_PROVIDER)); final Bootstrap boot1 = new Bootstrap(); boot1.group(group1) diff --git a/transport-udt/src/test/java/io/netty/test/udt/nio/NioUdtMessageRendezvousChannelTest.java b/transport-udt/src/test/java/io/netty/test/udt/nio/NioUdtMessageRendezvousChannelTest.java index 8c2b90f16b7..9167cc35155 100644 --- a/transport-udt/src/test/java/io/netty/test/udt/nio/NioUdtMessageRendezvousChannelTest.java +++ b/transport-udt/src/test/java/io/netty/test/udt/nio/NioUdtMessageRendezvousChannelTest.java @@ -20,7 +20,9 @@ import com.yammer.metrics.core.Meter; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.udt.nio.NioUdtMessageRendezvousChannel; import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.test.udt.util.EchoMessageHandler; @@ -77,10 +79,10 @@ public void basicEcho() throws Exception { final EchoMessageHandler handler1 = new EchoMessageHandler(rate1, messageSize); final EchoMessageHandler handler2 = new EchoMessageHandler(rate2, messageSize); - final NioEventLoopGroup group1 = new NioEventLoopGroup( - 1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER); - final NioEventLoopGroup group2 = new NioEventLoopGroup( - 1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER); + final EventLoopGroup group1 = new MultiThreadIoEventLoopGroup( + 1, Executors.defaultThreadFactory(), NioIoHandler.newFactory(NioUdtProvider.MESSAGE_PROVIDER)); + final EventLoopGroup group2 = new MultiThreadIoEventLoopGroup( + 1, Executors.defaultThreadFactory(), NioIoHandler.newFactory(NioUdtProvider.MESSAGE_PROVIDER)); final Bootstrap boot1 = new Bootstrap(); boot1.group(group1) diff --git a/transport/src/main/java/io/netty/channel/DefaultEventLoopGroup.java b/transport/src/main/java/io/netty/channel/DefaultEventLoopGroup.java index d12c288a8cf..ef78fa11025 100644 --- a/transport/src/main/java/io/netty/channel/DefaultEventLoopGroup.java +++ b/transport/src/main/java/io/netty/channel/DefaultEventLoopGroup.java @@ -21,6 +21,7 @@ /** * {@link MultithreadEventLoopGroup} which must be used for the local transport. */ +@Deprecated public class DefaultEventLoopGroup extends MultithreadEventLoopGroup { /** diff --git a/transport/src/main/java/io/netty/channel/nio/NioIoHandler.java b/transport/src/main/java/io/netty/channel/nio/NioIoHandler.java index e1d5ffd7000..800f5f20197 100644 --- a/transport/src/main/java/io/netty/channel/nio/NioIoHandler.java +++ b/transport/src/main/java/io/netty/channel/nio/NioIoHandler.java @@ -726,12 +726,24 @@ private void selectAgain() { } /** - * Returns a new {@link IoHandlerFactory} that creates {@link NioIoHandler} instances. + * Returns a new {@link IoHandlerFactory} that creates {@link NioIoHandler} instances + * + * @return factory the {@link IoHandlerFactory}. */ public static IoHandlerFactory newFactory() { return newFactory(SelectorProvider.provider(), DefaultSelectStrategyFactory.INSTANCE); } + /** + * Returns a new {@link IoHandlerFactory} that creates {@link NioIoHandler} instances. + * + * @param selectorProvider the {@link SelectorProvider} to use. + * @return factory the {@link IoHandlerFactory}. + */ + public static IoHandlerFactory newFactory(SelectorProvider selectorProvider) { + return newFactory(selectorProvider, DefaultSelectStrategyFactory.INSTANCE); + } + /** * Returns a new {@link IoHandlerFactory} that creates {@link NioIoHandler} instances. * diff --git a/transport/src/test/java/io/netty/bootstrap/ServerBootstrapTest.java b/transport/src/test/java/io/netty/bootstrap/ServerBootstrapTest.java index 36ed66cbc5a..7332cce6ec9 100644 --- a/transport/src/test/java/io/netty/bootstrap/ServerBootstrapTest.java +++ b/transport/src/test/java/io/netty/bootstrap/ServerBootstrapTest.java @@ -22,11 +22,11 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; -import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; -import io.netty.channel.local.LocalEventLoopGroup; +import io.netty.channel.local.LocalIoHandler; import io.netty.channel.local.LocalServerChannel; import io.netty.util.AttributeKey; import org.junit.jupiter.api.Test; @@ -51,7 +51,7 @@ public class ServerBootstrapTest { public void testHandlerRegister() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference error = new AtomicReference(); - LocalEventLoopGroup group = new LocalEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); try { ServerBootstrap sb = new ServerBootstrap(); sb.channel(LocalServerChannel.class) @@ -108,7 +108,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception } }; - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); Channel sch = null; Channel cch = null; try { @@ -151,7 +151,7 @@ protected void initChannel(Channel ch) throws Exception { @Test public void optionsAndAttributesMustBeAvailableOnChildChannelInit() throws InterruptedException { - EventLoopGroup group = new DefaultEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); LocalAddress addr = new LocalAddress(UUID.randomUUID().toString()); final AttributeKey key = AttributeKey.valueOf(UUID.randomUUID().toString()); final AtomicBoolean requestServed = new AtomicBoolean(); @@ -187,7 +187,7 @@ void mustCallInitializerExtensions() throws Exception { LocalAddress addr = new LocalAddress(ServerBootstrapTest.class); final AtomicReference expectedServerChannel = new AtomicReference(); final AtomicReference expectedChildChannel = new AtomicReference(); - LocalEventLoopGroup group = new LocalEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); final ServerBootstrap sb = new ServerBootstrap(); sb.group(group); sb.channel(LocalServerChannel.class); diff --git a/transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java b/transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java index fa86dd10a92..9d7ef7dd9a9 100644 --- a/transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java +++ b/transport/src/test/java/io/netty/channel/DefaultChannelPipelineTest.java @@ -25,8 +25,9 @@ import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; +import io.netty.channel.local.LocalIoHandler; import io.netty.channel.local.LocalServerChannel; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.oio.OioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.oio.OioSocketChannel; @@ -85,7 +86,7 @@ public class DefaultChannelPipelineTest { @BeforeAll public static void beforeClass() throws Exception { - group = new DefaultEventLoopGroup(1); + group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); } @AfterAll @@ -968,8 +969,8 @@ public void testAddReplaceHandlerNotRegistered() throws Throwable { @Test @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testHandlerAddedAndRemovedCalledInCorrectOrder() throws Throwable { - final EventExecutorGroup group1 = new DefaultEventExecutorGroup(1); - final EventExecutorGroup group2 = new DefaultEventExecutorGroup(1); + final EventExecutorGroup group1 = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); + final EventExecutorGroup group2 = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); try { BlockingQueue addedQueue = new LinkedBlockingQueue(); @@ -1012,7 +1013,7 @@ public void testHandlerAddedAndRemovedCalledInCorrectOrder() throws Throwable { @Test @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testHandlerAddedExceptionFromChildHandlerIsPropagated() { - final EventExecutorGroup group1 = new DefaultEventExecutorGroup(1); + final EventExecutorGroup group1 = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); try { final Promise promise = group1.next().newPromise(); final AtomicBoolean handlerAdded = new AtomicBoolean(); @@ -1037,7 +1038,7 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception { @Test @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testHandlerRemovedExceptionFromChildHandlerIsPropagated() { - final EventExecutorGroup group1 = new DefaultEventExecutorGroup(1); + final EventExecutorGroup group1 = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); try { final Promise promise = group1.next().newPromise(); String handlerName = "foo"; @@ -1061,7 +1062,7 @@ public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { @Test @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testHandlerAddedThrowsAndRemovedThrowsException() throws InterruptedException { - final EventExecutorGroup group1 = new DefaultEventExecutorGroup(1); + final EventExecutorGroup group1 = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); try { final CountDownLatch latch = new CountDownLatch(1); final Promise promise = group1.next().newPromise(); @@ -1182,7 +1183,7 @@ public void testAddBefore() throws Throwable { @Test @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testAddInListenerNio() { - testAddInListener(new NioSocketChannel(), new NioEventLoopGroup(1)); + testAddInListener(new NioSocketChannel(), new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory())); } @SuppressWarnings("deprecation") @@ -1195,7 +1196,7 @@ public void testAddInListenerOio() { @Test @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testAddInListenerLocal() { - testAddInListener(new LocalChannel(), new DefaultEventLoopGroup(1)); + testAddInListener(new LocalChannel(), new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory())); } private static void testAddInListener(Channel channel, EventLoopGroup group) { @@ -1287,7 +1288,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { @Test public void testPinExecutor() { - EventExecutorGroup group = new DefaultEventExecutorGroup(2); + EventExecutorGroup group = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()); ChannelPipeline pipeline = new LocalChannel().pipeline(); ChannelPipeline pipeline2 = new LocalChannel().pipeline(); @@ -1308,7 +1309,7 @@ public void testPinExecutor() { @Test public void testNotPinExecutor() { - EventExecutorGroup group = new DefaultEventExecutorGroup(2); + EventExecutorGroup group = new MultiThreadIoEventLoopGroup(2, LocalIoHandler.newFactory()); ChannelPipeline pipeline = new LocalChannel().pipeline(); pipeline.channel().config().setOption(ChannelOption.SINGLE_EVENTEXECUTOR_PER_GROUP, false); @@ -1356,7 +1357,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { // Test for https://github.com/netty/netty/issues/8676. @Test public void testHandlerRemovedOnlyCalledWhenHandlerAddedCalled() throws Exception { - EventLoopGroup group = new DefaultEventLoopGroup(1); + final EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, LocalIoHandler.newFactory()); try { final AtomicReference errorRef = new AtomicReference(); diff --git a/transport/src/test/java/io/netty/channel/group/DefaultChannelGroupTest.java b/transport/src/test/java/io/netty/channel/group/DefaultChannelGroupTest.java index 7ff3fffa54f..893cfba7827 100644 --- a/transport/src/test/java/io/netty/channel/group/DefaultChannelGroupTest.java +++ b/transport/src/test/java/io/netty/channel/group/DefaultChannelGroupTest.java @@ -20,7 +20,8 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.util.concurrent.GlobalEventExecutor; import org.junit.jupiter.api.Test; @@ -30,8 +31,8 @@ public class DefaultChannelGroupTest { // Test for #1183 @Test public void testNotThrowBlockingOperationException() throws Exception { - EventLoopGroup bossGroup = new NioEventLoopGroup(); - EventLoopGroup workerGroup = new NioEventLoopGroup(); + EventLoopGroup bossGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); final ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); diff --git a/transport/src/test/java/io/netty/channel/nio/NioEventLoopTest.java b/transport/src/test/java/io/netty/channel/nio/NioEventLoopTest.java index 72a92e7f2a6..ae63bc127e0 100644 --- a/transport/src/test/java/io/netty/channel/nio/NioEventLoopTest.java +++ b/transport/src/test/java/io/netty/channel/nio/NioEventLoopTest.java @@ -17,21 +17,20 @@ import io.netty.channel.AbstractEventLoopTest; import io.netty.channel.Channel; -import io.netty.channel.DefaultSelectStrategyFactory; import io.netty.channel.EventLoop; import io.netty.channel.EventLoopGroup; -import io.netty.channel.EventLoopTaskQueueFactory; +import io.netty.channel.IoEventLoop; +import io.netty.channel.IoEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.SelectStrategy; import io.netty.channel.SelectStrategyFactory; import io.netty.channel.SingleThreadEventLoop; +import io.netty.channel.SingleThreadIoEventLoop; import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.util.IntSupplier; -import io.netty.util.concurrent.DefaultEventExecutorChooserFactory; import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.RejectedExecutionHandlers; -import io.netty.util.concurrent.ThreadPerTaskExecutor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -41,13 +40,10 @@ import java.nio.channels.Selector; import java.nio.channels.SocketChannel; import java.nio.channels.spi.SelectorProvider; -import java.util.Queue; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.MatcherAssert.assertThat; @@ -62,7 +58,7 @@ public class NioEventLoopTest extends AbstractEventLoopTest { @Override protected EventLoopGroup newEventLoopGroup() { - return new NioEventLoopGroup(); + return new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); } @Override @@ -103,7 +99,7 @@ public void run() { @Test public void testScheduleBigDelayNotOverflow() { - EventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); final EventLoop el = group.next(); Future future = el.schedule(new Runnable() { @@ -164,8 +160,8 @@ public void run() { @Test @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testSelectableChannel() throws Exception { - NioEventLoopGroup group = new NioEventLoopGroup(1); - NioEventLoop loop = (NioEventLoop) group.next(); + IoEventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + IoEventLoop loop = group.next(); try { Channel channel = new NioServerSocketChannel(); @@ -178,16 +174,12 @@ public void testSelectableChannel() throws Exception { final CountDownLatch latch = new CountDownLatch(1); - loop.register(selectableChannel, SelectionKey.OP_CONNECT, new NioTask() { + loop.register(new NioSelectableChannelIoHandle(selectableChannel) { @Override - public void channelReady(SocketChannel ch, SelectionKey key) { + protected void handle(SocketChannel channel, SelectionKey key) { latch.countDown(); } - - @Override - public void channelUnregistered(SocketChannel ch, Throwable cause) { - } - }); + }, NioIoOps.valueOf(SelectionKey.OP_CONNECT)); latch.await(); @@ -210,8 +202,8 @@ public void run() { }; // Just run often enough to trigger it normally. for (int i = 0; i < 1000; i++) { - NioEventLoopGroup group = new NioEventLoopGroup(1); - final NioEventLoop loop = (NioEventLoop) group.next(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); + final EventLoop loop = group.next(); Thread t = new Thread(new Runnable() { @Override @@ -278,10 +270,9 @@ public int calculateStrategy(IntSupplier selectSupplier, boolean hasTasks) throw @Test @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testChannelsRegistered() throws Exception { - NioEventLoopGroup group = new NioEventLoopGroup(1); - final NioEventLoop loop = (NioEventLoop) group.next(); - + EventLoopGroup group = new NioEventLoopGroup(1); try { + final SingleThreadIoEventLoop loop = (SingleThreadIoEventLoop) group.next(); final Channel ch1 = new NioServerSocketChannel(); final Channel ch2 = new NioServerSocketChannel(); @@ -314,35 +305,4 @@ public Integer call() { } }).get(1, TimeUnit.SECONDS); } - - @Test - public void testCustomQueue() { - final AtomicBoolean called = new AtomicBoolean(); - NioEventLoopGroup group = new NioEventLoopGroup(1, - new ThreadPerTaskExecutor(new DefaultThreadFactory(NioEventLoopGroup.class)), - DefaultEventExecutorChooserFactory.INSTANCE, SelectorProvider.provider(), - DefaultSelectStrategyFactory.INSTANCE, RejectedExecutionHandlers.reject(), - new EventLoopTaskQueueFactory() { - @Override - public Queue newTaskQueue(int maxCapacity) { - called.set(true); - return new LinkedBlockingQueue(maxCapacity); - } - }); - - final NioEventLoop loop = (NioEventLoop) group.next(); - - try { - loop.submit(new Runnable() { - @Override - public void run() { - // NOOP. - } - }).syncUninterruptibly(); - assertTrue(called.get()); - } finally { - group.shutdownGracefully(); - } - } - } diff --git a/transport/src/test/java/io/netty/channel/pool/AbstractChannelPoolMapTest.java b/transport/src/test/java/io/netty/channel/pool/AbstractChannelPoolMapTest.java index 7a257ef3c21..9f7fe4f414b 100644 --- a/transport/src/test/java/io/netty/channel/pool/AbstractChannelPoolMapTest.java +++ b/transport/src/test/java/io/netty/channel/pool/AbstractChannelPoolMapTest.java @@ -19,9 +19,10 @@ import io.netty.channel.Channel; import io.netty.channel.EventLoop; import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalChannel; -import io.netty.channel.local.LocalEventLoopGroup; +import io.netty.channel.local.LocalIoHandler; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; @@ -43,7 +44,7 @@ public class AbstractChannelPoolMapTest { @Test public void testMap() throws Exception { - EventLoopGroup group = new LocalEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()); LocalAddress addr = new LocalAddress(getLocalAddrId()); final Bootstrap cb = new Bootstrap(); cb.remoteAddress(addr); @@ -85,7 +86,7 @@ public void execute() throws Throwable { @Test public void testRemoveClosesChannelPool() { - EventLoopGroup group = new LocalEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()); LocalAddress addr = new LocalAddress(getLocalAddrId()); final Bootstrap cb = new Bootstrap(); cb.remoteAddress(addr); @@ -113,7 +114,7 @@ protected TestPool newPool(EventLoop key) { @Test public void testCloseClosesPoolsImmediately() { - EventLoopGroup group = new LocalEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory()); LocalAddress addr = new LocalAddress(getLocalAddrId()); final Bootstrap cb = new Bootstrap(); cb.remoteAddress(addr); diff --git a/transport/src/test/java/io/netty/channel/socket/nio/NioDatagramChannelTest.java b/transport/src/test/java/io/netty/channel/socket/nio/NioDatagramChannelTest.java index fc89f805a3f..e0c56c9b8c0 100644 --- a/transport/src/test/java/io/netty/channel/socket/nio/NioDatagramChannelTest.java +++ b/transport/src/test/java/io/netty/channel/socket/nio/NioDatagramChannelTest.java @@ -19,8 +19,10 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; import io.netty.channel.group.DefaultChannelGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.DatagramChannel; import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.GlobalEventExecutor; @@ -41,7 +43,7 @@ public class NioDatagramChannelTest extends AbstractNioChannelTest futures = new LinkedBlockingQueue(); @@ -125,7 +126,7 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { */ @Test public void testFlushAfterGatheredFlush() throws Exception { - NioEventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); try { ServerBootstrap sb = new ServerBootstrap(); sb.group(group).channel(NioServerSocketChannel.class); @@ -176,7 +177,7 @@ public void testChannelReRegisterReadDifferentEventLoop() throws Exception { } private static void testChannelReRegisterRead(final boolean sameEventLoop) throws Exception { - final EventLoopGroup group = new NioEventLoopGroup(2); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory()); final CountDownLatch latch = new CountDownLatch(1); // Just some random bytes @@ -255,7 +256,7 @@ public void operationComplete(ChannelFuture cf) { @Test @Timeout(value = 3000, unit = TimeUnit.MILLISECONDS) public void testShutdownOutputAndClose() throws IOException { - NioEventLoopGroup group = new NioEventLoopGroup(1); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory()); ServerSocket socket = new ServerSocket(); socket.bind(new InetSocketAddress(0)); Socket accepted = null;