Search in sources :

Example 1 with HttpClientPipelineFactory

use of org.apache.druid.java.util.http.client.netty.HttpClientPipelineFactory in project druid by druid-io.

the class HttpClientInit method createBootstrap.

private static ClientBootstrap createBootstrap(Lifecycle lifecycle, Timer timer, int bossPoolSize, int workerPoolSize) {
    final NioClientBossPool bossPool = new NioClientBossPool(Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("HttpClient-Netty-Boss-%s").build()), bossPoolSize, timer, ThreadNameDeterminer.CURRENT);
    final NioWorkerPool workerPool = new NioWorkerPool(Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("HttpClient-Netty-Worker-%s").build()), workerPoolSize, ThreadNameDeterminer.CURRENT);
    final ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(bossPool, workerPool));
    bootstrap.setOption("keepAlive", true);
    bootstrap.setPipelineFactory(new HttpClientPipelineFactory());
    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
    try {
        lifecycle.addMaybeStartHandler(new Lifecycle.Handler() {

            @Override
            public void start() {
            }

            @Override
            public void stop() {
                bootstrap.releaseExternalResources();
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return bootstrap;
}
Also used : NioClientBossPool(org.jboss.netty.channel.socket.nio.NioClientBossPool) NioWorkerPool(org.jboss.netty.channel.socket.nio.NioWorkerPool) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) HttpClientPipelineFactory(org.apache.druid.java.util.http.client.netty.HttpClientPipelineFactory) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory)

Aggregations

ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)1 HttpClientPipelineFactory (org.apache.druid.java.util.http.client.netty.HttpClientPipelineFactory)1 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)1 NioClientBossPool (org.jboss.netty.channel.socket.nio.NioClientBossPool)1 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)1 NioWorkerPool (org.jboss.netty.channel.socket.nio.NioWorkerPool)1 Slf4JLoggerFactory (org.jboss.netty.logging.Slf4JLoggerFactory)1