Package dev.failsafe.internal
Class SmoothRateLimiterStats
- java.lang.Object
-
- dev.failsafe.internal.RateLimiterStats
-
- dev.failsafe.internal.SmoothRateLimiterStats
-
class SmoothRateLimiterStats extends RateLimiterStats
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 dev.failsafe.internal.RateLimiterStats
RateLimiterStats.Stopwatch
-
-
Field Summary
Fields Modifier and Type Field Description (package private) long
intervalNanos
private long
nextFreePermitNanos
-
Fields inherited from class dev.failsafe.internal.RateLimiterStats
stopwatch
-
-
Constructor Summary
Constructors Constructor Description SmoothRateLimiterStats(RateLimiterConfig<?> config, RateLimiterStats.Stopwatch stopwatch)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
acquirePermits(long requestedPermits, java.time.Duration maxWaitTime)
Eagerly acquires permits and returns the time in nanos that must be waited in order to use the permits, else returns-1
if the wait time would exceed themaxWaitTime
.(package private) long
getNextFreePermitNanos()
(package private) void
reset()
Resets the rate limiter's internal stats.-
Methods inherited from class dev.failsafe.internal.RateLimiterStats
exceedsMaxWaitTime, getElapsed
-
-
-
-
Constructor Detail
-
SmoothRateLimiterStats
SmoothRateLimiterStats(RateLimiterConfig<?> config, RateLimiterStats.Stopwatch stopwatch)
-
-
Method Detail
-
acquirePermits
public long acquirePermits(long requestedPermits, java.time.Duration maxWaitTime)
Description copied from class:RateLimiterStats
Eagerly acquires permits and returns the time in nanos that must be waited in order to use the permits, else returns-1
if the wait time would exceed themaxWaitTime
.- Specified by:
acquirePermits
in classRateLimiterStats
- Parameters:
requestedPermits
- the number of requested permitsmaxWaitTime
- the max time to wait for the requested permits, elsenull
to wait indefinitely
-
getNextFreePermitNanos
long getNextFreePermitNanos()
-
reset
void reset()
Description copied from class:RateLimiterStats
Resets the rate limiter's internal stats.- Specified by:
reset
in classRateLimiterStats
-
-