synchronized Transport borrowTransport ( ) { long now = System . currentTimeMillis ( ) ; List < PooledTransport > garbageTransports = new ArrayList < PooledTransport > ( ) ; PooledTransport candidate = null ; // Grab a transport for ( Map . Entry < PooledTransport , Long > entry : idle . entrySet ( ) ) { PooledTransport transport = entry . getKey ( ) ; if ( validate ( transport ) ) { candidate = transport ; break ; } else { garbageTransports . add ( transport ) ; } } // Remove any dead connections found for ( PooledTransport transport : garbageTransports ) { idle . remove ( transport ) ; release ( transport ) ; } // Create the connection if we didn't find any, remove it from the pool if we did. if ( candidate == null ) { candidate = create ( ) ; } else { idle . remove ( candidate ) ; } // Lease. leased . put ( candidate , now ) ; return new LeasedTransport ( candidate , this ) ; }
Borrows a Transport from this pool . If there are no pooled Transports available a new one is created .