Skip to content

Commit 4ba6fe4

Browse files
committed
add more comments and remove registration from context
1 parent f6a4a62 commit 4ba6fe4

4 files changed

Lines changed: 11 additions & 14 deletions

File tree

sdk/src/main/java/software/amazon/lambda/durable/BaseContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public abstract class BaseContext {
1414
private final String contextId;
1515
private boolean isReplaying;
1616

17-
/** Shared initialization — sets all fields but performs no thread registration. */
17+
/** Creates a new BaseContext instance. */
1818
protected BaseContext(
1919
ExecutionManager executionManager, DurableConfig durableConfig, Context lambdaContext, String contextId) {
2020
this.executionManager = executionManager;

sdk/src/main/java/software/amazon/lambda/durable/DurableContext.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import java.util.function.Supplier;
1111
import org.slf4j.LoggerFactory;
1212
import software.amazon.lambda.durable.execution.ExecutionManager;
13-
import software.amazon.lambda.durable.execution.ThreadContext;
14-
import software.amazon.lambda.durable.execution.ThreadType;
1513
import software.amazon.lambda.durable.logging.DurableLogger;
1614
import software.amazon.lambda.durable.operation.CallbackOperation;
1715
import software.amazon.lambda.durable.operation.ChildContextOperation;
@@ -24,7 +22,7 @@ public class DurableContext extends BaseContext {
2422
private final AtomicInteger operationCounter;
2523
private final DurableLogger logger;
2624

27-
/** Shared initialization — sets all fields but performs no thread registration. */
25+
/** Shared initialization — sets all fields. */
2826
private DurableContext(
2927
ExecutionManager executionManager, DurableConfig durableConfig, Context lambdaContext, String contextId) {
3028
super(executionManager, durableConfig, lambdaContext, contextId);
@@ -39,7 +37,7 @@ private DurableContext(
3937
}
4038

4139
/**
42-
* Creates a root context and registers the current thread for execution coordination.
40+
* Creates a root context (contextId = null)
4341
*
4442
* <p>The context itself always has a null contextId (making it a root context).
4543
*
@@ -50,16 +48,11 @@ private DurableContext(
5048
*/
5149
public static DurableContext createRootContext(
5250
ExecutionManager executionManager, DurableConfig durableConfig, Context lambdaContext) {
53-
var ctx = new DurableContext(executionManager, durableConfig, lambdaContext, null);
54-
executionManager.registerActiveThread(null);
55-
executionManager.setCurrentThreadContext(new ThreadContext(null, ThreadType.CONTEXT));
56-
return ctx;
51+
return new DurableContext(executionManager, durableConfig, lambdaContext, null);
5752
}
5853

5954
/**
60-
* Creates a child context without registering the current thread. Thread registration is handled by
61-
* ChildContextOperation, which registers on the parent thread before the executor runs and sets the context on the
62-
* child thread inside the executor.
55+
* Creates a child context.
6356
*
6457
* @param childContextId the child context's ID (the CONTEXT operation's operation ID)
6558
* @return a new DurableContext for the child context

sdk/src/main/java/software/amazon/lambda/durable/DurableExecutor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import software.amazon.lambda.durable.exception.UnrecoverableDurableExecutionException;
2020
import software.amazon.lambda.durable.execution.ExecutionManager;
2121
import software.amazon.lambda.durable.execution.SuspendExecutionException;
22+
import software.amazon.lambda.durable.execution.ThreadContext;
23+
import software.amazon.lambda.durable.execution.ThreadType;
2224
import software.amazon.lambda.durable.model.DurableExecutionInput;
2325
import software.amazon.lambda.durable.model.DurableExecutionOutput;
2426
import software.amazon.lambda.durable.serde.SerDes;
@@ -45,6 +47,8 @@ public static <I, O> DurableExecutionOutput execute(
4547
extractUserInput(executionManager.getExecutionOperation(), config.getSerDes(), inputType);
4648
// Create context in the executor thread so it detects the correct thread name
4749
var context = DurableContext.createRootContext(executionManager, config, lambdaContext);
50+
executionManager.registerActiveThread(null);
51+
executionManager.setCurrentThreadContext(new ThreadContext(null, ThreadType.CONTEXT));
4852
return handler.apply(userInput, context);
4953
},
5054
config.getExecutorService()); // Get executor from config for running user code

sdk/src/main/java/software/amazon/lambda/durable/StepContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public class StepContext extends BaseContext {
1111
private final DurableLogger logger;
1212

1313
/**
14-
* Shared initialization — sets all fields but performs no thread registration.
14+
* Creates a new StepContext instance for use in step operations.
1515
*
1616
* @param executionManager Manages durable execution state and operations
1717
* @param durableConfig Configuration for durable execution behavior
1818
* @param lambdaContext AWS Lambda runtime context
19-
* @param stepOperationId Unique identifier for this context instance
19+
* @param stepOperationId Unique identifier for this context instance that equals to step operation id
2020
*/
2121
protected StepContext(
2222
ExecutionManager executionManager,

0 commit comments

Comments
 (0)