Class ExecutionManager

java.lang.Object
software.amazon.lambda.durable.execution.ExecutionManager
All Implemented Interfaces:
AutoCloseable

public class ExecutionManager extends Object implements 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 Details

  • Method Details

    • getDurableExecutionArn

      public String getDurableExecutionArn()
    • isReplaying

      public boolean isReplaying()
    • registerOperation

      public void registerOperation(BaseDurableOperation<?> operation)
    • 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()
    • hasOperationsForContext

      public boolean hasOperationsForContext(String parentId)
      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

      public void setCurrentThreadContext(ThreadContext threadContext)
      Sets the current thread's ThreadContext (threadId and threadType). Called when a user thread is started.
    • getCurrentThreadContext

      public ThreadContext getCurrentThreadContext()
      Returns the current thread's ThreadContext (threadId and threadType), or null if not set.
    • registerActiveThread

      public void registerActiveThread(String threadId)
      Registers a thread as active.
      See Also:
    • deregisterActiveThread

      public void deregisterActiveThread(String threadId)
      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)
    • close

      public void close()
      Shutdown the checkpoint batcher.
      Specified by:
      close in interface AutoCloseable
    • isTerminalStatus

      public static boolean isTerminalStatus(software.amazon.awssdk.services.lambda.model.OperationStatus status)
    • terminateExecution

      public void terminateExecution(UnrecoverableDurableExecutionException exception)
    • suspendExecution

      public void suspendExecution()
    • runUntilCompleteOrSuspend

      public <T> CompletableFuture<T> runUntilCompleteOrSuspend(CompletableFuture<T> userFuture)
      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.