Skip to content

Commit

Permalink
Allow easier use of AIO transport via bootstrap. Related to [netty#725]
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Maurer committed Nov 10, 2012
1 parent 1cc104e commit fa805c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions transport/src/main/java/io/netty/bootstrap/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
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;
Expand Down Expand Up @@ -177,4 +179,22 @@ public Bootstrap duplicate() {
b.attrs().putAll(attrs());
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());
}
}
}
13 changes: 13 additions & 0 deletions transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
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;
Expand Down Expand Up @@ -98,6 +100,9 @@ public ServerBootstrap channel(Class<? extends Channel> channelClass) {
if (!ServerChannel.class.isAssignableFrom(channelClass)) {
throw new IllegalArgumentException();
}
if (channelClass == AioServerSocketChannel.class) {
channelFactory(new AioServerSocketChannelFactory());
}
return super.channel(channelClass);
}

Expand Down Expand Up @@ -258,4 +263,12 @@ public void inboundBufferUpdated(ChannelHandlerContext ctx) {
}
}
}

private final class AioServerSocketChannelFactory implements ChannelFactory {
@Override
public Channel newChannel() {
return new AioServerSocketChannel((AioEventLoopGroup) group(), (AioEventLoopGroup) childGroup);
}
}
}

0 comments on commit fa805c4

Please sign in to comment.