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

io.smallrye.stork.loadbalancer.poweroftwochoices.PowerOfTwoChoicesLoadBalancerProvider Maven / Gradle / Ivy

Go to download

SmallRye Stork Load Balancer provider based selecting two random destinations and then selecting the one with the least assigned requests.

There is a newer version: 2.7.1
Show newest version
package io.smallrye.stork.loadbalancer.poweroftwochoices;

import jakarta.enterprise.context.ApplicationScoped;

import io.smallrye.stork.api.LoadBalancer;
import io.smallrye.stork.api.ServiceDiscovery;
import io.smallrye.stork.api.config.LoadBalancerAttribute;
import io.smallrye.stork.api.config.LoadBalancerType;
import io.smallrye.stork.spi.LoadBalancerProvider;

/**
 * A load balancer provider following the Power of two random choices strategy.
 */
@LoadBalancerType("power-of-two-choices")
@LoadBalancerAttribute(name = "use-secure-random", defaultValue = "false", description = "Whether the load balancer should use a SecureRandom instead of a Random (default). Check [this page](https://stackoverflow.com/questions/11051205/difference-between-java-util-random-and-java-security-securerandom) to understand the difference")
@ApplicationScoped
public class PowerOfTwoChoicesLoadBalancerProvider
        implements LoadBalancerProvider {

    public LoadBalancer createLoadBalancer(PowerOfTwoChoicesConfiguration config,
            ServiceDiscovery serviceDiscovery) {
        return new PowerOfTwoChoicesLoadBalancer(Boolean.parseBoolean(config.getUseSecureRandom()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy