private static Endpoint selectByPartition ( final List < Endpoint > endpoints , final short partition ) { if ( partition >= 0 ) { int numEndpoints = endpoints . size ( ) ; Endpoint endpoint = numEndpoints == 1 ? endpoints . get ( 0 ) : endpoints . get ( partition % numEndpoints ) ; if ( endpoint != null && endpoint . isState ( LifecycleState . CONNECTED ) && endpoint . isFree ( ) ) { return endpoint ; } return null ; } else { return selectFirstConnected ( endpoints ) ; } }
Helper method to select the proper target endpoint by partition .