public static ZooKeeper ensureConnectedZooKeeper(ZooKeeper zookeeper, int timeout)
    throws ZooKeeperConnectionException {
    if (zookeeper.getState().isConnected()) {
      return zookeeper;
    }
    Stopwatch stopWatch = Stopwatch.createStarted();
    // Make sure we are connected before we hand it back.
    while (!zookeeper.getState().isConnected()) {
      Threads.sleep(1);
      if (stopWatch.elapsed(TimeUnit.MILLISECONDS) > timeout) {
        throw new ZooKeeperConnectionException("Failed connect after waiting "
          + stopWatch.elapsed(TimeUnit.MILLISECONDS) + "ms (zk session timeout); " + zookeeper);
      }
    }
    return zookeeper;
  }
Ensure passed zookeeper is connected.
@param timeout Time to wait on established Connection
hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperHelper.java