code: private static void isPrimaryAlive(String zkRegistry) throws IOException {
      String parts[] = zkRegistry.split(":");
      if (parts.length != 2) {
        throw new IllegalArgumentException("Invalid Address : " + zkRegistry);
      }
      String host = parts[0];
      int port = Integer.parseInt(parts[1]);
      InetSocketAddress clientSocket = new InetSocketAddress(host, port);
      ServerSocket socket = new ServerSocket();
      socket.bind(clientSocket);
      socket.close();
    }
docs: Tries to bind to the address specified in ZooKeeper, this will always fail
  if the primary is alive either on the same machine or on a remote machine.