# Elasticsearch server state listener

**URL:** <https://discuss.elastic.co/t/elasticsearch-server-state-listener/81782>\
**Category:** Elasticsearch\
**Created:** [April 10, 2017, 9:32am UTC](https://discuss.elastic.co/t/elasticsearch-server-state-listener/81782 "2017-04-10T09:32:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hitesh-inbetween](https://avatars.discourse-cdn.com/v4/letter/h/51bf81/32.png) [@hitesh-inbetween](https://discuss.elastic.co/u/hitesh-inbetween)\
**Post date:** [April 10, 2017, 9:32am UTC](https://discuss.elastic.co/t/elasticsearch-server-state-listener/81782/1 "2017-04-10T09:32:45Z")

</div>

Hey guys,

Is there a way by which i could get to know when elasticsearch server start/stops. Something like state listener.  
I'm using java to connect to elasticsearch node. The java code is responsible for inserting documents into elasticsearch. If while inserting data, elasticsearch stops (or is killed manually), the documents should not be processed till the server is on. Although I get NoNodeAvailable exception in such case, but it would be better to get a listener interface for nodes.  
Something like I have already implemented for cassandra using "Host.stateListener".

Any input appreciated 🙂

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 10, 2017, 9:47am UTC](https://discuss.elastic.co/t/elasticsearch-server-state-listener/81782/2 "2017-04-10T09:47:47Z")

</div>

Hey,

if you are using the TransportClient, you can use the sniffing option which polls the cluster state in the background to dynamically add or remove hosts to send queries to.

See [https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html)

--Alex

---

<div class="post-metadata">

**Author:** ![hitesh-inbetween](https://avatars.discourse-cdn.com/v4/letter/h/51bf81/32.png) [@hitesh-inbetween](https://discuss.elastic.co/u/hitesh-inbetween)\
**Post date:** [April 10, 2017, 11:21am UTC](https://discuss.elastic.co/t/elasticsearch-server-state-listener/81782/3 "2017-04-10T11:21:28Z")

</div>

But that would require me to check the state every time right. I'm using TransportClient Sniffing option already, but only during initialization. Also, Currently its a single node cluster.  
Currently the solution I'm looking for is,

```
class abc implements SomeListener
{
  @override
  public void onUp() {
    //Do something here
  }
  @override 
  public void onDown() {
    Do something
  }
}

```

So whenever elasticsearch is started, onUp() will be called, and when it shut downs, onDown() will be called.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 8, 2017, 11:22am UTC](https://discuss.elastic.co/t/elasticsearch-server-state-listener/81782/4 "2017-05-08T11:22:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
