io.github.devlibx.easy.ratelimit.IRateLimiter Maven / Gradle / Ivy
package io.github.devlibx.easy.ratelimit;
import io.gitbub.devlibx.easy.helper.map.StringObjectMap;
public interface IRateLimiter {
/**
* @return debug info
*/
default StringObjectMap debug() {
return new StringObjectMap();
}
/**
* Start rate limiter
*/
void start();
/**
* Stop rate limiter
*/
void stop();
/**
* 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
*/
boolean trySetRate(long rate);
/**
* 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.
*/
void acquire();
/**
* Acquires a specified permits
from 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.
*
* @param permits the number of permits to acquire
*/
void acquire(long permits);
/**
* No op implementation
*/
class NoOpRateLimiter implements IRateLimiter {
@Override
public void start() {
}
@Override
public void stop() {
}
@Override
public boolean trySetRate(long rate) {
return false;
}
@Override
public void acquire() {
}
@Override
public void acquire(long permits) {
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy