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

io.smallrye.stork.loadbalancer.poweroftwochoices.PowerOfTwoChoicesConfiguration 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 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);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy