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.
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 TypeMethodDescriptiontryAcquire(RateLimitKey key) Attempts to record one event underkeyagainst the policy's configured per-window limit.
-
Method Details
-
tryAcquire
Attempts to record one event underkeyagainst 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
-