Created
June 13, 2012 05:46
-
-
Save strokine/2922102 to your computer and use it in GitHub Desktop.
ElasticSearch Client on Spring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Notifications [Java Application] | |
mycomp.command.Notifications at localhost:52658 | |
Thread [Timer-0] (Running) | |
Daemon Thread [Poller SunPKCS11-Darwin] (Running) | |
Thread [DestroyJavaVM] (Running) | |
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java (Jun 13, 2012 1:40:47 AM) | |
------------------ | |
Notifications [Java Application] | |
mycomp.command.Notifications at localhost:56610 | |
Daemon Thread [elasticsearch[Hermes][timer]] (Running) | |
Daemon Thread [elasticsearch[Hermes][scheduler]-pool-24-thread-1] (Running) | |
Daemon Thread [elasticsearch[Hermes]transport_client_boss-pool-25-thread-1] (Running) | |
Daemon Thread [New I/O client worker #2-2] (Running) | |
Daemon Thread [New I/O client worker #2-5] (Running) | |
Daemon Thread [New I/O client worker #2-7] (Running) | |
Daemon Thread [elasticsearch[management]-pool-19-thread-1] (Running) | |
Daemon Thread [New I/O client worker #2-6] (Running) | |
Daemon Thread [New I/O client worker #2-4] (Running) | |
Daemon Thread [New I/O client worker #2-3] (Running) | |
Daemon Thread [New I/O client worker #2-1] (Running) | |
Daemon Thread [elasticsearch[cached]-pool-14-thread-1] (Running) | |
Daemon Thread [New I/O client worker #2-8] (Running) | |
Thread [Timer-0] (Running) | |
Thread [Timer-1] (Running) | |
Thread [DestroyJavaVM] (Running) | |
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java (Jun 14, 2012 6:03:34 PM) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Map; | |
import org.elasticsearch.client.Client; | |
import org.elasticsearch.client.transport.TransportClient; | |
import org.elasticsearch.common.settings.ImmutableSettings; | |
import org.elasticsearch.common.settings.Settings; | |
import org.elasticsearch.common.transport.InetSocketTransportAddress; | |
public class EsClientProvider { | |
private TransportClient client; | |
private String clusterName; | |
private String indexName; | |
private boolean sniff; | |
private Map<String, Integer> inetSockerTransportAddresses; | |
public void init(){ | |
Settings settings = ImmutableSettings.settingsBuilder() | |
.put("client.transport.sniff", sniff) | |
.put("client.transport.ping_timeout", "10s") | |
.put("cluster.name", clusterName) | |
.build(); | |
client = new TransportClient(settings); | |
for(String key : inetSockerTransportAddresses.keySet()) { | |
client.addTransportAddress(new InetSocketTransportAddress(key, inetSockerTransportAddresses.get(key))); | |
} | |
} | |
public void destroy(){ | |
client.close(); | |
client=null; | |
} | |
public Client getClient(){ | |
return client; | |
} | |
public void setClusterName(String clusterName) { | |
this.clusterName = clusterName; | |
} | |
public void setInetSockerTransportAddresses( | |
Map<String, Integer> inetSockerTransportAddresses) { | |
this.inetSockerTransportAddresses = inetSockerTransportAddresses; | |
} | |
public String getIndexName() { | |
return indexName; | |
} | |
public void setIndexName(String indexName) { | |
this.indexName = indexName; | |
} | |
public void setSniff(boolean sniff) { | |
this.sniff = sniff; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment