Class SmoothRateLimiterStats
java.lang.Object
dev.failsafe.internal.RateLimiterStats
dev.failsafe.internal.SmoothRateLimiterStats
A rate limiter implementation that evenly distributes permits over time, based on the max permits per period. This
implementation focuses on the interval between permits, and tracks the next interval in which a permit is free.
-
Nested Class Summary
Nested classes/interfaces inherited from class RateLimiterStats
RateLimiterStats.Stopwatch -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final longprivate longFields inherited from class RateLimiterStats
stopwatch -
Constructor Summary
ConstructorsConstructorDescriptionSmoothRateLimiterStats(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) voidreset()Resets the rate limiter's internal stats.Methods inherited from class RateLimiterStats
exceedsMaxWaitTime, getElapsed
-
Field Details
-
intervalNanos
final long intervalNanos -
nextFreePermitNanos
private long nextFreePermitNanos
-
-
Constructor Details
-
SmoothRateLimiterStats
SmoothRateLimiterStats(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
-
getNextFreePermitNanos
long getNextFreePermitNanos() -
reset
void reset()Description copied from class:RateLimiterStatsResets the rate limiter's internal stats.- Specified by:
resetin classRateLimiterStats
-