use of org.apache.druid.java.util.http.client.pool.ChannelResourceFactory 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);
}
}
Aggregations