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

netflix.ocelli.loadbalancer.weighting.LinearWeightingStrategy Maven / Gradle / Ivy

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy