Class RecyclableRateLimiterImpl

  • All Implemented Interfaces:
    RecyclableRateLimiter

    public class RecyclableRateLimiterImpl
    extends com.google.common.util.concurrent.RateLimiter
    implements RecyclableRateLimiter
    An alternative RateLimiter implementation that allows to "return" unused permits back to the pool to handle retries gracefully and allow precise control over outgoing rate. Also allows accumulating "credits" for unused permits over a time window other than 1 second.
    Author:
    vasily@wavefront.com, with portions from Guava library source code
    • Method Detail

      • create

        public static RecyclableRateLimiter create​(double permitsPerSecond,
                                                   double maxBurstSeconds)
        Create a new rate limiter instance with specified burst window.
        Parameters:
        permitsPerSecond - the rate of the returned rate limiter, in permits per second.
        maxBurstSeconds - time window (in seconds) to accumulate unused permits for.
      • immediatelyAvailable

        public boolean immediatelyAvailable​(int permits)
        Checks whether there's enough permits accumulated to cover the number of requested permits.
        Specified by:
        immediatelyAvailable in interface RecyclableRateLimiter
        Parameters:
        permits - permits to check
        Returns:
        true if enough accumulated permits
      • recyclePermits

        public void recyclePermits​(int permits)
        Return the specified number of permits back to the pool
        Specified by:
        recyclePermits in interface RecyclableRateLimiter
        Parameters:
        permits - number of permits to return