public class DefaultAsyncBucketProxy extends Object implements AsyncBucketProxy, AsyncOptimizationController, SchedulingBucket
| Constructor and Description |
|---|
DefaultAsyncBucketProxy(AsyncCommandExecutor commandExecutor,
RecoveryStrategy recoveryStrategy,
Supplier<CompletableFuture<BucketConfiguration>> configurationSupplier,
ImplicitConfigurationReplacement implicitConfigurationReplacement) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
addTokens(long tokensToAdd)
Asynchronous version of
Bucket.addTokens(long), follows the same semantic. |
SchedulingBucket |
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<Void> |
consume(long tokensToConsume,
ScheduledExecutorService scheduler)
Consumes the specified number of tokens from the bucket.
|
CompletableFuture<Long> |
consumeIgnoringRateLimits(long tokensToConsume)
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. |
CompletableFuture<Void> |
forceAddTokens(long tokensToAdd)
Asynchronous version of
Bucket.forceAddTokens(long), follows the same semantic. |
CompletableFuture<Long> |
getAvailableTokens()
Returns amount of available tokens in this bucket.
|
AsyncOptimizationController |
getOptimizationController()
Returns optimization controller for this proxy.
|
CompletableFuture<Void> |
replaceConfiguration(BucketConfiguration newConfiguration,
TokensInheritanceStrategy tokensInheritanceStrategy)
Has the same semantic with
Bucket.replaceConfiguration(BucketConfiguration, TokensInheritanceStrategy) |
CompletableFuture<Void> |
reset()
Reset all tokens up to maximum capacity.
|
CompletableFuture<Void> |
syncByCondition(long unsynchronizedTokens,
Duration timeSinceLastSync)
Initiates immediate synchronization of local copy of bucket with remote storage in case of both conditions bellow are
true:
Accumulated amount of locally consumed tokens without external synchronization is greater than or equal to unsynchronizedTokens
Time passed since last synchronization with external storage is greater than or equal to timeSinceLastSync
|
AsyncBucketProxy |
toListenable(BucketListener listener)
Returns new copy of this bucket instance decorated by
listener. |
CompletableFuture<Boolean> |
tryConsume(long tokensToConsume)
Asynchronous version of
Bucket.tryConsume(long), follows the same semantic. |
CompletableFuture<Boolean> |
tryConsume(long tokensToConsume,
long maxWaitTimeNanos,
ScheduledExecutorService scheduler)
Tries to consume the specified number of tokens from the bucket.
|
CompletableFuture<ConsumptionProbe> |
tryConsumeAndReturnRemaining(long tokensToConsume)
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. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsyncImmediatelytryConsumepublic DefaultAsyncBucketProxy(AsyncCommandExecutor commandExecutor, RecoveryStrategy recoveryStrategy, Supplier<CompletableFuture<BucketConfiguration>> configurationSupplier, ImplicitConfigurationReplacement implicitConfigurationReplacement)
public AsyncVerboseBucket asVerbose()
AsyncBucketProxyasVerbose in interface AsyncBucketProxypublic AsyncBucketProxy toListenable(BucketListener listener)
AsyncBucketProxylistener.
The created bucket will share same tokens with source bucket and vice versa.
See javadocs for BucketListener in order to understand semantic of listener.toListenable in interface AsyncBucketProxylistener - the listener of bucket events.listenerpublic SchedulingBucket asScheduler()
AsyncBucketProxyasScheduler in interface AsyncBucketProxypublic CompletableFuture<Long> consumeIgnoringRateLimits(long tokensToConsume)
AsyncBucketProxyBucket.consumeIgnoringRateLimits(long), follows the same semantic.consumeIgnoringRateLimits in interface AsyncBucketProxyBucket.consumeIgnoringRateLimits(long)public CompletableFuture<Boolean> tryConsume(long tokensToConsume)
AsyncBucketProxyBucket.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)tryConsume in interface AsyncBucketProxytokensToConsume - 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)public CompletableFuture<ConsumptionProbe> tryConsumeAndReturnRemaining(long tokensToConsume)
AsyncBucketProxyBucket.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)tryConsumeAndReturnRemaining in interface AsyncBucketProxytokensToConsume - 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)public CompletableFuture<EstimationProbe> estimateAbilityToConsume(long numTokens)
AsyncBucketProxyBucket.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)estimateAbilityToConsume in interface AsyncBucketProxynumTokens - 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)public CompletableFuture<Long> tryConsumeAsMuchAsPossible()
AsyncBucketProxyBucket.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()tryConsumeAsMuchAsPossible in interface AsyncBucketProxyBucket.tryConsumeAsMuchAsPossible()public CompletableFuture<Long> tryConsumeAsMuchAsPossible(long limit)
AsyncBucketProxyBucket.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)tryConsumeAsMuchAsPossible in interface AsyncBucketProxylimit - maximum number of tokens to consume, should be positive.Bucket.tryConsumeAsMuchAsPossible(long)public CompletableFuture<Boolean> tryConsume(long tokensToConsume, long maxWaitTimeNanos, ScheduledExecutorService scheduler)
SchedulingBucketThe 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).tryConsume in interface SchedulingBuckettokensToConsume - The number of tokens to consume from the bucket.maxWaitTimeNanos - limit of time(in nanoseconds) which thread can wait.scheduler - used to delayed future completionpublic CompletableFuture<Void> consume(long tokensToConsume, ScheduledExecutorService scheduler)
SchedulingBucketThe 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).consume in interface SchedulingBuckettokensToConsume - The number of tokens to consume from the bucket.scheduler - used to delayed future completionpublic CompletableFuture<Void> replaceConfiguration(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)
AsyncBucketProxyBucket.replaceConfiguration(BucketConfiguration, TokensInheritanceStrategy)replaceConfiguration in interface AsyncBucketProxypublic CompletableFuture<Void> addTokens(long tokensToAdd)
AsyncBucketProxyBucket.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)addTokens in interface AsyncBucketProxytokensToAdd - number of tokens to addBucket.addTokens(long)public CompletableFuture<Void> forceAddTokens(long tokensToAdd)
AsyncBucketProxyBucket.forceAddTokens(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)forceAddTokens in interface AsyncBucketProxytokensToAdd - number of tokens to addBucket.addTokens(long)public CompletableFuture<Void> reset()
AsyncBucketProxyreset in interface AsyncBucketProxypublic CompletableFuture<Long> getAvailableTokens()
AsyncBucketProxyThis 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.
getAvailableTokens in interface AsyncBucketProxypublic AsyncOptimizationController getOptimizationController()
AsyncBucketProxy
This method is actual only if an optimization was applied during bucket construction via RemoteAsyncBucketBuilder.withOptimization(Optimization)
otherwise returned controller will do nothing.
getOptimizationController in interface AsyncBucketProxypublic CompletableFuture<Void> syncByCondition(long unsynchronizedTokens, Duration timeSinceLastSync)
AsyncOptimizationControllertrue:
unsynchronizedTokenstimeSinceLastSyncsyncByCondition in interface AsyncOptimizationControllerunsynchronizedTokens - criterion for accumulated amount of unsynchronized tokenstimeSinceLastSync - criterion for time passed since last synchronizationCopyright © 2022. All rights reserved.