Skip to content

Commit

Permalink
use countdownlatch to wait for zookeeper connection
Browse files Browse the repository at this point in the history
  • Loading branch information
John Corwin committed Jul 1, 2010
1 parent ecec17c commit 3508d52
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/main/scala/com/twitter/zookeeper/ZooKeeperClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ object ZKWatch {
class ZooKeeperClient(servers: String, sessionTimeout: Int, basePath : String, watcher: Option[ZKWatch]) extends Watcher {
private val log = Logger.get
private val connectionLatch = new CountDownLatch(1)
private var connected = false
private val zk = new ZooKeeper(servers, sessionTimeout, this)
connectionLatch.await()

def process(event : WatchedEvent) {
log.info("Zookeeper event: %s".format(event))
event.getState match {
case KeeperState.SyncConnected => {
if (!connected) {
connected = true
connectionLatch.countDown()
}
connectionLatch.countDown()
}
case _ =>
}
Expand Down

0 comments on commit 3508d52

Please sign in to comment.