Interface RateLimitPolicy

All Known Implementing Classes:
InMemoryRateLimitPolicy
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@ExperimentalJSentinelApi @FunctionalInterface public interface RateLimitPolicy
Pluggable rate-limiting decision point — separate from LoginAttemptPolicy (which is purpose-built for password-guessing detection) and from SessionPolicy (which is about session lifetime).

Callers wrap the protected operation:

  RateLimitDecision d = policy.tryAcquire(key);
  if (d instanceof RateLimitDecision.Throttled t) {
      // 429 Too Many Requests + Retry-After: t.retryAfter().toSeconds()
      return;
  }
  // proceed

Implementations must be thread-safe.

  • Method Summary

    Modifier and Type
    Method
    Description
    Attempts to record one event under key against the policy's configured per-window limit.
  • Method Details

    • tryAcquire

      Attempts to record one event under key against the policy's configured per-window limit. The default behaviour mirrors a leaky bucket: an admitted event is counted, a throttled event is not. Concrete implementations document their semantics.
      Parameters:
      key - non-null key; the scope is the application's choice — IP, subject, endpoint, or composed
      Returns:
      admit / throttle decision, never null