io.smallrye.stork.loadbalancer.poweroftwochoices.PowerOfTwoChoicesConfiguration 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 java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import io.smallrye.stork.api.config.ConfigWithType;
/**
* Configuration for the {@code PowerOfTwoChoicesLoadBalancerProvider} LoadBalancer.
*/
public class PowerOfTwoChoicesConfiguration implements io.smallrye.stork.api.config.ConfigWithType{
private final Map parameters;
/**
* Creates a new PowerOfTwoChoicesConfiguration
*
* @param params the parameters, must not be {@code null}
*/
public PowerOfTwoChoicesConfiguration(Map params) {
parameters = Collections.unmodifiableMap(params);
}
/**
* Creates a new PowerOfTwoChoicesConfiguration
*/
public PowerOfTwoChoicesConfiguration() {
parameters = Collections.emptyMap();
}
/**
* @return the type
*/
@Override
public String type() {
return "power-of-two-choices";
}
/**
* @return the parameters
*/
@Override
public Map parameters() {
return parameters;
}
private PowerOfTwoChoicesConfiguration extend(String key, String value) {
Map copy = new HashMap<>(parameters);
copy.put(key, value);
return new PowerOfTwoChoicesConfiguration(copy);
}
/**
* 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 By default: false
*
* @return the configured use-secure-random, {@code false} if not set
*/
public String getUseSecureRandom() {
String result = parameters.get("use-secure-random");
return result == null ? "false" : result;
}
/**
* Set the 'use-secure-random' attribute. Default is false.
*
* @param value the value for use-secure-random
* @return the current PowerOfTwoChoicesConfiguration to chain calls
*/
public PowerOfTwoChoicesConfiguration withUseSecureRandom(String value) {
return extend("use-secure-random", value);
}
}