java.lang.Object
com.github.cowwoc.tokenbucket.Limit
A rate limit.
Thread safety: This class is thread-safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Builds a Limit.final class
Updates this Limit's configuration. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns the bucket containing this limit.long
Returns the initial number of tokens that the bucket starts with.long
Returns the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded).indicates how oftentokensPerPeriod
should be added to the bucket.long
Returns the number of tokens that are refilled at a time.long
Returns the number of tokens to add everyperiod
.Returns the data associated with this limit.int
hashCode()
toString()
Updates this Limit's configuration.
-
Method Details
-
getBucket
Returns the bucket containing this limit.- Returns:
- the bucket containing this limit
-
getTokensPerPeriod
public long getTokensPerPeriod()Returns the number of tokens to add everyperiod
.- Returns:
- the number of tokens to add every
period
-
getPeriod
indicates how oftentokensPerPeriod
should be added to the bucket.- Returns:
- indicates how often
tokensPerPeriod
should be added to the bucket
-
getInitialTokens
public long getInitialTokens()Returns the initial number of tokens that the bucket starts with.- Returns:
- the initial number of tokens that the bucket starts with
-
getMaximumTokens
public long getMaximumTokens()Returns the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded).- Returns:
- the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded)
-
getRefillSize
public long getRefillSize()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 refill all tokens at the end of theperiod
.NOTE: When completing a
period
, a smaller number of tokens may be refilled in order to avoid surpassingtokensPerPeriod
due to rounding errors.- Returns:
- the minimum number of tokens by which the limit may be refilled
-
getUserData
Returns the data associated with this limit.- Returns:
- the data associated with this limit
-
updateConfiguration
Updates this Limit's configuration.The
Limit
will be locked untilLimit.ConfigurationUpdater.close()
is invoked, at which point a new period will be started.- Returns:
- the configuration updater
-
hashCode
public int hashCode() -
equals
-
toString
-