1 | package org.springframework.data.elasticsearch.client; |
2 | |
3 | import org.elasticsearch.client.Client; |
4 | import org.elasticsearch.client.node.NodeClient; |
5 | import org.springframework.beans.factory.FactoryBean; |
6 | import org.springframework.beans.factory.InitializingBean; |
7 | |
8 | import static org.elasticsearch.node.NodeBuilder.nodeBuilder; |
9 | |
10 | public class NodeClientFactoryBean implements FactoryBean<NodeClient>, InitializingBean{ |
11 | |
12 | private boolean local; |
13 | private NodeClient nodeClient; |
14 | |
15 | NodeClientFactoryBean() { |
16 | } |
17 | |
18 | public NodeClientFactoryBean(boolean local) { |
19 | this.local = local; |
20 | } |
21 | |
22 | @Override |
23 | public NodeClient getObject() throws Exception { |
24 | return nodeClient; |
25 | } |
26 | |
27 | @Override |
28 | public Class<? extends Client> getObjectType() { |
29 | return NodeClient.class; |
30 | } |
31 | |
32 | @Override |
33 | public boolean isSingleton() { |
34 | return true; |
35 | } |
36 | |
37 | @Override |
38 | public void afterPropertiesSet() throws Exception { |
39 | nodeClient = (NodeClient) nodeBuilder().local(this.local).node().client(); |
40 | } |
41 | |
42 | public void setLocal(boolean local) { |
43 | this.local = local; |
44 | } |
45 | } |