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?
|