public synchronized boolean waitForConnection(long timeout, TimeUnit units)
     throws InterruptedException {
   long left = timeout > 0 ? units.toMillis(timeout) : Long.MAX_VALUE;
   while (!connectionMade.isSet() && left > 0) {
     long start = System.currentTimeMillis();
     this.wait(units.toMillis(timeout));
     left -= (System.currentTimeMillis() - start);
   }
   return connectionMade.isSet();
 }
 private synchronized void openChannel(String serverHost, int serverPort)
     throws InterruptedException {
   while (!clientStopped.isSet()) {
     try {
       DSO_LOGGER.debug("Trying to open channel....");
       final char[] pw;
       if (config.getSecurityInfo().hasCredentials()) {
         Assert.assertNotNull(securityManager);
         pw =
             securityManager.getPasswordForTC(
                 config.getSecurityInfo().getUsername(), serverHost, serverPort);
       } else {
         pw = null;
       }
       this.channel.open(pw);
       DSO_LOGGER.debug("Channel open");
       break;
     } catch (final TCTimeoutException tcte) {
       CONSOLE_LOGGER.warn("Timeout connecting to server: " + tcte.getMessage());
       this.wait(5000);
     } catch (final ConnectException e) {
       CONSOLE_LOGGER.warn("Connection refused from server: " + e);
       this.wait(5000);
     } catch (final MaxConnectionsExceededException e) {
       DSO_LOGGER.fatal(e.getMessage());
       CONSOLE_LOGGER.fatal(e.getMessage());
       throw new IllegalStateException(e.getMessage(), e);
     } catch (final CommStackMismatchException e) {
       DSO_LOGGER.fatal(e.getMessage());
       CONSOLE_LOGGER.fatal(e.getMessage());
       throw new IllegalStateException(e.getMessage(), e);
     } catch (final IOException ioe) {
       CONSOLE_LOGGER.warn(
           "IOException connecting to server: "
               + serverHost
               + ":"
               + serverPort
               + ". "
               + ioe.getMessage());
       this.wait(5000);
     }
   }
 }
 public boolean isTunnelingReady() {
   synchronized (jmxReadyLock) {
     return localJmxServerReady.isSet() && transportConnected;
   }
 }