Search in sources :

Example 1 with WeightedRandomLoadBalancer

use of org.apache.camel.processor.loadbalancer.WeightedRandomLoadBalancer in project camel by apache.

the class WeightedLoadBalancerDefinition method createLoadBalancer.

@Override
protected LoadBalancer createLoadBalancer(RouteContext routeContext) {
    WeightedLoadBalancer loadBalancer;
    List<Integer> distributionRatioList = new ArrayList<Integer>();
    try {
        String[] ratios = distributionRatio.split(getDistributionRatioDelimiter());
        for (String ratio : ratios) {
            distributionRatioList.add(new Integer(ratio.trim()));
        }
        boolean isRoundRobin = getRoundRobin() != null && getRoundRobin();
        if (isRoundRobin) {
            loadBalancer = new WeightedRoundRobinLoadBalancer(distributionRatioList);
        } else {
            loadBalancer = new WeightedRandomLoadBalancer(distributionRatioList);
        }
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
    return loadBalancer;
}
Also used : WeightedRoundRobinLoadBalancer(org.apache.camel.processor.loadbalancer.WeightedRoundRobinLoadBalancer) WeightedRandomLoadBalancer(org.apache.camel.processor.loadbalancer.WeightedRandomLoadBalancer) ArrayList(java.util.ArrayList) WeightedLoadBalancer(org.apache.camel.processor.loadbalancer.WeightedLoadBalancer)

Aggregations

ArrayList (java.util.ArrayList)1 WeightedLoadBalancer (org.apache.camel.processor.loadbalancer.WeightedLoadBalancer)1 WeightedRandomLoadBalancer (org.apache.camel.processor.loadbalancer.WeightedRandomLoadBalancer)1 WeightedRoundRobinLoadBalancer (org.apache.camel.processor.loadbalancer.WeightedRoundRobinLoadBalancer)1