mirror of https://github.com/apache/druid.git
Use daemon thread pool for AsyncHttpClient in emitters (#5057)
* use daemon thread pool for AsyncHttpClient in emitters * changed to use existing helper methods * refactored creation of AsyncHttpClient
This commit is contained in:
parent
2ecebb3173
commit
81f249874b
|
@ -32,6 +32,7 @@ import com.metamx.emitter.core.HttpPostEmitter;
|
||||||
import io.druid.guice.JsonConfigProvider;
|
import io.druid.guice.JsonConfigProvider;
|
||||||
import io.druid.guice.LazySingleton;
|
import io.druid.guice.LazySingleton;
|
||||||
import io.druid.guice.ManageLifecycle;
|
import io.druid.guice.ManageLifecycle;
|
||||||
|
import io.druid.java.util.common.concurrent.Execs;
|
||||||
import io.druid.java.util.common.lifecycle.Lifecycle;
|
import io.druid.java.util.common.lifecycle.Lifecycle;
|
||||||
import io.netty.handler.ssl.ClientAuth;
|
import io.netty.handler.ssl.ClientAuth;
|
||||||
import io.netty.handler.ssl.JdkSslContext;
|
import io.netty.handler.ssl.JdkSslContext;
|
||||||
|
@ -68,6 +69,19 @@ public class HttpEmitterModule implements Module
|
||||||
binder.bind(SSLContext.class).toProvider(Providers.of(context)).in(LazySingleton.class);
|
binder.bind(SSLContext.class).toProvider(Providers.of(context)).in(LazySingleton.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static AsyncHttpClient createAsyncHttpClient(
|
||||||
|
String nameFormat,
|
||||||
|
@Nullable SSLContext sslContext
|
||||||
|
)
|
||||||
|
{
|
||||||
|
final DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder()
|
||||||
|
.setThreadFactory(Execs.makeThreadFactory(nameFormat));
|
||||||
|
if (sslContext != null) {
|
||||||
|
builder.setSslContext(new JdkSslContext(sslContext, true, ClientAuth.NONE));
|
||||||
|
}
|
||||||
|
return new DefaultAsyncHttpClient(builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@ManageLifecycle
|
@ManageLifecycle
|
||||||
@Named("http")
|
@Named("http")
|
||||||
|
@ -78,13 +92,12 @@ public class HttpEmitterModule implements Module
|
||||||
ObjectMapper jsonMapper
|
ObjectMapper jsonMapper
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
final DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder();
|
return new HttpPostEmitter(
|
||||||
if (sslContext != null) {
|
config.get(),
|
||||||
builder.setSslContext(new JdkSslContext(sslContext, true, ClientAuth.NONE));
|
lifecycle.addCloseableInstance(
|
||||||
}
|
createAsyncHttpClient("HttpPostEmitter-AsyncHttpClient-%d", sslContext)
|
||||||
final AsyncHttpClient client = new DefaultAsyncHttpClient(builder.build());
|
),
|
||||||
lifecycle.addCloseableInstance(client);
|
jsonMapper
|
||||||
|
);
|
||||||
return new HttpPostEmitter(config.get(), client, jsonMapper);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,6 @@ import com.metamx.emitter.core.ParametrizedUriEmitterConfig;
|
||||||
import io.druid.guice.JsonConfigProvider;
|
import io.druid.guice.JsonConfigProvider;
|
||||||
import io.druid.guice.ManageLifecycle;
|
import io.druid.guice.ManageLifecycle;
|
||||||
import io.druid.java.util.common.lifecycle.Lifecycle;
|
import io.druid.java.util.common.lifecycle.Lifecycle;
|
||||||
import io.netty.handler.ssl.ClientAuth;
|
|
||||||
import io.netty.handler.ssl.JdkSslContext;
|
|
||||||
import org.asynchttpclient.AsyncHttpClient;
|
|
||||||
import org.asynchttpclient.DefaultAsyncHttpClient;
|
|
||||||
import org.asynchttpclient.DefaultAsyncHttpClientConfig;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
@ -59,13 +54,12 @@ public class ParametrizedUriEmitterModule implements Module
|
||||||
ObjectMapper jsonMapper
|
ObjectMapper jsonMapper
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
final DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder();
|
return new ParametrizedUriEmitter(
|
||||||
if (sslContext != null) {
|
config.get(),
|
||||||
builder.setSslContext(new JdkSslContext(sslContext, true, ClientAuth.NONE));
|
lifecycle.addCloseableInstance(
|
||||||
}
|
HttpEmitterModule.createAsyncHttpClient("ParmetrizedUriEmitter-AsyncHttpClient-%d", sslContext)
|
||||||
final AsyncHttpClient client = new DefaultAsyncHttpClient(builder.build());
|
),
|
||||||
lifecycle.addCloseableInstance(client);
|
jsonMapper
|
||||||
|
);
|
||||||
return new ParametrizedUriEmitter(config.get(), client, jsonMapper);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue