public boolean startConnection ( ) { State state = _state . get ( ) ; if ( state . isActive ( ) ) { // when active, always start a connection _connectionCount . incrementAndGet ( ) ; return true ; } long now = CurrentTime . currentTime ( ) ; long lastFailTime = _lastFailTime ; long recoverTimeout = _dynamicRecoverTimeout . get ( ) ; if ( now < lastFailTime + recoverTimeout ) { // if the fail recover hasn't timed out, return false return false ; } // when fail, only start a single connection int count ; do { count = _connectionCount . get ( ) ; if ( count > 0 ) { return false ; } } while ( ! _connectionCount . compareAndSet ( count , count + 1 ) ) ; return true ; }
Start a new connection . Returns true if the connection can be started .