@ Override public void waitForConnectionState ( final ConnectionState . State connectionState , long timeout ) throws InterruptedException , TimeoutException , CouldNotPerformException { synchronized ( connectionMonitor ) { boolean delayDetected = false ; while ( ! Thread . currentThread ( ) . isInterrupted ( ) ) { // check if requested connection state is reached. if ( this . connectionState . equals ( connectionState ) ) { if ( delayDetected ) { logger . info ( "Continue processing because " + getClass ( ) . getSimpleName ( ) . replace ( "Remote" , "" ) + "[" + getScopeStringRep ( ) + "] is now " + this . connectionState . name ( ) . toLowerCase ( ) + "." ) ; } return ; } failOnShutdown ( "Waiting for connectionState[" + connectionState . name ( ) + "] in connectionState[" + this . connectionState . name ( ) + "] on shutdown" ) ; // detect delay for long term wait if ( timeout == 0 ) { connectionMonitor . wait ( 15000 ) ; if ( ! this . connectionState . equals ( connectionState ) ) { failOnShutdown ( "Waiting for connectionState[" + connectionState . name ( ) + "] in connectionState[" + this . connectionState . name ( ) + "] on shutdown" ) ; delayDetected = true ; logger . info ( "Wait for " + this . connectionState . name ( ) . toLowerCase ( ) + " " + getClass ( ) . getSimpleName ( ) . replace ( "Remote" , "" ) + "[" + getScopeStringRep ( ) + "] to be " + connectionState . name ( ) . toLowerCase ( ) + "..." ) ; connectionMonitor . wait ( ) ; } continue ; } // wait till timeout connectionMonitor . wait ( timeout ) ; if ( timeout != 0 && ! this . connectionState . equals ( connectionState ) ) { throw new TimeoutException ( "Timeout expired!" ) ; } } } }
Method blocks until the remote reaches the desired connection state . In case the timeout is expired an TimeoutException will be thrown .