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.
  • Field Details

    • intervalNanos

      final long intervalNanos
    • nextFreePermitNanos

      private long nextFreePermitNanos
  • Constructor Details

  • Method Details

    • acquirePermits

      public long acquirePermits(long requestedPermits, 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 the maxWaitTime.
      Specified by:
      acquirePermits in class RateLimiterStats
      Parameters:
      requestedPermits - the number of requested permits
      maxWaitTime - the max time to wait for the requested permits, else null 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 class RateLimiterStats