java.lang.Object
io.github.bucket4j.AbstractBucket
io.github.bucket4j.local.LockFreeBucket
- All Implemented Interfaces:
Bucket,LocalBucket,ComparableByContent<LockFreeBucket>
public class LockFreeBucket
extends AbstractBucket
implements LocalBucket, ComparableByContent<LockFreeBucket>
-
Field Summary
FieldsFields inherited from class io.github.bucket4j.AbstractBucket
INFINITY_DURATION, UNLIMITED_AMOUNT -
Constructor Summary
ConstructorsConstructorDescriptionLockFreeBucket(BucketConfiguration configuration, MathType mathType, TimeMeter timeMeter, 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) booleanequalsByContent(LockFreeBucket other) protected EstimationProbeestimateAbilityToConsumeImpl(long tokensToEstimate) protected VerboseResult<EstimationProbe>estimateAbilityToConsumeVerboseImpl(long tokensToEstimate) protected voidforceAddTokensImpl(long tokensToAdd) protected VerboseResult<Nothing>forceAddTokensVerboseImpl(long tokensToAdd) longReturns amount of available tokens in this bucket.protected VerboseResult<Long>Returns configuration of this bucket.Returns the synchronization strategy that is used by this bucketReturns the clock that is used by this bucketprotected voidreplaceConfigurationImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy) protected VerboseResult<Nothing>replaceConfigurationVerboseImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy) protected longreserveAndCalculateTimeToSleepImpl(long tokensToConsume, long waitIfBusyNanosLimit) protected VerboseResult<Long>reserveAndCalculateTimeToSleepVerboseImpl(long tokensToConsume, long maxWaitTimeNanos) voidreset()Reset all tokens up to maximum capacity.protected VerboseResult<Nothing>toListenable(BucketListener listener) Returns new copy of this bucket instance decorated bylistener.toString()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, 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.local.LocalBucket
toBinarySnapshot, toJsonCompatibleSnapshot
-
Field Details
-
SERIALIZATION_HANDLE
-
-
Constructor Details
-
LockFreeBucket
public LockFreeBucket(BucketConfiguration configuration, MathType mathType, TimeMeter timeMeter, 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- Parameters:
listener- the listener of bucket events.- Returns:
- new bucket instance decorated by
listener
-
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 waitIfBusyNanosLimit) - 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
-
reset
public void reset()Description copied from interface:BucketReset all tokens up to maximum capacity. -
replaceConfigurationImpl
protected void replaceConfigurationImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy) - Specified by:
replaceConfigurationImplin classAbstractBucket
-
consumeIgnoringRateLimitsImpl
protected long consumeIgnoringRateLimitsImpl(long tokensToConsume) - Specified by:
consumeIgnoringRateLimitsImplin classAbstractBucket
-
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
-
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
-
getConfiguration
Description copied from interface:LocalBucketReturns configuration of this bucket.- Specified by:
getConfigurationin interfaceLocalBucket- Returns:
- configuration
-
getTimeMeter
Description copied from interface:LocalBucketReturns the clock that is used by this bucket- Specified by:
getTimeMeterin interfaceLocalBucket- Returns:
- the clock that is used by this bucket
-
getSynchronizationStrategy
Description copied from interface:LocalBucketReturns the synchronization strategy that is used by this bucket- Specified by:
getSynchronizationStrategyin interfaceLocalBucket- Returns:
- synchronization strategy that is used by this bucket
-
toString
-
equalsByContent
- Specified by:
equalsByContentin interfaceComparableByContent<LockFreeBucket>
-