public class SimpleBucket extends Object implements RateLimiter
| Constructor and Description |
|---|
SimpleBucket(long capacity,
Duration refillPeriod) |
| Modifier and Type | Method and Description |
|---|---|
long |
delayMillisToConsume(long tokens)
Calculate the time (in milliseconds) a consumer should delay a call to
RateLimiter.tryConsume(int) in order to be
successful. |
boolean |
tryConsume(int numberTokens)
Attempt to consume a given number of permits from this limiter.
|
public SimpleBucket(long capacity,
Duration refillPeriod)
public boolean tryConsume(int numberTokens)
RateLimiter
This method does not block or incur in any waiting step. If no permits are available, this method will simply
return false. To obtain the delay needed to wait in order to consume the next tokens, see
RateLimiter.delayMillisToConsume(long).
tryConsume in interface RateLimiternumberTokens - the permits to consumetrue if it was successful, false otherwisepublic long delayMillisToConsume(long tokens)
RateLimiterRateLimiter.tryConsume(int) in order to be
successful.delayMillisToConsume in interface RateLimitertokens - the number of permits sought to consumetokens amount of permits.