public Optional < Server > chooseRandomlyAfterFiltering ( List < Server > servers ) { List < Server > eligible = getEligibleServers ( servers ) ; if ( eligible . size ( ) == 0 ) { return Optional . absent ( ) ; } return Optional . of ( eligible . get ( random . nextInt ( eligible . size ( ) ) ) ) ; }
Choose a random server after the predicate filters a list of servers . Load balancer key is presumed to be null .