public interface TokenBucket
| Modifier and Type | Interface and Description |
|---|---|
static interface |
TokenBucket.RefillStrategy
Encapsulation of a refilling strategy for a token bucket.
|
static interface |
TokenBucket.SleepStrategy
Encapsulation of a strategy for relinquishing control of the CPU.
|
| Modifier and Type | Method and Description |
|---|---|
void |
consume()
Consume a single token from the bucket.
|
void |
consume(long numTokens)
Consumes multiple tokens from the bucket.
|
long |
getCapacity()
Returns the capacity of this token bucket.
|
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 |
getNumTokens()
Returns the current number of tokens in the bucket.
|
void |
refill(long numTokens)
Refills the bucket with the specified number of tokens.
|
boolean |
tryConsume()
Attempt to consume a single token from the bucket.
|
boolean |
tryConsume(long numTokens)
Attempt to consume a specified number of tokens from the bucket.
|
long getCapacity()
long getNumTokens()
long getDurationUntilNextRefill(TimeUnit unit) throws UnsupportedOperationException
unit - The time unit to express the return value in.UnsupportedOperationExceptionTokenBucket.RefillStrategy.getDurationUntilNextRefill(java.util.concurrent.TimeUnit)boolean tryConsume()
true is returned, otherwise
false is returned.true if a token was consumed, false otherwise.boolean tryConsume(long numTokens)
true
is returned, otherwise false is returned.numTokens - The number of tokens to consume from the bucket, must be a positive number.true if the tokens were consumed, false otherwise.void consume()
void consume(long numTokens)
numTokens - The number of tokens to consume from teh bucket, must be a positive number.void refill(long numTokens)
numTokens may be added.numTokens - The number of tokens to add to the bucket.Copyright © 2015. All Rights Reserved.