private Connection getConnection ( ConnectionRequestContext context ) throws SQLException { concurrentConnectionRequestCountHistogram . update ( concurrentConnectionRequestCount . incrementAndGet ( ) ) ; long startNanos = System . nanoTime ( ) ; try { Connection connection = null ; if ( ! connectionAcquiringStrategies . isEmpty ( ) ) { for ( ConnectionAcquiringStrategy strategy : connectionAcquiringStrategies ) { try { connection = strategy . getConnection ( context ) ; break ; } catch ( AcquireTimeoutException e ) { LOGGER . warn ( "Couldn't retrieve connection from strategy {} with context {}" , strategy , context ) ; } } } else { connection = poolAdapter . getConnection ( context ) ; } if ( connection != null ) { return connectionProxyFactory . newInstance ( connection , this ) ; } else { throw new CantAcquireConnectionException ( "Couldn't acquire connection for current strategies: " + connectionAcquiringStrategies ) ; } } finally { long endNanos = System . nanoTime ( ) ; long acquireDurationMillis = TimeUnit . NANOSECONDS . toMillis ( endNanos - startNanos ) ; connectionAcquireTotalTimer . update ( acquireDurationMillis , TimeUnit . MILLISECONDS ) ; concurrentConnectionRequestCountHistogram . update ( concurrentConnectionRequestCount . decrementAndGet ( ) ) ; if ( acquireDurationMillis > connectionAcquireTimeThresholdMillis ) { eventPublisher . publish ( new ConnectionAcquireTimeThresholdExceededEvent ( uniqueName , connectionAcquireTimeThresholdMillis , acquireDurationMillis ) ) ; LOGGER . info ( "Connection acquired in {} millis, while threshold is set to {} in {} FlexyPoolDataSource" , acquireDurationMillis , connectionAcquireTimeThresholdMillis , uniqueName ) ; } } }
Try to obtain a connection by going through all available strategies