netflix.ocelli.selectors.WeightedSelectionStrategy 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 rx.Observable;
import rx.Observable.OnSubscribe;
import rx.Subscriber;
import rx.functions.Func1;
/**
* Load balancer that selects Clients based on weight
*
* @author elandau
*
* @param
*/
public class WeightedSelectionStrategy implements Func1, Observable> {
private final WeightSelector func;
public WeightedSelectionStrategy(WeightSelector func) {
this.func = func;
}
@Override
public Observable call(final ClientsAndWeights hosts) {
if (hosts.isEmpty()) {
return Observable.empty();
}
return Observable.create(new OnSubscribe() {
int pos = func.call(hosts.getWeights(), hosts.getTotalWeights());
@Override
public void call(Subscriber super Client> t1) {
t1.onNext(hosts.getClients().get(pos++ % hosts.getClients().size()));
t1.onCompleted();
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy