private Optional < T > getServerIdToTry ( ) { if ( m_serverIdsToTry . isEmpty ( ) ) { final Collection < T > moreCandidates = getMoreCandidates ( ) ; if ( moreCandidates . isEmpty ( ) ) { // We were unable to find more candidates. To avoid hammering // the service that provides potential candidates, flag that we // should sleep for a little while before trying again to get // more potential candidates. m_sleepBeforeTryingToGetMoreCandidates = true ; return ( new NoneImpl < T > ( ) ) ; } else { // We successfully retrieved more candidates. We clear the // flag that prevented requesting more potential candidates, // since all is well. Since we have candidates with which to // work, we probably will not be hitting the service that // provides potential candidates any time soon. m_sleepBeforeTryingToGetMoreCandidates = false ; m_serverIdsToTry . addAll ( moreCandidates ) ; return ( new SomeImpl < T > ( m_serverIdsToTry . remove ( 0 ) ) ) ; } } else { // We already have servers to try. Try one of them. return ( new SomeImpl < T > ( m_serverIdsToTry . remove ( 0 ) ) ) ; } }
Returns a server identifier to try .