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

io.github.wycst.wast.clients.http.loadbalance.RandomLoadBalanceStrategy Maven / Gradle / Ivy

Go to download

Wast is a high-performance Java toolset library package that includes JSON, YAML, CSV, HttpClient, JDBC and EL engines

There is a newer version: 0.0.16
Show newest version
package io.github.wycst.wast.clients.http.loadbalance;

import io.github.wycst.wast.clients.http.provider.ServerZone;
import io.github.wycst.wast.clients.http.provider.ServiceInstance;

import java.util.List;
import java.util.Random;

/**
 * 负载均衡随机策略
 *
 * @Author: wangy
 * @Date: 2020/8/25 14:30
 * @Description:
 */
public class RandomLoadBalanceStrategy extends AbstractLoadBalanceStrategy {

    @Override
    public ServiceInstance doSelect(List aliveInstances, ServerZone serverZone) {
        int count = aliveInstances.size();
        Random random = new Random();
        int index = random.nextInt(count);
        return aliveInstances.get(index);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy