类 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.
    • bindSession

      public void bindSession(Agent agent, Session session, SessionKey sessionKey)
    • checkAndClearShutdownInterrupted

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

      Called from GracefulShutdownHook at PreCallEvent 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)
    • unregisterRequest

      public void unregisterRequest(Agent agent)
    • interruptIfShuttingDown

      public void interruptIfShuttingDown(Agent agent)
    • saveOnInterruptObserved

      public void saveOnInterruptObserved(Agent agent)
      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.