code: private ZooKeeper connect(String quorumAddresses) throws IOException {
          final CountDownLatch latch = new CountDownLatch(1);
          ZooKeeper zookeeper;
  
          // Connect to the quorum and wait for the successful connection callback.;
          zookeeper = new ZooKeeper(quorumAddresses, (int) SECONDS.toMillis(10), watchedEvent -> {
              if (watchedEvent.getState() == Watcher.Event.KeeperState.SyncConnected) {
                  // Signal that the Zookeeper connection is established.
                  latch.countDown();
              }
          });
  
          boolean successfullyConnected = false;
          try {
              successfullyConnected = latch.await(11, SECONDS);
          } catch (InterruptedException e) {
              Thread.currentThread().interrupt();
          }
          if (!successfullyConnected) {
              throw new IOException(String.format(
                      "Connection to ZooKeeper quorum timed out after %d seconds.", CONNECTION_TIMEOUT));
          }
  
          return zookeeper;
      }
docs: Connect to the ZooKeeper quorum, or timeout if it is unreachable.
  
  @throws IOException Thrown when connecting to the ZooKeeper quorum fails.