use of org.jboss.netty.channel.socket.nio.WorkerPool in project camel by apache.
the class ClientModeTCPNettyServerBootstrapFactory method startServerBootstrap.
protected void startServerBootstrap() {
// prefer using explicit configured thread pools
BossPool bp = configuration.getBossPool();
WorkerPool wp = configuration.getWorkerPool();
if (bp == null) {
// create new pool which we should shutdown when stopping as its not shared
bossPool = new NettyClientBossPoolBuilder().withTimer(new HashedWheelTimer()).withBossCount(configuration.getBossCount()).withName("NettyClientTCPBoss").build();
bp = bossPool;
}
if (wp == null) {
// create new pool which we should shutdown when stopping as its not shared
workerPool = new NettyWorkerPoolBuilder().withWorkerCount(configuration.getWorkerCount()).withName("NettyServerTCPWorker").build();
wp = workerPool;
}
channelFactory = new NioClientSocketChannelFactory(bp, wp);
serverBootstrap = new ClientBootstrap(channelFactory);
serverBootstrap.setOption("keepAlive", configuration.isKeepAlive());
serverBootstrap.setOption("tcpNoDelay", configuration.isTcpNoDelay());
serverBootstrap.setOption("reuseAddress", configuration.isReuseAddress());
serverBootstrap.setOption("connectTimeoutMillis", configuration.getConnectTimeout());
if (configuration.getBacklog() > 0) {
serverBootstrap.setOption("backlog", configuration.getBacklog());
}
// set any additional netty options
if (configuration.getOptions() != null) {
for (Map.Entry<String, Object> entry : configuration.getOptions().entrySet()) {
serverBootstrap.setOption(entry.getKey(), entry.getValue());
}
}
LOG.debug("Created ServerBootstrap {} with options: {}", serverBootstrap, serverBootstrap.getOptions());
// set the pipeline factory, which creates the pipeline for each newly created channels
serverBootstrap.setPipelineFactory(pipelineFactory);
LOG.info("ServerBootstrap connecting to {}:{}", configuration.getHost(), configuration.getPort());
ChannelFuture connectFuture = serverBootstrap.connect(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
try {
channel = openChannel(connectFuture);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.jboss.netty.channel.socket.nio.WorkerPool in project pinpoint by naver.
the class ClientChannelFactory method createChannelFactory.
public ChannelFactory createChannelFactory(int bossCount, int workerCount, Timer timer) {
ExecutorService boss = newCachedThreadPool("Pinpoint-Client-Boss");
BossPool bossPool = new NioClientBossPool(boss, bossCount, timer, ThreadNameDeterminer.CURRENT);
ExecutorService worker = newCachedThreadPool("Pinpoint-Client-Worker");
WorkerPool workerPool = new NioWorkerPool(worker, workerCount, ThreadNameDeterminer.CURRENT);
return new NioClientSocketChannelFactory(bossPool, workerPool);
}
use of org.jboss.netty.channel.socket.nio.WorkerPool in project camel by apache.
the class NettyProducer method setupTCPCommunication.
protected void setupTCPCommunication() throws Exception {
if (channelFactory == null) {
// prefer using explicit configured thread pools
BossPool bp = configuration.getBossPool();
WorkerPool wp = configuration.getWorkerPool();
if (bp == null) {
// create new pool which we should shutdown when stopping as its not shared
bossPool = new NettyClientBossPoolBuilder().withTimer(getEndpoint().getTimer()).withBossCount(configuration.getBossCount()).withName("NettyClientTCPBoss").build();
bp = bossPool;
}
if (wp == null) {
// create new pool which we should shutdown when stopping as its not shared
workerPool = new NettyWorkerPoolBuilder().withWorkerCount(configuration.getWorkerCount()).withName("NettyClientTCPWorker").build();
wp = workerPool;
}
channelFactory = new NioClientSocketChannelFactory(bp, wp);
}
}
use of org.jboss.netty.channel.socket.nio.WorkerPool in project camel by apache.
the class SingleTCPNettyServerBootstrapFactory method startServerBootstrap.
protected void startServerBootstrap() {
// prefer using explicit configured thread pools
BossPool bp = configuration.getBossPool();
WorkerPool wp = configuration.getWorkerPool();
if (bp == null) {
// create new pool which we should shutdown when stopping as its not shared
bossPool = new NettyServerBossPoolBuilder().withBossCount(configuration.getBossCount()).withName("NettyServerTCPBoss").build();
bp = bossPool;
}
if (wp == null) {
// create new pool which we should shutdown when stopping as its not shared
workerPool = new NettyWorkerPoolBuilder().withWorkerCount(configuration.getWorkerCount()).withName("NettyServerTCPWorker").build();
wp = workerPool;
}
channelFactory = new NioServerSocketChannelFactory(bp, wp);
serverBootstrap = new ServerBootstrap(channelFactory);
serverBootstrap.setOption("child.keepAlive", configuration.isKeepAlive());
serverBootstrap.setOption("child.tcpNoDelay", configuration.isTcpNoDelay());
serverBootstrap.setOption("reuseAddress", configuration.isReuseAddress());
serverBootstrap.setOption("child.reuseAddress", configuration.isReuseAddress());
serverBootstrap.setOption("child.connectTimeoutMillis", configuration.getConnectTimeout());
if (configuration.getBacklog() > 0) {
serverBootstrap.setOption("backlog", configuration.getBacklog());
}
// set any additional netty options
if (configuration.getOptions() != null) {
for (Map.Entry<String, Object> entry : configuration.getOptions().entrySet()) {
serverBootstrap.setOption(entry.getKey(), entry.getValue());
}
}
LOG.debug("Created ServerBootstrap {} with options: {}", serverBootstrap, serverBootstrap.getOptions());
// set the pipeline factory, which creates the pipeline for each newly created channels
serverBootstrap.setPipelineFactory(pipelineFactory);
LOG.info("ServerBootstrap binding to {}:{}", configuration.getHost(), configuration.getPort());
channel = serverBootstrap.bind(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
// to keep track of all channels in use
allChannels.add(channel);
}
Aggregations