io.smallrye.stork.loadbalancer.poweroftwochoices.PowerOfTwoChoicesLoadBalancerProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stork-load-balancer-power-of-two-choices Show documentation
Show all versions of stork-load-balancer-power-of-two-choices Show documentation
SmallRye Stork Load Balancer provider based selecting two random destinations and then selecting the one with the least assigned requests.
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()));
}
}