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

com.zhizus.forest.thrift.client.cluster.loadbalance.RandomLoadBalance 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.ThreadLocalRandom;

/**
 * Created by Dempe on 2016/12/26.
 */
public class RandomLoadBalance extends AbstractLoadBalance {

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

    @Override
    public ServerInfo select(String key) {
        List availableServers = getAvailableServerList();
        int idx = (int) (ThreadLocalRandom.current().nextDouble() * availableServers.size());
        return availableServers.get((idx) % availableServers.size());
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy