public interface AsyncBucket
Extension
behind the bucket provides asynchronous mode.
A special notes about local buckets: Majority of methods(excepting tryConsume(long, long, ScheduledExecutorService)
)
from interface AsyncBucket
are useless for local buckets,
because local bucket does not communicate with external back-ends, as result any thread is never blocked,
thus for local buckets only conditional consuming with timed limit
) is the legal use case of asynchronous API.
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Void> |
addTokens(long tokensToAdd)
Asynchronous version of
Bucket.addTokens(long) , follows the same semantic. |
CompletableFuture<Void> |
replaceConfiguration(BucketConfiguration newConfiguration)
Asynchronous version of
Bucket.replaceConfiguration(BucketConfiguration) , follows the same rules and semantic. |
CompletableFuture<Boolean> |
tryConsume(long numTokens)
Asynchronous version of
Bucket.tryConsume(long) , follows the same semantic. |
CompletableFuture<Boolean> |
tryConsume(long numTokens,
long maxWaitNanos,
ScheduledExecutorService scheduler)
Tries to consume the specified number of tokens from the bucket.
|
CompletableFuture<ConsumptionProbe> |
tryConsumeAndReturnRemaining(long numTokens)
Asynchronous version of
Bucket.tryConsumeAndReturnRemaining(long) , follows the same semantic. |
CompletableFuture<Long> |
tryConsumeAsMuchAsPossible()
Asynchronous version of
Bucket.tryConsumeAsMuchAsPossible() , follows the same semantic. |
CompletableFuture<Long> |
tryConsumeAsMuchAsPossible(long limit)
Asynchronous version of
Bucket.tryConsumeAsMuchAsPossible(long) , follows the same semantic. |
CompletableFuture<Boolean> tryConsume(long numTokens)
Bucket.tryConsume(long)
, follows the same semantic.
The algorithm for distribute buckets is following:
CompletableFuture.thenApplyAsync(Function, Executor)
.
The algorithm for local buckets is following:
Bucket.tryConsume(long)
numTokens
- The number of tokens to consume from the bucket, must be a positive number.true
if the numTokens were consumed and completed by false
otherwise.Bucket.tryConsume(long)
CompletableFuture<ConsumptionProbe> tryConsumeAndReturnRemaining(long numTokens)
Bucket.tryConsumeAndReturnRemaining(long)
, follows the same semantic.
The algorithm for distribute buckets is following:
CompletableFuture.thenApplyAsync(Function, Executor)
.
The algorithm for local buckets is following:
Bucket.tryConsumeAndReturnRemaining(long)
numTokens
- The number of tokens to consume from the bucket, must be a positive number.probe
which describes both result of consumption and tokens remaining in the bucket after consumption.Bucket.tryConsumeAndReturnRemaining(long)
CompletableFuture<Long> tryConsumeAsMuchAsPossible()
Bucket.tryConsumeAsMuchAsPossible()
, follows the same semantic.
The algorithm for distribute buckets is following:
CompletableFuture.thenApplyAsync(Function, Executor)
.
The algorithm for local buckets is following:
Bucket.tryConsumeAsMuchAsPossible()
Bucket.tryConsumeAsMuchAsPossible()
CompletableFuture<Long> tryConsumeAsMuchAsPossible(long limit)
Bucket.tryConsumeAsMuchAsPossible(long)
, follows the same semantic.
The algorithm for distribute buckets is following:
CompletableFuture.thenApplyAsync(Function, Executor)
.
The algorithm for local buckets is following:
Bucket.tryConsumeAsMuchAsPossible(long)
limit
- maximum number of tokens to consume, should be positive.Bucket.tryConsumeAsMuchAsPossible(long)
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
has been consumed or false when numTokens
has not been consumedCompletableFuture<Void> addTokens(long tokensToAdd)
Bucket.addTokens(long)
, follows the same semantic.
The algorithm for distribute buckets is following:
CompletableFuture.thenApplyAsync(Function, Executor)
.
The algorithm for local buckets is following:
Bucket.addTokens(long)
tokensToAdd
- number of tokens to addBucket.addTokens(long)
CompletableFuture<Void> replaceConfiguration(BucketConfiguration newConfiguration)
Bucket.replaceConfiguration(BucketConfiguration)
, follows the same rules and semantic.
The algorithm for distribute buckets is following:
CompletableFuture.thenApplyAsync(Function, Executor)
.
The algorithm for local buckets is following:
Bucket.replaceConfiguration(BucketConfiguration)
newConfiguration
- new configurationIncompatibleConfigurationException
if new configuration is incompatible with previous.Bucket.replaceConfiguration(BucketConfiguration)
Copyright © 2018. All rights reserved.