public class TokenBucket
extends java.lang.Object
| コンストラクタ | 説明 |
|---|---|
TokenBucket(long capacity,
long initialTokens,
RefillStrategy refillStrategy,
SleepStrategy sleepStrategy) |
| 修飾子とタイプ | メソッド | 説明 |
|---|---|---|
void |
consume() |
Consume a single token from the bucket.
|
void |
consume(long numTokens) |
Consumes multiple tokens from the bucket.
|
long |
getCapacity() |
|
long |
getDurationUntilNextRefill(java.util.concurrent.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() |
|
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.
|
public TokenBucket(long capacity,
long initialTokens,
RefillStrategy refillStrategy,
SleepStrategy sleepStrategy)
public long getCapacity()
public long getNumTokens()
public long getDurationUntilNextRefill(java.util.concurrent.TimeUnit unit)
throws java.lang.UnsupportedOperationException
unit - The time unit to express the return value in.java.lang.UnsupportedOperationExceptionpublic boolean tryConsume()
true is returned, otherwise
false is returned.true if a token was consumed, false otherwise.public 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.public void consume()
public void consume(long numTokens)
numTokens - The number of tokens to consume from teh bucket, must be a positive number.public void refill(long numTokens)
numTokens may be added.numTokens - The number of tokens to add to the bucket.Copyright © 2016–2018. All rights reserved.