mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-12 07:02:10 +00:00
DATAES-314 - NodeClientFactoryBean doesn't shutdown ES on destroy life-cycle.
Original PR: #333
This commit is contained in:
parent
f7f103d331
commit
29f34b05d3
@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.client;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
@ -51,6 +49,7 @@ public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingB
|
||||
private boolean local;
|
||||
private boolean enableHttp;
|
||||
private String clusterName;
|
||||
private Node node;
|
||||
private NodeClient nodeClient;
|
||||
private String pathData;
|
||||
private String pathHome;
|
||||
@ -99,10 +98,17 @@ public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingB
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
nodeClient = (NodeClient) new TestNode(Settings.builder().put(loadConfig()).put("transport.type", "netty4")
|
||||
.put("http.type", "netty4").put("path.home", this.pathHome).put("path.data", this.pathData)
|
||||
.put("cluster.name", this.clusterName).put("node.max_local_storage_nodes", 100).build(),
|
||||
asList(Netty4Plugin.class)).start().client();
|
||||
Settings settings = Settings.builder() //
|
||||
.put(loadConfig()) //
|
||||
.put("transport.type", "netty4") //
|
||||
.put("http.type", "netty4") //
|
||||
.put("path.home", this.pathHome) //
|
||||
.put("path.data", this.pathData) //
|
||||
.put("cluster.name", this.clusterName) //
|
||||
.put("node.max_local_storage_nodes", 100) //
|
||||
.build();
|
||||
node = new TestNode(settings, Collections.singletonList(Netty4Plugin.class));
|
||||
nodeClient = (NodeClient) node.start().client();
|
||||
}
|
||||
|
||||
private Settings loadConfig() throws IOException {
|
||||
@ -144,9 +150,10 @@ public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingB
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
try {
|
||||
logger.info("Closing elasticSearch client");
|
||||
if (nodeClient != null) {
|
||||
nodeClient.close();
|
||||
// NodeClient.close() is a noop, no need to call it here
|
||||
logger.info("Closing elasticSearch node");
|
||||
if (node != null) {
|
||||
node.close();
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
logger.error("Error closing ElasticSearch client: ", e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user