zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Devendra Jain <deven...@gmail.com>
Subject zookeeper watcher infinite calling process() since zookkeeper is down.
Date Thu, 20 Dec 2018 16:19:26 GMT

I am facing one issue in my project when I am creating zookepper client and
if its not created due to zookepper server url is down. It's keep on trying
to connect and further sending the "Watcher" object mentioning the state is
"disconnected". I am not sure how to kill this endless callback if I want
to pass new zookeeper URL with is up.
Here is the code which I have written.

Class ZookeeperConnection {

final String zkConnectionStr;

public void ZookeeperConnection(String zkConnectionStr ){
     Zookeeper zkConnectionStr =zkConnectionStr;

    private ZooKeeper newZkConnection() {
        CountDownLatch zkConnectionLatch = new CountDownLatch(1);
        try {

            ZooKeeper zkClient = new ZooKeeper(zkConnectionStr, 40000, new
Watcher() {
                int i = 0;
                public void process(WatchedEvent watchedEvent) {
                    String zkSessionID = getZkSessionID();
                    switch (watchedEvent.getState()) {
                        case ConnectedReadOnly:
                        case SyncConnected:
                            // Wait for connection to ZooKeeper
                        case Disconnected:
                        case Expired:
                            restartZkServices(); //calling the same new
connection method again
                        case AuthFailed:

            long zkConnectionTimeout = 30;
            zkConnectionLatch.await(zkConnectionTimeout, TimeUnit.SECONDS);
// Wait 30 seconds
            if (zkClient.getState().isConnected()) {
                return zkClient;
        } catch (Exception ex) {
            LOG.error("An exception happened during connecting to ZooKeeper
[{}].", zkConnectionStr, ex);
        return null;
In this code I tried to create object of ZookeeperConnection class by
passing the zookeeper server URL and latter if user want to change the
zookepper server URL we again create a new method of ZookeeperConnection
class so if Zookeeeper is up I am able to connect through new object. But
old object which uses old zookepper url is still active and gets callback
and continuously show disconnected.

Please help me on this.
Devendra Jain

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message