public SuroConnection chooseConnection ( ) { SuroConnection connection = connectionQueue . poll ( ) ; if ( connection == null ) { connection = chooseFromPool ( ) ; } if ( config . getEnableOutPool ( ) ) { synchronized ( this ) { for ( int i = 0 ; i < config . getRetryCount ( ) && connection == null ; ++ i ) { Server server = lb . chooseServer ( null ) ; if ( server != null ) { connection = new SuroConnection ( server , config , false ) ; try { connection . connect ( ) ; ++ outPoolSize ; logger . info ( connection + " is created out of the pool" ) ; break ; } catch ( Exception e ) { logger . error ( "Error in connecting to " + connection + " message: " + e . getMessage ( ) , e ) ; lb . markServerDown ( server ) ; } } } } } if ( connection == null ) { logger . error ( "No valid connection exists after " + config . getRetryCount ( ) + " retries" ) ; } return connection ; }
When the client calls this method it will return the connection .