private Collection < T > getMoreCandidates ( ) { final Predicate < T > unusedPredicate = new UnusedServer ( ) ; final Collection < T > servers = new LinkedList < T > ( ) ; // We limit the number of times we try to retrieve more candidates. If // we try several times and fail, we just return an empty collection. int tries = 0 ; // We pull candidate URIs from the candidate provider. while ( servers . isEmpty ( ) && ( tries < 3 ) ) { LOG . debug ( "Trying to find candidate servers" ) ; // If we have been flagged to sleep before trying to get more // candidates, sleep before trying to get more candidates. if ( m_sleepBeforeTryingToGetMoreCandidates ) { LOG . debug ( "Long sleep..." ) ; ThreadUtils . safeSleep ( 60000 ) ; } else if ( ! m_firstRun ) { LOG . debug ( "Short sleep..." ) ; // Always sleep for a little while to avoid hammering the // server. ThreadUtils . safeSleep ( 10000 ) ; } m_firstRun = false ; final Collection < T > candidates = m_candidateProvider . getCandidates ( ) ; LOG . debug ( "Found candidates..." ) ; // We only accept servers that we have not already used. This // prevents us from establishing connections with the same // servers more than once. final Collection < T > unusedCandidates = m_collectionUtils . select ( candidates , unusedPredicate ) ; servers . addAll ( unusedCandidates ) ; ++ tries ; } LOG . debug ( "Found this many candidate servers: " + servers . size ( ) ) ; return servers ; }
Returns a collection of more candidates that can be tried for connections .