Esempio n. 1
0
  private static void busyWaitForPort(
      InetAddress address, int port, boolean expectedConnectionState) {
    long maxAcceptableWaitTime = TimeUnit.SECONDS.toMillis(10);
    long waitQuantum = TimeUnit.MILLISECONDS.toMillis(500);
    long waitTimeSoFar = 0;
    boolean connectionState = !expectedConnectionState;

    while (connectionState != expectedConnectionState && waitTimeSoFar < maxAcceptableWaitTime) {
      connectionState = CCMBridge.pingPort(address, port);
      try {
        Thread.sleep(waitQuantum);
        waitTimeSoFar += waitQuantum;
      } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while pinging " + address + ":" + port, e);
      }
    }
  }