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 AtomicLong CAS 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 Type
    Method
    Description
    boolean
    check(Bucket bucket, LimitConfig cfg, long[] out)
    Checks whether this request is within the limit and updates the bucket atomically.
  • Method Details

    • check

      boolean check(Bucket bucket, LimitConfig cfg, long[] out)
      Checks whether this request is within the limit and updates the bucket atomically.

      On return, out contains:

      • out[0] — remaining allowed requests in the current window (≥ 0).
      • out[1] — Unix epoch seconds at which the quota resets (for X-RateLimit-Reset and Retry-After headers).
      Parameters:
      bucket - per-key state carrier (pre-allocated, never null)
      cfg - immutable rule configuration
      out - caller-supplied two-element array; values are overwritten on every call
      Returns:
      true if the request is within the limit and should proceed