void connectDBConn ( DBConn dbConn ) throws DBNotAvailableException , RuntimeException { // If we're using failover hosts, see if it's time to try primary hosts again. if ( m_bUseSecondaryHosts && ( System . currentTimeMillis ( ) - m_lastPrimaryHostCheckTimeMillis ) > getParamInt ( "primary_host_recheck_millis" , 60000 ) ) { m_bUseSecondaryHosts = false ; } // Try all primary hosts first if possible. DBNotAvailableException lastException = null ; if ( ! m_bUseSecondaryHosts ) { String [ ] dbHosts = getParamString ( "dbhost" ) . split ( "," ) ; for ( int attempt = 1 ; ! dbConn . isOpen ( ) && attempt <= dbHosts . length ; attempt ++ ) { try { dbConn . connect ( chooseHost ( dbHosts ) ) ; } catch ( DBNotAvailableException ex ) { lastException = ex ; } catch ( RuntimeException ex ) { throw ex ; // bad keyspace; abort connection attempts } } m_lastPrimaryHostCheckTimeMillis = System . currentTimeMillis ( ) ; } // Try secondary hosts if needed and if configured. if ( ! dbConn . isOpen ( ) && ! Utils . isEmpty ( getParamString ( "secondary_dbhost" ) ) ) { if ( ! m_bUseSecondaryHosts ) { m_logger . info ( "All connections to 'dbhost' failed; trying 'secondary_dbhost'" ) ; } String [ ] dbHosts = getParamString ( "secondary_dbhost" ) . split ( "," ) ; for ( int attempt = 1 ; ! dbConn . isOpen ( ) && attempt <= dbHosts . length ; attempt ++ ) { try { dbConn . connect ( chooseHost ( dbHosts ) ) ; } catch ( DBNotAvailableException e ) { lastException = e ; } catch ( RuntimeException ex ) { throw ex ; // bad keyspace; abort connection attempts } } if ( dbConn . isOpen ( ) ) { m_bUseSecondaryHosts = true ; // stick with secondary hosts for now. } } if ( ! dbConn . isOpen ( ) ) { m_logger . error ( "All Thrift connection attempts failed." , lastException ) ; throw lastException ; } }
configured keyspace is not available a RuntimeException is thrown .