Simplified EventLoop implementation names
- Also - Fixed a test failure - Fixed compiler warnings related with ChannelInitializer type parameters
This commit is contained in:
parent
61314ef51b
commit
a1bdf671f1
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,9 @@ public class ByteArrayEncoder extends MessageToMessageEncoder<byte[], ChannelBuf
|
||||
|
||||
@Override
|
||||
public ChannelBuffer encode(ChannelOutboundHandlerContext<byte[]> ctx, byte[] msg) throws Exception {
|
||||
if (msg.length == 0) {
|
||||
return null;
|
||||
}
|
||||
return ChannelBuffers.wrappedBuffer(msg);
|
||||
}
|
||||
}
|
||||
|
@ -126,18 +126,7 @@ class EmbeddedChannel extends AbstractChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doRead(ChannelBuffer buf) 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();
|
||||
protected int doWriteBytes(ChannelBuffer buf, boolean lastSpin) throws Exception {
|
||||
int length = buf.readableBytes();
|
||||
if (length > 0) {
|
||||
productQueue.add(buf.readBytes(length));
|
||||
|
@ -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<SocketChannel>() {
|
||||
@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));
|
||||
|
@ -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<SocketChannel>() {
|
||||
@Override
|
||||
public void initChannel(Channel ch) throws Exception {
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
ch.pipeline().addLast(
|
||||
new LoggingHandler(LogLevel.INFO),
|
||||
new EchoServerHandler());
|
||||
|
@ -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));
|
||||
|
@ -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<SocketChannel> {
|
||||
|
||||
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();
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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<SocketChannel> {
|
||||
@Override
|
||||
public void initChannel(Channel ch) throws Exception {
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
// Create a default pipeline implementation.
|
||||
ChannelPipeline p = ch.pipeline();
|
||||
|
||||
|
@ -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<DatagramChannel>() {
|
||||
@Override
|
||||
public void initChannel(Channel ch) throws Exception {
|
||||
public void initChannel(DatagramChannel ch) throws Exception {
|
||||
ch.pipeline().addLast(new QuoteOfTheMomentClientHandler());
|
||||
}
|
||||
});
|
||||
|
@ -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<DatagramChannel>() {
|
||||
@Override
|
||||
public void initChannel(Channel ch) throws Exception {
|
||||
public void initChannel(DatagramChannel ch) throws Exception {
|
||||
ch.pipeline().addLast(new QuoteOfTheMomentServerHandler());
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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");
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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 {
|
@ -117,7 +117,7 @@ public class OioDatagramChannel extends AbstractChannel
|
||||
|
||||
@Override
|
||||
protected boolean isCompatible(EventLoop loop) {
|
||||
return loop instanceof SingleBlockingChannelEventLoop;
|
||||
return loop instanceof OioChildEventLoop;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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<SingleBlockingChannelEventLoop> activeChildren = Collections.newSetFromMap(
|
||||
new ConcurrentHashMap<SingleBlockingChannelEventLoop, Boolean>());
|
||||
final Queue<SingleBlockingChannelEventLoop> idleChildren =
|
||||
QueueFactory.createQueue(SingleBlockingChannelEventLoop.class);
|
||||
final Set<OioChildEventLoop> activeChildren = Collections.newSetFromMap(
|
||||
new ConcurrentHashMap<OioChildEventLoop, Boolean>());
|
||||
final Queue<OioChildEventLoop> 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");
|
||||
}
|
@ -118,7 +118,7 @@ public class OioServerSocketChannel extends AbstractServerChannel
|
||||
|
||||
@Override
|
||||
protected boolean isCompatible(EventLoop loop) {
|
||||
return loop instanceof SingleBlockingChannelEventLoop;
|
||||
return loop instanceof OioChildEventLoop;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,7 +111,7 @@ public class OioSocketChannel extends AbstractChannel
|
||||
|
||||
@Override
|
||||
protected boolean isCompatible(EventLoop loop) {
|
||||
return loop instanceof SingleBlockingChannelEventLoop;
|
||||
return loop instanceof OioChildEventLoop;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user