Package com.tnsai.coordination.lifecycle
Class GracefulShutdown
java.lang.Object
com.tnsai.coordination.lifecycle.GracefulShutdown
Orchestrates graceful shutdown of an agent group.
GracefulShutdown removes all members from a group and stops it within a specified timeout. If the timeout is exceeded, the shutdown is considered non-graceful and completes with that indication.
Usage Example
// Synchronous shutdown with 30-second timeout
ShutdownResult result = GracefulShutdown.shutdown(group, Duration.ofSeconds(30));
// Async shutdown
CompletableFuture<ShutdownResult> future = GracefulShutdown.shutdownAsync(group, Duration.ofSeconds(30));
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of a group shutdown operation. -
Method Summary
Modifier and TypeMethodDescriptionshutdown(DefaultAgentGroup group, Duration timeout) Performs a graceful shutdown of the group.shutdownAsync(DefaultAgentGroup group, Duration timeout) Performs an asynchronous graceful shutdown of the group.
-
Method Details
-
shutdown
Performs a graceful shutdown of the group.The shutdown process:
- Records current members
- Removes all members one by one
- Stops the group if it is active
- Checks if the entire process completed within the timeout
- Parameters:
group- the group to shut downtimeout- maximum time to allow for shutdown- Returns:
- result describing the shutdown outcome
- Throws:
NullPointerException- if group or timeout is null
-
shutdownAsync
public static CompletableFuture<GracefulShutdown.ShutdownResult> shutdownAsync(DefaultAgentGroup group, Duration timeout) Performs an asynchronous graceful shutdown of the group.- Parameters:
group- the group to shut downtimeout- maximum time to allow for shutdown- Returns:
- future completing with the shutdown result
- Throws:
NullPointerException- if group or timeout is null
-