All Downloads are FREE. Search and download functionalities are using the official Maven repository.

netflix.ocelli.selectors.RoundRobinSelectionStrategy Maven / Gradle / Ivy

There is a newer version: 0.1.0-rc.2
Show newest version
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