Class LocalPeriodicGate

java.lang.Object
io.agentscope.harness.agent.coordination.LocalPeriodicGate
All Implemented Interfaces:
PeriodicGate

public final class LocalPeriodicGate extends Object implements PeriodicGate
JVM-local PeriodicGate backed by a process-wide ConcurrentHashMap and CAS updates. Suitable for single-process deployments or as the default when no distributed store is configured.

The map is static so the throttle window survives across HarnessAgent.Builder.build() calls — each rebuild creates new middleware instances, and an instance-level map would reset to Instant.EPOCH on every request.

  • Constructor Details

    • LocalPeriodicGate

      public LocalPeriodicGate()
  • Method Details

    • tryClaim

      public boolean tryClaim(String name, Duration minGap)
      Description copied from interface: PeriodicGate
      Attempts to claim the named periodic slot.
      Specified by:
      tryClaim in interface PeriodicGate
      Parameters:
      name - logical slot identifier (e.g. "memory-flush:USER:alice" or "skill-curator")
      minGap - minimum elapsed time since the last successful claim
      Returns:
      true if the caller won the claim and may proceed, false otherwise
    • cleanupStaleEntries

      public void cleanupStaleEntries(Duration maxAge)
      Removes entries whose last claim is older than maxAge. Bounds map size in long-running services with high key churn.
    • clearForTests

      public static void clearForTests()
      Clears all entries — for unit tests only.
    • seedLastClaimAtForTests

      public static void seedLastClaimAtForTests(String name, Instant instant)
      Seeds a claim timestamp — for unit tests only.
    • hasClaimForTests

      public static boolean hasClaimForTests(String name)
      Returns whether a named slot exists — for unit tests only.