From a1bdf671f16978ac1fbb9ed6e3a6ea98b4e520bd Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 25 May 2012 15:51:22 -0700 Subject: [PATCH] Simplified EventLoop implementation names - Also - Fixed a test failure - Fixed compiler warnings related with ChannelInitializer type parameters --- .../codec/spdy/NioNioSocketSpdyEchoTest.java | 6 ++-- .../codec/spdy/NioOioSocketSpdyEchoTest.java | 8 ++--- .../codec/spdy/OioNioSocketSpdyEchoTest.java | 8 ++--- .../codec/spdy/OioOioSocketSpdyEchoTest.java | 6 ++-- .../handler/codec/bytes/ByteArrayEncoder.java | 3 ++ .../codec/embedder/EmbeddedChannel.java | 13 +------- .../io/netty/example/echo/EchoClient.java | 10 +++--- .../io/netty/example/echo/EchoServer.java | 10 +++--- .../example/http/snoop/HttpSnoopClient.java | 4 +-- .../snoop/HttpSnoopClientInitializer.java | 6 ++-- .../example/http/snoop/HttpSnoopServer.java | 4 +-- .../snoop/HttpSnoopServerInitializer.java | 6 ++-- .../example/qotm/QuoteOfTheMomentClient.java | 9 +++--- .../example/qotm/QuoteOfTheMomentServer.java | 10 +++--- .../socket/nio/AbstractNioChannel.java | 4 +-- ...rEventLoop.java => NioChildEventLoop.java} | 6 ++-- .../socket/nio/NioDatagramChannel.java | 4 +-- ...fig.java => NioDatagramChannelConfig.java} | 4 +-- .../channel/socket/nio/NioEventLoop.java | 32 +++++++++++++++++++ .../socket/nio/NioServerSocketChannel.java | 4 +-- .../channel/socket/nio/NioSocketChannel.java | 2 +- .../channel/socket/nio/SelectorEventLoop.java | 32 ------------------- ...lEventLoop.java => OioChildEventLoop.java} | 8 ++--- .../socket/oio/OioDatagramChannel.java | 2 +- ...hannelEventLoop.java => OioEventLoop.java} | 26 +++++++-------- .../socket/oio/OioServerSocketChannel.java | 2 +- .../channel/socket/oio/OioSocketChannel.java | 2 +- 27 files changed, 112 insertions(+), 119 deletions(-) rename transport/src/main/java/io/netty/channel/socket/nio/{SingleThreadSelectorEventLoop.java => NioChildEventLoop.java} (97%) rename transport/src/main/java/io/netty/channel/socket/nio/{DefaultNioDatagramChannelConfig.java => NioDatagramChannelConfig.java} (96%) create mode 100644 transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java delete mode 100644 transport/src/main/java/io/netty/channel/socket/nio/SelectorEventLoop.java rename transport/src/main/java/io/netty/channel/socket/oio/{SingleBlockingChannelEventLoop.java => OioChildEventLoop.java} (88%) rename transport/src/main/java/io/netty/channel/socket/oio/{BlockingChannelEventLoop.java => OioEventLoop.java} (88%) diff --git a/codec-http/src/test/java/io/netty/handler/codec/spdy/NioNioSocketSpdyEchoTest.java b/codec-http/src/test/java/io/netty/handler/codec/spdy/NioNioSocketSpdyEchoTest.java index b5aad7453f..041f943415 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/spdy/NioNioSocketSpdyEchoTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/spdy/NioNioSocketSpdyEchoTest.java @@ -20,21 +20,21 @@ import io.netty.channel.ChannelBootstrap; import io.netty.channel.ServerChannelBootstrap; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.channel.socket.nio.SelectorEventLoop; +import io.netty.channel.socket.nio.NioEventLoop; public class NioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { @Override protected ChannelBootstrap newClientBootstrap() { return new ChannelBootstrap() - .eventLoop(new SelectorEventLoop()) + .eventLoop(new NioEventLoop()) .channel(new NioSocketChannel()); } @Override protected ServerChannelBootstrap newServerBootstrap() { return new ServerChannelBootstrap() - .eventLoop(new SelectorEventLoop(), new SelectorEventLoop()) + .eventLoop(new NioEventLoop(), new NioEventLoop()) .channel(new NioServerSocketChannel()); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/spdy/NioOioSocketSpdyEchoTest.java b/codec-http/src/test/java/io/netty/handler/codec/spdy/NioOioSocketSpdyEchoTest.java index 46b403de23..95be0bafe4 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/spdy/NioOioSocketSpdyEchoTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/spdy/NioOioSocketSpdyEchoTest.java @@ -19,8 +19,8 @@ package io.netty.handler.codec.spdy; import io.netty.channel.ChannelBootstrap; import io.netty.channel.ServerChannelBootstrap; import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.channel.socket.nio.SelectorEventLoop; -import io.netty.channel.socket.oio.BlockingChannelEventLoop; +import io.netty.channel.socket.nio.NioEventLoop; +import io.netty.channel.socket.oio.OioEventLoop; import io.netty.channel.socket.oio.OioServerSocketChannel; public class NioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { @@ -28,14 +28,14 @@ public class NioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { @Override protected ChannelBootstrap newClientBootstrap() { return new ChannelBootstrap() - .eventLoop(new SelectorEventLoop()) + .eventLoop(new NioEventLoop()) .channel(new NioSocketChannel()); } @Override protected ServerChannelBootstrap newServerBootstrap() { return new ServerChannelBootstrap() - .eventLoop(new BlockingChannelEventLoop(), new BlockingChannelEventLoop()) + .eventLoop(new OioEventLoop(), new OioEventLoop()) .channel(new OioServerSocketChannel()); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/spdy/OioNioSocketSpdyEchoTest.java b/codec-http/src/test/java/io/netty/handler/codec/spdy/OioNioSocketSpdyEchoTest.java index 083983ee6a..c535257753 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/spdy/OioNioSocketSpdyEchoTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/spdy/OioNioSocketSpdyEchoTest.java @@ -19,8 +19,8 @@ package io.netty.handler.codec.spdy; import io.netty.channel.ChannelBootstrap; import io.netty.channel.ServerChannelBootstrap; import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.channel.socket.nio.SelectorEventLoop; -import io.netty.channel.socket.oio.BlockingChannelEventLoop; +import io.netty.channel.socket.nio.NioEventLoop; +import io.netty.channel.socket.oio.OioEventLoop; import io.netty.channel.socket.oio.OioSocketChannel; public class OioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { @@ -28,14 +28,14 @@ public class OioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { @Override protected ChannelBootstrap newClientBootstrap() { return new ChannelBootstrap() - .eventLoop(new BlockingChannelEventLoop()) + .eventLoop(new OioEventLoop()) .channel(new OioSocketChannel()); } @Override protected ServerChannelBootstrap newServerBootstrap() { return new ServerChannelBootstrap() - .eventLoop(new SelectorEventLoop(), new SelectorEventLoop()) + .eventLoop(new NioEventLoop(), new NioEventLoop()) .channel(new NioServerSocketChannel()); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/spdy/OioOioSocketSpdyEchoTest.java b/codec-http/src/test/java/io/netty/handler/codec/spdy/OioOioSocketSpdyEchoTest.java index 88d8e6364e..73e7aab76d 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/spdy/OioOioSocketSpdyEchoTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/spdy/OioOioSocketSpdyEchoTest.java @@ -18,7 +18,7 @@ package io.netty.handler.codec.spdy; import io.netty.channel.ChannelBootstrap; import io.netty.channel.ServerChannelBootstrap; -import io.netty.channel.socket.oio.BlockingChannelEventLoop; +import io.netty.channel.socket.oio.OioEventLoop; import io.netty.channel.socket.oio.OioServerSocketChannel; import io.netty.channel.socket.oio.OioSocketChannel; @@ -27,14 +27,14 @@ public class OioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { @Override protected ChannelBootstrap newClientBootstrap() { return new ChannelBootstrap() - .eventLoop(new BlockingChannelEventLoop()) + .eventLoop(new OioEventLoop()) .channel(new OioSocketChannel()); } @Override protected ServerChannelBootstrap newServerBootstrap() { return new ServerChannelBootstrap() - .eventLoop(new BlockingChannelEventLoop(), new BlockingChannelEventLoop()) + .eventLoop(new OioEventLoop(), new OioEventLoop()) .channel(new OioServerSocketChannel()); } } diff --git a/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayEncoder.java b/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayEncoder.java index 4998642370..4300286b0a 100644 --- a/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/bytes/ByteArrayEncoder.java @@ -60,6 +60,9 @@ public class ByteArrayEncoder extends MessageToMessageEncoder ctx, byte[] msg) throws Exception { + if (msg.length == 0) { + return null; + } return ChannelBuffers.wrappedBuffer(msg); } } diff --git a/codec/src/main/java/io/netty/handler/codec/embedder/EmbeddedChannel.java b/codec/src/main/java/io/netty/handler/codec/embedder/EmbeddedChannel.java index 0357040d4f..b6d1127bf9 100644 --- a/codec/src/main/java/io/netty/handler/codec/embedder/EmbeddedChannel.java +++ b/codec/src/main/java/io/netty/handler/codec/embedder/EmbeddedChannel.java @@ -126,18 +126,7 @@ class EmbeddedChannel extends AbstractChannel { } @Override - protected int doRead(ChannelBuffer buf) throws Exception { - return 0; - } - - @Override - protected int doRead(Queue buf) throws Exception { - return 0; - } - - @Override - protected int doFlush(boolean lastSpin) throws Exception { - ChannelBuffer buf = firstOut().byteBuffer(); + protected int doWriteBytes(ChannelBuffer buf, boolean lastSpin) throws Exception { int length = buf.readableBytes(); if (length > 0) { productQueue.add(buf.readBytes(length)); 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 9a802adfa8..b9a87e8d25 100644 --- a/example/src/main/java/io/netty/example/echo/EchoClient.java +++ b/example/src/main/java/io/netty/example/echo/EchoClient.java @@ -15,13 +15,13 @@ */ package io.netty.example.echo; -import io.netty.channel.Channel; import io.netty.channel.ChannelBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioEventLoop; import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.channel.socket.nio.SelectorEventLoop; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; @@ -49,13 +49,13 @@ public class EchoClient { // Configure the client. ChannelBootstrap b = new ChannelBootstrap(); try { - b.eventLoop(new SelectorEventLoop()) + b.eventLoop(new NioEventLoop()) .channel(new NioSocketChannel()) .option(ChannelOption.TCP_NODELAY, true) .remoteAddress(new InetSocketAddress(host, port)) - .initializer(new ChannelInitializer() { + .initializer(new ChannelInitializer() { @Override - public void initChannel(Channel ch) throws Exception { + public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast( new LoggingHandler(LogLevel.INFO), new EchoClientHandler(firstMessageSize)); 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 9f6e7e25f9..3b77a813bb 100644 --- a/example/src/main/java/io/netty/example/echo/EchoServer.java +++ b/example/src/main/java/io/netty/example/echo/EchoServer.java @@ -15,13 +15,13 @@ */ package io.netty.example.echo; -import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.ServerChannelBootstrap; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioEventLoop; import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.channel.socket.nio.SelectorEventLoop; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; @@ -42,14 +42,14 @@ public class EchoServer { // Configure the server. ServerChannelBootstrap b = new ServerChannelBootstrap(); try { - b.eventLoop(new SelectorEventLoop(), new SelectorEventLoop()) + b.eventLoop(new NioEventLoop(), new NioEventLoop()) .channel(new NioServerSocketChannel()) .option(ChannelOption.SO_BACKLOG, 100) .localAddress(new InetSocketAddress(port)) .childOption(ChannelOption.TCP_NODELAY, true) - .childInitializer(new ChannelInitializer() { + .childInitializer(new ChannelInitializer() { @Override - public void initChannel(Channel ch) throws Exception { + public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast( new LoggingHandler(LogLevel.INFO), new EchoServerHandler()); 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 99d837f75d..aee3915567 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 @@ -18,7 +18,7 @@ package io.netty.example.http.snoop; import io.netty.channel.Channel; import io.netty.channel.ChannelBootstrap; import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.channel.socket.nio.SelectorEventLoop; +import io.netty.channel.socket.nio.NioEventLoop; import io.netty.handler.codec.http.CookieEncoder; import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.HttpHeaders; @@ -63,7 +63,7 @@ public class HttpSnoopClient { // Configure the client. ChannelBootstrap b = new ChannelBootstrap(); try { - b.eventLoop(new SelectorEventLoop()) + b.eventLoop(new NioEventLoop()) .channel(new NioSocketChannel()) .initializer(new HttpSnoopClientInitializer(ssl)) .remoteAddress(new InetSocketAddress(host, port)); diff --git a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClientInitializer.java b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClientInitializer.java index 4bbec634dc..d6613b0718 100644 --- a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClientInitializer.java +++ b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClientInitializer.java @@ -15,9 +15,9 @@ */ package io.netty.example.http.snoop; -import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; import io.netty.example.securechat.SecureChatSslContextFactory; import io.netty.handler.codec.http.HttpClientCodec; import io.netty.handler.logging.LogLevel; @@ -25,7 +25,7 @@ import io.netty.handler.logging.LoggingHandler; import javax.net.ssl.SSLEngine; -public class HttpSnoopClientInitializer extends ChannelInitializer { +public class HttpSnoopClientInitializer extends ChannelInitializer { private final boolean ssl; @@ -34,7 +34,7 @@ public class HttpSnoopClientInitializer extends ChannelInitializer { } @Override - public void initChannel(Channel ch) throws Exception { + public void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. ChannelPipeline p = ch.pipeline(); 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 4697b1da7b..f11a8aba0a 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,7 @@ package io.netty.example.http.snoop; import io.netty.channel.Channel; import io.netty.channel.ServerChannelBootstrap; import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.channel.socket.nio.SelectorEventLoop; +import io.netty.channel.socket.nio.NioEventLoop; import java.net.InetSocketAddress; @@ -39,7 +39,7 @@ public class HttpSnoopServer { ServerChannelBootstrap b = new ServerChannelBootstrap(); try { - b.eventLoop(new SelectorEventLoop(), new SelectorEventLoop()) + b.eventLoop(new NioEventLoop(), new NioEventLoop()) .channel(new NioServerSocketChannel()) .childInitializer(new HttpSnoopServerInitializer()) .localAddress(new InetSocketAddress(port)); diff --git a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerInitializer.java b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerInitializer.java index 09ae47828e..ccd0ac9730 100644 --- a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerInitializer.java +++ b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerInitializer.java @@ -15,15 +15,15 @@ */ package io.netty.example.http.snoop; -import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.http.HttpRequestDecoder; import io.netty.handler.codec.http.HttpResponseEncoder; -public class HttpSnoopServerInitializer extends ChannelInitializer { +public class HttpSnoopServerInitializer extends ChannelInitializer { @Override - public void initChannel(Channel ch) throws Exception { + public void initChannel(SocketChannel ch) throws Exception { // Create a default pipeline implementation. ChannelPipeline p = ch.pipeline(); 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 b64abb675e..ab6288c345 100644 --- a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java +++ b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java @@ -20,9 +20,10 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; +import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.nio.NioDatagramChannel; -import io.netty.channel.socket.nio.SelectorEventLoop; +import io.netty.channel.socket.nio.NioEventLoop; import io.netty.util.CharsetUtil; import java.net.InetSocketAddress; @@ -44,13 +45,13 @@ public class QuoteOfTheMomentClient { public void run() throws Exception { ChannelBootstrap b = new ChannelBootstrap(); try { - b.eventLoop(new SelectorEventLoop()) + b.eventLoop(new NioEventLoop()) .channel(new NioDatagramChannel()) .localAddress(new InetSocketAddress(0)) .option(ChannelOption.SO_BROADCAST, true) - .initializer(new ChannelInitializer() { + .initializer(new ChannelInitializer() { @Override - public void initChannel(Channel ch) throws Exception { + public void initChannel(DatagramChannel ch) throws Exception { ch.pipeline().addLast(new QuoteOfTheMomentClientHandler()); } }); 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 57d329dbe0..b98ebe5b51 100644 --- a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java +++ b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java @@ -15,12 +15,12 @@ */ package io.netty.example.qotm; -import io.netty.channel.Channel; import io.netty.channel.ChannelBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; +import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel; -import io.netty.channel.socket.nio.SelectorEventLoop; +import io.netty.channel.socket.nio.NioEventLoop; import java.net.InetSocketAddress; @@ -41,13 +41,13 @@ public class QuoteOfTheMomentServer { public void run() throws Exception { ChannelBootstrap b = new ChannelBootstrap(); try { - b.eventLoop(new SelectorEventLoop()) + b.eventLoop(new NioEventLoop()) .channel(new NioDatagramChannel()) .localAddress(new InetSocketAddress(port)) .option(ChannelOption.SO_BROADCAST, true) - .initializer(new ChannelInitializer() { + .initializer(new ChannelInitializer() { @Override - public void initChannel(Channel ch) throws Exception { + public void initChannel(DatagramChannel ch) throws Exception { ch.pipeline().addLast(new QuoteOfTheMomentServerHandler()); } }); diff --git a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java index 8b41af86b2..b4442ef857 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java @@ -55,12 +55,12 @@ public abstract class AbstractNioChannel extends AbstractChannel { @Override protected boolean isCompatible(EventLoop loop) { - return loop instanceof SingleThreadSelectorEventLoop; + return loop instanceof NioChildEventLoop; } @Override protected void doRegister() throws Exception { - SingleThreadSelectorEventLoop loop = (SingleThreadSelectorEventLoop) eventLoop(); + NioChildEventLoop loop = (NioChildEventLoop) eventLoop(); selectionKey = javaChannel().register(loop.selector, isActive()? SelectionKey.OP_READ : 0, this); } diff --git a/transport/src/main/java/io/netty/channel/socket/nio/SingleThreadSelectorEventLoop.java b/transport/src/main/java/io/netty/channel/socket/nio/NioChildEventLoop.java similarity index 97% rename from transport/src/main/java/io/netty/channel/socket/nio/SingleThreadSelectorEventLoop.java rename to transport/src/main/java/io/netty/channel/socket/nio/NioChildEventLoop.java index afb9bec2ef..03c47ebaa7 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/SingleThreadSelectorEventLoop.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioChildEventLoop.java @@ -34,13 +34,13 @@ import java.util.Set; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicBoolean; -final class SingleThreadSelectorEventLoop extends SingleThreadEventLoop { +final class NioChildEventLoop extends SingleThreadEventLoop { /** * Internal Netty logger. */ protected static final InternalLogger logger = InternalLoggerFactory - .getInstance(SingleThreadSelectorEventLoop.class); + .getInstance(NioChildEventLoop.class); static final int CLEANUP_INTERVAL = 256; // XXX Hard-coded value, but won't need customization. @@ -59,7 +59,7 @@ final class SingleThreadSelectorEventLoop extends SingleThreadEventLoop { int cancelledKeys; - SingleThreadSelectorEventLoop(ThreadFactory threadFactory, SelectorProvider selectorProvider) { + NioChildEventLoop(ThreadFactory threadFactory, SelectorProvider selectorProvider) { super(threadFactory); if (selectorProvider == null) { throw new NullPointerException("selectorProvider"); diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java index 84e1ddf35a..54c87211fd 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java @@ -89,7 +89,7 @@ public final class NioDatagramChannel extends AbstractNioChannel implements io.n throw new ChannelException("Failed to enter non-blocking mode.", e); } - config = new DefaultNioDatagramChannelConfig(socket); + config = new NioDatagramChannelConfig(socket); } @@ -168,7 +168,7 @@ public final class NioDatagramChannel extends AbstractNioChannel implements io.n @Override protected void doDeregister() throws Exception { selectionKey().cancel(); - ((SingleThreadSelectorEventLoop) eventLoop()).cancelledKeys ++; + ((NioChildEventLoop) eventLoop()).cancelledKeys ++; } @Override diff --git a/transport/src/main/java/io/netty/channel/socket/nio/DefaultNioDatagramChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannelConfig.java similarity index 96% rename from transport/src/main/java/io/netty/channel/socket/nio/DefaultNioDatagramChannelConfig.java rename to transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannelConfig.java index b2a95eb1f7..e89624bc23 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/DefaultNioDatagramChannelConfig.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannelConfig.java @@ -26,7 +26,7 @@ import java.nio.channels.DatagramChannel; /** * The default {@link NioSocketChannelConfig} implementation. */ -class DefaultNioDatagramChannelConfig extends DefaultDatagramChannelConfig { +class NioDatagramChannelConfig extends DefaultDatagramChannelConfig { private static final Object IP_MULTICAST_IF; private static final Method GET_OPTION; @@ -70,7 +70,7 @@ class DefaultNioDatagramChannelConfig extends DefaultDatagramChannelConfig { private final DatagramChannel channel; - DefaultNioDatagramChannelConfig(DatagramChannel channel) { + NioDatagramChannelConfig(DatagramChannel channel) { super(channel.socket()); this.channel = channel; } diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java b/transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java new file mode 100644 index 0000000000..925a2e58bf --- /dev/null +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioEventLoop.java @@ -0,0 +1,32 @@ +package io.netty.channel.socket.nio; + +import io.netty.channel.EventLoopFactory; +import io.netty.channel.MultithreadEventLoop; + +import java.nio.channels.spi.SelectorProvider; +import java.util.concurrent.ThreadFactory; + +public class NioEventLoop extends MultithreadEventLoop { + + public NioEventLoop() { + this(DEFAULT_POOL_SIZE); + } + + public NioEventLoop(int nThreads) { + this(nThreads, DEFAULT_THREAD_FACTORY); + } + + public NioEventLoop(int nThreads, ThreadFactory threadFactory) { + this(nThreads, threadFactory, SelectorProvider.provider()); + } + + public NioEventLoop(int nThreads, ThreadFactory threadFactory, final SelectorProvider selectorProvider) { + super(new EventLoopFactory() { + @Override + public NioChildEventLoop newEventLoop(ThreadFactory threadFactory) throws Exception { + return new NioChildEventLoop(threadFactory, selectorProvider); + } + + }, nThreads, threadFactory); + } +} diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java index a19b963735..b604c7c69b 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java @@ -101,12 +101,12 @@ public class NioServerSocketChannel extends AbstractServerChannel @Override protected boolean isCompatible(EventLoop loop) { - return loop instanceof SingleThreadSelectorEventLoop; + return loop instanceof NioChildEventLoop; } @Override protected void doRegister() throws Exception { - SingleThreadSelectorEventLoop loop = (SingleThreadSelectorEventLoop) eventLoop(); + NioChildEventLoop loop = (NioChildEventLoop) eventLoop(); selectionKey = javaChannel().register( loop.selector, isActive()? SelectionKey.OP_ACCEPT : 0, this); } diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java index 498532dbe0..b051e9cf6d 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java @@ -155,7 +155,7 @@ public class NioSocketChannel extends AbstractNioChannel implements io.netty.cha @Override protected void doDeregister() throws Exception { selectionKey().cancel(); - ((SingleThreadSelectorEventLoop) eventLoop()).cancelledKeys ++; + ((NioChildEventLoop) eventLoop()).cancelledKeys ++; } @Override diff --git a/transport/src/main/java/io/netty/channel/socket/nio/SelectorEventLoop.java b/transport/src/main/java/io/netty/channel/socket/nio/SelectorEventLoop.java deleted file mode 100644 index e15fe599e1..0000000000 --- a/transport/src/main/java/io/netty/channel/socket/nio/SelectorEventLoop.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.netty.channel.socket.nio; - -import io.netty.channel.EventLoopFactory; -import io.netty.channel.MultithreadEventLoop; - -import java.nio.channels.spi.SelectorProvider; -import java.util.concurrent.ThreadFactory; - -public class SelectorEventLoop extends MultithreadEventLoop { - - public SelectorEventLoop() { - this(DEFAULT_POOL_SIZE); - } - - public SelectorEventLoop(int nThreads) { - this(nThreads, DEFAULT_THREAD_FACTORY); - } - - public SelectorEventLoop(int nThreads, ThreadFactory threadFactory) { - this(nThreads, threadFactory, SelectorProvider.provider()); - } - - public SelectorEventLoop(int nThreads, ThreadFactory threadFactory, final SelectorProvider selectorProvider) { - super(new EventLoopFactory() { - @Override - public SingleThreadSelectorEventLoop newEventLoop(ThreadFactory threadFactory) throws Exception { - return new SingleThreadSelectorEventLoop(threadFactory, selectorProvider); - } - - }, nThreads, threadFactory); - } -} diff --git a/transport/src/main/java/io/netty/channel/socket/oio/SingleBlockingChannelEventLoop.java b/transport/src/main/java/io/netty/channel/socket/oio/OioChildEventLoop.java similarity index 88% rename from transport/src/main/java/io/netty/channel/socket/oio/SingleBlockingChannelEventLoop.java rename to transport/src/main/java/io/netty/channel/socket/oio/OioChildEventLoop.java index 32c42857f0..357c135427 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/SingleBlockingChannelEventLoop.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioChildEventLoop.java @@ -6,12 +6,12 @@ import io.netty.channel.ChannelFutureListener; import io.netty.channel.SingleThreadEventLoop; -class SingleBlockingChannelEventLoop extends SingleThreadEventLoop { +class OioChildEventLoop extends SingleThreadEventLoop { - private final BlockingChannelEventLoop parent; + private final OioEventLoop parent; private Channel ch; - SingleBlockingChannelEventLoop(BlockingChannelEventLoop parent) { + OioChildEventLoop(OioEventLoop parent) { super(parent.threadFactory); this.parent = parent; } @@ -33,7 +33,7 @@ class SingleBlockingChannelEventLoop extends SingleThreadEventLoop { @Override protected void run() { for (;;) { - Channel ch = SingleBlockingChannelEventLoop.this.ch; + Channel ch = OioChildEventLoop.this.ch; if (ch == null || !ch.isActive()) { Runnable task; try { diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java index 0da81f4ae4..d074ad452f 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java @@ -117,7 +117,7 @@ public class OioDatagramChannel extends AbstractChannel @Override protected boolean isCompatible(EventLoop loop) { - return loop instanceof SingleBlockingChannelEventLoop; + return loop instanceof OioChildEventLoop; } @Override diff --git a/transport/src/main/java/io/netty/channel/socket/oio/BlockingChannelEventLoop.java b/transport/src/main/java/io/netty/channel/socket/oio/OioEventLoop.java similarity index 88% rename from transport/src/main/java/io/netty/channel/socket/oio/BlockingChannelEventLoop.java rename to transport/src/main/java/io/netty/channel/socket/oio/OioEventLoop.java index 7a10f52a37..b72927472d 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/BlockingChannelEventLoop.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioEventLoop.java @@ -23,25 +23,25 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -public class BlockingChannelEventLoop implements EventLoop { +public class OioEventLoop implements EventLoop { private final int maxChannels; final ThreadFactory threadFactory; - final Set activeChildren = Collections.newSetFromMap( - new ConcurrentHashMap()); - final Queue idleChildren = - QueueFactory.createQueue(SingleBlockingChannelEventLoop.class); + final Set activeChildren = Collections.newSetFromMap( + new ConcurrentHashMap()); + final Queue idleChildren = + QueueFactory.createQueue(OioChildEventLoop.class); private final ChannelException tooManyChannels; - public BlockingChannelEventLoop() { + public OioEventLoop() { this(0); } - public BlockingChannelEventLoop(int maxChannels) { + public OioEventLoop(int maxChannels) { this(maxChannels, Executors.defaultThreadFactory()); } - public BlockingChannelEventLoop(int maxChannels, ThreadFactory threadFactory) { + public OioEventLoop(int maxChannels, ThreadFactory threadFactory) { if (maxChannels < 0) { throw new IllegalArgumentException(String.format( "maxChannels: %d (expected: >= 0)", maxChannels)); @@ -234,20 +234,20 @@ public class BlockingChannelEventLoop implements EventLoop { } private EventLoop nextEventLoop() { - SingleBlockingChannelEventLoop loop = idleChildren.poll(); + OioChildEventLoop loop = idleChildren.poll(); if (loop == null) { if (maxChannels > 0 && activeChildren.size() >= maxChannels) { throw tooManyChannels; } - loop = new SingleBlockingChannelEventLoop(this); + loop = new OioChildEventLoop(this); } activeChildren.add(loop); return loop; } - private static SingleBlockingChannelEventLoop currentEventLoop() { - SingleBlockingChannelEventLoop loop = - (SingleBlockingChannelEventLoop) SingleThreadEventLoop.currentEventLoop(); + private static OioChildEventLoop currentEventLoop() { + OioChildEventLoop loop = + (OioChildEventLoop) SingleThreadEventLoop.currentEventLoop(); if (loop == null) { throw new IllegalStateException("not called from an event loop thread"); } diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java index aecb866087..136be6c661 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java @@ -118,7 +118,7 @@ public class OioServerSocketChannel extends AbstractServerChannel @Override protected boolean isCompatible(EventLoop loop) { - return loop instanceof SingleBlockingChannelEventLoop; + return loop instanceof OioChildEventLoop; } @Override diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java index 69b834e909..1f1755502a 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java @@ -111,7 +111,7 @@ public class OioSocketChannel extends AbstractChannel @Override protected boolean isCompatible(EventLoop loop) { - return loop instanceof SingleBlockingChannelEventLoop; + return loop instanceof OioChildEventLoop; } @Override