Module io.github.bucket4j.core
Class DefaultBucketProxy
- java.lang.Object
-
- io.github.bucket4j.AbstractBucket
-
- io.github.bucket4j.distributed.proxy.DefaultBucketProxy
-
- All Implemented Interfaces:
BlockingBucket,Bucket,BucketProxy,OptimizationController,SchedulingBucket
public class DefaultBucketProxy extends AbstractBucket implements BucketProxy, OptimizationController
-
-
Field Summary
-
Fields inherited from class io.github.bucket4j.AbstractBucket
INFINITY_DURATION, UNLIMITED_AMOUNT
-
-
Constructor Summary
Constructors Constructor Description DefaultBucketProxy(Supplier<BucketConfiguration> configurationSupplier, CommandExecutor commandExecutor, RecoveryStrategy recoveryStrategy, ImplicitConfigurationReplacement implicitConfigurationReplacement)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddTokensImpl(long tokensToAdd)protected VerboseResult<Nothing>addTokensVerboseImpl(long tokensToAdd)protected longconsumeAsMuchAsPossibleImpl(long limit)protected VerboseResult<Long>consumeAsMuchAsPossibleVerboseImpl(long limit)protected longconsumeIgnoringRateLimitsImpl(long tokensToConsume)protected VerboseResult<Long>consumeIgnoringRateLimitsVerboseImpl(long tokensToConsume)protected EstimationProbeestimateAbilityToConsumeImpl(long numTokens)protected VerboseResult<EstimationProbe>estimateAbilityToConsumeVerboseImpl(long numTokens)protected voidforceAddTokensImpl(long tokensToAdd)protected VerboseResult<Nothing>forceAddTokensVerboseImpl(long tokensToAdd)longgetAvailableTokens()Returns amount of available tokens in this bucket.protected VerboseResult<Long>getAvailableTokensVerboseImpl()OptimizationControllergetOptimizationController()Returns optimization controller for this proxy.protected voidreplaceConfigurationImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)protected VerboseResult<Nothing>replaceConfigurationVerboseImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)protected longreserveAndCalculateTimeToSleepImpl(long tokensToConsume, long waitIfBusyNanosLimit)voidreset()Reset all tokens up to maximum capacity.protected VerboseResult<Nothing>resetVerboseImpl()voidsyncByCondition(long unsynchronizedTokens, Duration timeSinceLastSync)Initiates immediate synchronization of local copy of bucket with remote storage in case of both conditions bellow aretrue: Accumulated amount of locally consumed tokens without external synchronization is greater than or equal tounsynchronizedTokensTime passed since last synchronization with external storage is greater than or equal totimeSinceLastSyncBucketProxytoListenable(BucketListener listener)Returns new copy of this bucket instance decorated bylistener.protected ConsumptionProbetryConsumeAndReturnRemainingTokensImpl(long tokensToConsume)protected VerboseResult<ConsumptionProbe>tryConsumeAndReturnRemainingTokensVerboseImpl(long tokensToConsume)protected booleantryConsumeImpl(long tokensToConsume)protected VerboseResult<Boolean>tryConsumeVerboseImpl(long tokensToConsume)-
Methods inherited from class io.github.bucket4j.AbstractBucket
addTokens, asBlocking, asScheduler, asVerbose, completedFuture, consume, consume, consumeIgnoringRateLimits, consumeUninterruptibly, estimateAbilityToConsume, failedFuture, forceAddTokens, getListener, replaceConfiguration, tryConsume, tryConsume, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossible, tryConsumeUninterruptibly
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.github.bucket4j.BlockingBucket
consume, consumeUninterruptibly, tryConsume, tryConsume, tryConsume, tryConsumeUninterruptibly, tryConsumeUninterruptibly, tryConsumeUninterruptibly
-
Methods inherited from interface io.github.bucket4j.Bucket
addTokens, asBlocking, asScheduler, asVerbose, consumeIgnoringRateLimits, estimateAbilityToConsume, forceAddTokens, replaceConfiguration, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossible
-
Methods inherited from interface io.github.bucket4j.distributed.OptimizationController
syncImmediately
-
Methods inherited from interface io.github.bucket4j.SchedulingBucket
tryConsume
-
-
-
-
Constructor Detail
-
DefaultBucketProxy
public DefaultBucketProxy(Supplier<BucketConfiguration> configurationSupplier, CommandExecutor commandExecutor, RecoveryStrategy recoveryStrategy, ImplicitConfigurationReplacement implicitConfigurationReplacement)
-
-
Method Detail
-
toListenable
public BucketProxy toListenable(BucketListener listener)
Description copied from interface:BucketReturns 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.- Specified by:
toListenablein interfaceBucket- Specified by:
toListenablein interfaceBucketProxy- Parameters:
listener- the listener of bucket events.- Returns:
- new bucket instance decorated by
listener
-
getOptimizationController
public OptimizationController getOptimizationController()
Description copied from interface:BucketProxyReturns optimization controller for this proxy.This method is actual only if an optimization was applied during bucket construction via
RemoteBucketBuilder.withOptimization(Optimization)otherwise returned controller will do nothing.- Specified by:
getOptimizationControllerin interfaceBucketProxy- Returns:
- optimization controller for this proxy
-
syncByCondition
public void syncByCondition(long unsynchronizedTokens, Duration timeSinceLastSync)Description copied from interface:OptimizationControllerInitiates immediate synchronization of local copy of bucket with remote storage in case of both conditions bellow aretrue:- 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
- Specified by:
syncByConditionin interfaceOptimizationController- Parameters:
unsynchronizedTokens- criterion for accumulated amount of unsynchronized tokenstimeSinceLastSync- criterion for time passed since last synchronization
- Accumulated amount of locally consumed tokens without external synchronization is greater than or equal to
-
consumeAsMuchAsPossibleImpl
protected long consumeAsMuchAsPossibleImpl(long limit)
- Specified by:
consumeAsMuchAsPossibleImplin classAbstractBucket
-
tryConsumeImpl
protected boolean tryConsumeImpl(long tokensToConsume)
- Specified by:
tryConsumeImplin classAbstractBucket
-
tryConsumeAndReturnRemainingTokensImpl
protected ConsumptionProbe tryConsumeAndReturnRemainingTokensImpl(long tokensToConsume)
- Specified by:
tryConsumeAndReturnRemainingTokensImplin classAbstractBucket
-
estimateAbilityToConsumeImpl
protected EstimationProbe estimateAbilityToConsumeImpl(long numTokens)
- Specified by:
estimateAbilityToConsumeImplin classAbstractBucket
-
reserveAndCalculateTimeToSleepImpl
protected long reserveAndCalculateTimeToSleepImpl(long tokensToConsume, long waitIfBusyNanosLimit)- Specified by:
reserveAndCalculateTimeToSleepImplin classAbstractBucket
-
addTokensImpl
protected void addTokensImpl(long tokensToAdd)
- Specified by:
addTokensImplin classAbstractBucket
-
forceAddTokensImpl
protected void forceAddTokensImpl(long tokensToAdd)
- Specified by:
forceAddTokensImplin classAbstractBucket
-
replaceConfigurationImpl
protected void replaceConfigurationImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)
- Specified by:
replaceConfigurationImplin classAbstractBucket
-
consumeIgnoringRateLimitsImpl
protected long consumeIgnoringRateLimitsImpl(long tokensToConsume)
- Specified by:
consumeIgnoringRateLimitsImplin classAbstractBucket
-
reset
public void reset()
Description copied from interface:BucketReset all tokens up to maximum capacity.
-
getAvailableTokens
public long getAvailableTokens()
Description copied from interface:BucketReturns amount of available tokens in this bucket.Typically you should avoid using of this method for, because available tokens can be changed by concurrent transactions for case of multithreaded/multi-process environment.
- Specified by:
getAvailableTokensin interfaceBucket- Returns:
- amount of available tokens
-
consumeAsMuchAsPossibleVerboseImpl
protected VerboseResult<Long> consumeAsMuchAsPossibleVerboseImpl(long limit)
- Specified by:
consumeAsMuchAsPossibleVerboseImplin classAbstractBucket
-
tryConsumeVerboseImpl
protected VerboseResult<Boolean> tryConsumeVerboseImpl(long tokensToConsume)
- Specified by:
tryConsumeVerboseImplin classAbstractBucket
-
tryConsumeAndReturnRemainingTokensVerboseImpl
protected VerboseResult<ConsumptionProbe> tryConsumeAndReturnRemainingTokensVerboseImpl(long tokensToConsume)
- Specified by:
tryConsumeAndReturnRemainingTokensVerboseImplin classAbstractBucket
-
estimateAbilityToConsumeVerboseImpl
protected VerboseResult<EstimationProbe> estimateAbilityToConsumeVerboseImpl(long numTokens)
- Specified by:
estimateAbilityToConsumeVerboseImplin classAbstractBucket
-
getAvailableTokensVerboseImpl
protected VerboseResult<Long> getAvailableTokensVerboseImpl()
- Specified by:
getAvailableTokensVerboseImplin classAbstractBucket
-
addTokensVerboseImpl
protected VerboseResult<Nothing> addTokensVerboseImpl(long tokensToAdd)
- Specified by:
addTokensVerboseImplin classAbstractBucket
-
forceAddTokensVerboseImpl
protected VerboseResult<Nothing> forceAddTokensVerboseImpl(long tokensToAdd)
- Specified by:
forceAddTokensVerboseImplin classAbstractBucket
-
resetVerboseImpl
protected VerboseResult<Nothing> resetVerboseImpl()
- Specified by:
resetVerboseImplin classAbstractBucket
-
replaceConfigurationVerboseImpl
protected VerboseResult<Nothing> replaceConfigurationVerboseImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)
- Specified by:
replaceConfigurationVerboseImplin classAbstractBucket
-
consumeIgnoringRateLimitsVerboseImpl
protected VerboseResult<Long> consumeIgnoringRateLimitsVerboseImpl(long tokensToConsume)
- Specified by:
consumeIgnoringRateLimitsVerboseImplin classAbstractBucket
-
-