netflix.ocelli.loadbalancer.weighting.LinearWeightingStrategy Maven / Gradle / Ivy
package netflix.ocelli.loadbalancer.weighting;
import java.util.ArrayList;
import java.util.List;
import rx.functions.Func1;
public class LinearWeightingStrategy implements WeightingStrategy {
private Func1 func;
public LinearWeightingStrategy(Func1 func) {
this.func = func;
}
@Override
public ClientsAndWeights call(List clients) {
ArrayList weights = new ArrayList(clients.size());
if (clients.size() > 0) {
for (int i = 0; i < clients.size(); i++) {
weights.add(func.call(clients.get(i)));
}
int sum = 0;
for (int i = 0; i < weights.size(); i++) {
sum += weights.get(i);
weights.set(i, sum);
}
}
return new ClientsAndWeights(clients, weights);
}
}