clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(daemonThreadFactory(settings, "transport_client_boss")),
Executors.newCachedThreadPool(daemonThreadFactory(settings, "transport_client_worker")),
workerCount));
}
ChannelPipelineFactory clientPipelineFactory = new ChannelPipelineFactory() {
@Override public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoder", new SizeHeaderFrameDecoder());
pipeline.addLast("dispatcher", new MessageChannelHandler(NettyTransport.this, logger));
return pipeline;
}
};
clientBootstrap.setPipelineFactory(clientPipelineFactory);
clientBootstrap.setOption("connectTimeoutMillis", connectTimeout.millis());
if (tcpNoDelay != null) {
clientBootstrap.setOption("tcpNoDelay", tcpNoDelay);
}
if (tcpKeepAlive != null) {
clientBootstrap.setOption("keepAlive", tcpKeepAlive);
}
if (tcpSendBufferSize != null) {
clientBootstrap.setOption("sendBufferSize", tcpSendBufferSize.bytes());
}
if (tcpReceiveBufferSize != null) {
clientBootstrap.setOption("receiveBufferSize", tcpReceiveBufferSize.bytes());
}
if (reuseAddress != null) {
clientBootstrap.setOption("reuseAddress", reuseAddress);
}
if (!settings.getAsBoolean("network.server", true)) {
return;
}
serverOpenChannels = new OpenChannelsHandler();
if (blockingServer) {
serverBootstrap = new ServerBootstrap(new OioServerSocketChannelFactory(
Executors.newCachedThreadPool(daemonThreadFactory(settings, "transport_server_boss")),
Executors.newCachedThreadPool(daemonThreadFactory(settings, "transport_server_worker"))
));
} else {
serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(daemonThreadFactory(settings, "transport_server_boss")),
Executors.newCachedThreadPool(daemonThreadFactory(settings, "transport_server_worker")),
workerCount));
}
ChannelPipelineFactory serverPipelineFactory = new ChannelPipelineFactory() {
@Override public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("openChannels", serverOpenChannels);
pipeline.addLast("decoder", new SizeHeaderFrameDecoder());
pipeline.addLast("dispatcher", new MessageChannelHandler(NettyTransport.this, logger));