Class BackoffConfig

java.lang.Object
com.tccc.kos.commons.util.BackoffConfig

public class BackoffConfig extends Object
Configuration for any of the available backoff delays. This provides the underlying configuration information that can be be combined with count values to compute a final delay. This allows the backoff algorithm to be changed without needing to change existing code. This also allows configurations to be stored as part of a ConfigBean and used directly in a backoff algorithm which allows the configurations to be modified using the config system.

This provides fluent setters which allows this class to act as a bridge between other storage systems directly into a backoff algorithm.

The following types use config properties as described below:

  • FIXED: A fixed delay that doesn't depend on the count provided. Simply returns baseDelayMs.
  • LINEAR: A delay that grows linearly based on the count. Returns baseDelayMs plus count * unitDelayMs where count is first limited to maxCount and the final delay is limited to maxDelayMs.
  • EXPONENTIAL: A delay that grows exponentially based on the count. Returns baseDelayMs plus unitDelayMs * Math.pow(unitMultipilier, count) where count is limited to maxCount and the final delay is limited to maxDelayMs.

The default constructor will return an exponential configuration with values that will work but are unlikely to match the needs of any given application. Expect to override the defaults with application appropriate values.

Since:
1.0
  • Field Details

  • Constructor Details

    • BackoffConfig

      public BackoffConfig()
  • Method Details

    • setType

      public BackoffConfig setType(String type)
      Set the type of backoff algorithm to use. If the type is unknown then exponential will be used as it is the least likely to result in excessive load due to excessively short delays.
      Parameters:
      type - one of the available TYPE constants
    • setBaseDelayMs

      public BackoffConfig setBaseDelayMs(int baseDelayMs)
      Set the base delay for the backoff delay. This is the number of ms to delay before adding on any additional backoff.
      Parameters:
      baseDelayMs - the base delay all other factors add to
    • setUnitDelayMs

      public BackoffConfig setUnitDelayMs(int unitDelayMs)
      Set the unit delay for the backoff delay. This is multiplied by the count portion of the delay and is added to baesDelayMs before clipping to the max delay.
      Parameters:
      unitDelayMs - multiplied by the count portion of the backoff
    • setMaxDelayMs

      public BackoffConfig setMaxDelayMs(int maxDelayMs)
      Set the max delay the backoff can generate. This is ignored if less than or equal to zero.
      Parameters:
      maxDelayMs - the max delay possible
    • setMaxCount

      public BackoffConfig setMaxCount(int maxCount)
      Set the max count that will be used in the backoff algorithm. This prevents counters from overflowing the backoff algorithm. Each algorithm has a default max count which will be applied if this value is less than or equal to zero.
    • getType

      public String getType()
    • getBaseDelayMs

      public int getBaseDelayMs()
    • getUnitDelayMs

      public int getUnitDelayMs()
    • getUnitMultiplier

      public double getUnitMultiplier()
    • getMaxDelayMs

      public int getMaxDelayMs()
    • getMaxCount

      public int getMaxCount()