- All Implemented Interfaces:
Serializable,Comparable<TokensInheritanceStrategy>,Constable
Bucket.replaceConfiguration(BucketConfiguration, TokensInheritanceStrategy) happens.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionInstructs to copy available tokens as is, but with one exclusion: if new bandwidth capacity is greater than old capacity, available tokens will be increased by the difference between the old and the new configuration.Instructs to copy available tokens as is, but with one exclusion: if available tokens is greater than new capacity, available tokens will be decreased to new capacity.Makes to copy available tokens proportional to bandwidth capacity by following formula:newAvailableTokens = availableTokensBeforeReplacement * (newBandwidthCapacity / capacityBeforeReplacement)Use this mode when you want just to forget about previous bucket state. -
Method Summary
Modifier and TypeMethodDescriptionstatic TokensInheritanceStrategygetById(byte id) bytegetId()static TokensInheritanceStrategyReturns the enum constant of this class with the specified name.static TokensInheritanceStrategy[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
PROPORTIONALLY
Makes to copy available tokens proportional to bandwidth capacity by following formula:newAvailableTokens = availableTokensBeforeReplacement * (newBandwidthCapacity / capacityBeforeReplacement)Let's describe few examples.
Example 1: imagine bandwidth that was created by
Bandwidth.builder().capacity(100).refillGreedy(10, ofMinutes(1)).build(). At the moment of config replacement it was 40 available tokens. After replacing this bandwidth by followingBandwidth.builder().capacity(200).refillGreedy(10, ofMinutes(1)).build()40 available tokens will be multiplied by 2(200/100), and after replacement we will have 80 available tokens.Example 2: imagine bandwidth that was created by
Bandwidth.builder().capacity(100).refillGreedy(10, ofMinutes(1)).build(). At the moment of config replacement it was 40 available tokens. After replacing this bandwidth by followingBandwidth.builder().capacity(20).refillGreedy(10, ofMinutes(1)).build()40 available tokens will be multiplied by 0.2(20/100), and after replacement we will have 8 available tokens. -
AS_IS
Instructs to copy available tokens as is, but with one exclusion: if available tokens is greater than new capacity, available tokens will be decreased to new capacity.Let's describe few examples.
Example 1: imagine bandwidth that was created by
Bandwidth.builder().capacity(100).refillGreedy(10, ofMinutes(1)).build(). At the moment of config replacement it was 40 available tokens. After replacing this bandwidth by followingBandwidth.builder().capacity(200).refillGreedy(10, ofMinutes(1)).build()40 available tokens will be just copied, and after replacement we will have 40 available tokens.Example 2: imagine bandwidth that was created by
Bandwidth.builder().capacity(100).refillGreedy(10, ofMinutes(1)).build(). At the moment of config replacement it was 40 available tokens. After replacing this bandwidth by followingBandwidth.builder().capacity(20).refillGreedy(10, ofMinutes(1)).build()40 available tokens can not be copied as is, because it is greater than new capacity, so available tokens will be reduced to 20. -
RESET
Use this mode when you want just to forget about previous bucket state.bucket.replaceConfiguration(newConfiguration, TokensInheritanceStrategy.RESET)just erases all previous state. Using this strategy equals to removing bucket and creating again with new configuration. -
ADDITIVE
Instructs to copy available tokens as is, but with one exclusion: if new bandwidth capacity is greater than old capacity, available tokens will be increased by the difference between the old and the new configuration.The formula is
newAvailableTokens = Math.min(availableTokensBeforeReplacement, newBandwidthCapacity) + Math.max(0, newBandwidthCapacity - capacityBeforeReplacement)Let's describe few examples.
Example 1: imagine bandwidth that was created by
Bandwidth.builder().capacity(100).refillGreedy(10, ofMinutes(1)).build(). At the moment of configuration replacement, it was 40 available tokens. After replacing this bandwidth by followingBandwidth.builder().capacity(200).refillGreedy(200, ofMinutes(1)).build()40 available tokens will be copied and added to the difference between old and new configuration, and after replacement, we will have 140 available tokens.Example 2: imagine bandwidth that was created by
Bandwidth.builder().capacity(100).refillGreedy(10, ofMinutes(1)).build(). At the moment of config replacement it was 40 available tokens. After replacing this bandwidth by followingBandwidth.builder().capacity(20).refillGreedy(10, ofMinutes(1)).build(), and after replacement we will have 20 available tokens.Example 3: imagine bandwidth that was created by
Bandwidth.builder().capacity(100).refillGreedy(10, ofMinutes(1)).build(). At the moment of config replacement it was 10 available tokens. After replacing this bandwidth by followingBandwidth.builder().capacity(100).refillGreedy(20, ofMinutes(1)).build(), and after replacement we will have 10 available tokens.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getById
-
getId
public byte getId()
-