Class QuotaEnforcer

java.lang.Object
io.jenkins.plugins.explain_error.QuotaEnforcer

public class QuotaEnforcer extends Object
Thread-safe counter that enforces a maximum number of AI provider calls within a rolling time window.

When tryAcquire(QuotaWindow, int) is called:

  1. If the current time window has expired the counter is reset and the call is allowed.
  2. 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 Details

    • QuotaEnforcer

      public QuotaEnforcer()
  • Method Details

    • tryAcquire

      public boolean tryAcquire(QuotaWindow window, int maxCalls)
      Attempt to acquire a quota slot.
      Parameters:
      window - the time window that governs this quota
      maxCalls - the maximum number of provider calls permitted within the window
      Returns:
      true if the call is within the quota and should proceed; false if 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.