Class BaseDurableOperation<T>

java.lang.Object
software.amazon.lambda.durable.operation.BaseDurableOperation<T>
All Implemented Interfaces:
DurableFuture<T>
Direct Known Subclasses:
CallbackOperation, ChildContextOperation, InvokeOperation, StepOperation, WaitOperation

public abstract class BaseDurableOperation<T> extends Object implements DurableFuture<T>
Base class for all durable operations (STEP, WAIT, etc.).

Key methods:

  • execute() starts the operation (returns immediately)
  • get() blocks until complete and returns the result

The separation allows:

  • Starting multiple async operations quickly
  • Blocking on results later when needed
  • Proper thread coordination via future
  • Field Details

  • Constructor Details

    • BaseDurableOperation

      protected BaseDurableOperation(String operationId, String name, software.amazon.awssdk.services.lambda.model.OperationType operationType, TypeToken<T> resultTypeToken, SerDes resultSerDes, DurableContext durableContext)
  • Method Details

    • getOperationId

      public String getOperationId()
      Gets the unique identifier for this operation.
    • getName

      public String getName()
      Gets the operation name (maybe null).
    • getContext

      protected DurableContext getContext()
      Gets the parent context.
    • getType

      public software.amazon.awssdk.services.lambda.model.OperationType getType()
      Gets the operation type
    • execute

      public void execute()
      Starts the operation, processes the operation updates from backend. Does not block.
    • start

      protected abstract void start()
      Starts the operation.
    • replay

      protected abstract void replay(software.amazon.awssdk.services.lambda.model.Operation existing)
      Replays the operation.
    • getOperation

      protected software.amazon.awssdk.services.lambda.model.Operation getOperation()
      Gets the Operation from ExecutionManager and update the replay state from REPLAY to EXECUTE if operation is not found. Operation IDs are globally unique (prefixed for child contexts), so no parentId is needed for lookups.
      Returns:
      the operation if found, otherwise null
    • getChildOperations

      protected List<software.amazon.awssdk.services.lambda.model.Operation> getChildOperations(String operationId)
      Gets the direct child Operations of a give context operation.
      Parameters:
      operationId - the operation id of the context
      Returns:
      list of the child Operations
    • isOperationCompleted

      protected boolean isOperationCompleted()
      Checks if this operation is completed
    • waitForOperationCompletion

      protected software.amazon.awssdk.services.lambda.model.Operation waitForOperationCompletion()
      Waits for the operation to complete and suspends the execution if no active thread is running
    • onCheckpointComplete

      public void onCheckpointComplete(software.amazon.awssdk.services.lambda.model.Operation operation)
      Receives operation updates from ExecutionManager and updates the internal state of the operation
    • markAlreadyCompleted

      protected void markAlreadyCompleted()
      Marks the operation as already completed (in replay).
    • terminateExecution

      protected T terminateExecution(UnrecoverableDurableExecutionException exception)
    • terminateExecutionWithIllegalDurableOperationException

      protected T terminateExecutionWithIllegalDurableOperationException(String message)
    • registerActiveThread

      protected void registerActiveThread(String threadId)
    • getCurrentThreadContext

      protected ThreadContext getCurrentThreadContext()
    • pollForOperationUpdates

      protected CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation> pollForOperationUpdates()
    • pollForOperationUpdates

      protected CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation> pollForOperationUpdates(Duration delay)
    • sendOperationUpdate

      protected void sendOperationUpdate(software.amazon.awssdk.services.lambda.model.OperationUpdate.Builder builder)
    • sendOperationUpdateAsync

      protected CompletableFuture<Void> sendOperationUpdateAsync(software.amazon.awssdk.services.lambda.model.OperationUpdate.Builder builder)
    • deserializeResult

      protected T deserializeResult(String result)
    • serializeResult

      protected String serializeResult(T result)
    • serializeException

      protected software.amazon.awssdk.services.lambda.model.ErrorObject serializeException(Throwable throwable)
    • deserializeException

      protected Throwable deserializeException(software.amazon.awssdk.services.lambda.model.ErrorObject errorObject)
    • validateReplay

      protected void validateReplay(software.amazon.awssdk.services.lambda.model.Operation checkpointed)
      Validates that current operation matches checkpointed operation during replay.