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 classBuilds a Limit.final classUpdates this Limit's configuration. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the bucket containing this limit.longReturns the initial number of tokens that the bucket starts with.longReturns the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded).indicates how oftentokensPerPeriodshould be added to the bucket.longReturns the number of tokens that are refilled at a time.longReturns the number of tokens to add everyperiod.Returns the data associated with this limit.inthashCode()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 oftentokensPerPeriodshould be added to the bucket.- Returns:
- indicates how often
tokensPerPeriodshould 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 surpassingtokensPerPerioddue 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
Limitwill 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
-