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()
      Returns the ARN of the durable execution being managed.
    • isReplaying

      public boolean isReplaying()
      Returns true if the execution is currently replaying completed operations.
    • registerOperation

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

      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, Instant at)
      Pools for operation updates at a specific time
      Parameters:
      operationId - the operation id to poll for updates
      at - 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:
      close in interface AutoCloseable
    • isTerminalStatus

      public static boolean isTerminalStatus(software.amazon.awssdk.services.lambda.model.OperationStatus status)
      Returns true if the given status represents a terminal (final) operation state.
    • terminateExecution

      public void terminateExecution(UnrecoverableDurableExecutionException exception)
      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 a SuspendExecutionException.
    • isExecutionCompletedExceptionally

      public boolean isExecutionCompletedExceptionally()
      returns true if the execution is terminated exceptionally (with a SuspendExecutionException or an unrecoverable error).
    • 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.