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

com.zhizus.forest.thrift.client.cluster.loadbalance.RoundRobinLoadBalance Maven / Gradle / Ivy

The newest version!
package com.zhizus.forest.thrift.client.cluster.loadbalance;

import com.zhizus.forest.thrift.client.ServerInfo;
import com.zhizus.forest.thrift.client.cluster.IsolationStrategy;
import com.zhizus.forest.thrift.client.registry.Registry;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by Dempe on 2016/12/22.
 */
public class RoundRobinLoadBalance extends AbstractLoadBalance {

    private AtomicInteger idx = new AtomicInteger(0);

    public RoundRobinLoadBalance(Registry registry, IsolationStrategy isolationStrategy) {
        super(registry, isolationStrategy);
    }

    @Override
    public ServerInfo select(String key) {
        List availableServerList = getAvailableServerList();
        return availableServerList.get(idx.incrementAndGet() % availableServerList.size());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy