zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edward Capriolo <edlinuxg...@gmail.com>
Subject session establishment
Date Thu, 29 Jan 2015 01:27:31 GMT
http://zookeeper.apache.org/doc/r3.4.5/api/org/apache/zookeeper/ZooKeeper.html

Session establishment is asynchronous. This constructor will initiate
connection to the server and return immediately - potentially (usually)
before the session is fully established. The watcher argument specifies the
watcher that will be notified of any changes in state.


>>This notification can come at any point before or after the constructor
call has returned.

public class DummyWatcher implements Watcher {

  private CountDownLatch awaitConnection;

  public DummyWatcher(){
    awaitConnection = new CountDownLatch(1);
  }

  public boolean connectOrThrow(long timeout, TimeUnit unit) throws
InterruptedException{
    return awaitConnection.await(timeout, unit);
  }

  @Override
  public void process(WatchedEvent event) {
    if (event.getState() == KeeperState.SyncConnected){
      awaitConnection.countDown();
    }
  }

}

Does this mean that the following event might never fire or does it always
fire?

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