public class FixedIntervalRefillStrategy extends Object implements TokenBucket.RefillStrategy
| Constructor and Description |
|---|
FixedIntervalRefillStrategy(com.google.common.base.Ticker ticker,
long numTokensPerPeriod,
long period,
TimeUnit unit)
Create a FixedIntervalRefillStrategy.
|
| Modifier and Type | Method and Description |
|---|---|
long |
getDurationUntilNextRefill(TimeUnit unit)
Returns the amount of time in the specified time unit until the next group of tokens can be added to the token
bucket.
|
long |
refill()
Returns the number of tokens to add to the token bucket.
|
public FixedIntervalRefillStrategy(com.google.common.base.Ticker ticker,
long numTokensPerPeriod,
long period,
TimeUnit unit)
ticker - A ticker to use to measure time.numTokensPerPeriod - The number of tokens to add to the bucket every period.period - How often to refill the bucket.unit - Unit for period.public long refill()
TokenBucket.RefillStrategyrefill in interface TokenBucket.RefillStrategypublic long getDurationUntilNextRefill(TimeUnit unit)
TokenBucket.RefillStrategySleepStrategy used by the token bucket, tokens may not actually
be added until much after the returned duration. If for some reason the implementation of
RefillStrategy doesn't support knowing when the next batch of tokens will be added, then an
UnsupportedOperationException may be thrown. Lastly, if the duration until the next time tokens will
be added to the token bucket is less than a single unit of the passed in time unit then this method will
return 0.getDurationUntilNextRefill in interface TokenBucket.RefillStrategyunit - The time unit to express the return value in.Copyright © 2015. All Rights Reserved.