Search in sources :

Example 1 with ResourcePool

use of org.apache.druid.java.util.http.client.pool.ResourcePool in project druid by druid-io.

the class HttpClientInit method createClient.

public static HttpClient createClient(HttpClientConfig config, Lifecycle lifecycle) {
    try {
        // We need to use the full constructor in order to set a ThreadNameDeterminer. The other parameters are taken
        // from the defaults in HashedWheelTimer's other constructors.
        final HashedWheelTimer timer = new HashedWheelTimer(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("HttpClient-Timer-%s").build(), ThreadNameDeterminer.CURRENT, 100, TimeUnit.MILLISECONDS, 512);
        lifecycle.addMaybeStartHandler(new Lifecycle.Handler() {

            @Override
            public void start() {
                timer.start();
            }

            @Override
            public void stop() {
                timer.stop();
            }
        });
        return lifecycle.addMaybeStartManagedInstance(new NettyHttpClient(new ResourcePool<>(new ChannelResourceFactory(createBootstrap(lifecycle, timer, config.getBossPoolSize(), config.getWorkerPoolSize()), config.getSslContext(), config.getProxyConfig(), timer, config.getSslHandshakeTimeout() == null ? -1 : config.getSslHandshakeTimeout().getMillis()), new ResourcePoolConfig(config.getNumConnections(), config.getUnusedConnectionTimeoutDuration().getMillis())), config.getReadTimeout(), config.getCompressionCodec(), timer));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ChannelResourceFactory(org.apache.druid.java.util.http.client.pool.ChannelResourceFactory) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) ResourcePool(org.apache.druid.java.util.http.client.pool.ResourcePool) ResourcePoolConfig(org.apache.druid.java.util.http.client.pool.ResourcePoolConfig)

Aggregations

ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)1 ChannelResourceFactory (org.apache.druid.java.util.http.client.pool.ChannelResourceFactory)1 ResourcePool (org.apache.druid.java.util.http.client.pool.ResourcePool)1 ResourcePoolConfig (org.apache.druid.java.util.http.client.pool.ResourcePoolConfig)1 HashedWheelTimer (org.jboss.netty.util.HashedWheelTimer)1