public class SynchronizedBucket extends AbstractBucket implements LocalBucket, ComparableByContent<SynchronizedBucket>
Modifier and Type | Field and Description |
---|---|
static SerializationHandle<SynchronizedBucket> |
SERIALIZATION_HANDLE |
INFINITY_DURATION, UNLIMITED_AMOUNT
Constructor and Description |
---|
SynchronizedBucket(BucketConfiguration configuration,
MathType mathType,
TimeMeter timeMeter) |
Modifier and Type | Method and Description |
---|---|
protected void |
addTokensImpl(long tokensToAdd) |
protected VerboseResult<Nothing> |
addTokensVerboseImpl(long tokensToAdd) |
protected long |
consumeAsMuchAsPossibleImpl(long limit) |
protected VerboseResult<Long> |
consumeAsMuchAsPossibleVerboseImpl(long limit) |
protected long |
consumeIgnoringRateLimitsImpl(long tokensToConsume) |
protected VerboseResult<Long> |
consumeIgnoringRateLimitsVerboseImpl(long tokensToConsume) |
boolean |
equalsByContent(SynchronizedBucket other) |
protected EstimationProbe |
estimateAbilityToConsumeImpl(long tokensToEstimate) |
protected VerboseResult<EstimationProbe> |
estimateAbilityToConsumeVerboseImpl(long tokensToEstimate) |
protected void |
forceAddTokensImpl(long tokensToAdd) |
protected VerboseResult<Nothing> |
forceAddTokensVerboseImpl(long tokensToAdd) |
long |
getAvailableTokens()
Returns amount of available tokens in this bucket.
|
protected VerboseResult<Long> |
getAvailableTokensVerboseImpl() |
BucketConfiguration |
getConfiguration()
Returns configuration of this bucket.
|
SynchronizationStrategy |
getSynchronizationStrategy()
Returns the synchronization strategy that is used by this bucket
|
TimeMeter |
getTimeMeter()
Returns the clock that is used by this bucket
|
protected void |
replaceConfigurationImpl(BucketConfiguration newConfiguration,
TokensInheritanceStrategy tokensInheritanceStrategy) |
protected VerboseResult<Nothing> |
replaceConfigurationVerboseImpl(BucketConfiguration newConfiguration,
TokensInheritanceStrategy tokensInheritanceStrategy) |
protected long |
reserveAndCalculateTimeToSleepImpl(long tokensToConsume,
long waitIfBusyNanosLimit) |
void |
reset()
Reset all tokens up to maximum capacity.
|
protected VerboseResult<Nothing> |
resetVerboseImpl() |
void |
setConfiguration(BucketConfiguration configuration) |
Bucket |
toListenable(BucketListener listener)
Returns new copy of this bucket instance decorated by
listener . |
String |
toString() |
protected ConsumptionProbe |
tryConsumeAndReturnRemainingTokensImpl(long tokensToConsume) |
protected VerboseResult<ConsumptionProbe> |
tryConsumeAndReturnRemainingTokensVerboseImpl(long tokensToConsume) |
protected boolean |
tryConsumeImpl(long tokensToConsume) |
protected VerboseResult<Boolean> |
tryConsumeVerboseImpl(long tokensToConsume) |
addTokens, asBlocking, asScheduler, asVerbose, completedFuture, consume, consume, consumeIgnoringRateLimits, consumeUninterruptibly, estimateAbilityToConsume, failedFuture, forceAddTokens, getListener, replaceConfiguration, tryConsume, tryConsume, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossible, tryConsumeUninterruptibly
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
fromBinarySnapshot, fromJsonCompatibleSnapshot, toBinarySnapshot, toJsonCompatibleSnapshot
addTokens, asBlocking, asScheduler, asVerbose, builder, consumeIgnoringRateLimits, estimateAbilityToConsume, forceAddTokens, replaceConfiguration, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossible
equals
consume, consumeUninterruptibly, tryConsume, tryConsume, tryConsume, tryConsumeUninterruptibly, tryConsumeUninterruptibly, tryConsumeUninterruptibly
tryConsume
public static final SerializationHandle<SynchronizedBucket> SERIALIZATION_HANDLE
public SynchronizedBucket(BucketConfiguration configuration, MathType mathType, TimeMeter timeMeter)
public void setConfiguration(BucketConfiguration configuration)
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
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> resetVerboseImpl()
resetVerboseImpl
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 void reset()
Bucket
public long getAvailableTokens()
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.
getAvailableTokens
in interface Bucket
protected void replaceConfigurationImpl(BucketConfiguration newConfiguration, TokensInheritanceStrategy tokensInheritanceStrategy)
replaceConfigurationImpl
in class AbstractBucket
public BucketConfiguration getConfiguration()
LocalBucket
getConfiguration
in interface LocalBucket
public TimeMeter getTimeMeter()
LocalBucket
getTimeMeter
in interface LocalBucket
public SynchronizationStrategy getSynchronizationStrategy()
LocalBucket
getSynchronizationStrategy
in interface LocalBucket
public boolean equalsByContent(SynchronizedBucket other)
equalsByContent
in interface ComparableByContent<SynchronizedBucket>
Copyright © 2022. All rights reserved.