Class ExecutionManager
java.lang.Object
software.amazon.lambda.durable.execution.ExecutionManager
Central manager for durable execution coordination.
Consolidates:
- Execution state (operations, checkpoint token)
- Thread lifecycle (registration/deregistration)
- Checkpoint batching (via CheckpointBatcher)
- Checkpoint result handling (CheckpointBatcher 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:
-
Constructor Summary
ConstructorsConstructorDescriptionExecutionManager(String durableExecutionArn, String checkpointToken, software.amazon.awssdk.services.lambda.model.CheckpointUpdatedExecutionState initialExecutionState, DurableConfig config) -
Method Summary
Modifier and TypeMethodDescriptionvoidderegisterActiveThread(String threadId) Mark a thread as inactive.Returns the current thread's ThreadContext (threadId and threadType), or null if not set.software.amazon.awssdk.services.lambda.model.Operationsoftware.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.booleanstatic booleanisTerminalStatus(software.amazon.awssdk.services.lambda.model.OperationStatus status) CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation> pollForOperationUpdates(String operationId) CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation> pollForOperationUpdates(String operationId, Duration delay) voidregisterActiveThread(String threadId) Registers a thread as active.voidregisterOperation(BaseDurableOperation<?> operation) <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).voidshutdown()voidvoid
-
Constructor Details
-
ExecutionManager
public ExecutionManager(String durableExecutionArn, String checkpointToken, software.amazon.awssdk.services.lambda.model.CheckpointUpdatedExecutionState initialExecutionState, DurableConfig config)
-
-
Method Details
-
getDurableExecutionArn
-
isReplaying
public boolean isReplaying() -
registerOperation
-
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() -
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, Duration delay) -
shutdown
public void shutdown() -
isTerminalStatus
public static boolean isTerminalStatus(software.amazon.awssdk.services.lambda.model.OperationStatus status) -
terminateExecution
-
suspendExecution
public void suspendExecution() -
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.
-