private static boolean waitForServerUp(String hostname, int port, long timeout) {
    long start = System.currentTimeMillis();
    while (true) {
      try {
        Socket sock = new Socket(hostname, port);
        BufferedReader reader = null;
        try {
          OutputStream outstream = sock.getOutputStream();
          outstream.write("stat".getBytes());
          outstream.flush();

          Reader isr = new InputStreamReader(sock.getInputStream());
          reader = new BufferedReader(isr);
          String line = reader.readLine();
          if (line != null && line.startsWith("Zookeeper version:")) {
            return true;
          }
        } finally {
          sock.close();
          if (reader != null) {
            reader.close();
          }
        }
      } catch (IOException e) {
        // ignore as this is expected
        logger.info("server " + hostname + ":" + port + " not up " + e);
      }

      if (System.currentTimeMillis() > start + timeout) {
        break;
      }
      try {
        Thread.sleep(250);
      } catch (InterruptedException e) {
        // ignore
      }
    }
    return false;
  }
private static boolean waitForServerUp ( String hostname , int port , long timeout ) { long start = System . currentTimeMillis ( ) ; while ( true ) { try { Socket sock = new Socket ( hostname , port ) ; BufferedReader reader = null ; try { OutputStream outstream = sock . getOutputStream ( ) ; outstream . write ( "stat" . getBytes ( ) ) ; outstream . flush ( ) ; Reader isr = new InputStreamReader ( sock . getInputStream ( ) ) ; reader = new BufferedReader ( isr ) ; String line = reader . readLine ( ) ; if ( line != null && line . startsWith ( "Zookeeper version:" ) ) { return true ; } } finally { sock . close ( ) ; if ( reader != null ) { reader . close ( ) ; } } } catch ( IOException e ) { logger . info ( "server " + hostname + ":" + port + " not up " + e ) ; } if ( System . currentTimeMillis ( ) > start + timeout ) { break ; } try { Thread . sleep ( 250 ) ; } catch ( InterruptedException e ) { } } return false ; }
XXX: From o.a.zk.t.ClientBase