java.lang.Object
com.github.cowwoc.tokenbucket.Limit.Builder
- Enclosing class:
- Limit
Builds a Limit.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a new Limit.long
Returns the initial number of tokens in the bucket.initialTokens
(long initialTokens) Sets the initial number of tokens in the bucket.long
Returns the maximum number of tokens that the bucket may hold before overflowing.maximumTokens
(long maximumTokens) Sets the maximum number of tokens that the bucket may hold before overflowing.period()
Indicates how oftentokensPerPeriod
should be added to the bucket.Indicates how oftentokensPerPeriod
should be added to the bucket.long
Returns the number of tokens that are refilled at a time.refillSize
(long refillSize) Sets the number of tokens that are refilled at a time.long
Returns the number of tokens to add to the bucket everyperiod
.tokensPerPeriod
(long tokensPerPeriod) Sets the number of tokens to add to the bucket everyperiod
.toString()
userData()
Returns user data associated with this limit.Sets user data associated with this limit.
-
Method Details
-
tokensPerPeriod
public long tokensPerPeriod()Returns the number of tokens to add to the bucket everyperiod
. The default is1
.- Returns:
- the number of tokens to add to the bucket every
period
-
tokensPerPeriod
Sets the number of tokens to add to the bucket everyperiod
.- Parameters:
tokensPerPeriod
- the number of tokens to add to the bucket everyperiod
- Returns:
- this
- Throws:
IllegalArgumentException
- iftokensPerPeriod
is negative or zero
-
period
Indicates how oftentokensPerPeriod
should be added to the bucket. The default is1 second
.- Returns:
- how often
tokensPerPeriod
should be added to the bucket
-
period
Indicates how oftentokensPerPeriod
should be added to the bucket.- Parameters:
period
- indicates how oftentokensPerPeriod
should be added to the bucket- Returns:
- this
- Throws:
IllegalArgumentException
- ifperiod
is negative or zeroNullPointerException
- ifperiod
is null
-
initialTokens
public long initialTokens()Returns the initial number of tokens in the bucket. The value may be negative, in which case the bucket must accumulate a positive number of tokens before they may be consumed. The default is0
.- Returns:
- the number amount of tokens in the bucket
-
initialTokens
Sets the initial number of tokens in the bucket. The value may be negative, in which case the bucket must accumulate a positive number of tokens before they may be consumed.- Parameters:
initialTokens
- the initial number of tokens in the bucket- Returns:
- this
-
maximumTokens
public long maximumTokens()Returns the maximum number of tokens that the bucket may hold before overflowing. The default isLong.MAX_VALUE
.- Returns:
- the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded)
-
maximumTokens
Sets the maximum number of tokens that the bucket may hold before overflowing.- Parameters:
maximumTokens
- the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded)- Returns:
- this
- Throws:
IllegalArgumentException
- ifmaximumTokens
is negative or zero
-
refillSize
public long refillSize()Returns the number of tokens that are refilled at a time.At one end of the spectrum, one may refill tokens one at a time during the
period
. On the other spectrum, one may refilltokensPerPeriod
tokens once perperiod
.NOTE: When completing a
period
a smaller number of tokens may be refilled in order to avoid surpassingtokensPerPeriod
due to rounding errors.The default is
1
.- Returns:
- the minimum number of tokens by which the limit may be refilled
-
refillSize
Sets the number of tokens that are refilled at a time.At one end of the spectrum, one may refill tokens one at a time during the
period
. On the other spectrum, one may refilltokensPerPeriod
tokens once perperiod
.NOTE: When completing a
period
a smaller number of tokens may be refilled in order to avoid surpassingtokensPerPeriod
due to rounding errors.- Parameters:
refillSize
- the minimum number of tokens by which the limit may be refilled- Returns:
- this
- Throws:
IllegalArgumentException
- ifrefillSize
is negative or zero
-
userData
Returns user data associated with this limit. The default isnull
.- Returns:
- the data associated with this limit
-
userData
Sets user data associated with this limit.- Parameters:
userData
- the data associated with this limit- Returns:
- this
-
build
Builds a new Limit.- Returns:
- a new Limit
-
toString
-