You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Hongchao Deng (JIRA)" <ji...@apache.org> on 2014/09/15 23:00:34 UTC
[jira] [Created] (ZOOKEEPER-2037) ZooKeeper methods to wait on
client connection (re)establishment.
Hongchao Deng created ZOOKEEPER-2037:
----------------------------------------
Summary: ZooKeeper methods to wait on client connection (re)establishment.
Key: ZOOKEEPER-2037
URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2037
Project: ZooKeeper
Issue Type: Sub-task
Components: java client
Reporter: Hongchao Deng
Assignee: Hongchao Deng
When a ZooKeeper object is created and returned, it is not guaranteed that connection to a server is established.
Usually, a wait/signal pattern is used for the ZK watcher
{code}
latch = new CountDownLatch(1)
zk = new ZooKeeper(..., new Watcher() {
override void process(WatchedEvent event) {
if (event.type = SyncConnected) {
latch.countDown()
}
}
},...)
latch.wait();
// connection has been established. do something with zk.
{code}
There are two disadvantages:
1. The latch object isn't being garbage-collected. Because the watcher keeps monitoring all kinds of events.
2. With the introduction of dynamic reconfig, client move to other servers on needed and this latch method doesn't work so well.
Here I propose to add (both sync and async) wait methods to act as latch for connection establish such that it becomes much easier to manage and work around:
{code}
zk = new ZooKeeper(...)
zk.waitUntilConnected()
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)