1 | /* |
2 | * Copyright 2013 the original author or authors. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.springframework.data.elasticsearch.client; |
17 | |
18 | import org.elasticsearch.client.Client; |
19 | import org.elasticsearch.client.node.NodeClient; |
20 | import org.springframework.beans.factory.FactoryBean; |
21 | import org.springframework.beans.factory.InitializingBean; |
22 | |
23 | import static org.elasticsearch.node.NodeBuilder.nodeBuilder; |
24 | |
25 | /** |
26 | * NodeClientFactoryBean |
27 | * |
28 | * @author Rizwan Idrees |
29 | * @author Mohsin Husen |
30 | */ |
31 | |
32 | public class NodeClientFactoryBean implements FactoryBean<NodeClient>, InitializingBean{ |
33 | |
34 | private boolean local; |
35 | private NodeClient nodeClient; |
36 | |
37 | NodeClientFactoryBean() { |
38 | } |
39 | |
40 | public NodeClientFactoryBean(boolean local) { |
41 | this.local = local; |
42 | } |
43 | |
44 | @Override |
45 | public NodeClient getObject() throws Exception { |
46 | return nodeClient; |
47 | } |
48 | |
49 | @Override |
50 | public Class<? extends Client> getObjectType() { |
51 | return NodeClient.class; |
52 | } |
53 | |
54 | @Override |
55 | public boolean isSingleton() { |
56 | return true; |
57 | } |
58 | |
59 | @Override |
60 | public void afterPropertiesSet() throws Exception { |
61 | nodeClient = (NodeClient) nodeBuilder().local(this.local).node().client(); |
62 | } |
63 | |
64 | public void setLocal(boolean local) { |
65 | this.local = local; |
66 | } |
67 | } |