GracefulShutdownManager
public final class GracefulShutdownManager
io/agentscope/core/shutdown/GracefulShutdownManager.java:41–362Graceful Shutdown 管理器,为框架提供通用类型与基础能力。位于 io.agentscope.core.shutdown 包。核心成员包括 getInstance、getState、getConfig、setConfig、getShutdownTimeoutSignal、bindStateSaver。
Global manager for graceful shutdown lifecycle and active request tracking.
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static GracefulShutdownManager getInstance()static | 获取实例。 Returns the instance. |
public ShutdownState getState() | 获取状态。 Returns the state. |
public GracefulShutdownConfig getConfig() | 获取配置。 Returns the config. |
public void setConfig(GracefulShutdownConfig config) | 设置配置。 Sets the config. |
public Mono<Void> getShutdownTimeoutSignal() | 获取 `getShutdownTimeoutSignal`。 Returns a `Mono` that completes when the shutdown timeout is reached. |
public void bindStateSaver(Agent agent, ShutdownStateSaver saver) | 执行 `bindStateSaver` 方法。 Register a `ShutdownStateSaver` for the given agent. |
public void unbindStateSaver(Agent agent) | 设置该参数。 Remove the `ShutdownStateSaver` previously registered for the given agent. |
public boolean checkAndClearShutdownInterrupted(Agent agent) | 检查 `checkAndClearShutdownInterrupted` 条件。 Check whether the agent's default state was previously interrupted by shutdown, and clear
the flag. |
public boolean checkAndClearShutdownInterruptedForState(AgentState state) | 检查 `checkAndClearShutdownInterruptedForState` 条件。 Check whether a call-scoped state was previously interrupted by shutdown, and clear the flag. |
public boolean isAcceptingRequests() | 判断是否 `isAcceptingRequests`。 Returns whether the accepting requests. |
public int getActiveRequestCount() | 获取 `getActiveRequestCount`。 Returns the active request count. |
public void ensureAcceptingRequests() | 执行 `ensureAcceptingRequests` 方法。 Returns the ensure accepting requests. |
public String registerRequest(Agent agent, RunControl control) | 注册请求。 Registers the request. |
public void bindRequestState(String requestId, AgentState state) | 执行 `bindRequestState` 方法。 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. |
public void unregisterRequest(String requestId) | 注销请求。 Unregisters the request. |
public void interruptIfShuttingDown(String requestId) | 设置该参数。 Performs the interrupt if shutting down operation. |
public void saveOnInterruptObserved(String requestId) | 保存 `saveOnInterruptObserved`。 Called from agent's handleInterrupt when a SYSTEM interrupt is observed. |
public boolean performGracefulShutdown() | 返回 `performGracefulShutdown` 结果。 Returns the perform graceful shutdown. |
public boolean awaitTermination(Duration timeout) | 设置该参数。 Block until the shutdown state reaches TERMINATED or the given timeout elapses. |
public void resetForTesting() | 重置 `resetForTesting`。 Reset manager state. |
方法详情Method Detail
getInstance
public static GracefulShutdownManager getInstance()
获取实例。
Returns the instance.
GracefulShutdownManagerio/agentscope/core/shutdown/GracefulShutdownManager.java:82–84getState
public ShutdownState getState()
获取状态。
Returns the state.
ShutdownStateio/agentscope/core/shutdown/GracefulShutdownManager.java:86–88getConfig
public GracefulShutdownConfig getConfig()
获取配置。
Returns the config.
GracefulShutdownConfigio/agentscope/core/shutdown/GracefulShutdownManager.java:90–92setConfig
public void setConfig(GracefulShutdownConfig config)
设置配置。
Sets the config.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
config | GracefulShutdownConfig | 配置对象(类型 `GracefulShutdownConfig`)。The config. |
io/agentscope/core/shutdown/GracefulShutdownManager.java:94–96getShutdownTimeoutSignal
public Mono<Void> getShutdownTimeoutSignal()
获取 getShutdownTimeoutSignal。
Returns a Mono that completes when the shutdown timeout is reached.
Mono<Void>io/agentscope/core/shutdown/GracefulShutdownManager.java:102–104bindStateSaver
public void bindStateSaver(Agent agent, ShutdownStateSaver saver)
执行 bindStateSaver 方法。
Register a ShutdownStateSaver for the given agent.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。The agent. |
saver | ShutdownStateSaver | saver(类型 `ShutdownStateSaver`)。The saver. |
io/agentscope/core/shutdown/GracefulShutdownManager.java:112–117unbindStateSaver
public void unbindStateSaver(Agent agent)
设置该参数。
Remove the ShutdownStateSaver previously registered for the given agent.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。the agent whose saver should be removed; no-op if `null` |
io/agentscope/core/shutdown/GracefulShutdownManager.java:128–133checkAndClearShutdownInterrupted
public boolean checkAndClearShutdownInterrupted(Agent agent)
检查 checkAndClearShutdownInterrupted 条件。
Check whether the agent's default state was previously interrupted by shutdown, and clear the flag.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。The agent. |
booleanio/agentscope/core/shutdown/GracefulShutdownManager.java:145–150checkAndClearShutdownInterruptedForState
public boolean checkAndClearShutdownInterruptedForState(AgentState state)
检查 checkAndClearShutdownInterruptedForState 条件。
Check whether a call-scoped state was previously interrupted by shutdown, and clear the flag.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
state | AgentState | 已解析状态用于当前调用。the resolved state for the current call |
booleanio/agentscope/core/shutdown/GracefulShutdownManager.java:161–167isAcceptingRequests
public boolean isAcceptingRequests()
判断是否 isAcceptingRequests。
Returns whether the accepting requests.
booleanio/agentscope/core/shutdown/GracefulShutdownManager.java:169–171getActiveRequestCount
public int getActiveRequestCount()
获取 getActiveRequestCount。
Returns the active request count.
intio/agentscope/core/shutdown/GracefulShutdownManager.java:173–175ensureAcceptingRequests
public void ensureAcceptingRequests()
执行 ensureAcceptingRequests 方法。
Returns the ensure accepting requests.
io/agentscope/core/shutdown/GracefulShutdownManager.java:177–181registerRequest
public String registerRequest(Agent agent, RunControl control)
注册请求。
Registers the request.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。The agent. |
control | RunControl | control(类型 `RunControl`)。The control. |
Stringio/agentscope/core/shutdown/GracefulShutdownManager.java:183–192bindRequestState
public void bindRequestState(String requestId, AgentState state)
执行 bindRequestState 方法。
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
requestId | String | 请求标识(类型 `String`)。The request id. |
state | AgentState | 状态对象(类型 `AgentState`)。The state. |
io/agentscope/core/shutdown/GracefulShutdownManager.java:201–206unregisterRequest
public void unregisterRequest(String requestId)
注销请求。
Unregisters the request.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
requestId | String | 请求标识(类型 `String`)。The request id. |
io/agentscope/core/shutdown/GracefulShutdownManager.java:208–214interruptIfShuttingDown
public void interruptIfShuttingDown(String requestId)
设置该参数。
Performs the interrupt if shutting down operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
requestId | String | 请求标识(类型 `String`)。The request id. |
io/agentscope/core/shutdown/GracefulShutdownManager.java:223–231saveOnInterruptObserved
public void saveOnInterruptObserved(String requestId)
保存 saveOnInterruptObserved。
Called from agent's handleInterrupt when a SYSTEM interrupt is observed.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
requestId | String | 请求标识(类型 `String`)。The request id. |
io/agentscope/core/shutdown/GracefulShutdownManager.java:237–239performGracefulShutdown
public boolean performGracefulShutdown()
返回 performGracefulShutdown 结果。
Returns the perform graceful shutdown.
booleanio/agentscope/core/shutdown/GracefulShutdownManager.java:241–256awaitTermination
public boolean awaitTermination(Duration timeout)
设置该参数。
Block until the shutdown state reaches TERMINATED or the given timeout elapses.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
timeout | Duration | 超时时间(类型 `Duration`)。maximum time to wait; `null` means wait indefinitely |
booleanio/agentscope/core/shutdown/GracefulShutdownManager.java:326–345resetForTesting
public void resetForTesting()
重置 resetForTesting。
Reset manager state.
io/agentscope/core/shutdown/GracefulShutdownManager.java:350–361