Class 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 Detail

      • intervalNanos

        final long intervalNanos
      • nextFreePermitNanos

        private long nextFreePermitNanos
    • 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 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()