public interface AsyncBucketProxy
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Void> |
addTokens(long tokensToAdd)
Asynchronous version of
Bucket.addTokens(long) , follows the same semantic. |
ScheduledBucket |
asScheduler()
Returns asynchronous view of this bucket that allows to use bucket as async scheduler.
|
AsyncVerboseBucket |
asVerbose()
Returns the verbose view of this bucket.
|
CompletableFuture<Long> |
consumeIgnoringRateLimits(long tokens)
Asynchronous version of
Bucket.consumeIgnoringRateLimits(long) , follows the same semantic. |
CompletableFuture<EstimationProbe> |
estimateAbilityToConsume(long numTokens)
Asynchronous version of
Bucket.estimateAbilityToConsume(long) , follows the same semantic. |
static AsyncBucketProxy |
fromSync(Bucket bucket) |
CompletableFuture<Long> |
getAvailableTokens()
Returns amount of available tokens in this bucket.
|
CompletableFuture<Void> |
replaceConfiguration(BucketConfiguration newConfiguration)
Asynchronous version of
Bucket.replaceConfiguration(BucketConfiguration) , follows the same rules and semantic. |
CompletableFuture<Void> |
syncByCondition(long unsynchronizedTokens,
Duration timeSinceLastSync)
TODO javadocs
|
default CompletableFuture<Void> |
syncImmediately()
TODO javadocs
|
AsyncBucketProxy |
toListenable(BucketListener listener)
Returns new copy of this bucket instance decorated by
listener . |
CompletableFuture<Boolean> |
tryConsume(long numTokens)
Asynchronous version of
Bucket.tryConsume(long) , follows the same semantic. |
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. |
ScheduledBucket asScheduler()
AsyncVerboseBucket asVerbose()
static AsyncBucketProxy fromSync(Bucket bucket)
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<Long> consumeIgnoringRateLimits(long tokens)
Bucket.consumeIgnoringRateLimits(long)
, follows the same semantic.Bucket.consumeIgnoringRateLimits(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<EstimationProbe> estimateAbilityToConsume(long numTokens)
Bucket.estimateAbilityToConsume(long)
, follows the same semantic.
The algorithm for distribute buckets is following:
CompletableFuture.thenApplyAsync(Function, Executor)
.
The algorithm for local buckets is following:
Bucket.estimateAbilityToConsume(long)
numTokens
- The number of tokens to consume from the bucket, must be a positive number.probe
which describes the ability to consume specified amount of tokens.Bucket.estimateAbilityToConsume(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<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)
AsyncBucketProxy toListenable(BucketListener listener)
listener
.
The created bucket will share same tokens with source bucket and vice versa.
See javadocs for BucketListener
in order to understand semantic of listener.listener
- the listener of bucket events.listener
CompletableFuture<Long> getAvailableTokens()
This method designed to be used only for monitoring and testing, you should never use this method for business cases, because available tokens can be changed by concurrent transactions for case of multithreaded/multi-process environment.
default CompletableFuture<Void> syncImmediately()
CompletableFuture<Void> syncByCondition(long unsynchronizedTokens, Duration timeSinceLastSync)
unsynchronizedTokens
- timeSinceLastSync
- Copyright © 2020. All rights reserved.