Package dev.relism.flash.ext.limiter
Enum Class LimitStrategy
- All Implemented Interfaces:
Serializable,Comparable<LimitStrategy>,Constable
Enumeration of built-in rate-limit algorithms. Each constant is a factory
for its corresponding
RateLimitStrategy implementation.
New algorithms can be added here without touching the rest of the extension.
The enum value is referenced by Limit.strategy() so user code refers
to the algorithm by name (LimitStrategy.FIXED_WINDOW) rather than
instantiating strategy objects directly.
@Limit(key = "ip", requests = 100, window = 1, strategy = LimitStrategy.TOKEN_BUCKET)
public class SearchHandler extends RequestHandler { ... }
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionFixed-window counter: resets to zero at each clock-aligned window boundary.Sliding-window counter: interpolates between the previous window's count and the current window's count weighted by how far into the current window we are.Token-bucket: tokens refill continuously. -
Method Summary
Modifier and TypeMethodDescriptionabstract RateLimitStrategycreate()Creates a fresh, statelessRateLimitStrategyinstance for this algorithm.static LimitStrategyReturns the enum constant of this class with the specified name.static LimitStrategy[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
FIXED_WINDOW
Fixed-window counter: resets to zero at each clock-aligned window boundary. Simple, minimal memory, but allows up to 2× the limit in bursts that straddle two windows. -
TOKEN_BUCKET
Token-bucket: tokens refill continuously. Smooth burst absorption — a client that was idle accumulates tokens and can fire a short burst, but sustained excess traffic is rejected. Preferred for API endpoints where occasional bursts are legitimate. -
SLIDING_WINDOW
Sliding-window counter: interpolates between the previous window's count and the current window's count weighted by how far into the current window we are. Eliminates the boundary burst ofFIXED_WINDOWwhile remaining O(1) memory and lock-free. Slight approximation — worst-case error ≈ a few percent at window boundaries.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
create
Creates a fresh, statelessRateLimitStrategyinstance for this algorithm.
-