public enum TokensInheritanceStrategy extends Enum<TokensInheritanceStrategy>
Bucket.replaceConfiguration(BucketConfiguration, TokensInheritanceStrategy)
happens.Enum Constant and Description |
---|
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.
|
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.
|
PROPORTIONALLY
Makes to copy available tokens proportional to bandwidth capacity by following formula:
newAvailableTokens = availableTokensBeforeReplacement * (newBandwidthCapacity / capacityBeforeReplacement)
|
RESET
Use this mode when you want just to forget about previous bucket state.
|
Modifier and Type | Method and Description |
---|---|
static TokensInheritanceStrategy |
getById(byte id) |
byte |
getId() |
static TokensInheritanceStrategy |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static TokensInheritanceStrategy[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final TokensInheritanceStrategy PROPORTIONALLY
newAvailableTokens = availableTokensBeforeReplacement * (newBandwidthCapacity / capacityBeforeReplacement)
Let's describe few examples.
Example 1: imagine bandwidth that was created by Bandwidth.classic(100, Refill.gready(10, Duration.ofMinutes(1)))
.
At the moment of config replacement it was 40 available tokens. After replacing this bandwidth by following Bandwidth.classic(200, Refill.gready(10, Duration.ofMinutes(1)))
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.classic(100, Refill.gready(10, Duration.ofMinutes(1)))
.
At the moment of config replacement it was 40 available tokens. After replacing this bandwidth by following Bandwidth.classic(20, Refill.gready(10, Duration.ofMinutes(1)))
40 available tokens will be multiplied by 0.2(20/100), and after replacement we will have 8 available tokens.
public static final TokensInheritanceStrategy AS_IS
Let's describe few examples.
Example 1: imagine bandwidth that was created by Bandwidth.classic(100, Refill.gready(10, Duration.ofMinutes(1)))
.
At the moment of config replacement it was 40 available tokens. After replacing this bandwidth by following Bandwidth.classic(200, Refill.gready(10, Duration.ofMinutes(1)))
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.classic(100, Refill.gready(10, Duration.ofMinutes(1)))
.
At the moment of config replacement it was 40 available tokens. After replacing this bandwidth by following Bandwidth.classic(20, Refill.gready(10, Duration.ofMinutes(1)))
40 available tokens can not be copied as is, because it is greater then new capacity, so available tokens will be reduced to 20.
public static final TokensInheritanceStrategy RESET
bucket.replaceConfiguration(newConfiguration, TokensInheritanceStrategy.RESET)
just erases all previous state.
Using this strategy equals to removing bucket and creating again with new configuration.public static final TokensInheritanceStrategy ADDITIVE
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.classic(100, Refill.gready(10, Duration.ofMinutes(1)))
.
At the moment of configuration replacement, it was 40 available tokens.
After replacing this bandwidth by following Bandwidth.classic(200, Refill.gready(10, Duration.ofMinutes(1)))
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.classic(100, Refill.gready(10, Duration.ofMinutes(1)))
.
At the moment of config replacement it was 40 available tokens.
After replacing this bandwidth by following Bandwidth.classic(20, Refill.gready(10, Duration.ofMinutes(1))))
,
and after replacement we will have 20 available tokens.
Example 3: imagine bandwidth that was created by Bandwidth.classic(100, Refill.gready(10, Duration.ofMinutes(1)))
.
At the moment of config replacement it was 10 available tokens.
After replacing this bandwidth by following Bandwidth.classic(20, Refill.gready(10, Duration.ofMinutes(1))))
,
and after replacement we will have 10 available tokens.
public static TokensInheritanceStrategy[] values()
for (TokensInheritanceStrategy c : TokensInheritanceStrategy.values()) System.out.println(c);
public static TokensInheritanceStrategy valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static TokensInheritanceStrategy getById(byte id)
public byte getId()
Copyright © 2022. All rights reserved.