Package com.tccc.kos.commons.util
Class BackoffConfig
java.lang.Object
com.tccc.kos.commons.util.BackoffConfig
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
pluscount * unitDelayMs
where count is first limited tomaxCount
and the final delay is limited tomaxDelayMs
. - EXPONENTIAL: A delay that grows exponentially based on
the count. Returns
baseDelayMs
plusunitDelayMs * Math.pow(unitMultipilier, count)
where count is limited tomaxCount
and the final delay is limited tomaxDelayMs
.
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
int
int
getType()
int
double
setBaseDelayMs
(int baseDelayMs) Set the base delay for the backoff delay.setMaxCount
(int maxCount) Set the max count that will be used in the backoff algorithm.setMaxDelayMs
(int maxDelayMs) Set the max delay the backoff can generate.Set the type of backoff algorithm to use.setUnitDelayMs
(int unitDelayMs) Set the unit delay for the backoff delay.
-
Field Details
-
TYPE_FIXED
- See Also:
-
TYPE_LINEAR
- See Also:
-
TYPE_EXPONENTIAL
- See Also:
-
-
Constructor Details
-
BackoffConfig
public BackoffConfig()
-
-
Method Details
-
setType
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 availableTYPE
constants
-
setBaseDelayMs
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
Set the unit delay for the backoff delay. This is multiplied by the count portion of the delay and is added tobaesDelayMs
before clipping to the max delay.- Parameters:
unitDelayMs
- multiplied by the count portion of the backoff
-
setMaxDelayMs
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
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
-
getBaseDelayMs
public int getBaseDelayMs() -
getUnitDelayMs
public int getUnitDelayMs() -
getUnitMultiplier
public double getUnitMultiplier() -
getMaxDelayMs
public int getMaxDelayMs() -
getMaxCount
public int getMaxCount()
-