Package com.rale4j.sb.core
Class TokenBucketRateLimiter
java.lang.Object
com.rale4j.sb.core.TokenBucketRateLimiter
- All Implemented Interfaces:
RateLimitStrategy
@Component("tokenBucket")
public class TokenBucketRateLimiter
extends Object
implements RateLimitStrategy
Rate limiter implementation using the Token Bucket algorithm.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
allowRequest
(String key, int limit, int duration) Allows or denies a request based on the rate limit.
-
Constructor Details
-
TokenBucketRateLimiter
public TokenBucketRateLimiter()
-
-
Method Details
-
allowRequest
Allows or denies a request based on the rate limit.- Specified by:
allowRequest
in interfaceRateLimitStrategy
- Parameters:
key
- the key to identify the rate limit bucketlimit
- the maximum number of tokens availableduration
- the duration in seconds for the rate limit- Returns:
- true if the request is allowed, false otherwise
-