Class BucketRateLimiter<T>
java.lang.Object
io.micronaut.kubernetes.client.openapi.operator.workqueue.ratelimiter.BucketRateLimiter<T>
- Type Parameters:
T
- item type
- All Implemented Interfaces:
RateLimiter<T>
A light-weight token bucket implementation for RateLimiter.
The code has been copied from the official client and modified: BucketRateLimiter
-
Constructor Summary
ConstructorsConstructorDescriptionBucketRateLimiter
(long capacity, long tokensGeneratedInPeriod, Duration period) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Indicates that an item is finished being retried (failed or succeeded).int
numRequeues
(T item) Returns a number of failures that the item has had.void
reset()
Resets the rate limiter.Decides how long an item should wait before adding it back to the queue.
-
Constructor Details
-
BucketRateLimiter
- Parameters:
capacity
- Capacity is the maximum number of tokens can be consumed.tokensGeneratedInPeriod
- Tokens generated in period.period
- Period that generating specific number of tokens.
-
-
Method Details
-
when
Description copied from interface:RateLimiter
Decides how long an item should wait before adding it back to the queue.- Specified by:
when
in interfaceRateLimiter<T>
- Parameters:
item
- an item that should wait- Returns:
- how long an item should wait before adding it back to the queue
-
forget
Description copied from interface:RateLimiter
Indicates that an item is finished being retried (failed or succeeded).- Specified by:
forget
in interfaceRateLimiter<T>
- Parameters:
item
- an item to remove from internal tracking
-
numRequeues
Description copied from interface:RateLimiter
Returns a number of failures that the item has had.- Specified by:
numRequeues
in interfaceRateLimiter<T>
- Parameters:
item
- an item- Returns:
- number of failures that the item has had
-
reset
public void reset()Description copied from interface:RateLimiter
Resets the rate limiter.- Specified by:
reset
in interfaceRateLimiter<T>
-