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, ExecutionManager executionManager, String parentId)
    • BaseDurableOperation

      public BaseDurableOperation(String operationId, String name, software.amazon.awssdk.services.lambda.model.OperationType operationType, TypeToken<T> resultTypeToken, SerDes resultSerDes, ExecutionManager executionManager)
      Convenience constructor for root-context operations where parentId is null.
  • Method Details

    • getOperationId

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

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

      protected String getParentId()
      Gets the parent context ID. Null for root-context operations, set for child context operations.
    • getType

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

      public abstract void execute()
      Starts the operation. Returns immediately after starting background work or checkpointing. Does not block.
    • 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
    • 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)
    • deregisterActiveThread

      protected void deregisterActiveThread(String threadId)
    • registerActiveThread

      protected void registerActiveThread(String threadId)
    • getCurrentThreadContext

      protected ThreadContext getCurrentThreadContext()
    • setCurrentThreadContext

      protected void setCurrentThreadContext(ThreadContext threadContext)
    • 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.