public interface AsyncScheduledBucket
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Void> |
consume(long numTokens,
ScheduledExecutorService scheduler)
Consumes the specified number of tokens from the bucket.
|
default CompletableFuture<Boolean> |
tryConsume(long numTokens,
Duration maxWait,
ScheduledExecutorService scheduler)
This is just overloaded equivalent of
tryConsume(long, long, ScheduledExecutorService) |
CompletableFuture<Boolean> |
tryConsume(long numTokens,
long maxWaitNanos,
ScheduledExecutorService scheduler)
Tries to consume the specified number of tokens from the bucket.
|
CompletableFuture<Boolean> tryConsume(long numTokens, long maxWaitNanos, ScheduledExecutorService scheduler)
The algorithm for all type of buckets is following:
ScheduledExecutorService.schedule(Runnable, long, TimeUnit)
,
when delay equals to time required to refill the deficit of tokens. After scheduler executes task the future completed by true.
CompletableFuture.thenApplyAsync(Function, Executor)
.numTokens
- The number of tokens to consume from the bucket.maxWaitNanos
- limit of time(in nanoseconds) which thread can wait.scheduler
- used to delayed future completiondefault CompletableFuture<Boolean> tryConsume(long numTokens, Duration maxWait, ScheduledExecutorService scheduler)
tryConsume(long, long, ScheduledExecutorService)
numTokens
- The number of tokens to consume from the bucket.maxWait
- limit of time which thread can wait.scheduler
- used to delayed future completiontryConsume(long, long, ScheduledExecutorService)
CompletableFuture<Void> consume(long numTokens, ScheduledExecutorService scheduler)
The algorithm for all type of buckets is following:
ScheduledExecutorService.schedule(Runnable, long, TimeUnit)
,
when delay equals to time required to refill the deficit of tokens. After scheduler executes task the future completed.
CompletableFuture.thenApplyAsync(Function, Executor)
.numTokens
- The number of tokens to consume from the bucket.scheduler
- used to delayed future completionCopyright © 2021. All rights reserved.