Class GracefulShutdown

java.lang.Object
com.tnsai.coordination.lifecycle.GracefulShutdown

public final class GracefulShutdown extends Object
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));
 
  • Method Details

    • shutdown

      public static GracefulShutdown.ShutdownResult shutdown(DefaultAgentGroup group, Duration timeout)
      Performs a graceful shutdown of the group.

      The shutdown process:

      1. Records current members
      2. Removes all members one by one
      3. Stops the group if it is active
      4. Checks if the entire process completed within the timeout
      Parameters:
      group - the group to shut down
      timeout - 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 down
      timeout - maximum time to allow for shutdown
      Returns:
      future completing with the shutdown result
      Throws:
      NullPointerException - if group or timeout is null