Skip to content

Commit 29f34b0

Browse files
authored
DATAES-314 - NodeClientFactoryBean doesn't shutdown ES on destroy life-cycle.
Original PR: #333
1 parent f7f103d commit 29f34b0

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/main/java/org/springframework/data/elasticsearch/client/NodeClientFactoryBean.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.elasticsearch.client;
1717

18-
import static java.util.Arrays.*;
19-
2018
import java.io.IOException;
2119
import java.io.InputStream;
2220
import java.util.Collection;
@@ -51,6 +49,7 @@ public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingB
5149
private boolean local;
5250
private boolean enableHttp;
5351
private String clusterName;
52+
private Node node;
5453
private NodeClient nodeClient;
5554
private String pathData;
5655
private String pathHome;
@@ -99,10 +98,17 @@ public boolean isSingleton() {
9998
@Override
10099
public void afterPropertiesSet() throws Exception {
101100

102-
nodeClient = (NodeClient) new TestNode(Settings.builder().put(loadConfig()).put("transport.type", "netty4")
103-
.put("http.type", "netty4").put("path.home", this.pathHome).put("path.data", this.pathData)
104-
.put("cluster.name", this.clusterName).put("node.max_local_storage_nodes", 100).build(),
105-
asList(Netty4Plugin.class)).start().client();
101+
Settings settings = Settings.builder() //
102+
.put(loadConfig()) //
103+
.put("transport.type", "netty4") //
104+
.put("http.type", "netty4") //
105+
.put("path.home", this.pathHome) //
106+
.put("path.data", this.pathData) //
107+
.put("cluster.name", this.clusterName) //
108+
.put("node.max_local_storage_nodes", 100) //
109+
.build();
110+
node = new TestNode(settings, Collections.singletonList(Netty4Plugin.class));
111+
nodeClient = (NodeClient) node.start().client();
106112
}
107113

108114
private Settings loadConfig() throws IOException {
@@ -144,9 +150,10 @@ public void setPathConfiguration(String configuration) {
144150
@Override
145151
public void destroy() throws Exception {
146152
try {
147-
logger.info("Closing elasticSearch client");
148-
if (nodeClient != null) {
149-
nodeClient.close();
153+
// NodeClient.close() is a noop, no need to call it here
154+
logger.info("Closing elasticSearch node");
155+
if (node != null) {
156+
node.close();
150157
}
151158
} catch (final Exception e) {
152159
logger.error("Error closing ElasticSearch client: ", e);

0 commit comments

Comments
 (0)