|
15 | 15 | */
|
16 | 16 | package org.springframework.data.elasticsearch.client;
|
17 | 17 |
|
18 |
| -import static java.util.Arrays.*; |
19 |
| - |
20 | 18 | import java.io.IOException;
|
21 | 19 | import java.io.InputStream;
|
22 | 20 | import java.util.Collection;
|
@@ -51,6 +49,7 @@ public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingB
|
51 | 49 | private boolean local;
|
52 | 50 | private boolean enableHttp;
|
53 | 51 | private String clusterName;
|
| 52 | + private Node node; |
54 | 53 | private NodeClient nodeClient;
|
55 | 54 | private String pathData;
|
56 | 55 | private String pathHome;
|
@@ -99,10 +98,10 @@ public boolean isSingleton() {
|
99 | 98 | @Override
|
100 | 99 | public void afterPropertiesSet() throws Exception {
|
101 | 100 |
|
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 | + node = new TestNode(Settings.builder().put(loadConfig()).put("transport.type", "netty4").put("http.type", "netty4") |
| 102 | + .put("path.home", this.pathHome).put("path.data", this.pathData).put("cluster.name", this.clusterName) |
| 103 | + .put("node.max_local_storage_nodes", 100).build(), Collections.singletonList(Netty4Plugin.class)); |
| 104 | + nodeClient = (NodeClient) node.start().client(); |
106 | 105 | }
|
107 | 106 |
|
108 | 107 | private Settings loadConfig() throws IOException {
|
@@ -144,9 +143,10 @@ public void setPathConfiguration(String configuration) {
|
144 | 143 | @Override
|
145 | 144 | public void destroy() throws Exception {
|
146 | 145 | try {
|
147 |
| - logger.info("Closing elasticSearch client"); |
148 |
| - if (nodeClient != null) { |
149 |
| - nodeClient.close(); |
| 146 | + // NodeClient.close() is a noop, no need to call it here |
| 147 | + logger.info("Closing elasticSearch node"); |
| 148 | + if (node != null) { |
| 149 | + node.close(); |
150 | 150 | }
|
151 | 151 | } catch (final Exception e) {
|
152 | 152 | logger.error("Error closing ElasticSearch client: ", e);
|
|
0 commit comments