Class ExecutionManager
java.lang.Object
software.amazon.lambda.durable.execution.ExecutionManager
- All Implemented Interfaces:
AutoCloseable
Central manager for durable execution coordination.
Consolidates:
- Execution state (operations, checkpoint token)
- Thread lifecycle (registration/deregistration)
- Checkpoint batching (via CheckpointManager)
- Checkpoint result handling (CheckpointManager callback)
- Polling (for waits and retries)
This is the single entry point for all execution coordination. Internal coordination (polling, checkpointing) uses a dedicated SDK thread pool, while user-defined operations run on a customer-configured executor.
Operations are keyed by their globally unique operation ID. Child context operations use prefixed IDs (e.g., "1-1", "1-2") to avoid collisions with root-level operations.
- See Also:
-
InternalExecutor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shutdown the checkpoint batcher.voidderegisterActiveThread(String threadId) Mark a thread as inactive.List<software.amazon.awssdk.services.lambda.model.Operation>getChildOperations(String operationId) Gets all child operations for a given operationId.Returns the current thread's ThreadContext (threadId and threadType), or null if not set.Returns the ARN of the durable execution being managed.software.amazon.awssdk.services.lambda.model.OperationReturns the initial EXECUTION operation from the checkpoint state.software.amazon.awssdk.services.lambda.model.OperationgetOperationAndUpdateReplayState(String operationId) Gets an operation by its globally unique operationId, and updates replay state.booleanhasOperationsForContext(String parentId) Checks whether there are any cached operations for the given parent context ID.booleanreturnstrueif the execution is terminated exceptionally (with aSuspendExecutionExceptionor an unrecoverable error).booleanReturnstrueif the execution is currently replaying completed operations.static booleanisTerminalStatus(software.amazon.awssdk.services.lambda.model.OperationStatus status) Returnstrueif the given status represents a terminal (final) operation state.CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation>pollForOperationUpdates(String operationId) CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation>pollForOperationUpdates(String operationId, Instant at) Pools for operation updates at a specific timevoidregisterActiveThread(String threadId) Registers a thread as active.voidregisterOperation(BaseDurableOperation operation) Registers an operation so it can receive checkpoint completion notifications.<T> CompletableFuture<T>runUntilCompleteOrSuspend(CompletableFuture<T> userFuture) return a future that completes when userFuture completes successfully or the execution is terminated or suspended.sendOperationUpdate(software.amazon.awssdk.services.lambda.model.OperationUpdate update) voidsetCurrentThreadContext(ThreadContext threadContext) Sets the current thread's ThreadContext (threadId and threadType).voidSuspends the execution by completing the execution exception future with aSuspendExecutionException.voidTerminates the execution immediately with an unrecoverable error.
-
Constructor Details
-
ExecutionManager
-
-
Method Details
-
getDurableExecutionArn
Returns the ARN of the durable execution being managed. -
isReplaying
public boolean isReplaying()Returnstrueif the execution is currently replaying completed operations. -
registerOperation
Registers an operation so it can receive checkpoint completion notifications. -
getChildOperations
public List<software.amazon.awssdk.services.lambda.model.Operation> getChildOperations(String operationId) Gets all child operations for a given operationId.- Parameters:
operationId- the operationId to get children for- Returns:
- List of child operations for the given operationId
-
getOperationAndUpdateReplayState
public software.amazon.awssdk.services.lambda.model.Operation getOperationAndUpdateReplayState(String operationId) Gets an operation by its globally unique operationId, and updates replay state. Transitions from REPLAY to EXECUTION mode if the operation is not found or is not in a terminal state (still in progress).- Parameters:
operationId- the globally unique operation ID (e.g., "1" for root, "1-1" for child context)- Returns:
- the existing operation, or null if not found (first execution)
-
getExecutionOperation
public software.amazon.awssdk.services.lambda.model.Operation getExecutionOperation()Returns the initial EXECUTION operation from the checkpoint state. -
hasOperationsForContext
Checks whether there are any cached operations for the given parent context ID. Used to initialize per-context replay state — a context starts in replay mode if the ExecutionManager has cached operations belonging to it.- Parameters:
parentId- the context ID to check (null for root context)- Returns:
- true if at least one operation exists with the given parentId
-
setCurrentThreadContext
Sets the current thread's ThreadContext (threadId and threadType). Called when a user thread is started. -
getCurrentThreadContext
Returns the current thread's ThreadContext (threadId and threadType), or null if not set. -
registerActiveThread
Registers a thread as active.- See Also:
-
deregisterActiveThread
Mark a thread as inactive. If no threads remain, suspends the execution.- Parameters:
threadId- the thread ID to deregister
-
sendOperationUpdate
public CompletableFuture<Void> sendOperationUpdate(software.amazon.awssdk.services.lambda.model.OperationUpdate update) -
pollForOperationUpdates
public CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation> pollForOperationUpdates(String operationId) -
pollForOperationUpdates
public CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation> pollForOperationUpdates(String operationId, Instant at) Pools for operation updates at a specific time- Parameters:
operationId- the operation id to poll for updatesat- the time to poll for updates- Returns:
- a completable future that completes with the operation update
-
close
public void close()Shutdown the checkpoint batcher.- Specified by:
closein interfaceAutoCloseable
-
isTerminalStatus
public static boolean isTerminalStatus(software.amazon.awssdk.services.lambda.model.OperationStatus status) Returnstrueif the given status represents a terminal (final) operation state. -
terminateExecution
Terminates the execution immediately with an unrecoverable error.- Parameters:
exception- the unrecoverable exception that caused termination
-
suspendExecution
public void suspendExecution()Suspends the execution by completing the execution exception future with aSuspendExecutionException. -
isExecutionCompletedExceptionally
public boolean isExecutionCompletedExceptionally()returnstrueif the execution is terminated exceptionally (with aSuspendExecutionExceptionor an unrecoverable error). -
runUntilCompleteOrSuspend
return a future that completes when userFuture completes successfully or the execution is terminated or suspended.- Parameters:
userFuture- user provided function- Returns:
- a future of userFuture result if userFuture completes successfully, a user exception if userFuture completes with an exception, a SuspendExecutionException if the execution is suspended, or an UnrecoverableDurableExecutionException if the execution is terminated.
-