Class MemoryBackgroundTasks

java.lang.Object
io.agentscope.harness.agent.memory.MemoryBackgroundTasks

public final class MemoryBackgroundTasks extends Object
Tracks in-flight fire-and-forget memory background tasks (flush, maintenance) so HarnessAgent.close() can wait for them to quiesce before releasing resources.

The middleware instances that dispatch these tasks are created per agent call, so they cannot be reached from the agent's close() method. Like SessionTree.awaitMirrorQuiescence(long, java.util.concurrent.TimeUnit), the in-flight count is process-wide: close() blocks until every background task started before the call has finished, so async workspace writes do not race with resource cleanup (e.g. temp workspace deletion in tests).

  • Method Details

    • begin

      public static void begin()
      Marks the start of a fire-and-forget background task.
    • end

      public static void end()
      Marks the end of a fire-and-forget background task (must pair with begin()).
    • awaitQuiescence

      public static boolean awaitQuiescence(long timeout, TimeUnit unit)
      Blocks until all background tasks started before this call have finished, or the timeout elapses.
      Parameters:
      timeout - maximum time to wait
      unit - time unit of timeout
      Returns:
      true if the tasks quiesced within the timeout