|
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,17 @@ 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 | + 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(); |
106 | 112 | }
|
107 | 113 |
|
108 | 114 | private Settings loadConfig() throws IOException {
|
@@ -144,9 +150,10 @@ public void setPathConfiguration(String configuration) {
|
144 | 150 | @Override
|
145 | 151 | public void destroy() throws Exception {
|
146 | 152 | 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(); |
150 | 157 | }
|
151 | 158 | } catch (final Exception e) {
|
152 | 159 | logger.error("Error closing ElasticSearch client: ", e);
|
|
0 commit comments