java.lang.Object
com.agentforge4j.llm.fake.FakeRunLifecycle
The single per-run store for the fake provider: each run id maps to one entry holding the run's
FakeScript
and its ordinal counters, so registering, deregistering, or evicting a run clears both in one place — there
is no separate counter map to keep in sync, and the FakeLlmClient stays stateless.
Lifecycle:
register(String, FakeScript)installs (or atomically replaces) a run's script, resetting that run's counters — a fresh script implies a fresh sequence.deregister(String)removes the run's script and counters together.- A TTL leak guard evicts runs whose last access is older than the configured TTL; it runs opportunistically when a new run is first seen (never on a hot read path) so an active long-running run — kept fresh by its own calls — is not evicted (no LRU on the leak guard).
- An optional max-run cap (dev/demo only) evicts the least-recently-accessed run when the cap is exceeded, always logging the eviction — never a silent drop.
Thread-safe: a ConcurrentHashMap of runs, per-run ConcurrentHashMap counters,
and AtomicInteger.getAndIncrement() ordinals. A single instance serves concurrent runs.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a lifecycle with no TTL eviction and no run cap (system UTC clock).FakeRunLifecycle(Clock clock, Duration ttl, int maxRuns) Creates a lifecycle with the given leak guards. -
Method Summary
Modifier and TypeMethodDescriptionvoidderegister(String runId) Removes a run's script and ordinal counters together.booleanisRegistered(String runId) Returns whether a run currently has state (script and/or counters) tracked.voidregister(String runId, FakeScript script) Installs (or atomically replaces) the script for a run, resetting that run's ordinal counters.voidsweep()Runs the TTL leak guard immediately, evicting stale runs.
-
Constructor Details
-
FakeRunLifecycle
public FakeRunLifecycle()Creates a lifecycle with no TTL eviction and no run cap (system UTC clock). -
FakeRunLifecycle
Creates a lifecycle with the given leak guards.- Parameters:
clock- clock for last-access timestamps and TTL; must not benullttl- stale-run time-to-live, ornull/zero/negative to disable TTL evictionmaxRuns- optional max concurrent runs (0disables the cap); dev/demo only
-
-
Method Details
-
register
Installs (or atomically replaces) the script for a run, resetting that run's ordinal counters.- Parameters:
runId- run id; must not be blankscript- script to register; must not benull
-
deregister
Removes a run's script and ordinal counters together. No-op when the run is unknown.- Parameters:
runId- run id; must not be blank
-
sweep
public void sweep()Runs the TTL leak guard immediately, evicting stale runs. -
isRegistered
Returns whether a run currently has state (script and/or counters) tracked.- Parameters:
runId- run id; must not be blank- Returns:
trueif the run is tracked
-