make AsyncHttpCLient instance timer thread daemon (#5076)

This commit is contained in:
Himanshu 2017-11-10 19:54:29 -06:00 committed by Parag Jain
parent 3ad5f51f7e
commit 1c64f02574
2 changed files with 14 additions and 3 deletions

View File

@ -36,6 +36,7 @@ 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;
import io.netty.util.HashedWheelTimer;
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.DefaultAsyncHttpClient;
import org.asynchttpclient.DefaultAsyncHttpClientConfig;
@ -71,11 +72,13 @@ public class HttpEmitterModule implements Module
static AsyncHttpClient createAsyncHttpClient(
String nameFormat,
String timerThreadNameFormat,
@Nullable SSLContext sslContext
)
{
final DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder()
.setThreadFactory(Execs.makeThreadFactory(nameFormat));
.setThreadFactory(Execs.makeThreadFactory(nameFormat))
.setNettyTimer(new HashedWheelTimer(Execs.makeThreadFactory(timerThreadNameFormat)));
if (sslContext != null) {
builder.setSslContext(new JdkSslContext(sslContext, true, ClientAuth.NONE));
}
@ -95,7 +98,11 @@ public class HttpEmitterModule implements Module
return new HttpPostEmitter(
config.get(),
lifecycle.addCloseableInstance(
createAsyncHttpClient("HttpPostEmitter-AsyncHttpClient-%d", sslContext)
createAsyncHttpClient(
"HttpPostEmitter-AsyncHttpClient-%d",
"HttpPostEmitter-AsyncHttpClient-Timer-%d",
sslContext
)
),
jsonMapper
);

View File

@ -57,7 +57,11 @@ public class ParametrizedUriEmitterModule implements Module
return new ParametrizedUriEmitter(
config.get(),
lifecycle.addCloseableInstance(
HttpEmitterModule.createAsyncHttpClient("ParmetrizedUriEmitter-AsyncHttpClient-%d", sslContext)
HttpEmitterModule.createAsyncHttpClient(
"ParmetrizedUriEmitter-AsyncHttpClient-%d",
"ParmetrizedUriEmitter-AsyncHttpClient-Timer-%d",
sslContext
)
),
jsonMapper
);