public synchronized void waitForConnected(long waitForConnection) throws TimeoutException {
		log.info("Waiting for client to connect to ZooKeeper");
		long expire = System.currentTimeMillis() + waitForConnection;
		long left = 1;
		while (!connected && left > 0) {
			if (isClosed) {
				break;
			}
			try {
				wait(500);
			} catch (InterruptedException e) {
				Thread.currentThread().interrupt();
				throw new RuntimeException(e);
			}
			left = expire - System.currentTimeMillis();
		}
		if (!connected) {
			throw new TimeoutException("Could not connect to ZooKeeper " + zkServerAddress + " within "
					+ waitForConnection + " ms");
		}
		log.info("Client is connected to ZooKeeper");
	}