diff --git a/server/src/main/java/io/druid/server/emitter/HttpEmitterModule.java b/server/src/main/java/io/druid/server/emitter/HttpEmitterModule.java index 7497c21f8f1..db927fff7ae 100644 --- a/server/src/main/java/io/druid/server/emitter/HttpEmitterModule.java +++ b/server/src/main/java/io/druid/server/emitter/HttpEmitterModule.java @@ -32,6 +32,7 @@ import com.metamx.emitter.core.HttpPostEmitter; import io.druid.guice.JsonConfigProvider; import io.druid.guice.LazySingleton; import io.druid.guice.ManageLifecycle; +import io.druid.java.util.common.concurrent.Execs; import io.druid.java.util.common.lifecycle.Lifecycle; import io.netty.handler.ssl.ClientAuth; 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); } + 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 @ManageLifecycle @Named("http") @@ -78,13 +92,12 @@ public class HttpEmitterModule implements Module ObjectMapper jsonMapper ) { - final DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder(); - if (sslContext != null) { - builder.setSslContext(new JdkSslContext(sslContext, true, ClientAuth.NONE)); - } - final AsyncHttpClient client = new DefaultAsyncHttpClient(builder.build()); - lifecycle.addCloseableInstance(client); - - return new HttpPostEmitter(config.get(), client, jsonMapper); + return new HttpPostEmitter( + config.get(), + lifecycle.addCloseableInstance( + createAsyncHttpClient("HttpPostEmitter-AsyncHttpClient-%d", sslContext) + ), + jsonMapper + ); } } diff --git a/server/src/main/java/io/druid/server/emitter/ParametrizedUriEmitterModule.java b/server/src/main/java/io/druid/server/emitter/ParametrizedUriEmitterModule.java index 6d8633c9f6c..370869f6e77 100644 --- a/server/src/main/java/io/druid/server/emitter/ParametrizedUriEmitterModule.java +++ b/server/src/main/java/io/druid/server/emitter/ParametrizedUriEmitterModule.java @@ -31,11 +31,6 @@ import com.metamx.emitter.core.ParametrizedUriEmitterConfig; import io.druid.guice.JsonConfigProvider; import io.druid.guice.ManageLifecycle; 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.net.ssl.SSLContext; @@ -59,13 +54,12 @@ public class ParametrizedUriEmitterModule implements Module ObjectMapper jsonMapper ) { - final DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder(); - if (sslContext != null) { - builder.setSslContext(new JdkSslContext(sslContext, true, ClientAuth.NONE)); - } - final AsyncHttpClient client = new DefaultAsyncHttpClient(builder.build()); - lifecycle.addCloseableInstance(client); - - return new ParametrizedUriEmitter(config.get(), client, jsonMapper); + return new ParametrizedUriEmitter( + config.get(), + lifecycle.addCloseableInstance( + HttpEmitterModule.createAsyncHttpClient("ParmetrizedUriEmitter-AsyncHttpClient-%d", sslContext) + ), + jsonMapper + ); } }