public class SynchronizedBucket extends AbstractBucket implements LocalBucket
INFINITY_DURATION
Constructor and Description |
---|
SynchronizedBucket(BucketConfiguration configuration,
TimeMeter timeMeter) |
addTokens, asAsync, asAsyncScheduler, asScheduler, asVerbose, consume, consumeIgnoringRateLimits, consumeUninterruptibly, estimateAbilityToConsume, forceAddTokens, replaceConfiguration, tryConsume, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossible, tryConsumeUninterruptibly
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addTokens, asAsync, asAsyncScheduler, asScheduler, asVerbose, consumeIgnoringRateLimits, estimateAbilityToConsume, forceAddTokens, replaceConfiguration, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossible
consume, consumeUninterruptibly, tryConsume, tryConsume, tryConsume, tryConsumeUninterruptibly, tryConsumeUninterruptibly, tryConsumeUninterruptibly
public SynchronizedBucket(BucketConfiguration configuration, TimeMeter timeMeter)
public Bucket toListenable(BucketListener listener)
Bucket
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 Bucket
listener
- the listener of bucket events.listener
public boolean isAsyncModeSupported()
Bucket
If asynchronous mode is not supported any attempt to call Bucket.asAsync()
will fail with UnsupportedOperationException
isAsyncModeSupported
in interface Bucket
protected long consumeAsMuchAsPossibleImpl(long limit)
consumeAsMuchAsPossibleImpl
in class AbstractBucket
protected boolean tryConsumeImpl(long tokensToConsume)
tryConsumeImpl
in class AbstractBucket
protected ConsumptionProbe tryConsumeAndReturnRemainingTokensImpl(long tokensToConsume)
tryConsumeAndReturnRemainingTokensImpl
in class AbstractBucket
protected EstimationProbe estimateAbilityToConsumeImpl(long tokensToEstimate)
estimateAbilityToConsumeImpl
in class AbstractBucket
protected long reserveAndCalculateTimeToSleepImpl(long tokensToConsume, long waitIfBusyNanosLimit)
reserveAndCalculateTimeToSleepImpl
in class AbstractBucket
protected long consumeIgnoringRateLimitsImpl(long tokensToConsume)
consumeIgnoringRateLimitsImpl
in class AbstractBucket
protected VerboseResult<Long> consumeAsMuchAsPossibleVerboseImpl(long limit)
consumeAsMuchAsPossibleVerboseImpl
in class AbstractBucket
protected VerboseResult<Boolean> tryConsumeVerboseImpl(long tokensToConsume)
tryConsumeVerboseImpl
in class AbstractBucket
protected VerboseResult<ConsumptionProbe> tryConsumeAndReturnRemainingTokensVerboseImpl(long tokensToConsume)
tryConsumeAndReturnRemainingTokensVerboseImpl
in class AbstractBucket
protected VerboseResult<EstimationProbe> estimateAbilityToConsumeVerboseImpl(long tokensToEstimate)
estimateAbilityToConsumeVerboseImpl
in class AbstractBucket
protected VerboseResult<Long> getAvailableTokensVerboseImpl()
getAvailableTokensVerboseImpl
in class AbstractBucket
protected VerboseResult<Nothing> addTokensVerboseImpl(long tokensToAdd)
addTokensVerboseImpl
in class AbstractBucket
protected VerboseResult<Nothing> forceAddTokensVerboseImpl(long tokensToAdd)
forceAddTokensVerboseImpl
in class AbstractBucket
protected VerboseResult<Nothing> replaceConfigurationVerboseImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)
replaceConfigurationVerboseImpl
in class AbstractBucket
protected VerboseResult<Long> consumeIgnoringRateLimitsVerboseImpl(long tokensToConsume)
consumeIgnoringRateLimitsVerboseImpl
in class AbstractBucket
protected void addTokensImpl(long tokensToAdd)
addTokensImpl
in class AbstractBucket
protected void forceAddTokensImpl(long tokensToAdd)
forceAddTokensImpl
in class AbstractBucket
public long getAvailableTokens()
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.
getAvailableTokens
in interface Bucket
protected void replaceConfigurationImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)
replaceConfigurationImpl
in class AbstractBucket
protected CompletableFuture<Boolean> tryConsumeAsyncImpl(long tokensToConsume)
tryConsumeAsyncImpl
in class AbstractBucket
protected CompletableFuture<Void> addTokensAsyncImpl(long tokensToAdd)
addTokensAsyncImpl
in class AbstractBucket
protected CompletableFuture<Void> forceAddTokensAsyncImpl(long tokensToAdd)
forceAddTokensAsyncImpl
in class AbstractBucket
protected CompletableFuture<ConsumptionProbe> tryConsumeAndReturnRemainingTokensAsyncImpl(long tokensToConsume)
tryConsumeAndReturnRemainingTokensAsyncImpl
in class AbstractBucket
protected CompletableFuture<EstimationProbe> estimateAbilityToConsumeAsyncImpl(long tokensToEstimate)
estimateAbilityToConsumeAsyncImpl
in class AbstractBucket
protected CompletableFuture<Long> tryConsumeAsMuchAsPossibleAsyncImpl(long limit)
tryConsumeAsMuchAsPossibleAsyncImpl
in class AbstractBucket
protected CompletableFuture<Long> reserveAndCalculateTimeToSleepAsyncImpl(long tokensToConsume, long maxWaitTimeNanos)
reserveAndCalculateTimeToSleepAsyncImpl
in class AbstractBucket
protected CompletableFuture<Nothing> replaceConfigurationAsyncImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)
replaceConfigurationAsyncImpl
in class AbstractBucket
protected CompletableFuture<Long> consumeIgnoringRateLimitsAsyncImpl(long tokensToConsume)
consumeIgnoringRateLimitsAsyncImpl
in class AbstractBucket
protected CompletableFuture<VerboseResult<Long>> tryConsumeAsMuchAsPossibleVerboseAsyncImpl(long limit)
tryConsumeAsMuchAsPossibleVerboseAsyncImpl
in class AbstractBucket
protected CompletableFuture<VerboseResult<Boolean>> tryConsumeVerboseAsyncImpl(long tokensToConsume)
tryConsumeVerboseAsyncImpl
in class AbstractBucket
protected CompletableFuture<VerboseResult<ConsumptionProbe>> tryConsumeAndReturnRemainingTokensVerboseAsyncImpl(long tokensToConsume)
tryConsumeAndReturnRemainingTokensVerboseAsyncImpl
in class AbstractBucket
protected CompletableFuture<VerboseResult<EstimationProbe>> estimateAbilityToConsumeVerboseAsyncImpl(long tokensToEstimate)
estimateAbilityToConsumeVerboseAsyncImpl
in class AbstractBucket
protected CompletableFuture<VerboseResult<Nothing>> addTokensVerboseAsyncImpl(long tokensToAdd)
addTokensVerboseAsyncImpl
in class AbstractBucket
protected CompletableFuture<VerboseResult<Nothing>> forceAddTokensVerboseAsyncImpl(long tokensToAdd)
forceAddTokensVerboseAsyncImpl
in class AbstractBucket
protected CompletableFuture<VerboseResult<Nothing>> replaceConfigurationVerboseAsyncImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)
replaceConfigurationVerboseAsyncImpl
in class AbstractBucket
protected CompletableFuture<VerboseResult<Long>> consumeIgnoringRateLimitsVerboseAsyncImpl(long tokensToConsume)
consumeIgnoringRateLimitsVerboseAsyncImpl
in class AbstractBucket
public BucketState createSnapshot()
Bucket
This method is designed to be used only for monitoring and testing, you should never use this method for business cases.
createSnapshot
in interface Bucket
public BucketConfiguration getConfiguration()
LocalBucket
getConfiguration
in interface LocalBucket
Copyright © 2021. All rights reserved.