Module io.github.bucket4j.core
Class DefaultBucketProxy
java.lang.Object
io.github.bucket4j.AbstractBucket
io.github.bucket4j.distributed.proxy.DefaultBucketProxy
- All Implemented Interfaces:
Bucket,BucketProxy,OptimizationController
public class DefaultBucketProxy
extends AbstractBucket
implements BucketProxy, OptimizationController
-
Field Summary
Fields inherited from class io.github.bucket4j.AbstractBucket
INFINITY_DURATION, UNLIMITED_AMOUNT -
Constructor Summary
ConstructorsConstructorDescriptionDefaultBucketProxy(Supplier<BucketConfiguration> configurationSupplier, CommandExecutor commandExecutor, RecoveryStrategy recoveryStrategy, ImplicitConfigurationReplacement implicitConfigurationReplacement, BucketListener listener) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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) longReturns amount of available tokens in this bucket.protected VerboseResult<Long>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 maxWaitTimeNanos) protected VerboseResult<Long>reserveAndCalculateTimeToSleepVerboseImpl(long tokensToConsume, long maxWaitTimeNanos) voidreset()Reset all tokens up to maximum capacity.protected VerboseResult<Nothing>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 totimeSinceLastSynctoListenable(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, consumeIgnoringRateLimits, estimateAbilityToConsume, failedFuture, forceAddTokens, getListener, replaceConfiguration, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.bucket4j.Bucket
addTokens, asBlocking, asScheduler, asVerbose, consumeIgnoringRateLimits, estimateAbilityToConsume, forceAddTokens, replaceConfiguration, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossibleMethods inherited from interface io.github.bucket4j.distributed.OptimizationController
syncImmediately
-
Constructor Details
-
DefaultBucketProxy
public DefaultBucketProxy(Supplier<BucketConfiguration> configurationSupplier, CommandExecutor commandExecutor, RecoveryStrategy recoveryStrategy, ImplicitConfigurationReplacement implicitConfigurationReplacement, BucketListener listener)
-
-
Method Details
-
toListenable
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 for
BucketListenerin 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
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
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
- Specified by:
tryConsumeAndReturnRemainingTokensImplin classAbstractBucket
-
estimateAbilityToConsumeImpl
- Specified by:
estimateAbilityToConsumeImplin classAbstractBucket
-
reserveAndCalculateTimeToSleepImpl
protected long reserveAndCalculateTimeToSleepImpl(long tokensToConsume, long maxWaitTimeNanos) - Specified by:
reserveAndCalculateTimeToSleepImplin classAbstractBucket
-
reserveAndCalculateTimeToSleepVerboseImpl
protected VerboseResult<Long> reserveAndCalculateTimeToSleepVerboseImpl(long tokensToConsume, long maxWaitTimeNanos) - Specified by:
reserveAndCalculateTimeToSleepVerboseImplin 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/multiprocess environment.
- Specified by:
getAvailableTokensin interfaceBucket- Returns:
- amount of available tokens
-
consumeAsMuchAsPossibleVerboseImpl
- Specified by:
consumeAsMuchAsPossibleVerboseImplin classAbstractBucket
-
tryConsumeVerboseImpl
- Specified by:
tryConsumeVerboseImplin classAbstractBucket
-
tryConsumeAndReturnRemainingTokensVerboseImpl
protected VerboseResult<ConsumptionProbe> tryConsumeAndReturnRemainingTokensVerboseImpl(long tokensToConsume) - Specified by:
tryConsumeAndReturnRemainingTokensVerboseImplin classAbstractBucket
-
estimateAbilityToConsumeVerboseImpl
- Specified by:
estimateAbilityToConsumeVerboseImplin classAbstractBucket
-
getAvailableTokensVerboseImpl
- Specified by:
getAvailableTokensVerboseImplin classAbstractBucket
-
addTokensVerboseImpl
- Specified by:
addTokensVerboseImplin classAbstractBucket
-
forceAddTokensVerboseImpl
- Specified by:
forceAddTokensVerboseImplin classAbstractBucket
-
resetVerboseImpl
- Specified by:
resetVerboseImplin classAbstractBucket
-
replaceConfigurationVerboseImpl
protected VerboseResult<Nothing> replaceConfigurationVerboseImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy) - Specified by:
replaceConfigurationVerboseImplin classAbstractBucket
-
consumeIgnoringRateLimitsVerboseImpl
- Specified by:
consumeIgnoringRateLimitsVerboseImplin classAbstractBucket
-