public class TokenBucket extends Object
Constructor and Description |
---|
TokenBucket(int maxCapacity)
Create a bucket containing the specified number of tokens.
|
Modifier and Type | Method and Description |
---|---|
int |
currentCapacity()
Retrieve a snapshot of the current number of tokens in the bucket.
|
boolean |
equals(Object o) |
int |
hashCode() |
int |
maxCapacity()
Retrieve the maximum capacity of the bucket configured when the bucket was created.
|
void |
release(int amountToRelease)
Release a certain number of tokens back to this bucket.
|
Optional<TokenBucketRetryCondition.Capacity> |
tryAcquire(int amountToAcquire)
Try to acquire a certain number of tokens from this bucket.
|
public TokenBucket(int maxCapacity)
public Optional<TokenBucketRetryCondition.Capacity> tryAcquire(int amountToAcquire)
Optional.empty()
is returned.public void release(int amountToRelease)
public int currentCapacity()
TokenBucketRetryCondition.Capacity.capacityRemaining()
returned by the tryAcquire(int)
method whenever
possible.public int maxCapacity()
Copyright © 2022. All rights reserved.