- java.lang.Object
-
- io.github.bucket4j.AbstractBucket
-
- io.github.bucket4j.local.ThreadUnsafeBucket
-
- All Implemented Interfaces:
BlockingBucket,Bucket,LocalBucket,SchedulingBucket,ComparableByContent<ThreadUnsafeBucket>
public class ThreadUnsafeBucket extends AbstractBucket implements LocalBucket, ComparableByContent<ThreadUnsafeBucket>
-
-
Field Summary
Fields Modifier and Type Field Description static SerializationHandle<ThreadUnsafeBucket>SERIALIZATION_HANDLE-
Fields inherited from class io.github.bucket4j.AbstractBucket
INFINITY_DURATION, UNLIMITED_AMOUNT
-
-
Constructor Summary
Constructors Constructor Description ThreadUnsafeBucket(BucketConfiguration configuration, MathType mathType, TimeMeter timeMeter)
-
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)booleanequalsByContent(ThreadUnsafeBucket other)protected EstimationProbeestimateAbilityToConsumeImpl(long tokensToEstimate)protected VerboseResult<EstimationProbe>estimateAbilityToConsumeVerboseImpl(long tokensToEstimate)protected voidforceAddTokensImpl(long tokensToAdd)protected VerboseResult<Nothing>forceAddTokensVerboseImpl(long tokensToAdd)longgetAvailableTokens()Returns amount of available tokens in this bucket.protected VerboseResult<Long>getAvailableTokensVerboseImpl()BucketConfigurationgetConfiguration()Returns configuration of this bucket.SynchronizationStrategygetSynchronizationStrategy()Returns the synchronization strategy that is used by this bucketTimeMetergetTimeMeter()Returns 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)voidreset()Reset all tokens up to maximum capacity.protected VerboseResult<Nothing>resetVerboseImpl()voidsetConfiguration(BucketConfiguration configuration)BuckettoListenable(BucketListener listener)Returns new copy of this bucket instance decorated bylistener.StringtoString()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, 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.local.LocalBucket
toBinarySnapshot, toJsonCompatibleSnapshot
-
Methods inherited from interface io.github.bucket4j.SchedulingBucket
tryConsume
-
-
-
-
Field Detail
-
SERIALIZATION_HANDLE
public static final SerializationHandle<ThreadUnsafeBucket> SERIALIZATION_HANDLE
-
-
Constructor Detail
-
ThreadUnsafeBucket
public ThreadUnsafeBucket(BucketConfiguration configuration, MathType mathType, TimeMeter timeMeter)
-
-
Method Detail
-
setConfiguration
public void setConfiguration(BucketConfiguration configuration)
-
toListenable
public Bucket 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- 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
protected ConsumptionProbe tryConsumeAndReturnRemainingTokensImpl(long tokensToConsume)
- Specified by:
tryConsumeAndReturnRemainingTokensImplin classAbstractBucket
-
estimateAbilityToConsumeImpl
protected EstimationProbe estimateAbilityToConsumeImpl(long tokensToEstimate)
- Specified by:
estimateAbilityToConsumeImplin classAbstractBucket
-
reserveAndCalculateTimeToSleepImpl
protected long reserveAndCalculateTimeToSleepImpl(long tokensToConsume, long waitIfBusyNanosLimit)- Specified by:
reserveAndCalculateTimeToSleepImplin classAbstractBucket
-
consumeIgnoringRateLimitsImpl
protected long consumeIgnoringRateLimitsImpl(long tokensToConsume)
- Specified by:
consumeIgnoringRateLimitsImplin classAbstractBucket
-
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 tokensToEstimate)
- 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
-
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.
-
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
-
replaceConfigurationImpl
protected void replaceConfigurationImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)
- Specified by:
replaceConfigurationImplin classAbstractBucket
-
getConfiguration
public BucketConfiguration getConfiguration()
Description copied from interface:LocalBucketReturns configuration of this bucket.- Specified by:
getConfigurationin interfaceLocalBucket- Returns:
- configuration
-
getTimeMeter
public TimeMeter 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
public SynchronizationStrategy 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
-
equalsByContent
public boolean equalsByContent(ThreadUnsafeBucket other)
- Specified by:
equalsByContentin interfaceComparableByContent<ThreadUnsafeBucket>
-
-