diff --git a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java index c4ccae4657..fe1a0b52b6 100644 --- a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java @@ -20,6 +20,8 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.aio.AioEventLoopGroup; +import io.netty.channel.socket.aio.AioSocketChannel; import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.util.AttributeKey; @@ -177,4 +179,22 @@ public class Bootstrap extends AbstractBootstrap { b.attrs().putAll(attrs()); return b; } + + @Override + public Bootstrap channel(Class channelClass) { + if (channelClass == null) { + throw new NullPointerException("channelClass"); + } + if (channelClass == AioSocketChannel.class) { + return channelFactory(new AioSocketChannelFactory()); + } + return super.channel(channelClass); + } + + private final class AioSocketChannelFactory implements ChannelFactory { + @Override + public Channel newChannel() { + return new AioSocketChannel((AioEventLoopGroup) group()); + } + } } diff --git a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java index d06d25c56e..8299f4e4be 100644 --- a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java @@ -30,6 +30,8 @@ import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.aio.AioEventLoopGroup; +import io.netty.channel.socket.aio.AioServerSocketChannel; import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.util.AttributeKey; @@ -98,6 +100,9 @@ public class ServerBootstrap extends AbstractBootstrap { if (!ServerChannel.class.isAssignableFrom(channelClass)) { throw new IllegalArgumentException(); } + if (channelClass == AioServerSocketChannel.class) { + channelFactory(new AioServerSocketChannelFactory()); + } return super.channel(channelClass); } @@ -258,4 +263,12 @@ public class ServerBootstrap extends AbstractBootstrap { } } } + + private final class AioServerSocketChannelFactory implements ChannelFactory { + @Override + public Channel newChannel() { + return new AioServerSocketChannel((AioEventLoopGroup) group(), (AioEventLoopGroup) childGroup); + } + } } +