Class LocalPeriodicGate
java.lang.Object
io.agentscope.harness.agent.coordination.LocalPeriodicGate
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanupStaleEntries(Duration maxAge) Removes entries whose last claim is older thanmaxAge.static voidClears all entries — for unit tests only.static booleanhasClaimForTests(String name) Returns whether a named slot exists — for unit tests only.static voidseedLastClaimAtForTests(String name, Instant instant) Seeds a claim timestamp — for unit tests only.booleanAttempts to claim the named periodic slot.
-
Constructor Details
-
LocalPeriodicGate
public LocalPeriodicGate()
-
-
Method Details
-
tryClaim
Description copied from interface:PeriodicGateAttempts to claim the named periodic slot.- Specified by:
tryClaimin interfacePeriodicGate- Parameters:
name- logical slot identifier (e.g."memory-flush:USER:alice"or"skill-curator")minGap- minimum elapsed time since the last successful claim- Returns:
trueif the caller won the claim and may proceed,falseotherwise
-
cleanupStaleEntries
Removes entries whose last claim is older thanmaxAge. Bounds map size in long-running services with high key churn. -
clearForTests
public static void clearForTests()Clears all entries — for unit tests only. -
seedLastClaimAtForTests
Seeds a claim timestamp — for unit tests only. -
hasClaimForTests
Returns whether a named slot exists — for unit tests only.
-