类 GracefulShutdownManager
java.lang.Object
io.agentscope.core.shutdown.GracefulShutdownManager
Global manager for graceful shutdown lifecycle and active request tracking.
-
方法概要
修饰符和类型方法说明booleanawaitTermination(Duration timeout) Block until the shutdown state reaches TERMINATED or the given timeout elapses.voidbindRequestState(String requestId, AgentState state) Bind the per-callAgentStateresolved for the in-flight request identified byrequestId, so shutdown interruption and state-saving target that exact(userId, sessionId)session rather than the agent's no-arg "most-recently-active" accessors.voidbindStateSaver(Agent agent, ShutdownStateSaver saver) Register aShutdownStateSaverfor the given agent.booleanCheck whether the agent was previously interrupted by shutdown, and clear the flag.voidintstatic GracefulShutdownManagerreactor.core.publisher.Mono<Void> Returns aMonothat completes when the shutdown timeout is reached.getState()voidinterruptIfShuttingDown(String requestId) booleanbooleanregisterRequest(Agent agent) voidReset manager state.voidsaveOnInterruptObserved(String requestId) Called from agent's handleInterrupt when a SYSTEM interrupt is observed.voidsetConfig(GracefulShutdownConfig config) voidunregisterRequest(String requestId)
-
方法详细资料
-
getInstance
-
getState
-
getConfig
-
setConfig
-
getShutdownTimeoutSignal
Returns aMonothat completes when the shutdown timeout is reached. Tool executors can race their execution against this signal to abort early. -
bindStateSaver
Register aShutdownStateSaverfor the given agent.The saver is invoked during shutdown to persist the agent's
AgentState(withshutdownInterruptedset totrue). -
checkAndClearShutdownInterrupted
Check whether the agent was previously interrupted by shutdown, and clear the flag.Called from
GracefulShutdownMiddlewareon eachonAgentto 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
-
bindRequestState
Bind the per-callAgentStateresolved for the in-flight request identified byrequestId, so shutdown interruption and state-saving target that exact(userId, sessionId)session rather than the agent's no-arg "most-recently-active" accessors. Invoked byAgentBaseonce a call has activated its session slot. No-op when no request is tracked for the id or the state isnull. -
unregisterRequest
-
interruptIfShuttingDown
-
saveOnInterruptObserved
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
Block until the shutdown state reaches TERMINATED or the given timeout elapses.- 参数:
timeout- maximum time to wait;nullmeans 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.
-