类 GracefulShutdownManager

java.lang.Object
io.agentscope.core.shutdown.GracefulShutdownManager

public final class GracefulShutdownManager extends Object
Global manager for graceful shutdown lifecycle and active request tracking.
  • 方法详细资料

    • getInstance

      public static GracefulShutdownManager getInstance()
    • getState

      public ShutdownState getState()
    • getConfig

      public GracefulShutdownConfig getConfig()
    • setConfig

      public void setConfig(GracefulShutdownConfig config)
    • getShutdownTimeoutSignal

      public reactor.core.publisher.Mono<Void> getShutdownTimeoutSignal()
      Returns a Mono that completes when the shutdown timeout is reached. Tool executors can race their execution against this signal to abort early.
    • bindStateSaver

      public void bindStateSaver(Agent agent, ShutdownStateSaver saver)
      Register a ShutdownStateSaver for the given agent.

      The saver is invoked during shutdown to persist the agent's AgentState (with shutdownInterrupted set to true).

    • checkAndClearShutdownInterrupted

      public boolean checkAndClearShutdownInterrupted(Agent agent)
      Check whether the agent was previously interrupted by shutdown, and clear the flag.

      Called from GracefulShutdownMiddleware on each onAgent to detect a client retry after shutdown interruption, so the duplicate user prompt can be replaced with a "continue" message.

      返回:
      true if the flag was present and cleared
    • isAcceptingRequests

      public boolean isAcceptingRequests()
    • getActiveRequestCount

      public int getActiveRequestCount()
    • ensureAcceptingRequests

      public void ensureAcceptingRequests()
    • registerRequest

      public String registerRequest(Agent agent)
    • bindRequestState

      public void bindRequestState(String requestId, AgentState state)
      Bind the per-call AgentState resolved for the in-flight request identified by requestId, so shutdown interruption and state-saving target that exact (userId, sessionId) session rather than the agent's no-arg "most-recently-active" accessors. Invoked by AgentBase once a call has activated its session slot. No-op when no request is tracked for the id or the state is null.
    • unregisterRequest

      public void unregisterRequest(String requestId)
    • interruptIfShuttingDown

      public void interruptIfShuttingDown(String requestId)
    • saveOnInterruptObserved

      public void saveOnInterruptObserved(String requestId)
      Called from agent's handleInterrupt when a SYSTEM interrupt is observed. Always saves because memory may have been updated after the previous safe-point/timeout save.
    • performGracefulShutdown

      public boolean performGracefulShutdown()
    • awaitTermination

      public boolean awaitTermination(Duration timeout)
      Block until the shutdown state reaches TERMINATED or the given timeout elapses.
      参数:
      timeout - maximum time to wait; null means wait indefinitely
      返回:
      true if TERMINATED was reached, false if timed out
    • resetForTesting

      public void resetForTesting()
      Reset manager state. Intended for testing and demo purposes only.