Class LifecycleManager

java.lang.Object
com.tnsai.agents.lifecycle.LifecycleManager

public final class LifecycleManager extends Object
Manages agent lifecycle method execution based on Lifecycle annotations.

LifecycleManager scans agent classes for @Lifecycle annotated methods and invokes them at the appropriate lifecycle phases with proper timeout and async handling.

Key Features

  • Automatic discovery of @Lifecycle methods
  • Ordered execution within phases
  • Configurable timeout enforcement
  • Async execution support
  • Error handling and propagation

Usage Example


 LifecycleManager manager = LifecycleManager.getInstance();

 // Execute all INIT phase methods
 manager.executePhase(agent, Lifecycle.Phase.INIT);

 // Execute all START phase methods
 manager.executePhase(agent, Lifecycle.Phase.START);
 
Author:
TnsAI Team
See Also:
  • Method Details

    • getInstance

      public static LifecycleManager getInstance()
      Returns the singleton instance.
      Returns:
      the LifecycleManager instance
    • executePhase

      public void executePhase(Agent agent, Lifecycle.Phase phase) throws LifecycleManager.LifecycleException
      Executes all lifecycle methods for a given phase.

      Methods are executed in order (lowest order value first). Async methods are started but not awaited. Timeout is enforced per-method.

      Parameters:
      agent - the agent
      phase - the lifecycle phase
      Throws:
      LifecycleManager.LifecycleException - if a required method fails
    • executeErrorPhase

      public void executeErrorPhase(Agent agent, Throwable error)
      Executes the ERROR phase with the given error.
      Parameters:
      agent - the agent
      error - the error that occurred
    • clearCache

      public void clearCache()
      Clears the method cache (for testing).
    • shutdown

      public void shutdown()
      Shuts down the async executor.