# Need to know or be notified that all the nodes have been initialized successfully using Elastic Search Sniffer

**URL:** <https://discuss.elastic.co/t/need-to-know-or-be-notified-that-all-the-nodes-have-been-initialized-successfully-using-elastic-search-sniffer/177232>\
**Category:** Elasticsearch\
**Created:** [April 17, 2019, 8:27am UTC](https://discuss.elastic.co/t/need-to-know-or-be-notified-that-all-the-nodes-have-been-initialized-successfully-using-elastic-search-sniffer/177232 "2019-04-17T08:27:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zqzhao5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zqzhao5/32/44303_2.png) [@zqzhao5](https://discuss.elastic.co/u/zqzhao5)\
**Post date:** [April 17, 2019, 8:27am UTC](https://discuss.elastic.co/t/need-to-know-or-be-notified-that-all-the-nodes-have-been-initialized-successfully-using-elastic-search-sniffer/177232/1 "2019-04-17T08:27:20Z")

</div>

I use a proxy server to determine how to route request to the backend elastic search clusters. The client makes request directly to the proxy server, so I need to implement some kind of service discovery mechanism in the client side.  
Now I'm working on a Sniffer to sniff proxy nodes from ETCD.After reading the code from `elasticsearch-rest-client 6.4.0`,  
I found the initial sniff procedure is running in a dedicated scheduling thread, which may result in no nodes available when making request meanwhile.so How could I know or be notified that all the nodes have been initialized successfully from ETCD before I start making request ?

```java
    Sniffer(RestClient restClient, NodesSniffer nodesSniffer, Scheduler scheduler, long sniffInterval, long sniffAfterFailureDelay) {
        this.nodesSniffer = nodesSniffer;
        this.restClient = restClient;
        this.sniffIntervalMillis = sniffInterval;
        this.sniffAfterFailureDelayMillis = sniffAfterFailureDelay;
        this.scheduler = scheduler;
        /*
         * The first sniffing round is async, so this constructor returns before nextScheduledTask is assigned to a task.
         * The initialized flag is a protection against NPE due to that.
         */
        Task task = new Task(sniffIntervalMillis) {
            @Override
            public void run() {
                super.run();
                initialized.compareAndSet(false, true);
            }
        };
        /*
         * We do not keep track of the returned future as we never intend to cancel the initial sniffing round, we rather
         * prevent any other operation from being executed till the sniffer is properly initialized
         */
        
        scheduler.schedule(task, 0L);
    }

```

---

<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 15, 2019, 8:27am UTC](https://discuss.elastic.co/t/need-to-know-or-be-notified-that-all-the-nodes-have-been-initialized-successfully-using-elastic-search-sniffer/177232/2 "2019-05-15T08:27:22Z")

</div>

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