Class BaseDurableOperation
java.lang.Object
software.amazon.lambda.durable.operation.BaseDurableOperation
- Direct Known Subclasses:
SerializableDurableOperation,WaitOperation
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final CompletableFuture<BaseDurableOperation>protected final ExecutionManagerprotected final BaseDurableOperation -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseDurableOperation(OperationIdentifier operationIdentifier, DurableContextImpl durableContext, BaseDurableOperation parentOperation) Constructs a new durable operation. -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()Starts the operation by checking for an existing checkpoint.protected List<software.amazon.awssdk.services.lambda.model.Operation>Gets the direct child Operations of this context operationprotected DurableContextImplGets the parent context.protected ThreadContextReturns the current thread's context from the execution manager.getName()Gets the operation name (may be null).protected software.amazon.awssdk.services.lambda.model.OperationGets the Operation from ExecutionManager and update the replay state from REPLAY to EXECUTE if operation is not found.Gets the unique identifier for this operation.Gets the operation sub-type (e.g.software.amazon.awssdk.services.lambda.model.OperationTypegetType()Gets the operation type.protected booleanReturns true if this operation has completed (successfully or exceptionally).protected voidMarks the operation as already completed (in replay).voidonCheckpointComplete(software.amazon.awssdk.services.lambda.model.Operation operation) Receives operation updates from ExecutionManager.protected CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation>Polls the backend for updates to this operation.protected CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation>Polls the backend for updates to this operation at a specific time.protected voidregisterActiveThread(String threadId) Registers a thread as active in the execution manager.protected abstract voidreplay(software.amazon.awssdk.services.lambda.model.Operation existing) Replays the operation from an existing checkpoint.protected voidrunUserHandler(Runnable runnable, String contextId, ThreadType threadType) protected voidsendOperationUpdate(software.amazon.awssdk.services.lambda.model.OperationUpdate.Builder builder) Sends an operation update synchronously (blocks until the update is acknowledged).protected CompletableFuture<Void>sendOperationUpdateAsync(software.amazon.awssdk.services.lambda.model.OperationUpdate.Builder builder) Sends an operation update asynchronously.protected abstract voidstart()Starts the operation on first execution (no existing checkpoint).protected RuntimeExceptionTerminates the execution with the given exception.protected RuntimeExceptionTerminates the execution with anIllegalDurableOperationException.protected voidvalidateReplay(software.amazon.awssdk.services.lambda.model.Operation checkpointed) Validates that current operation matches checkpointed operation during replay.protected software.amazon.awssdk.services.lambda.model.OperationWaits for the operation to complete.
-
Field Details
-
executionManager
-
completionFuture
-
parentOperation
-
-
Constructor Details
-
BaseDurableOperation
protected BaseDurableOperation(OperationIdentifier operationIdentifier, DurableContextImpl durableContext, BaseDurableOperation parentOperation) Constructs a new durable operation.- Parameters:
operationIdentifier- the unique identifier for this operationdurableContext- the parent context this operation belongs toparentOperation- the parent operation if this is a branch/iteration of a ConcurrencyOperation
-
-
Method Details
-
getCompletionFuture
-
getSubType
Gets the operation sub-type (e.g. RUN_IN_CHILD_CONTEXT, WAIT_FOR_CALLBACK). -
getOperationId
Gets the unique identifier for this operation. -
getName
Gets the operation name (may be null). -
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 by checking for an existing checkpoint. If a checkpoint exists, validates and replays it; otherwise starts fresh execution. -
start
protected abstract void start()Starts the operation on first execution (no existing checkpoint). -
replay
protected abstract void replay(software.amazon.awssdk.services.lambda.model.Operation existing) Replays the operation from an existing checkpoint.- Parameters:
existing- the checkpointed operation state
-
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
Gets the direct child Operations of this context operation- Returns:
- list of the child Operations
-
isOperationCompleted
protected boolean isOperationCompleted()Returns true if this operation has completed (successfully or exceptionally). -
waitForOperationCompletion
protected software.amazon.awssdk.services.lambda.model.Operation waitForOperationCompletion()Waits for the operation to complete. Deregisters the current thread to allow Lambda suspension if the operation is still in progress, then re-registers when the operation completes.- Returns:
- the completed operation
-
runUserHandler
-
onCheckpointComplete
public void onCheckpointComplete(software.amazon.awssdk.services.lambda.model.Operation operation) Receives operation updates from ExecutionManager. Completes the internal future when the operation reaches a terminal status, unblocking any threads waiting on this operation.- Parameters:
operation- the updated operation state
-
markAlreadyCompleted
protected void markAlreadyCompleted()Marks the operation as already completed (in replay). -
terminateExecution
Terminates the execution with the given exception.- Parameters:
exception- the unrecoverable exception- Returns:
- never returns normally; always throws
-
terminateExecutionWithIllegalDurableOperationException
Terminates the execution with anIllegalDurableOperationException.- Parameters:
message- the error message- Returns:
- never returns normally; always throws
-
registerActiveThread
Registers a thread as active in the execution manager.- Parameters:
threadId- the thread identifier to register
-
getCurrentThreadContext
Returns the current thread's context from the execution manager. -
pollForOperationUpdates
protected CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation> pollForOperationUpdates()Polls the backend for updates to this operation. -
pollForOperationUpdates
protected CompletableFuture<software.amazon.awssdk.services.lambda.model.Operation> pollForOperationUpdates(Instant at) Polls the backend for updates to this operation at a specific time.- Parameters:
at- the time to poll for updates- Returns:
- a future that completes with the updated operation
-
sendOperationUpdate
protected void sendOperationUpdate(software.amazon.awssdk.services.lambda.model.OperationUpdate.Builder builder) Sends an operation update synchronously (blocks until the update is acknowledged). -
sendOperationUpdateAsync
protected CompletableFuture<Void> sendOperationUpdateAsync(software.amazon.awssdk.services.lambda.model.OperationUpdate.Builder builder) Sends an operation update asynchronously. -
validateReplay
protected void validateReplay(software.amazon.awssdk.services.lambda.model.Operation checkpointed) Validates that current operation matches checkpointed operation during replay.
-