private void waitForStart(long timeout) throws CommunicationException, InterruptedException {
  if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
    SNMP_ADAPTOR_LOGGER.logp(Level.FINER,dbgTag,"waitForStart","Timeout=" + timeout + " ; current state = "+ getStateString());
  }
  final long startTime=System.currentTimeMillis();
synchronized (stateLock) {
    while (state == STARTING) {
      final long elapsed=System.currentTimeMillis() - startTime;
      final long remainingTime=timeout - elapsed;
      if (remainingTime < 0) {
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
          SNMP_ADAPTOR_LOGGER.logp(Level.FINER,dbgTag,"waitForStart","timeout < 0, return without wait");
        }
        throw new InterruptedException("Timeout expired");
      }
      try {
        stateLock.wait(remainingTime);
      }
 catch (      InterruptedException e) {
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
          SNMP_ADAPTOR_LOGGER.logp(Level.FINER,dbgTag,"waitForStart","wait interrupted");
        }
        if (state != ONLINE)         throw e;
      }
    }
    if (state == ONLINE) {
      if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER,dbgTag,"waitForStart","started");
      }
      return;
    }
 else     if (startException instanceof CommunicationException) {
      throw (CommunicationException)startException;
    }
 else     if (startException instanceof InterruptedException) {
      throw (InterruptedException)startException;
    }
 else     if (startException != null) {
      throw new CommunicationException(startException,"Failed to start: " + startException);
    }
 else {
      throw new CommunicationException("Failed to start: state is " + getStringForState(state));
    }
  }
}

private void waitForStart ( long timeout ) throws CommunicationException , InterruptedException { if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINER ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINER , dbgTag , "waitForStart" , "Timeout=" + timeout + " ; current state = " + getStateString ( ) ) ; } final long startTime = System . currentTimeMillis ( ) ; synchronized ( stateLock ) { while ( state == STARTING ) { final long elapsed = System . currentTimeMillis ( ) - startTime ; final long remainingTime = timeout - elapsed ; if ( remainingTime < 0 ) { if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINER ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINER , dbgTag , "waitForStart" , "timeout < 0, return without wait" ) ; } throw new InterruptedException ( "Timeout expired" ) ; } try { stateLock . wait ( remainingTime ) ; } catch ( InterruptedException e ) { if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINER ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINER , dbgTag , "waitForStart" , "wait interrupted" ) ; } if ( state != ONLINE ) throw e ; } } if ( state == ONLINE ) { if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINER ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINER , dbgTag , "waitForStart" , "started" ) ; } return ; } else if ( startException instanceof CommunicationException ) { throw ( CommunicationException ) startException ; } else if ( startException instanceof InterruptedException ) { throw ( InterruptedException ) startException ; } else if ( startException != null ) { throw new CommunicationException ( startException , "Failed to start: " + startException ) ; } else { throw new CommunicationException ( "Failed to start: state is " + getStringForState ( state ) ) ; } } }
< p > waits until the communicator is started or timeout expires .
