Package io.github.devlibx.easy.ratelimit
Interface IRateLimiter
- All Known Implementing Classes:
IRateLimiter.NoOpRateLimiter,RedisBasedRateLimiter,RedisBasedRateLimiterV2,RedisBasedRateLimiterV3
public interface IRateLimiter
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classNo op implementation -
Method Summary
Modifier and TypeMethodDescriptionvoidacquire()Acquires a permit from this RateLimiter, blocking until one is available.voidacquire(long permits) Acquires a specifiedpermitsfrom this RateLimiter, blocking until one is available.default StringObjectMapdebug()voidstart()Start rate limitervoidstop()Stop rate limiterbooleantrySetRate(long rate) Initializes RateLimiter's state and stores config to Redis server.
-
Method Details
-
debug
- Returns:
- debug info
-
start
void start()Start rate limiter -
stop
void stop()Stop rate limiter -
trySetRate
boolean trySetRate(long rate) Initializes RateLimiter's state and stores config to Redis server. Params: mode – - rate mode rate – - rate rateInterval – - rate time interval rateIntervalUnit – - rate time interval unit Returns: true if rate was set and false otherwise -
acquire
void acquire()Acquires a permit from this RateLimiter, blocking until one is available. Acquires a permit, if one is available and returns immediately, reducing the number of available permits by one. -
acquire
void acquire(long permits) Acquires a specifiedpermitsfrom this RateLimiter, blocking until one is available.Acquires the given number of permits, if they are available and returns immediately, reducing the number of available permits by the given amount.
- Parameters:
permits- the number of permits to acquire
-