public class AsyncBucketProxyAdapter extends Object implements AsyncBucketProxy
Constructor and Description |
---|
AsyncBucketProxyAdapter(Bucket target) |
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. |
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
|
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. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
fromSync, syncImmediately
public AsyncBucketProxyAdapter(Bucket target)
public ScheduledBucket asScheduler()
AsyncBucketProxy
asScheduler
in interface AsyncBucketProxy
public AsyncVerboseBucket asVerbose()
AsyncBucketProxy
asVerbose
in interface AsyncBucketProxy
public CompletableFuture<Boolean> tryConsume(long numTokens)
AsyncBucketProxy
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)
tryConsume
in interface AsyncBucketProxy
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)
public CompletableFuture<Long> consumeIgnoringRateLimits(long tokens)
AsyncBucketProxy
Bucket.consumeIgnoringRateLimits(long)
, follows the same semantic.consumeIgnoringRateLimits
in interface AsyncBucketProxy
Bucket.consumeIgnoringRateLimits(long)
public CompletableFuture<ConsumptionProbe> tryConsumeAndReturnRemaining(long numTokens)
AsyncBucketProxy
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)
tryConsumeAndReturnRemaining
in interface AsyncBucketProxy
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)
public CompletableFuture<EstimationProbe> estimateAbilityToConsume(long numTokens)
AsyncBucketProxy
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)
estimateAbilityToConsume
in interface AsyncBucketProxy
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)
public CompletableFuture<Long> tryConsumeAsMuchAsPossible()
AsyncBucketProxy
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()
tryConsumeAsMuchAsPossible
in interface AsyncBucketProxy
Bucket.tryConsumeAsMuchAsPossible()
public CompletableFuture<Long> tryConsumeAsMuchAsPossible(long limit)
AsyncBucketProxy
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)
tryConsumeAsMuchAsPossible
in interface AsyncBucketProxy
limit
- maximum number of tokens to consume, should be positive.Bucket.tryConsumeAsMuchAsPossible(long)
public CompletableFuture<Void> addTokens(long tokensToAdd)
AsyncBucketProxy
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)
addTokens
in interface AsyncBucketProxy
tokensToAdd
- number of tokens to addBucket.addTokens(long)
public CompletableFuture<Void> replaceConfiguration(BucketConfiguration newConfiguration)
AsyncBucketProxy
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)
replaceConfiguration
in interface AsyncBucketProxy
newConfiguration
- new configurationIncompatibleConfigurationException
if new configuration is incompatible with previous.Bucket.replaceConfiguration(BucketConfiguration)
public CompletableFuture<Long> getAvailableTokens()
AsyncBucketProxy
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.
getAvailableTokens
in interface AsyncBucketProxy
public CompletableFuture<Void> syncByCondition(long unsynchronizedTokens, Duration timeSinceLastSync)
AsyncBucketProxy
syncByCondition
in interface AsyncBucketProxy
public AsyncBucketProxy toListenable(BucketListener listener)
AsyncBucketProxy
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.toListenable
in interface AsyncBucketProxy
listener
- the listener of bucket events.listener
Copyright © 2020. All rights reserved.