Package com.github.cowwoc.tokenbucket
Class Limit.ConfigurationUpdater
java.lang.Object
com.github.cowwoc.tokenbucket.Limit.ConfigurationUpdater
- All Implemented Interfaces:
 AutoCloseable
- Enclosing class:
 - Limit
 
Updates this Limit's configuration.
 
Thread-safety: This class is not thread-safe.
- 
Method Summary
Modifier and TypeMethodDescriptionlongReturns the number of available tokens.availableTokens(long availableTokens) Sets the number of available tokens.voidclose()Updates this Limit's configuration and releases its lock.longReturns 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 oftentokensPerPeriodshould be added to the bucket.Indicates how oftentokensPerPeriodshould be added to the bucket.longReturns the number of tokens that are refilled at a time.refillSize(long refillSize) Sets the number of tokens that are refilled at a time.longReturns 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 the data associated with this limit.Sets the data associated with this limit. 
- 
Method Details
- 
tokensPerPeriod
public long tokensPerPeriod()Returns the number of tokens to add to the bucket everyperiod.- Returns:
 - the number of tokens to add to the bucket every 
period - Throws:
 IllegalStateException- if the updater is closed
 - 
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- iftokensPerPeriodis negative or zeroIllegalStateException- if the updater is closed
 - 
period
Indicates how oftentokensPerPeriodshould be added to the bucket.- Returns:
 - how often 
tokensPerPeriodshould be added to the bucket - Throws:
 IllegalStateException- if the updater is closed
 - 
period
Indicates how oftentokensPerPeriodshould be added to the bucket.- Parameters:
 period- indicates how oftentokensPerPeriodshould be added to the bucket- Returns:
 - this
 - Throws:
 NullPointerException- ifperiodis nullIllegalStateException- if the updater is closed
 - 
availableTokens
public long availableTokens()Returns the number of available tokens. The value may be negative, in which case the bucket must accumulate a positive number of tokens before they may be consumed.- Returns:
 - the number of available tokens
 - Throws:
 IllegalStateException- if the updater is closed
 - 
availableTokens
Sets the number of available tokens. The value may be negative, in which case the bucket must accumulate a positive number of tokens before they may be consumed.- Parameters:
 availableTokens- the number of available tokens- Returns:
 - this
 - Throws:
 IllegalStateException- if the updater is closed
 - 
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 refilltokensPerPeriodtokens once perperiod.NOTE: When completing a
perioda 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
 - Throws:
 IllegalStateException- if the updater is closed
 - 
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 refilltokensPerPeriodtokens once perperiod.NOTE: When completing a
perioda smaller number of tokens may be refilled in order to avoid surpassingtokensPerPerioddue to rounding errors.- Parameters:
 refillSize- the minimum number of tokens by which the limit may be refilled- Returns:
 - this
 - Throws:
 IllegalArgumentException- ifrefillSizeis negative or zeroIllegalStateException- if the updater is closed
 - 
maximumTokens
public long maximumTokens()Returns the maximum number of tokens that the bucket may hold before overflowing.- Returns:
 - the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded)
 - Throws:
 IllegalStateException- if the updater is closed
 - 
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- ifmaximumTokensis negative or zeroIllegalStateException- if the updater is closed
 - 
userData
Returns the data associated with this limit.- Returns:
 - the data associated with this limit
 - Throws:
 IllegalStateException- if the updater is closed
 - 
userData
Sets the data associated with this limit.- Parameters:
 userData- the data associated with this limit- Returns:
 - this
 - Throws:
 IllegalStateException- if the updater is closed
 - 
close
public void close()Updates this Limit's configuration and releases its lock.A new period is started immediately after the update takes place.
- Specified by:
 closein interfaceAutoCloseable
 - 
toString
 
 -