Class DurableContextImpl
- All Implemented Interfaces:
AutoCloseable,BaseContext,DurableContext
Provides methods for creating steps, waits, chained invokes, callbacks, and child contexts. Each method creates a checkpoint-backed operation that survives Lambda interruptions.
-
Nested Class Summary
Nested classes/interfaces inherited from interface software.amazon.lambda.durable.DurableContext
DurableContext.MapFunction<I,O> -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Clears the logger's thread properties.<T> DurableCallbackFuture<T>createCallback(String name, TypeToken<T> resultType, CallbackConfig config) Creates a callback operation that suspends execution until an external system completes it.createChildContext(String childContextId, String childContextName) Creates a child context.static DurableContextImplcreateRootContext(ExecutionManager executionManager, DurableConfig durableConfig, com.amazonaws.services.lambda.runtime.Context lambdaContext) Creates a root context (contextId = null)createStepContext(String stepOperationId, String stepOperationName, int attempt) Creates a step context for executing step operations.Gets a logger with additional information of the current execution context.<T,U> DurableFuture<T> invokeAsync(String name, String functionName, U payload, TypeToken<T> resultType, InvokeConfig config) Asynchronously invokes another Lambda function using aTypeTokenand custom configuration.<I,O> DurableFuture<MapResult<O>> mapAsync(String name, Collection<I> items, TypeToken<O> resultType, DurableContext.MapFunction<I, O> function, MapConfig config) parallel(String name, ParallelConfig config) Creates aParallelDurableFuturefor executing multiple branches concurrently.<T> DurableFuture<T>runInChildContextAsync(String name, TypeToken<T> resultType, Function<DurableContext, T> func, RunInChildContextConfig config) Runs a function in a child context, blocking until it completes.<T> DurableFuture<T>stepAsync(String name, TypeToken<T> resultType, Function<StepContext, T> func, StepConfig config) Asynchronously executes a durable step using aTypeTokenand custom configuration.Asynchronously suspends execution for the specified duration.<T> DurableFuture<T>waitForCallbackAsync(String name, TypeToken<T> resultType, BiConsumer<String, StepContext> func, WaitForCallbackConfig waitForCallbackConfig) Asynchronously executes a submitter and waits for an external callback using aTypeTokenand custom configuration.<T> DurableFuture<T>waitForConditionAsync(String name, TypeToken<T> resultType, BiFunction<T, StepContext, WaitForConditionResult<T>> checkFunc, WaitForConditionConfig<T> config) Asynchronously polls a condition function until it signals done, using aTypeTokenand custom configuration.Methods inherited from class software.amazon.lambda.durable.context.BaseContextImpl
getContextId, getContextName, getDurableConfig, getExecutionArn, getExecutionManager, getLambdaContext, isReplaying, setExecutionModeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface software.amazon.lambda.durable.context.BaseContext
getContextId, getContextName, getDurableConfig, getExecutionArn, getLambdaContext, isReplayingMethods inherited from interface software.amazon.lambda.durable.DurableContext
createCallback, createCallback, createCallback, invoke, invoke, invoke, invoke, invokeAsync, invokeAsync, invokeAsync, map, map, map, map, mapAsync, mapAsync, mapAsync, parallel, runInChildContext, runInChildContext, runInChildContext, runInChildContext, runInChildContextAsync, runInChildContextAsync, runInChildContextAsync, step, step, step, step, step, step, step, step, stepAsync, stepAsync, stepAsync, stepAsync, stepAsync, stepAsync, stepAsync, wait, waitForCallback, waitForCallback, waitForCallback, waitForCallback, waitForCallbackAsync, waitForCallbackAsync, waitForCallbackAsync, waitForCondition, waitForCondition, waitForCondition, waitForCondition, waitForConditionAsync, waitForConditionAsync, waitForConditionAsync
-
Method Details
-
createRootContext
public static DurableContextImpl createRootContext(ExecutionManager executionManager, DurableConfig durableConfig, com.amazonaws.services.lambda.runtime.Context lambdaContext) Creates a root context (contextId = null)The context itself always has a null contextId (making it a root context).
- Parameters:
executionManager- the execution managerdurableConfig- the durable configurationlambdaContext- the Lambda context- Returns:
- a new root DurableContext
-
createChildContext
Creates a child context.- Parameters:
childContextId- the child context's ID (the CONTEXT operation's operation ID)childContextName- the name of the child context- Returns:
- a new DurableContext for the child context
-
createStepContext
public StepContextImpl createStepContext(String stepOperationId, String stepOperationName, int attempt) Creates a step context for executing step operations.- Parameters:
stepOperationId- the ID of the step operation (used for thread registration)stepOperationName- the name of the step operationattempt- the current retry attempt number (0-based)- Returns:
- a new StepContext instance
-
stepAsync
public <T> DurableFuture<T> stepAsync(String name, TypeToken<T> resultType, Function<StepContext, T> func, StepConfig config) Description copied from interface:DurableContextAsynchronously executes a durable step using aTypeTokenand custom configuration.This is the core stepAsync implementation. All other step/stepAsync overloads delegate here.
- Specified by:
stepAsyncin interfaceDurableContext- Type Parameters:
T- the result type- Parameters:
name- the unique operation name within this contextresultType- the type token for deserialization of generic typesfunc- the function to execute, receiving aStepContextconfig- the step configuration (retry strategy, semantics, custom SerDes)- Returns:
- a future representing the step result
-
waitAsync
Description copied from interface:DurableContextAsynchronously suspends execution for the specified duration.- Specified by:
waitAsyncin interfaceDurableContext- Parameters:
name- the unique operation name within this contextduration- the duration to wait- Returns:
- a future that completes when the wait duration has elapsed
-
invokeAsync
public <T,U> DurableFuture<T> invokeAsync(String name, String functionName, U payload, TypeToken<T> resultType, InvokeConfig config) Description copied from interface:DurableContextAsynchronously invokes another Lambda function using aTypeTokenand custom configuration.This is the core invokeAsync implementation. All other invoke/invokeAsync overloads delegate here.
- Specified by:
invokeAsyncin interfaceDurableContext- Type Parameters:
T- the result typeU- the payload type- Parameters:
name- the unique operation name within this contextfunctionName- the ARN or name of the Lambda function to invokepayload- the input payload to send to the target functionresultType- the type token for deserialization of generic result typesconfig- the invoke configuration (custom SerDes for result and payload)- Returns:
- a future representing the invocation result
-
createCallback
public <T> DurableCallbackFuture<T> createCallback(String name, TypeToken<T> resultType, CallbackConfig config) Description copied from interface:DurableContextCreates a callback operation that suspends execution until an external system completes it.This is the core createCallback implementation. Returns a
DurableCallbackFuturecontaining a callback ID that external systems use to report completion via the Lambda Durable API.- Specified by:
createCallbackin interfaceDurableContext- Type Parameters:
T- the result type- Parameters:
name- the unique operation name within this contextresultType- the type token for deserialization of generic result typesconfig- the callback configuration (custom SerDes)- Returns:
- a future containing the callback ID and eventual result
-
runInChildContextAsync
public <T> DurableFuture<T> runInChildContextAsync(String name, TypeToken<T> resultType, Function<DurableContext, T> func, RunInChildContextConfig config) Runs a function in a child context, blocking until it completes.Child contexts provide isolated operation ID namespaces, allowing nested workflows to be composed without ID collisions. On replay, the child context's operations are replayed independently.
- Specified by:
runInChildContextAsyncin interfaceDurableContext- Parameters:
name- the operation name within this contextresultType- the result class for deserializationfunc- the function to execute, receiving a childDurableContextconfig- the configuration for the child context- Returns:
- the DurableFuture wrapping the child context result
-
mapAsync
public <I,O> DurableFuture<MapResult<O>> mapAsync(String name, Collection<I> items, TypeToken<O> resultType, DurableContext.MapFunction<I, O> function, MapConfig config) - Specified by:
mapAsyncin interfaceDurableContext
-
parallel
Description copied from interface:DurableContextCreates aParallelDurableFuturefor executing multiple branches concurrently.- Specified by:
parallelin interfaceDurableContextconfig- the parallel execution configuration- Returns:
- a new ParallelDurableFuture for registering and executing branches
-
waitForCallbackAsync
public <T> DurableFuture<T> waitForCallbackAsync(String name, TypeToken<T> resultType, BiConsumer<String, StepContext> func, WaitForCallbackConfig waitForCallbackConfig) Description copied from interface:DurableContextAsynchronously executes a submitter and waits for an external callback using aTypeTokenand custom configuration.This is the core waitForCallbackAsync implementation. All other waitForCallback/waitForCallbackAsync overloads delegate here. Internally creates a child context containing a callback operation and a step that runs the submitter function.
- Specified by:
waitForCallbackAsyncin interfaceDurableContext- Type Parameters:
T- the result type- Parameters:
name- the unique operation name within this contextresultType- the type token for deserialization of generic result typesfunc- the submitter function, receiving the callback ID and aStepContextwaitForCallbackConfig- the configuration for both the callback and submitter step- Returns:
- a future representing the callback result
-
waitForConditionAsync
public <T> DurableFuture<T> waitForConditionAsync(String name, TypeToken<T> resultType, BiFunction<T, StepContext, WaitForConditionResult<T>> checkFunc, WaitForConditionConfig<T> config) Description copied from interface:DurableContextAsynchronously polls a condition function until it signals done, using aTypeTokenand custom configuration.This is the core waitForConditionAsync implementation. All other waitForCondition/waitForConditionAsync overloads delegate here.
- Specified by:
waitForConditionAsyncin interfaceDurableContext- Type Parameters:
T- the type of state being polled- Parameters:
name- the unique operation name within this contextresultType- the type token for deserialization of generic typescheckFunc- the function that evaluates the condition and returns aWaitForConditionResultconfig- the waitForCondition configuration (wait strategy, custom SerDes)- Returns:
- a future representing the final state value
-
getLogger
Description copied from interface:BaseContextGets a logger with additional information of the current execution context.- Specified by:
getLoggerin interfaceBaseContext- Returns:
- a DurableLogger instance
-
close
public void close()Clears the logger's thread properties. Called during context destruction to prevent memory leaks and ensure clean state for subsequent executions.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBaseContext
-