public class TokenBucket
extends java.lang.Object
tryAcquire() method.| Modifier and Type | Class and Description |
|---|---|
static class |
TokenBucket.Builder
This class is a builder for
TokenBuckets. |
| Modifier and Type | Field and Description |
|---|---|
static java.time.Duration |
DEFAULT_ACQUIRE_INTEVAL |
static int |
DEFAULT_CAPACITY |
static java.time.Duration |
DEFAULT_INCREMENT_INTERVAL |
static int |
DEFAULT_INITIAL_COUNT |
| Modifier | Constructor and Description |
|---|---|
protected |
TokenBucket(int initial,
int capacity,
java.time.Duration incrementInterval,
java.time.Duration acquireInterval)
A TokenBucket acts as a rate limiting helper.
|
| Modifier and Type | Method and Description |
|---|---|
static TokenBucket.Builder |
newBuilder() |
protected long |
now() |
TokenBucket.Builder |
toBuilder() |
boolean |
tryAcquire()
This method returns true if a rate-limited action should be executed, and false if the action should not occur.
|
public static final int DEFAULT_CAPACITY
public static final int DEFAULT_INITIAL_COUNT
public static final java.time.Duration DEFAULT_ACQUIRE_INTEVAL
public static final java.time.Duration DEFAULT_INCREMENT_INTERVAL
protected TokenBucket(int initial,
int capacity,
java.time.Duration incrementInterval,
java.time.Duration acquireInterval)
tryAcquire() method.initial - The initial number of tokens availablecapacity - The maximum number of tokens the bucket may holdincrementInterval - The interval between adding new tokens to the bucketacquireInterval - The minimum interval between allowing tokens to be acquiredpublic static TokenBucket.Builder newBuilder()
public TokenBucket.Builder toBuilder()
public boolean tryAcquire()
protected long now()