Class BurstyRateLimiterStats
java.lang.Object
dev.failsafe.internal.RateLimiterStats
dev.failsafe.internal.BurstyRateLimiterStats
A rate limiter implementation that allows bursts of executions, up to the max permits per period. This implementation
tracks the current period and available permits, which can go into a deficit. A deficit of available permits will
cause wait times for callers that can be several periods long, depending on the size of the deficit and the number of
requested permits.
-
Nested Class Summary
Nested classes/interfaces inherited from class RateLimiterStats
RateLimiterStats.Stopwatch -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longprivate longprivate final long(package private) final longFields inherited from class RateLimiterStats
stopwatch -
Constructor Summary
ConstructorsConstructorDescriptionBurstyRateLimiterStats(RateLimiterConfig<?> config, RateLimiterStats.Stopwatch stopwatch) -
Method Summary
Modifier and TypeMethodDescriptionlongacquirePermits(long requestedPermits, Duration maxWaitTime) Eagerly acquires permits and returns the time in nanos that must be waited in order to use the permits, else returns-1if the wait time would exceed themaxWaitTime.(package private) long(package private) long(package private) voidreset()Resets the rate limiter's internal stats.Methods inherited from class RateLimiterStats
exceedsMaxWaitTime, getElapsed
-
Field Details
-
periodPermits
final long periodPermits -
periodNanos
private final long periodNanos -
availablePermits
private long availablePermits -
currentPeriod
private long currentPeriod
-
-
Constructor Details
-
BurstyRateLimiterStats
BurstyRateLimiterStats(RateLimiterConfig<?> config, RateLimiterStats.Stopwatch stopwatch)
-
-
Method Details
-
acquirePermits
Description copied from class:RateLimiterStatsEagerly acquires permits and returns the time in nanos that must be waited in order to use the permits, else returns-1if the wait time would exceed themaxWaitTime.- Specified by:
acquirePermitsin classRateLimiterStats- Parameters:
requestedPermits- the number of requested permitsmaxWaitTime- the max time to wait for the requested permits, elsenullto wait indefinitely
-
getAvailablePermits
long getAvailablePermits() -
getCurrentPeriod
long getCurrentPeriod() -
reset
void reset()Description copied from class:RateLimiterStatsResets the rate limiter's internal stats.- Specified by:
resetin classRateLimiterStats
-