public interface BlockingBucket
Modifier and Type | Method and Description |
---|---|
default void |
consume(long numTokens)
This is just overloaded equivalent of
consume(long, BlockingStrategy) |
void |
consume(long numTokens,
BlockingStrategy blockingStrategy)
Consumes a specified number of tokens from the bucket.
|
default void |
consumeUninterruptibly(long numTokens)
This is just overloaded equivalent of
consumeUninterruptibly(long, UninterruptibleBlockingStrategy) |
void |
consumeUninterruptibly(long numTokens,
UninterruptibleBlockingStrategy blockingStrategy)
Has same semantic with
consume(long, BlockingStrategy) but ignores interrupts(just restores interruption flag on exit). |
default boolean |
tryConsume(long numTokens,
Duration maxWait)
This is just overloaded equivalent of
tryConsume(long, long, BlockingStrategy) |
default boolean |
tryConsume(long numTokens,
Duration maxWait,
BlockingStrategy blockingStrategy)
This is just overloaded equivalent of
tryConsume(long, long, BlockingStrategy) |
default boolean |
tryConsume(long numTokens,
long maxWaitTimeNanos)
This is just overloaded equivalent of
tryConsume(long, long, BlockingStrategy) |
boolean |
tryConsume(long numTokens,
long maxWaitTimeNanos,
BlockingStrategy blockingStrategy)
Tries to consume a specified number of tokens from the bucket.
|
default boolean |
tryConsumeUninterruptibly(long numTokens,
Duration maxWait)
This is just overloaded equivalent of
tryConsumeUninterruptibly(long, long, UninterruptibleBlockingStrategy) |
default boolean |
tryConsumeUninterruptibly(long numTokens,
Duration maxWait,
UninterruptibleBlockingStrategy blockingStrategy)
This is just overloaded equivalent of
tryConsumeUninterruptibly(long, long, UninterruptibleBlockingStrategy) |
default boolean |
tryConsumeUninterruptibly(long numTokens,
long maxWaitTimeNanos)
This is just overloaded equivalent of
tryConsumeUninterruptibly(long, long, UninterruptibleBlockingStrategy) |
boolean |
tryConsumeUninterruptibly(long numTokens,
long maxWaitTimeNanos,
UninterruptibleBlockingStrategy blockingStrategy)
Has same semantic with
tryConsume(long, long, BlockingStrategy) but ignores interrupts(just restores interruption flag on exit). |
boolean tryConsume(long numTokens, long maxWaitTimeNanos, BlockingStrategy blockingStrategy) throws InterruptedException
The algorithm is following:
maxWaitTimeNanos
nanoseconds,
then consumes nothing and returns false immediately.
maxWaitTimeNanos
nanoseconds,
then tokens consumed(reserved in fair manner) from bucket and current thread blocked for a time required to close deficit,
after unblocking method returns true.
Note: If InterruptedException happen when thread was blocked
then tokens will be not returned back to bucket,
but you can use Bucket.addTokens(long)
to returned tokens back.
numTokens
- The number of tokens to consume from the bucket.maxWaitTimeNanos
- limit of time(in nanoseconds) which thread can wait.blockingStrategy
- specifies the way to block current thread to amount of time required to refill missed number of tokens in the bucketnumTokens
has been consumed or false when numTokens
has not been consumedInterruptedException
- in case of current thread has been interrupted during the waitingdefault boolean tryConsume(long numTokens, Duration maxWait, BlockingStrategy blockingStrategy) throws InterruptedException
tryConsume(long, long, BlockingStrategy)
numTokens
- The number of tokens to consume from the bucket.maxWait
- limit of time which thread can wait.blockingStrategy
- specifies the way to block current thread to amount of time required to refill missed number of tokens in the bucketnumTokens
has been consumed or false when numTokens
has not been consumedInterruptedException
- in case of current thread has been interrupted during the waitingtryConsume(long, long, BlockingStrategy)
default boolean tryConsume(long numTokens, long maxWaitTimeNanos) throws InterruptedException
tryConsume(long, long, BlockingStrategy)
numTokens
- The number of tokens to consume from the bucket.maxWaitTimeNanos
- limit of time(in nanoseconds) which thread can wait.numTokens
has been consumed or false when numTokens
has not been consumedInterruptedException
- in case of current thread has been interrupted during the waitingtryConsume(long, long, BlockingStrategy)
default boolean tryConsume(long numTokens, Duration maxWait) throws InterruptedException
tryConsume(long, long, BlockingStrategy)
numTokens
- The number of tokens to consume from the bucket.maxWait
- limit of time which thread can wait.numTokens
has been consumed or false when numTokens
has not been consumedInterruptedException
- in case of current thread has been interrupted during the waitingtryConsume(long, long, BlockingStrategy)
boolean tryConsumeUninterruptibly(long numTokens, long maxWaitTimeNanos, UninterruptibleBlockingStrategy blockingStrategy)
tryConsume(long, long, BlockingStrategy)
but ignores interrupts(just restores interruption flag on exit).numTokens
- The number of tokens to consume from the bucket.maxWaitTimeNanos
- limit of time(in nanoseconds) which thread can wait.blockingStrategy
- specifies the way to block current thread to amount of time required to refill missed number of tokens in the bucketnumTokens
has been consumed or false when numTokens
has not been consumedtryConsume(long, long, BlockingStrategy)
default boolean tryConsumeUninterruptibly(long numTokens, Duration maxWait, UninterruptibleBlockingStrategy blockingStrategy)
tryConsumeUninterruptibly(long, long, UninterruptibleBlockingStrategy)
numTokens
- The number of tokens to consume from the bucket.maxWait
- limit of time which thread can wait.blockingStrategy
- specifies the way to block current thread to amount of time required to refill missed number of tokens in the bucketnumTokens
has been consumed or false when numTokens
has not been consumedtryConsumeUninterruptibly(long, long, UninterruptibleBlockingStrategy)
default boolean tryConsumeUninterruptibly(long numTokens, long maxWaitTimeNanos)
tryConsumeUninterruptibly(long, long, UninterruptibleBlockingStrategy)
numTokens
- The number of tokens to consume from the bucket.maxWaitTimeNanos
- limit of time(in nanoseconds) which thread can wait.numTokens
has been consumed or false when numTokens
has not been consumedtryConsumeUninterruptibly(long, long, UninterruptibleBlockingStrategy)
default boolean tryConsumeUninterruptibly(long numTokens, Duration maxWait)
tryConsumeUninterruptibly(long, long, UninterruptibleBlockingStrategy)
numTokens
- The number of tokens to consume from the bucket.maxWait
- limit of time which thread can wait.numTokens
has been consumed or false when numTokens
has not been consumedtryConsumeUninterruptibly(long, long, UninterruptibleBlockingStrategy)
void consume(long numTokens, BlockingStrategy blockingStrategy) throws InterruptedException
The algorithm is following:
Bucket.addTokens(long)
to returned tokens back.
numTokens
- The number of tokens to consume from the bucket.blockingStrategy
- specifies the way to block current thread to amount of time required to refill missed number of tokens in the bucketInterruptedException
- in case of current thread has been interrupted during the waitingdefault void consume(long numTokens) throws InterruptedException
consume(long, BlockingStrategy)
numTokens
- The number of tokens to consume from the bucket.InterruptedException
- in case of current thread has been interrupted during the waitingconsume(long, BlockingStrategy)
void consumeUninterruptibly(long numTokens, UninterruptibleBlockingStrategy blockingStrategy)
consume(long, BlockingStrategy)
but ignores interrupts(just restores interruption flag on exit).numTokens
- The number of tokens to consume from the bucket.blockingStrategy
- specifies the way to block current thread to amount of time required to refill missed number of tokens in the bucketconsume(long, BlockingStrategy)
default void consumeUninterruptibly(long numTokens)
consumeUninterruptibly(long, UninterruptibleBlockingStrategy)
numTokens
- The number of tokens to consume from the bucket.consumeUninterruptibly(long, UninterruptibleBlockingStrategy)
Copyright © 2020. All rights reserved.