Class GuardRateLimiterRegistry

java.lang.Object
org.frontcache.guard.ratelimit.GuardRateLimiterRegistry

public class GuardRateLimiterRegistry extends Object
Holds the WindowLimiter of every rate-limit bucket, keyed by bucket name. Process-scoped on purpose. FrontCacheEngine.reload() constructs a new GuardRuleEngine, and reload-guard-rules rebuilds the rule list; if the slot array lived in the predicate, either would wipe every client's count - so an operator editing an unrelated rule during an attack would hand every attacker a fresh window. This registry outlives both. Arrays whose bucket is no longer referenced after a load are dropped by retain(Set), and an array whose limit or window changed is rebuilt (its counts cannot be reinterpreted under a different window). Static state is otherwise hostile to tests, so reset() exists for them.
  • Field Details

  • Method Details

    • isEnabled

      public static boolean isEnabled()
      Returns:
      true unless the master switch is off. Read at load time - it is a property, so it applies at the next restart, like every other property-level switch in the pipeline.
    • limiter

      public static WindowLimiter limiter(RateLimitSpec spec)
      The limiter for one bucket, created on first use and reused across reloads when its limit and window are unchanged - which is what makes counts survive a reload.
      Throws:
      GuardConfigException - when allocating it would exceed max-total-slots, so the offending rule is skipped with an error instead of the node running out of heap
    • retain

      public static void retain(Set<String> bucketsInUse)
      Drops the limiters of buckets no longer named by any loaded rule. Called at the end of a load, so a deleted rule gives its memory back without a restart.
    • getLimiters

      public static Collection<WindowLimiter> getLimiters()
    • reset

      public static void reset()
      for tests