How best to verify a client connection?

I'd like a simple way of verifying that ES is available to a Java
client. I have a factory that looks something like this to get a
client instance:

What's the best way to gracefully handle the scenario of ES not being
available or is what I have sufficient?

I forgot to mention that I get the following debug messages every 5
seconds. Is there a way to avoid these messages while verifying the
connection?

13:52:47,365 INFO [STDOUT] elasticsearch[cached]-pool-14-thread-1
[2011-11-14 13:52:47,365][client.transport]DEBUG: [Orbit] Failed to
connect to node [#transport#-1][inet[localhost/127.0.0.1:9300]],
removed from nodes list
org.elasticsearch.transport.ConnectTransportException:
[inet[localhost/127.0.0.1:9300]] connect_timeout[30s]
at
org.elasticsearch.transport.netty.NettyTransport.connectToChannels(NettyTransport.java:
563)
at
org.elasticsearch.transport.netty.NettyTransport.connectToNode(NettyTransport.java:
506)
at
org.elasticsearch.transport.netty.NettyTransport.connectToNode(NettyTransport.java:
485)
at
org.elasticsearch.transport.TransportService.connectToNode(TransportService.java:
121)
at org.elasticsearch.client.transport.TransportClientNodesService
$SimpleNodeSampler.sample(TransportClientNodesService.java:260)
at org.elasticsearch.client.transport.TransportClientNodesService
$ScheduledNodeSampler.run(TransportClientNodesService.java:243)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:
567)
at
org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink
$Boss.connect(NioClientSocketPipelineSink.java:384)
at
org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink
$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:354)
at
org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink
$Boss.run(NioClientSocketPipelineSink.java:276)
at
org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:
108)
at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker
$1.run(DeadLockProofWorker.java:44)
... 3 more

On Nov 14, 1:49 pm, Shane Witbeck sh...@digitalsanctum.com wrote:

I'd like a simple way of verifying that ES is available to a Java
client. I have a factory that looks something like this to get a
client instance:

factory for getting ES client · GitHub

What's the best way to gracefully handle the scenario of ES not being
available or is what I have sufficient?

Yes, what you did looks good. It will continue to try and reconnect in the
background though, so if you throw an exception if it has not connected,
you might want to close the client as well.

On Mon, Nov 14, 2011 at 8:49 PM, Shane Witbeck shane@digitalsanctum.comwrote:

I'd like a simple way of verifying that ES is available to a Java
client. I have a factory that looks something like this to get a
client instance:

factory for getting ES client · GitHub

What's the best way to gracefully handle the scenario of ES not being
available or is what I have sufficient?

Thanks! The addition of closing the client prevents the retries and
debug messages.

On Nov 15, 8:51 am, Shay Banon kim...@gmail.com wrote:

Yes, what you did looks good. It will continue to try and reconnect in the
background though, so if you throw an exception if it has not connected,
you might want to close the client as well.

On Mon, Nov 14, 2011 at 8:49 PM, Shane Witbeck sh...@digitalsanctum.comwrote:

I'd like a simple way of verifying that ES is available to a Java
client. I have a factory that looks something like this to get a
client instance:

https://gist.github.com/1364734

What's the best way to gracefully handle the scenario of ES not being
available or is what I have sufficient?