netflix.ocelli.selectors.RoundRobinSelectionStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ocelli-core Show documentation
Show all versions of ocelli-core Show documentation
ocelli-core developed by Netflix
package netflix.ocelli.selectors;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import rx.Observable;
import rx.functions.Func1;
/**
* Very simple LoadBlancer that when queried gets an ImmutableList of active clients
* and round robins on the elements in that list
*
* @author elandau
*
* @param
*/
public class RoundRobinSelectionStrategy implements Func1, Observable> {
private final AtomicInteger position = new AtomicInteger();
@Override
public Observable call(ClientsAndWeights hosts) {
List clients = hosts.getClients();
if (clients == null || hosts.isEmpty()) {
return Observable.empty();
}
return Observable.just(clients.get(position.incrementAndGet() % clients.size()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy