Package dev.relism.flash.ext.limiter
Interface RateLimitStrategy
- All Known Implementing Classes:
FixedWindowStrategy,SlidingWindowStrategy,TokenBucketStrategy
public interface RateLimitStrategy
Contract for a rate-limit algorithm. Implementations must be:
- Lock-free — rely only on
AtomicLongCAS operations. - Stateless — all mutable state lives in the
Bucket; the strategy itself holds no instance fields so the same object can be shared across threads and rules.
Called on every request — must not allocate on the hot path.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleancheck(Bucket bucket, LimitConfig cfg, long[] out) Checks whether this request is within the limit and updates the bucket atomically.
-
Method Details
-
check
Checks whether this request is within the limit and updates the bucket atomically.On return,
outcontains:out[0]— remaining allowed requests in the current window (≥ 0).out[1]— Unix epoch seconds at which the quota resets (forX-RateLimit-ResetandRetry-Afterheaders).
- Parameters:
bucket- per-key state carrier (pre-allocated, never null)cfg- immutable rule configurationout- caller-supplied two-element array; values are overwritten on every call- Returns:
trueif the request is within the limit and should proceed
-