Class BurstyRateLimiterStats

java.lang.Object
dev.failsafe.internal.RateLimiterStats
dev.failsafe.internal.BurstyRateLimiterStats

class BurstyRateLimiterStats extends RateLimiterStats
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.
  • Field Details

    • periodPermits

      final long periodPermits
    • periodNanos

      private final long periodNanos
    • availablePermits

      private long availablePermits
    • currentPeriod

      private long currentPeriod
  • 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
    • getAvailablePermits

      long getAvailablePermits()
    • getCurrentPeriod

      long getCurrentPeriod()
    • reset

      void reset()
      Description copied from class: RateLimiterStats
      Resets the rate limiter's internal stats.
      Specified by:
      reset in class RateLimiterStats