Simplified EventLoop implementation names

- Also
  - Fixed a test failure
  - Fixed compiler warnings related with ChannelInitializer type
    parameters
This commit is contained in:
Trustin Lee 2012-05-25 15:51:22 -07:00
parent 61314ef51b
commit a1bdf671f1
27 changed files with 112 additions and 119 deletions

View File

@ -20,21 +20,21 @@ import io.netty.channel.ChannelBootstrap;
import io.netty.channel.ServerChannelBootstrap; import io.netty.channel.ServerChannelBootstrap;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel; 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 { public class NioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
@Override @Override
protected ChannelBootstrap newClientBootstrap() { protected ChannelBootstrap newClientBootstrap() {
return new ChannelBootstrap() return new ChannelBootstrap()
.eventLoop(new SelectorEventLoop()) .eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()); .channel(new NioSocketChannel());
} }
@Override @Override
protected ServerChannelBootstrap newServerBootstrap() { protected ServerChannelBootstrap newServerBootstrap() {
return new ServerChannelBootstrap() return new ServerChannelBootstrap()
.eventLoop(new SelectorEventLoop(), new SelectorEventLoop()) .eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()); .channel(new NioServerSocketChannel());
} }
} }

View File

@ -19,8 +19,8 @@ package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelBootstrap; import io.netty.channel.ChannelBootstrap;
import io.netty.channel.ServerChannelBootstrap; import io.netty.channel.ServerChannelBootstrap;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.channel.socket.nio.SelectorEventLoop; import io.netty.channel.socket.nio.NioEventLoop;
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.OioServerSocketChannel;
public class NioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { public class NioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
@ -28,14 +28,14 @@ public class NioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
@Override @Override
protected ChannelBootstrap newClientBootstrap() { protected ChannelBootstrap newClientBootstrap() {
return new ChannelBootstrap() return new ChannelBootstrap()
.eventLoop(new SelectorEventLoop()) .eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()); .channel(new NioSocketChannel());
} }
@Override @Override
protected ServerChannelBootstrap newServerBootstrap() { protected ServerChannelBootstrap newServerBootstrap() {
return new ServerChannelBootstrap() return new ServerChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop(), new BlockingChannelEventLoop()) .eventLoop(new OioEventLoop(), new OioEventLoop())
.channel(new OioServerSocketChannel()); .channel(new OioServerSocketChannel());
} }
} }

View File

@ -19,8 +19,8 @@ package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelBootstrap; import io.netty.channel.ChannelBootstrap;
import io.netty.channel.ServerChannelBootstrap; import io.netty.channel.ServerChannelBootstrap;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.SelectorEventLoop; import io.netty.channel.socket.nio.NioEventLoop;
import io.netty.channel.socket.oio.BlockingChannelEventLoop; import io.netty.channel.socket.oio.OioEventLoop;
import io.netty.channel.socket.oio.OioSocketChannel; import io.netty.channel.socket.oio.OioSocketChannel;
public class OioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest { public class OioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
@ -28,14 +28,14 @@ public class OioNioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
@Override @Override
protected ChannelBootstrap newClientBootstrap() { protected ChannelBootstrap newClientBootstrap() {
return new ChannelBootstrap() return new ChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop()) .eventLoop(new OioEventLoop())
.channel(new OioSocketChannel()); .channel(new OioSocketChannel());
} }
@Override @Override
protected ServerChannelBootstrap newServerBootstrap() { protected ServerChannelBootstrap newServerBootstrap() {
return new ServerChannelBootstrap() return new ServerChannelBootstrap()
.eventLoop(new SelectorEventLoop(), new SelectorEventLoop()) .eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()); .channel(new NioServerSocketChannel());
} }
} }

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelBootstrap; import io.netty.channel.ChannelBootstrap;
import io.netty.channel.ServerChannelBootstrap; 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.OioServerSocketChannel;
import io.netty.channel.socket.oio.OioSocketChannel; import io.netty.channel.socket.oio.OioSocketChannel;
@ -27,14 +27,14 @@ public class OioOioSocketSpdyEchoTest extends AbstractSocketSpdyEchoTest {
@Override @Override
protected ChannelBootstrap newClientBootstrap() { protected ChannelBootstrap newClientBootstrap() {
return new ChannelBootstrap() return new ChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop()) .eventLoop(new OioEventLoop())
.channel(new OioSocketChannel()); .channel(new OioSocketChannel());
} }
@Override @Override
protected ServerChannelBootstrap newServerBootstrap() { protected ServerChannelBootstrap newServerBootstrap() {
return new ServerChannelBootstrap() return new ServerChannelBootstrap()
.eventLoop(new BlockingChannelEventLoop(), new BlockingChannelEventLoop()) .eventLoop(new OioEventLoop(), new OioEventLoop())
.channel(new OioServerSocketChannel()); .channel(new OioServerSocketChannel());
} }
} }

View File

@ -60,6 +60,9 @@ public class ByteArrayEncoder extends MessageToMessageEncoder<byte[], ChannelBuf
@Override @Override
public ChannelBuffer encode(ChannelOutboundHandlerContext<byte[]> ctx, byte[] msg) throws Exception { public ChannelBuffer encode(ChannelOutboundHandlerContext<byte[]> ctx, byte[] msg) throws Exception {
if (msg.length == 0) {
return null;
}
return ChannelBuffers.wrappedBuffer(msg); return ChannelBuffers.wrappedBuffer(msg);
} }
} }

View File

@ -126,18 +126,7 @@ class EmbeddedChannel extends AbstractChannel {
} }
@Override @Override
protected int doRead(ChannelBuffer buf) throws Exception { protected int doWriteBytes(ChannelBuffer buf, boolean lastSpin) throws Exception {
return 0;
}
@Override
protected int doRead(Queue<Object> buf) throws Exception {
return 0;
}
@Override
protected int doFlush(boolean lastSpin) throws Exception {
ChannelBuffer buf = firstOut().byteBuffer();
int length = buf.readableBytes(); int length = buf.readableBytes();
if (length > 0) { if (length > 0) {
productQueue.add(buf.readBytes(length)); productQueue.add(buf.readBytes(length));

View File

@ -15,13 +15,13 @@
*/ */
package io.netty.example.echo; package io.netty.example.echo;
import io.netty.channel.Channel;
import io.netty.channel.ChannelBootstrap; import io.netty.channel.ChannelBootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; 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.NioSocketChannel;
import io.netty.channel.socket.nio.SelectorEventLoop;
import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; import io.netty.handler.logging.LoggingHandler;
@ -49,13 +49,13 @@ public class EchoClient {
// Configure the client. // Configure the client.
ChannelBootstrap b = new ChannelBootstrap(); ChannelBootstrap b = new ChannelBootstrap();
try { try {
b.eventLoop(new SelectorEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.TCP_NODELAY, true)
.remoteAddress(new InetSocketAddress(host, port)) .remoteAddress(new InetSocketAddress(host, port))
.initializer(new ChannelInitializer() { .initializer(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(Channel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast( ch.pipeline().addLast(
new LoggingHandler(LogLevel.INFO), new LoggingHandler(LogLevel.INFO),
new EchoClientHandler(firstMessageSize)); new EchoClientHandler(firstMessageSize));

View File

@ -15,13 +15,13 @@
*/ */
package io.netty.example.echo; package io.netty.example.echo;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.ServerChannelBootstrap; 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.NioServerSocketChannel;
import io.netty.channel.socket.nio.SelectorEventLoop;
import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; import io.netty.handler.logging.LoggingHandler;
@ -42,14 +42,14 @@ public class EchoServer {
// Configure the server. // Configure the server.
ServerChannelBootstrap b = new ServerChannelBootstrap(); ServerChannelBootstrap b = new ServerChannelBootstrap();
try { try {
b.eventLoop(new SelectorEventLoop(), new SelectorEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.option(ChannelOption.SO_BACKLOG, 100) .option(ChannelOption.SO_BACKLOG, 100)
.localAddress(new InetSocketAddress(port)) .localAddress(new InetSocketAddress(port))
.childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.TCP_NODELAY, true)
.childInitializer(new ChannelInitializer() { .childInitializer(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(Channel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast( ch.pipeline().addLast(
new LoggingHandler(LogLevel.INFO), new LoggingHandler(LogLevel.INFO),
new EchoServerHandler()); new EchoServerHandler());

View File

@ -18,7 +18,7 @@ package io.netty.example.http.snoop;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelBootstrap; import io.netty.channel.ChannelBootstrap;
import io.netty.channel.socket.nio.NioSocketChannel; 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.CookieEncoder;
import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpHeaders;
@ -63,7 +63,7 @@ public class HttpSnoopClient {
// Configure the client. // Configure the client.
ChannelBootstrap b = new ChannelBootstrap(); ChannelBootstrap b = new ChannelBootstrap();
try { try {
b.eventLoop(new SelectorEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.initializer(new HttpSnoopClientInitializer(ssl)) .initializer(new HttpSnoopClientInitializer(ssl))
.remoteAddress(new InetSocketAddress(host, port)); .remoteAddress(new InetSocketAddress(host, port));

View File

@ -15,9 +15,9 @@
*/ */
package io.netty.example.http.snoop; package io.netty.example.http.snoop;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.example.securechat.SecureChatSslContextFactory; import io.netty.example.securechat.SecureChatSslContextFactory;
import io.netty.handler.codec.http.HttpClientCodec; import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LogLevel;
@ -25,7 +25,7 @@ import io.netty.handler.logging.LoggingHandler;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
public class HttpSnoopClientInitializer extends ChannelInitializer { public class HttpSnoopClientInitializer extends ChannelInitializer<SocketChannel> {
private final boolean ssl; private final boolean ssl;
@ -34,7 +34,7 @@ public class HttpSnoopClientInitializer extends ChannelInitializer {
} }
@Override @Override
public void initChannel(Channel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
// Create a default pipeline implementation. // Create a default pipeline implementation.
ChannelPipeline p = ch.pipeline(); ChannelPipeline p = ch.pipeline();

View File

@ -18,7 +18,7 @@ package io.netty.example.http.snoop;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ServerChannelBootstrap; import io.netty.channel.ServerChannelBootstrap;
import io.netty.channel.socket.nio.NioServerSocketChannel; 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; import java.net.InetSocketAddress;
@ -39,7 +39,7 @@ public class HttpSnoopServer {
ServerChannelBootstrap b = new ServerChannelBootstrap(); ServerChannelBootstrap b = new ServerChannelBootstrap();
try { try {
b.eventLoop(new SelectorEventLoop(), new SelectorEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.childInitializer(new HttpSnoopServerInitializer()) .childInitializer(new HttpSnoopServerInitializer())
.localAddress(new InetSocketAddress(port)); .localAddress(new InetSocketAddress(port));

View File

@ -15,15 +15,15 @@
*/ */
package io.netty.example.http.snoop; package io.netty.example.http.snoop;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpRequestDecoder; import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.codec.http.HttpResponseEncoder;
public class HttpSnoopServerInitializer extends ChannelInitializer { public class HttpSnoopServerInitializer extends ChannelInitializer<SocketChannel> {
@Override @Override
public void initChannel(Channel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
// Create a default pipeline implementation. // Create a default pipeline implementation.
ChannelPipeline p = ch.pipeline(); ChannelPipeline p = ch.pipeline();

View File

@ -20,9 +20,10 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelBootstrap; import io.netty.channel.ChannelBootstrap;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.DatagramPacket;
import io.netty.channel.socket.nio.NioDatagramChannel; 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 io.netty.util.CharsetUtil;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -44,13 +45,13 @@ public class QuoteOfTheMomentClient {
public void run() throws Exception { public void run() throws Exception {
ChannelBootstrap b = new ChannelBootstrap(); ChannelBootstrap b = new ChannelBootstrap();
try { try {
b.eventLoop(new SelectorEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioDatagramChannel()) .channel(new NioDatagramChannel())
.localAddress(new InetSocketAddress(0)) .localAddress(new InetSocketAddress(0))
.option(ChannelOption.SO_BROADCAST, true) .option(ChannelOption.SO_BROADCAST, true)
.initializer(new ChannelInitializer() { .initializer(new ChannelInitializer<DatagramChannel>() {
@Override @Override
public void initChannel(Channel ch) throws Exception { public void initChannel(DatagramChannel ch) throws Exception {
ch.pipeline().addLast(new QuoteOfTheMomentClientHandler()); ch.pipeline().addLast(new QuoteOfTheMomentClientHandler());
} }
}); });

View File

@ -15,12 +15,12 @@
*/ */
package io.netty.example.qotm; package io.netty.example.qotm;
import io.netty.channel.Channel;
import io.netty.channel.ChannelBootstrap; import io.netty.channel.ChannelBootstrap;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.nio.NioDatagramChannel; 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; import java.net.InetSocketAddress;
@ -41,13 +41,13 @@ public class QuoteOfTheMomentServer {
public void run() throws Exception { public void run() throws Exception {
ChannelBootstrap b = new ChannelBootstrap(); ChannelBootstrap b = new ChannelBootstrap();
try { try {
b.eventLoop(new SelectorEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioDatagramChannel()) .channel(new NioDatagramChannel())
.localAddress(new InetSocketAddress(port)) .localAddress(new InetSocketAddress(port))
.option(ChannelOption.SO_BROADCAST, true) .option(ChannelOption.SO_BROADCAST, true)
.initializer(new ChannelInitializer() { .initializer(new ChannelInitializer<DatagramChannel>() {
@Override @Override
public void initChannel(Channel ch) throws Exception { public void initChannel(DatagramChannel ch) throws Exception {
ch.pipeline().addLast(new QuoteOfTheMomentServerHandler()); ch.pipeline().addLast(new QuoteOfTheMomentServerHandler());
} }
}); });

View File

@ -55,12 +55,12 @@ public abstract class AbstractNioChannel extends AbstractChannel {
@Override @Override
protected boolean isCompatible(EventLoop loop) { protected boolean isCompatible(EventLoop loop) {
return loop instanceof SingleThreadSelectorEventLoop; return loop instanceof NioChildEventLoop;
} }
@Override @Override
protected void doRegister() throws Exception { protected void doRegister() throws Exception {
SingleThreadSelectorEventLoop loop = (SingleThreadSelectorEventLoop) eventLoop(); NioChildEventLoop loop = (NioChildEventLoop) eventLoop();
selectionKey = javaChannel().register(loop.selector, isActive()? SelectionKey.OP_READ : 0, this); selectionKey = javaChannel().register(loop.selector, isActive()? SelectionKey.OP_READ : 0, this);
} }

View File

@ -34,13 +34,13 @@ import java.util.Set;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
final class SingleThreadSelectorEventLoop extends SingleThreadEventLoop { final class NioChildEventLoop extends SingleThreadEventLoop {
/** /**
* Internal Netty logger. * Internal Netty logger.
*/ */
protected static final InternalLogger logger = InternalLoggerFactory 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. 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; int cancelledKeys;
SingleThreadSelectorEventLoop(ThreadFactory threadFactory, SelectorProvider selectorProvider) { NioChildEventLoop(ThreadFactory threadFactory, SelectorProvider selectorProvider) {
super(threadFactory); super(threadFactory);
if (selectorProvider == null) { if (selectorProvider == null) {
throw new NullPointerException("selectorProvider"); throw new NullPointerException("selectorProvider");

View File

@ -89,7 +89,7 @@ public final class NioDatagramChannel extends AbstractNioChannel implements io.n
throw new ChannelException("Failed to enter non-blocking mode.", e); 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 @Override
protected void doDeregister() throws Exception { protected void doDeregister() throws Exception {
selectionKey().cancel(); selectionKey().cancel();
((SingleThreadSelectorEventLoop) eventLoop()).cancelledKeys ++; ((NioChildEventLoop) eventLoop()).cancelledKeys ++;
} }
@Override @Override

View File

@ -26,7 +26,7 @@ import java.nio.channels.DatagramChannel;
/** /**
* The default {@link NioSocketChannelConfig} implementation. * The default {@link NioSocketChannelConfig} implementation.
*/ */
class DefaultNioDatagramChannelConfig extends DefaultDatagramChannelConfig { class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
private static final Object IP_MULTICAST_IF; private static final Object IP_MULTICAST_IF;
private static final Method GET_OPTION; private static final Method GET_OPTION;
@ -70,7 +70,7 @@ class DefaultNioDatagramChannelConfig extends DefaultDatagramChannelConfig {
private final DatagramChannel channel; private final DatagramChannel channel;
DefaultNioDatagramChannelConfig(DatagramChannel channel) { NioDatagramChannelConfig(DatagramChannel channel) {
super(channel.socket()); super(channel.socket());
this.channel = channel; this.channel = channel;
} }

View File

@ -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<NioChildEventLoop>() {
@Override
public NioChildEventLoop newEventLoop(ThreadFactory threadFactory) throws Exception {
return new NioChildEventLoop(threadFactory, selectorProvider);
}
}, nThreads, threadFactory);
}
}

View File

@ -101,12 +101,12 @@ public class NioServerSocketChannel extends AbstractServerChannel
@Override @Override
protected boolean isCompatible(EventLoop loop) { protected boolean isCompatible(EventLoop loop) {
return loop instanceof SingleThreadSelectorEventLoop; return loop instanceof NioChildEventLoop;
} }
@Override @Override
protected void doRegister() throws Exception { protected void doRegister() throws Exception {
SingleThreadSelectorEventLoop loop = (SingleThreadSelectorEventLoop) eventLoop(); NioChildEventLoop loop = (NioChildEventLoop) eventLoop();
selectionKey = javaChannel().register( selectionKey = javaChannel().register(
loop.selector, isActive()? SelectionKey.OP_ACCEPT : 0, this); loop.selector, isActive()? SelectionKey.OP_ACCEPT : 0, this);
} }

View File

@ -155,7 +155,7 @@ public class NioSocketChannel extends AbstractNioChannel implements io.netty.cha
@Override @Override
protected void doDeregister() throws Exception { protected void doDeregister() throws Exception {
selectionKey().cancel(); selectionKey().cancel();
((SingleThreadSelectorEventLoop) eventLoop()).cancelledKeys ++; ((NioChildEventLoop) eventLoop()).cancelledKeys ++;
} }
@Override @Override

View File

@ -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<SingleThreadSelectorEventLoop>() {
@Override
public SingleThreadSelectorEventLoop newEventLoop(ThreadFactory threadFactory) throws Exception {
return new SingleThreadSelectorEventLoop(threadFactory, selectorProvider);
}
}, nThreads, threadFactory);
}
}

View File

@ -6,12 +6,12 @@ import io.netty.channel.ChannelFutureListener;
import io.netty.channel.SingleThreadEventLoop; import io.netty.channel.SingleThreadEventLoop;
class SingleBlockingChannelEventLoop extends SingleThreadEventLoop { class OioChildEventLoop extends SingleThreadEventLoop {
private final BlockingChannelEventLoop parent; private final OioEventLoop parent;
private Channel ch; private Channel ch;
SingleBlockingChannelEventLoop(BlockingChannelEventLoop parent) { OioChildEventLoop(OioEventLoop parent) {
super(parent.threadFactory); super(parent.threadFactory);
this.parent = parent; this.parent = parent;
} }
@ -33,7 +33,7 @@ class SingleBlockingChannelEventLoop extends SingleThreadEventLoop {
@Override @Override
protected void run() { protected void run() {
for (;;) { for (;;) {
Channel ch = SingleBlockingChannelEventLoop.this.ch; Channel ch = OioChildEventLoop.this.ch;
if (ch == null || !ch.isActive()) { if (ch == null || !ch.isActive()) {
Runnable task; Runnable task;
try { try {

View File

@ -117,7 +117,7 @@ public class OioDatagramChannel extends AbstractChannel
@Override @Override
protected boolean isCompatible(EventLoop loop) { protected boolean isCompatible(EventLoop loop) {
return loop instanceof SingleBlockingChannelEventLoop; return loop instanceof OioChildEventLoop;
} }
@Override @Override

View File

@ -23,25 +23,25 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
public class BlockingChannelEventLoop implements EventLoop { public class OioEventLoop implements EventLoop {
private final int maxChannels; private final int maxChannels;
final ThreadFactory threadFactory; final ThreadFactory threadFactory;
final Set<SingleBlockingChannelEventLoop> activeChildren = Collections.newSetFromMap( final Set<OioChildEventLoop> activeChildren = Collections.newSetFromMap(
new ConcurrentHashMap<SingleBlockingChannelEventLoop, Boolean>()); new ConcurrentHashMap<OioChildEventLoop, Boolean>());
final Queue<SingleBlockingChannelEventLoop> idleChildren = final Queue<OioChildEventLoop> idleChildren =
QueueFactory.createQueue(SingleBlockingChannelEventLoop.class); QueueFactory.createQueue(OioChildEventLoop.class);
private final ChannelException tooManyChannels; private final ChannelException tooManyChannels;
public BlockingChannelEventLoop() { public OioEventLoop() {
this(0); this(0);
} }
public BlockingChannelEventLoop(int maxChannels) { public OioEventLoop(int maxChannels) {
this(maxChannels, Executors.defaultThreadFactory()); this(maxChannels, Executors.defaultThreadFactory());
} }
public BlockingChannelEventLoop(int maxChannels, ThreadFactory threadFactory) { public OioEventLoop(int maxChannels, ThreadFactory threadFactory) {
if (maxChannels < 0) { if (maxChannels < 0) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"maxChannels: %d (expected: >= 0)", maxChannels)); "maxChannels: %d (expected: >= 0)", maxChannels));
@ -234,20 +234,20 @@ public class BlockingChannelEventLoop implements EventLoop {
} }
private EventLoop nextEventLoop() { private EventLoop nextEventLoop() {
SingleBlockingChannelEventLoop loop = idleChildren.poll(); OioChildEventLoop loop = idleChildren.poll();
if (loop == null) { if (loop == null) {
if (maxChannels > 0 && activeChildren.size() >= maxChannels) { if (maxChannels > 0 && activeChildren.size() >= maxChannels) {
throw tooManyChannels; throw tooManyChannels;
} }
loop = new SingleBlockingChannelEventLoop(this); loop = new OioChildEventLoop(this);
} }
activeChildren.add(loop); activeChildren.add(loop);
return loop; return loop;
} }
private static SingleBlockingChannelEventLoop currentEventLoop() { private static OioChildEventLoop currentEventLoop() {
SingleBlockingChannelEventLoop loop = OioChildEventLoop loop =
(SingleBlockingChannelEventLoop) SingleThreadEventLoop.currentEventLoop(); (OioChildEventLoop) SingleThreadEventLoop.currentEventLoop();
if (loop == null) { if (loop == null) {
throw new IllegalStateException("not called from an event loop thread"); throw new IllegalStateException("not called from an event loop thread");
} }

View File

@ -118,7 +118,7 @@ public class OioServerSocketChannel extends AbstractServerChannel
@Override @Override
protected boolean isCompatible(EventLoop loop) { protected boolean isCompatible(EventLoop loop) {
return loop instanceof SingleBlockingChannelEventLoop; return loop instanceof OioChildEventLoop;
} }
@Override @Override

View File

@ -111,7 +111,7 @@ public class OioSocketChannel extends AbstractChannel
@Override @Override
protected boolean isCompatible(EventLoop loop) { protected boolean isCompatible(EventLoop loop) {
return loop instanceof SingleBlockingChannelEventLoop; return loop instanceof OioChildEventLoop;
} }
@Override @Override