Package io.jenkins.plugins.explain_error
Class QuotaEnforcer
java.lang.Object
io.jenkins.plugins.explain_error.QuotaEnforcer
Thread-safe counter that enforces a maximum number of AI provider calls within a rolling time window.
When tryAcquire(QuotaWindow, int) is called:
- If the current time window has expired the counter is reset and the call is allowed.
- Otherwise the counter is incremented atomically. If the new count exceeds the configured maximum, the call is rejected.
The enforcer is intentionally stateless with respect to Jenkins configuration: callers pass the window and limit on every invocation so the enforcer reacts immediately to configuration changes without requiring a restart.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidreset()Resets the quota counter and starts a fresh window.booleantryAcquire(QuotaWindow window, int maxCalls) Attempt to acquire a quota slot.
-
Constructor Details
-
QuotaEnforcer
public QuotaEnforcer()
-
-
Method Details
-
tryAcquire
Attempt to acquire a quota slot.- Parameters:
window- the time window that governs this quotamaxCalls- the maximum number of provider calls permitted within the window- Returns:
trueif the call is within the quota and should proceed;falseif the quota has been exceeded and the call should be rejected
-
reset
public void reset()Resets the quota counter and starts a fresh window. Intended for testing and for manual admin resets.
-