public static ZooKeeper open(String serverAddress, int sessionTimeoutMillis, int connectionTimeoutMillis)
    throws IOException, InterruptedException, IllegalStateException
  {
    final CountDownLatch connSignal = new CountDownLatch(1);
    ZooKeeper zooKeeper = new ZooKeeper(serverAddress, sessionTimeoutMillis, new Watcher() {
      @Override
      public void process(WatchedEvent event) {
        if (event.getState() == SyncConnected) {
          connSignal.countDown();
        }
      }
    });
    connSignal.await(connectionTimeoutMillis, MILLISECONDS);
    return zooKeeper;
  }
Opens a connection to zookeeper and waits until the connection established
ambari-agent/src/main/java/org/apache/ambari/tools/zk/ZkConnection.java