Class RecyclableRateLimiterImpl
- java.lang.Object
-
- com.google.common.util.concurrent.RateLimiter
-
- com.google.common.util.concurrent.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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static RecyclableRateLimitercreate(double permitsPerSecond, double maxBurstSeconds)Create a new rate limiter instance with specified burst window.booleanimmediatelyAvailable(int permits)Checks whether there's enough permits accumulated to cover the number of requested permits.voidrecyclePermits(int permits)Return the specified number of permits back to the pool-
Methods inherited from class com.google.common.util.concurrent.RateLimiter
acquire, acquire, create, create, getRate, setRate, toString, tryAcquire, tryAcquire, tryAcquire, tryAcquire
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.common.util.concurrent.RecyclableRateLimiter
acquire, acquire, getRate, setRate, tryAcquire, tryAcquire
-
-
-
-
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:
immediatelyAvailablein interfaceRecyclableRateLimiter- 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:
recyclePermitsin interfaceRecyclableRateLimiter- Parameters:
permits- number of permits to return
-
-