private ConnectionData findConnectionDataToUse ( ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . entry ( this , tc , "findConnectionDataToUse" ) ; // Look through the the connection data in this group to try and find // a connection with the lowest use count. ConnectionData connectionDataToUse = null ; synchronized ( connectionData ) { int lowestUseCount = conversationsPerConnection ; for ( int i = 0 ; i < connectionData . size ( ) ; ++ i ) { final ConnectionData cd = connectionData . get ( i ) ; if ( cd . getUseCount ( ) < lowestUseCount ) { lowestUseCount = cd . getUseCount ( ) ; connectionDataToUse = cd ; } } // If we cannot find a suitable connection data object, see if the // idle connections pool has a connection we could use to create one. if ( connectionDataToUse == null ) { final IdleConnectionPool p = IdleConnectionPool . getInstance ( ) ; final OutboundConnection oc = p . remove ( groupEndpointDescriptor ) ; if ( oc != null ) { connectionDataToUse = new ConnectionData ( this , groupEndpointDescriptor ) ; oc . setConnectionData ( connectionDataToUse ) ; connectionDataToUse . setConnection ( oc ) ; connectionData . add ( connectionDataToUse ) ; } } // If we now have a connectionDataToUse, increment its use count NOW // so that it won't get accidentally added to the idle pool if ( connectionDataToUse != null ) { connectionDataToUse . incrementUseCount ( ) ; } } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . exit ( this , tc , "findConnectionDataToUse" , connectionDataToUse ) ; return connectionDataToUse ; }
Helper method chooses the connection to use for a new conversation .