Wait for Netty 4 threads to terminate on close
Today if the PreBuiltTransportClient is using Netty 4 transport, on shutdown some Netty 4 threads could linger. This commit causes the client to wait for these threads to shutdown upon termination.
This commit is contained in:
parent
b0730bb214
commit
c08557d033
|
@ -34,7 +34,7 @@ dependencies {
|
||||||
compile "org.elasticsearch.plugin:percolator-client:${version}"
|
compile "org.elasticsearch.plugin:percolator-client:${version}"
|
||||||
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
|
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
|
||||||
testCompile "junit:junit:${versions.junit}"
|
testCompile "junit:junit:${versions.junit}"
|
||||||
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"`
|
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencyLicenses {
|
dependencyLicenses {
|
||||||
|
|
|
@ -19,7 +19,10 @@
|
||||||
|
|
||||||
package org.elasticsearch.transport.client;
|
package org.elasticsearch.transport.client;
|
||||||
|
|
||||||
|
import io.netty.util.ThreadDeathWatcher;
|
||||||
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
|
import org.elasticsearch.common.network.NetworkModule;
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.reindex.ReindexPlugin;
|
import org.elasticsearch.index.reindex.ReindexPlugin;
|
||||||
|
@ -33,6 +36,7 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder to create an instance of {@link TransportClient}
|
* A builder to create an instance of {@link TransportClient}
|
||||||
|
@ -84,4 +88,18 @@ public class PreBuiltTransportClient extends TransportClient {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
super.close();
|
||||||
|
if (!NetworkModule.TRANSPORT_TYPE_SETTING.exists(settings)
|
||||||
|
|| NetworkModule.TRANSPORT_TYPE_SETTING.get(settings).equals(Netty4Plugin.NETTY_TRANSPORT_NAME)) {
|
||||||
|
try {
|
||||||
|
GlobalEventExecutor.INSTANCE.awaitInactivity(5, TimeUnit.SECONDS);
|
||||||
|
ThreadDeathWatcher.awaitInactivity(5, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue