Package com.tnsai.agents.lifecycle
Class LifecycleManager
java.lang.Object
com.tnsai.agents.lifecycle.LifecycleManager
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when a lifecycle method fails.static classException thrown when a lifecycle method times out. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the method cache (for testing).voidexecuteErrorPhase(Agent agent, Throwable error) Executes the ERROR phase with the given error.voidexecutePhase(Agent agent, Lifecycle.Phase phase) Executes all lifecycle methods for a given phase.static LifecycleManagerReturns the singleton instance.voidshutdown()Shuts down the async executor.
-
Method Details
-
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 agentphase- the lifecycle phase- Throws:
LifecycleManager.LifecycleException- if a required method fails
-
executeErrorPhase
Executes the ERROR phase with the given error.- Parameters:
agent- the agenterror- the error that occurred
-
clearCache
public void clearCache()Clears the method cache (for testing). -
shutdown
public void shutdown()Shuts down the async executor.
-