-
- All Known Implementing Classes:
AsyncBucketProxyAdapter,DefaultAsyncBucketProxy
public interface AsyncBucketProxyAsynchronous analog ofBucketProxy.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CompletableFuture<Void>addTokens(long tokensToAdd)Asynchronous version ofBucket.addTokens(long), follows the same semantic.SchedulingBucketasScheduler()Returns asynchronous view of this bucket that allows to use bucket as async scheduler.AsyncVerboseBucketasVerbose()Returns the verbose view of this bucket.CompletableFuture<Long>consumeIgnoringRateLimits(long tokens)Asynchronous version ofBucket.consumeIgnoringRateLimits(long), follows the same semantic.CompletableFuture<EstimationProbe>estimateAbilityToConsume(long numTokens)Asynchronous version ofBucket.estimateAbilityToConsume(long), follows the same semantic.CompletableFuture<Void>forceAddTokens(long tokensToAdd)Asynchronous version ofBucket.forceAddTokens(long), follows the same semantic.CompletableFuture<Long>getAvailableTokens()Returns amount of available tokens in this bucket.AsyncOptimizationControllergetOptimizationController()Returns optimization controller for this proxy.CompletableFuture<Void>replaceConfiguration(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)Has the same semantic withBucket.replaceConfiguration(BucketConfiguration, TokensInheritanceStrategy)CompletableFuture<Void>reset()Reset all tokens up to maximum capacity.AsyncBucketProxytoListenable(BucketListener listener)Returns new copy of this bucket instance decorated bylistener.CompletableFuture<Boolean>tryConsume(long numTokens)Asynchronous version ofBucket.tryConsume(long), follows the same semantic.CompletableFuture<ConsumptionProbe>tryConsumeAndReturnRemaining(long numTokens)Asynchronous version ofBucket.tryConsumeAndReturnRemaining(long), follows the same semantic.CompletableFuture<Long>tryConsumeAsMuchAsPossible()Asynchronous version ofBucket.tryConsumeAsMuchAsPossible(), follows the same semantic.CompletableFuture<Long>tryConsumeAsMuchAsPossible(long limit)Asynchronous version ofBucket.tryConsumeAsMuchAsPossible(long), follows the same semantic.
-
-
-
Method Detail
-
asScheduler
SchedulingBucket asScheduler()
Returns asynchronous view of this bucket that allows to use bucket as async scheduler.- Returns:
- Asynchronous view of this bucket that allows to use bucket as async scheduler.
-
asVerbose
AsyncVerboseBucket asVerbose()
Returns the verbose view of this bucket.
-
tryConsume
CompletableFuture<Boolean> tryConsume(long numTokens)
Asynchronous version ofBucket.tryConsume(long), follows the same semantic.The algorithm for distribute buckets is following:
- Implementation issues asynchronous request to back-end behind the bucket in way which specific for each particular back-end.
- Then uncompleted future returned to the caller.
- When back-end provides signal(through callback) that request is done, then future completed.
- If back-end provides signal(through callback) that asynchronous request failed, then future completed exceptionally.
CompletableFuture.thenApplyAsync(Function, Executor).The algorithm for local buckets is following:
- Implementation just redirects request to synchronous version
Bucket.tryConsume(long) - Then returns feature immediately completed by results from previous step. So using this method for local buckets is useless, because there are no differences with synchronous version.
- Parameters:
numTokens- The number of tokens to consume from the bucket, must be a positive number.- Returns:
- the future which eventually will be completed by
trueif the numTokens were consumed and completed byfalseotherwise. - See Also:
Bucket.tryConsume(long)
-
consumeIgnoringRateLimits
CompletableFuture<Long> consumeIgnoringRateLimits(long tokens)
Asynchronous version ofBucket.consumeIgnoringRateLimits(long), follows the same semantic.- See Also:
Bucket.consumeIgnoringRateLimits(long)
-
tryConsumeAndReturnRemaining
CompletableFuture<ConsumptionProbe> tryConsumeAndReturnRemaining(long numTokens)
Asynchronous version ofBucket.tryConsumeAndReturnRemaining(long), follows the same semantic.The algorithm for distribute buckets is following:
- Implementation issues asynchronous request to back-end behind the bucket in way which specific for each particular back-end.
- Then uncompleted future returned to the caller.
- When back-end provides signal(through callback) that request is done, then future completed.
- If back-end provides signal(through callback) that asynchronous request failed, then future completed exceptionally.
CompletableFuture.thenApplyAsync(Function, Executor).The algorithm for local buckets is following:
- Implementation just redirects request to synchronous version
Bucket.tryConsumeAndReturnRemaining(long) - Then returns feature immediately completed by results from previous step. So using this method for local buckets is useless, because there are no differences with synchronous version.
- Parameters:
numTokens- The number of tokens to consume from the bucket, must be a positive number.- Returns:
- the future which eventually will be completed by
probewhich describes both result of consumption and tokens remaining in the bucket after consumption. - See Also:
Bucket.tryConsumeAndReturnRemaining(long)
-
estimateAbilityToConsume
CompletableFuture<EstimationProbe> estimateAbilityToConsume(long numTokens)
Asynchronous version ofBucket.estimateAbilityToConsume(long), follows the same semantic.The algorithm for distribute buckets is following:
- Implementation issues asynchronous request to back-end behind the bucket in way which specific for each particular back-end.
- Then uncompleted future returned to the caller.
- When back-end provides signal(through callback) that request is done, then future completed.
- If back-end provides signal(through callback) that asynchronous request failed, then future completed exceptionally.
CompletableFuture.thenApplyAsync(Function, Executor).The algorithm for local buckets is following:
- Implementation just redirects request to synchronous version
Bucket.estimateAbilityToConsume(long) - Then returns feature immediately completed by results from previous step. So using this method for local buckets is useless, because there are no differences with synchronous version.
- Parameters:
numTokens- The number of tokens to consume from the bucket, must be a positive number.- Returns:
- the future which eventually will be completed by
probewhich describes the ability to consume specified amount of tokens. - See Also:
Bucket.estimateAbilityToConsume(long)
-
tryConsumeAsMuchAsPossible
CompletableFuture<Long> tryConsumeAsMuchAsPossible()
Asynchronous version ofBucket.tryConsumeAsMuchAsPossible(), follows the same semantic.The algorithm for distribute buckets is following:
- Implementation issues asynchronous request to back-end behind the bucket in way which specific for each particular back-end.
- Then uncompleted future returned to the caller.
- When back-end provides signal(through callback) that request is done, then future completed.
- If back-end provides signal(through callback) that asynchronous request failed, then future completed exceptionally.
CompletableFuture.thenApplyAsync(Function, Executor).The algorithm for local buckets is following:
- Implementation just redirects request to synchronous version
Bucket.tryConsumeAsMuchAsPossible() - Then returns feature immediately completed by results from previous step. So using this method for local buckets is useless, because there are no differences with synchronous version.
- Returns:
- the future which eventually will be completed by number of tokens which has been consumed, or completed by zero if was consumed nothing.
- See Also:
Bucket.tryConsumeAsMuchAsPossible()
-
tryConsumeAsMuchAsPossible
CompletableFuture<Long> tryConsumeAsMuchAsPossible(long limit)
Asynchronous version ofBucket.tryConsumeAsMuchAsPossible(long), follows the same semantic.The algorithm for distribute buckets is following:
- Implementation issues asynchronous request to back-end behind the bucket in way which specific for each particular back-end.
- Then uncompleted future returned to the caller.
- When back-end provides signal(through callback) that request is done, then future completed.
- If back-end provides signal(through callback) that asynchronous request failed, then future completed exceptionally.
CompletableFuture.thenApplyAsync(Function, Executor).The algorithm for local buckets is following:
- Implementation just redirects request to synchronous version
Bucket.tryConsumeAsMuchAsPossible(long) - Then returns feature immediately completed by results from previous step. So using this method for local buckets is useless, because there are no differences with synchronous version.
- Parameters:
limit- maximum number of tokens to consume, should be positive.- Returns:
- the future which eventually will be completed by number of tokens which has been consumed, or completed by zero if was consumed nothing.
- See Also:
Bucket.tryConsumeAsMuchAsPossible(long)
-
addTokens
CompletableFuture<Void> addTokens(long tokensToAdd)
Asynchronous version ofBucket.addTokens(long), follows the same semantic.The algorithm for distribute buckets is following:
- Implementation issues asynchronous request to back-end behind the bucket in way which specific for each particular back-end.
- Then uncompleted future returned to the caller.
- When back-end provides signal(through callback) that request is done, then future completed.
- If back-end provides signal(through callback) that asynchronous request failed, then future completed exceptionally.
CompletableFuture.thenApplyAsync(Function, Executor).The algorithm for local buckets is following:
- Implementation just redirects request to synchronous version
Bucket.addTokens(long) - Then returns feature immediately completed by results from previous step. So using this method for local buckets is useless, because there are no differences with synchronous version.
- Parameters:
tokensToAdd- number of tokens to add- Returns:
- the future which eventually will be completed by null if operation successfully completed without exception, otherwise(if any exception happen in asynchronous flow) the future will be completed exceptionally.
- See Also:
Bucket.addTokens(long)
-
forceAddTokens
CompletableFuture<Void> forceAddTokens(long tokensToAdd)
Asynchronous version ofBucket.forceAddTokens(long), follows the same semantic.The algorithm for distribute buckets is following:
- Implementation issues asynchronous request to back-end behind the bucket in way which specific for each particular back-end.
- Then uncompleted future returned to the caller.
- When back-end provides signal(through callback) that request is done, then future completed.
- If back-end provides signal(through callback) that asynchronous request failed, then future completed exceptionally.
CompletableFuture.thenApplyAsync(Function, Executor).The algorithm for local buckets is following:
- Implementation just redirects request to synchronous version
Bucket.addTokens(long) - Then returns feature immediately completed by results from previous step. So using this method for local buckets is useless, because there are no differences with synchronous version.
- Parameters:
tokensToAdd- number of tokens to add- Returns:
- the future which eventually will be completed by null if operation successfully completed without exception, otherwise(if any exception happen in asynchronous flow) the future will be completed exceptionally.
- See Also:
Bucket.addTokens(long)
-
reset
CompletableFuture<Void> reset()
Reset all tokens up to maximum capacity.
-
replaceConfiguration
CompletableFuture<Void> replaceConfiguration(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)
Has the same semantic withBucket.replaceConfiguration(BucketConfiguration, TokensInheritanceStrategy)
-
toListenable
AsyncBucketProxy toListenable(BucketListener listener)
Returns new copy of this bucket instance decorated bylistener. The created bucket will share same tokens with source bucket and vice versa. See javadocs forBucketListenerin order to understand semantic of listener.- Parameters:
listener- the listener of bucket events.- Returns:
- new bucket instance decorated by
listener
-
getAvailableTokens
CompletableFuture<Long> getAvailableTokens()
Returns amount of available tokens in this bucket.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.
- Returns:
- amount of available tokens
-
getOptimizationController
AsyncOptimizationController getOptimizationController()
Returns optimization controller for this proxy.This method is actual only if an optimization was applied during bucket construction via
RemoteAsyncBucketBuilder.withOptimization(Optimization)otherwise returned controller will do nothing.- Returns:
- optimization controller for this proxy
-
-