Interface RateLimiter
- All Known Implementing Classes:
ExactRateLimiter, FastRateLimiter, RateLimiterBase
public interface RateLimiter
Defines the contract for a rate limiter that tracks and limits the number of
requests per time window for a given identifier.
-
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Cleanup no longer needed resources.intReturns the actual duration of a time window in seconds.default StringReturns the full representation of the current rate limit policy in the format defined by the IETF draft for RateLimit header fields.Returns the name of the rate limit policy.default StringgetQuota(int requestCount) Provide the quota header for this rate limit for a given request count within the current time window.intReturns the maximum number of requests allowed per time window.intIncrements the number of requests by the given identifier in the current time window.voidsetDuration(int duration) Sets the configured duration value in seconds.voidsetFilterConfig(FilterConfig filterConfig) Pass the FilterConfig to configure the filter.voidsetPolicyName(String name) Sets the policy name, otherwise an auto-generated name is used.voidsetRequests(int requests) Sets the configured number of requests allowed per time window.
-
Method Details
-
getDuration
int getDuration()Returns the actual duration of a time window in seconds.- Returns:
- the duration in seconds
-
setDuration
void setDuration(int duration) Sets the configured duration value in seconds.- Parameters:
duration- The duration of the time window in seconds
-
getRequests
int getRequests()Returns the maximum number of requests allowed per time window.- Returns:
- the maximum number of requests
-
setRequests
void setRequests(int requests) Sets the configured number of requests allowed per time window.- Parameters:
requests- The number of requests per time window
-
increment
Increments the number of requests by the given identifier in the current time window.- Parameters:
identifier- the identifier for which the number of associated requests should be incremented- Returns:
- the new value after incrementing
-
destroy
void destroy()Cleanup no longer needed resources. -
setFilterConfig
Pass the FilterConfig to configure the filter.- Parameters:
filterConfig- The FilterConfig used to configure the associated filter
-
getPolicyName
-
setPolicyName
Sets the policy name, otherwise an auto-generated name is used.- Parameters:
name- of rate limit policy
-
getPolicy
Returns the full representation of the current rate limit policy in the format defined by the IETF draft for RateLimit header fields.- Returns:
- the policy representation string
- See Also:
-
getQuota
Provide the quota header for this rate limit for a given request count within the current time window.- Parameters:
requestCount- The request count within the current time window- Returns:
- the quota header for the given value of request count
- See Also:
-