public interface RateLimiter
| Modifier and Type | Method and Description |
|---|---|
long |
delayMillisToConsume(long tokens)
Calculate the time (in milliseconds) a consumer should delay a call to
tryConsume(int) in order to be
successful. |
boolean |
tryConsume(int numberTokens)
Attempt to consume a given number of permits from this limiter.
|
boolean tryConsume(int numberTokens)
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
delayMillisToConsume(long).
numberTokens - the permits to consumetrue if it was successful, false otherwiselong delayMillisToConsume(long tokens)
tryConsume(int) in order to be
successful.tokens - the number of permits sought to consumetokens amount of permits.