use of org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory in project jstorm by alibaba.
the class NettyContext method prepare.
/**
* initialization per Storm configuration
*/
@SuppressWarnings("rawtypes")
public void prepare(Map storm_conf) {
this.storm_conf = storm_conf;
int maxWorkers = Utils.getInt(storm_conf.get(Config.STORM_MESSAGING_NETTY_CLIENT_WORKER_THREADS));
ThreadFactory bossFactory = new NettyRenameThreadFactory(MetricDef.NETTY_CLI + "boss");
ThreadFactory workerFactory = new NettyRenameThreadFactory(MetricDef.NETTY_CLI + "worker");
if (maxWorkers > 0) {
clientChannelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(bossFactory), Executors.newCachedThreadPool(workerFactory), maxWorkers);
} else {
clientChannelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(bossFactory), Executors.newCachedThreadPool(workerFactory));
}
reconnector = new ReconnectRunnable();
new AsyncLoopThread(reconnector, true, Thread.MIN_PRIORITY, true);
}
use of org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory 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.NioClientSocketChannelFactory in project databus by linkedin.
the class TestHttpResponseProcessor method createChannelFuture.
static ChannelFuture createChannelFuture(final GenericHttpResponseHandler responseHandler, int port) {
ClientBootstrap client = new ClientBootstrap(new NioClientSocketChannelFactory(BOSS_POOL, IO_POOL));
client.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new LoggingHandler(InternalLogLevel.DEBUG), new HttpClientCodec(), new LoggingHandler(InternalLogLevel.DEBUG), responseHandler);
}
});
final ChannelFuture connectFuture = client.connect(new InetSocketAddress("localhost", port));
return connectFuture;
}
use of org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory in project http-client by biasedbit.
the class DefaultHttpClient method init.
// HttpClient -----------------------------------------------------------------------------------------------------
@Override
public boolean init() {
if (timeoutController == null) {
// prefer lower resources consumption over precision
timeoutController = new HashedWheelTimeoutController();
timeoutController.init();
internalTimeoutManager = true;
}
if (connectionFactory == null)
connectionFactory = new DefaultConnectionFactory();
if ((sslContextFactory == null) && isHttps())
sslContextFactory = BogusSslContextFactory.getInstance();
eventConsumerLatch = new CountDownLatch(1);
eventQueue = new LinkedBlockingQueue<>();
// TODO instead of fixed size thread pool, use a cached thread pool with size limit (limited growth cached pool)
executor = Executors.newFixedThreadPool(maxHelperThreads, new NamedThreadFactory("httpHelpers"));
Executor workerPool = Executors.newFixedThreadPool(maxIoWorkerThreads, new NamedThreadFactory("httpWorkers"));
if (useNio) {
// It's only going to create 1 thread, so no harm done here.
Executor bossPool = Executors.newCachedThreadPool();
channelFactory = new NioClientSocketChannelFactory(bossPool, workerPool);
} else {
channelFactory = new OioClientSocketChannelFactory(workerPool);
}
channelGroup = new CleanupChannelGroup(toString());
// Create a pipeline without the last handler (it will be added right before connecting).
pipelineFactory = new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (useSsl) {
SSLEngine engine = sslContextFactory.getClientContext().createSSLEngine();
engine.setUseClientMode(true);
pipeline.addLast("ssl", new SslHandler(engine));
}
pipeline.addLast("codec", new HttpClientCodec());
if (autoDecompress)
pipeline.addLast("decompressor", new HttpContentDecompressor());
return pipeline;
}
};
executor.execute(new Runnable() {
@Override
public void run() {
eventHandlingLoop();
}
});
return true;
}
use of org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory in project cdap by caskdata.
the class NettyRouter method bootstrapClient.
private void bootstrapClient(final ChannelUpstreamHandler connectionTracker) {
ExecutorService clientBossExecutor = createExecutorService(clientBossThreadPoolSize, "router-client-boss-thread-%d");
ExecutorService clientWorkerExecutor = createExecutorService(clientWorkerThreadPoolSize, "router-client-worker-thread-%d");
clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(new NioClientBossPool(clientBossExecutor, clientBossThreadPoolSize), new NioWorkerPool(clientWorkerExecutor, clientWorkerThreadPoolSize)));
ChannelPipelineFactory pipelineFactory = new ClientChannelPipelineFactory(connectionTracker, connectionTimeout, timer);
clientBootstrap.setPipelineFactory(pipelineFactory);
clientBootstrap.setOption("bufferFactory", new DirectChannelBufferFactory());
}
Aggregations