public class LockFreeBucket extends AbstractBucket implements LocalBucket
| Constructor and Description |
|---|
LockFreeBucket(BucketConfiguration configuration,
TimeMeter timeMeter) |
| Modifier and Type | Method and Description |
|---|---|
protected CompletableFuture<Void> |
addTokensAsyncImpl(long tokensToAdd) |
protected void |
addTokensImpl(long tokensToAdd) |
protected long |
consumeAsMuchAsPossibleImpl(long limit) |
BucketState |
createSnapshot()
Creates the copy of internal state.
|
long |
getAvailableTokens()
Returns amount of available tokens in this bucket.
|
BucketConfiguration |
getConfiguration()
Returns configuration of this bucket.
|
boolean |
isAsyncModeSupported()
Describes whether or not this bucket supports asynchronous mode.
|
protected CompletableFuture<Void> |
replaceConfigurationAsyncImpl(BucketConfiguration newConfiguration) |
protected void |
replaceConfigurationImpl(BucketConfiguration newConfiguration) |
protected CompletableFuture<Long> |
reserveAndCalculateTimeToSleepAsyncImpl(long tokensToConsume,
long maxWaitTimeNanos) |
protected long |
reserveAndCalculateTimeToSleepImpl(long tokensToConsume,
long waitIfBusyNanosLimit) |
Bucket |
toListenable(BucketListener listener)
Returns new copy of this bucket instance decorated by
listener. |
String |
toString() |
protected CompletableFuture<ConsumptionProbe> |
tryConsumeAndReturnRemainingTokensAsyncImpl(long tokensToConsume) |
protected ConsumptionProbe |
tryConsumeAndReturnRemainingTokensImpl(long tokensToConsume) |
protected CompletableFuture<Long> |
tryConsumeAsMuchAsPossibleAsyncImpl(long limit) |
protected CompletableFuture<Boolean> |
tryConsumeAsyncImpl(long tokensToConsume) |
protected boolean |
tryConsumeImpl(long tokensToConsume) |
addTokens, asAsync, asAsyncScheduler, asScheduler, consume, consumeUninterruptibly, replaceConfiguration, tryConsume, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossible, tryConsumeUninterruptiblyclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddTokens, asAsync, asAsyncScheduler, asScheduler, replaceConfiguration, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossibleconsume, consumeUninterruptibly, tryConsume, tryConsume, tryConsume, tryConsumeUninterruptibly, tryConsumeUninterruptibly, tryConsumeUninterruptiblypublic LockFreeBucket(BucketConfiguration configuration, TimeMeter timeMeter)
public Bucket toListenable(BucketListener listener)
Bucketlistener.
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 Bucketlistener - the listener of bucket events.listenerpublic boolean isAsyncModeSupported()
BucketIf asynchronous mode is not supported any attempt to call Bucket.asAsync() will fail with UnsupportedOperationException
isAsyncModeSupported in interface Bucketprotected long consumeAsMuchAsPossibleImpl(long limit)
consumeAsMuchAsPossibleImpl in class AbstractBucketprotected boolean tryConsumeImpl(long tokensToConsume)
tryConsumeImpl in class AbstractBucketprotected ConsumptionProbe tryConsumeAndReturnRemainingTokensImpl(long tokensToConsume)
tryConsumeAndReturnRemainingTokensImpl in class AbstractBucketprotected long reserveAndCalculateTimeToSleepImpl(long tokensToConsume,
long waitIfBusyNanosLimit)
reserveAndCalculateTimeToSleepImpl in class AbstractBucketprotected void addTokensImpl(long tokensToAdd)
addTokensImpl in class AbstractBucketprotected void replaceConfigurationImpl(BucketConfiguration newConfiguration)
replaceConfigurationImpl in class AbstractBucketpublic long getAvailableTokens()
BucketThis method designed to be used only for monitoring and testing, you should never use this method for business cases, because available tokens can be changed by concurrent transactions for case of multithreaded/multi-process environment.
getAvailableTokens in interface Bucketprotected CompletableFuture<Boolean> tryConsumeAsyncImpl(long tokensToConsume)
tryConsumeAsyncImpl in class AbstractBucketprotected CompletableFuture<Void> addTokensAsyncImpl(long tokensToAdd)
addTokensAsyncImpl in class AbstractBucketprotected CompletableFuture<Void> replaceConfigurationAsyncImpl(BucketConfiguration newConfiguration)
replaceConfigurationAsyncImpl in class AbstractBucketprotected CompletableFuture<ConsumptionProbe> tryConsumeAndReturnRemainingTokensAsyncImpl(long tokensToConsume)
tryConsumeAndReturnRemainingTokensAsyncImpl in class AbstractBucketprotected CompletableFuture<Long> tryConsumeAsMuchAsPossibleAsyncImpl(long limit)
tryConsumeAsMuchAsPossibleAsyncImpl in class AbstractBucketprotected CompletableFuture<Long> reserveAndCalculateTimeToSleepAsyncImpl(long tokensToConsume, long maxWaitTimeNanos)
reserveAndCalculateTimeToSleepAsyncImpl in class AbstractBucketpublic BucketState createSnapshot()
BucketThis method is designed to be used only for monitoring and testing, you should never use this method for business cases.
createSnapshot in interface Bucketpublic BucketConfiguration getConfiguration()
LocalBucketgetConfiguration in interface LocalBucketCopyright © 2018. All rights reserved.