Allow easier use of AIO transport via bootstrap. Related to [#725]
This commit is contained in:
parent
1cc104e1c0
commit
fa805c4c13
@ -20,6 +20,8 @@ import io.netty.channel.ChannelFuture;
|
|||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.ChannelPipeline;
|
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.InternalLogger;
|
||||||
import io.netty.logging.InternalLoggerFactory;
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
@ -177,4 +179,22 @@ public class Bootstrap extends AbstractBootstrap<Bootstrap> {
|
|||||||
b.attrs().putAll(attrs());
|
b.attrs().putAll(attrs());
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Bootstrap channel(Class<? extends Channel> 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ import io.netty.channel.ChannelPipeline;
|
|||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.ServerChannel;
|
import io.netty.channel.ServerChannel;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
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.InternalLogger;
|
||||||
import io.netty.logging.InternalLoggerFactory;
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
@ -98,6 +100,9 @@ public class ServerBootstrap extends AbstractBootstrap<ServerBootstrap> {
|
|||||||
if (!ServerChannel.class.isAssignableFrom(channelClass)) {
|
if (!ServerChannel.class.isAssignableFrom(channelClass)) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
if (channelClass == AioServerSocketChannel.class) {
|
||||||
|
channelFactory(new AioServerSocketChannelFactory());
|
||||||
|
}
|
||||||
return super.channel(channelClass);
|
return super.channel(channelClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,4 +263,12 @@ public class ServerBootstrap extends AbstractBootstrap<ServerBootstrap> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final class AioServerSocketChannelFactory implements ChannelFactory {
|
||||||
|
@Override
|
||||||
|
public Channel newChannel() {
|
||||||
|
return new AioServerSocketChannel((AioEventLoopGroup) group(), (AioEventLoopGroup) childGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user