Skip to content

Make SocketChannel and EventLoopGroup configurable #902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public NettyWebSocket newNettyWebSocket(Channel channel, AsyncHttpClientConfig c
*/
private EventLoopGroup eventLoopGroup;

private Class<? extends Channel> socketChannelClass;

private AdditionalPipelineInitializer httpAdditionalPipelineInitializer;
private AdditionalPipelineInitializer wsAdditionalPipelineInitializer;
private AdditionalPipelineInitializer httpsAdditionalPipelineInitializer;
Expand All @@ -155,6 +157,14 @@ public void setEventLoopGroup(EventLoopGroup eventLoopGroup) {
this.eventLoopGroup = eventLoopGroup;
}

public Class<? extends Channel> getSocketChannelClass() {
return socketChannelClass;
}

public void setSocketChannelClass(Class<? extends Channel> socketChannelClass) {
this.socketChannelClass = socketChannelClass;
}

public AdditionalPipelineInitializer getHttpAdditionalPipelineInitializer() {
return httpAdditionalPipelineInitializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.netty.channel.EventLoopGroup;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.oio.OioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpContentDecompressor;
Expand Down Expand Up @@ -82,6 +83,7 @@ public class ChannelManager {
private final SSLEngineFactory sslEngineFactory;
private final EventLoopGroup eventLoopGroup;
private final boolean allowReleaseEventLoopGroup;
private final Class<? extends Channel> socketChannelClass;
private final Bootstrap plainBootstrap;
private final Bootstrap secureBootstrap;
private final Bootstrap webSocketBootstrap;
Expand Down Expand Up @@ -167,13 +169,16 @@ public Semaphore apply(Object partitionKey) {
// check if external EventLoopGroup is defined
allowReleaseEventLoopGroup = nettyConfig.getEventLoopGroup() == null;
eventLoopGroup = allowReleaseEventLoopGroup ? new NioEventLoopGroup() : nettyConfig.getEventLoopGroup();
if (!(eventLoopGroup instanceof NioEventLoopGroup))
throw new IllegalArgumentException("Only Nio is supported");
if (eventLoopGroup instanceof OioEventLoopGroup)
throw new IllegalArgumentException("Oio is not supported");

plainBootstrap = new Bootstrap().channel(NioSocketChannel.class).group(eventLoopGroup);
secureBootstrap = new Bootstrap().channel(NioSocketChannel.class).group(eventLoopGroup);
webSocketBootstrap = new Bootstrap().channel(NioSocketChannel.class).group(eventLoopGroup);
secureWebSocketBootstrap = new Bootstrap().channel(NioSocketChannel.class).group(eventLoopGroup);
// allow users to specify SocketChannel class and default to NioSocketChannel
socketChannelClass = nettyConfig.getSocketChannelClass() == null ? NioSocketChannel.class : nettyConfig.getSocketChannelClass();

plainBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup);
secureBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup);
webSocketBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup);
secureWebSocketBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup);

if (config.getConnectTimeout() > 0)
nettyConfig.addChannelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout());
Expand Down