AS AgentScopeAPI 手册 / API Reference

GracefulShutdownManager

public final class GracefulShutdownManager
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:41–362

Graceful 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()
static

获取实例。

Returns the instance.

返回Returns GracefulShutdownManager
返回GracefulShutdownManager。Returns graceful shutdown manager.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:82–84

getState

public ShutdownState getState()

获取状态。

Returns the state.

返回Returns ShutdownState
返回ShutdownState。Returns shutdown state.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:86–88

getConfig

public GracefulShutdownConfig getConfig()

获取配置。

Returns the config.

返回Returns GracefulShutdownConfig
返回GracefulShutdownConfig。Returns graceful shutdown config.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:90–92

setConfig

public void setConfig(GracefulShutdownConfig config)

设置配置。

Sets the config.

参数Parameters
名称Name类型Type说明Description
configGracefulShutdownConfig配置对象(类型 `GracefulShutdownConfig`)。The config.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:94–96

getShutdownTimeoutSignal

public Mono<Void> getShutdownTimeoutSignal()

获取 getShutdownTimeoutSignal。

Returns a Mono that completes when the shutdown timeout is reached.

返回Returns Mono<Void>
返回Mono。Returns mono.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:102–104

bindStateSaver

public void bindStateSaver(Agent agent, ShutdownStateSaver saver)

执行 bindStateSaver 方法。

Register a ShutdownStateSaver for the given agent.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The agent.
saverShutdownStateSaversaver(类型 `ShutdownStateSaver`)。The saver.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:112–117

unbindStateSaver

public void unbindStateSaver(Agent agent)

设置该参数。

Remove the ShutdownStateSaver previously registered for the given agent.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。the agent whose saver should be removed; no-op if `null`
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:128–133

checkAndClearShutdownInterrupted

public boolean checkAndClearShutdownInterrupted(Agent agent)

检查 checkAndClearShutdownInterrupted 条件。

Check whether the agent's default state was previously interrupted by shutdown, and clear the flag.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The agent.
返回Returns boolean
返回布尔值,表示判断结果。true if the flag was present and cleared
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:145–150

checkAndClearShutdownInterruptedForState

public boolean checkAndClearShutdownInterruptedForState(AgentState state)

检查 checkAndClearShutdownInterruptedForState 条件。

Check whether a call-scoped state was previously interrupted by shutdown, and clear the flag.

参数Parameters
名称Name类型Type说明Description
stateAgentState已解析状态用于当前调用。the resolved state for the current call
返回Returns boolean
返回布尔值,表示判断结果。true if the flag was present and cleared
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:161–167

isAcceptingRequests

public boolean isAcceptingRequests()

判断是否 isAcceptingRequests。

Returns whether the accepting requests.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:169–171

getActiveRequestCount

public int getActiveRequestCount()

获取 getActiveRequestCount。

Returns the active request count.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:173–175

ensureAcceptingRequests

public void ensureAcceptingRequests()

执行 ensureAcceptingRequests 方法。

Returns the ensure accepting requests.

源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:177–181

registerRequest

public String registerRequest(Agent agent, RunControl control)

注册请求。

Registers the request.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The agent.
controlRunControlcontrol(类型 `RunControl`)。The control.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:183–192

bindRequestState

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.

参数Parameters
名称Name类型Type说明Description
requestIdString请求标识(类型 `String`)。The request id.
stateAgentState状态对象(类型 `AgentState`)。The state.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:201–206

unregisterRequest

public void unregisterRequest(String requestId)

注销请求。

Unregisters the request.

参数Parameters
名称Name类型Type说明Description
requestIdString请求标识(类型 `String`)。The request id.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:208–214

interruptIfShuttingDown

public void interruptIfShuttingDown(String requestId)

设置该参数。

Performs the interrupt if shutting down operation.

参数Parameters
名称Name类型Type说明Description
requestIdString请求标识(类型 `String`)。The request id.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:223–231

saveOnInterruptObserved

public void saveOnInterruptObserved(String requestId)

保存 saveOnInterruptObserved。

Called from agent's handleInterrupt when a SYSTEM interrupt is observed.

参数Parameters
名称Name类型Type说明Description
requestIdString请求标识(类型 `String`)。The request id.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:237–239

performGracefulShutdown

public boolean performGracefulShutdown()

返回 performGracefulShutdown 结果。

Returns the perform graceful shutdown.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:241–256

awaitTermination

public boolean awaitTermination(Duration timeout)

设置该参数。

Block until the shutdown state reaches TERMINATED or the given timeout elapses.

参数Parameters
名称Name类型Type说明Description
timeoutDuration超时时间(类型 `Duration`)。maximum time to wait; `null` means wait indefinitely
返回Returns boolean
返回布尔值,表示判断结果。true if TERMINATED was reached, false if timed out
源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:326–345

resetForTesting

public void resetForTesting()

重置 resetForTesting。

Reset manager state.

源码Source io/agentscope/core/shutdown/GracefulShutdownManager.java:350–361
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.