Skip to content

Commit f6a4a62

Browse files
committed
add more javadoc and minor code cleanups
1 parent 0b0ae78 commit f6a4a62

5 files changed

Lines changed: 25 additions & 16 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,18 @@ protected BaseContext(
2626
}
2727

2828
// =============== accessors ================
29+
/**
30+
* Gets a logger with additional information of the current execution context.
31+
*
32+
* @return a DurableLogger instance
33+
*/
2934
public abstract DurableLogger getLogger();
3035

36+
/**
37+
* Returns the AWS Lambda runtime context.
38+
*
39+
* @return the Lambda context
40+
*/
3141
public Context getLambdaContext() {
3242
return lambdaContext;
3343
}

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@
2323
public class DurableContext extends BaseContext {
2424
private final AtomicInteger operationCounter;
2525
private final DurableLogger logger;
26-
private final ExecutionContext executionContext;
2726

2827
/** Shared initialization — sets all fields but performs no thread registration. */
2928
private DurableContext(
3029
ExecutionManager executionManager, DurableConfig durableConfig, Context lambdaContext, String contextId) {
3130
super(executionManager, durableConfig, lambdaContext, contextId);
3231
this.operationCounter = new AtomicInteger(0);
33-
this.executionContext = new ExecutionContext(executionManager.getDurableExecutionArn());
3432

3533
var requestId = lambdaContext != null ? lambdaContext.getAwsRequestId() : null;
3634
this.logger = new DurableLogger(
@@ -73,6 +71,7 @@ public DurableContext createChildContext(String childContextId) {
7371
/**
7472
* Creates a step context for executing step operations.
7573
*
74+
* @param stepOperationId the ID of the step operation (used for thread registration)
7675
* @return a new StepContext instance
7776
*/
7877
public StepContext createStepContext(String stepOperationId) {
@@ -307,21 +306,19 @@ public <T> DurableFuture<T> runInChildContextAsync(
307306
}
308307

309308
// =============== accessors ================
310-
311309
/**
312-
* Gets a logger with additional information of the current execution context.
310+
* Returns a logger with execution context information for replay-aware logging.
313311
*
314-
* @return a DurableLogger instance
312+
* @return the durable logger
315313
*/
316314
public DurableLogger getLogger() {
317315
return logger;
318316
}
319317

320318
/**
321319
* Get the next operationId. For root contexts, returns sequential IDs like "1", "2", "3". For child contexts,
322-
* prefixes with the getContextId() to ensure global uniqueness, e.g. "1-1", "1-2" for operations inside child
323-
* context "1". This matches the JavaScript SDK's stepPrefix convention and prevents ID collisions in checkpoint
324-
* batches.
320+
* prefixes with the contextId to ensure global uniqueness, e.g. "1-1", "1-2" for operations inside child context
321+
* "1". This matches the JavaScript SDK's stepPrefix convention and prevents ID collisions in checkpoint batches.
325322
*/
326323
private String nextOperationId() {
327324
var counter = String.valueOf(operationCounter.incrementAndGet());

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ public class StepContext extends BaseContext {
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 contextId Unique identifier for this context instance
19+
* @param stepOperationId Unique identifier for this context instance
2020
*/
2121
protected StepContext(
22-
ExecutionManager executionManager, DurableConfig durableConfig, Context lambdaContext, String contextId) {
23-
super(executionManager, durableConfig, lambdaContext, contextId);
22+
ExecutionManager executionManager,
23+
DurableConfig durableConfig,
24+
Context lambdaContext,
25+
String stepOperationId) {
26+
super(executionManager, durableConfig, lambdaContext, stepOperationId);
2427

2528
var requestId = lambdaContext != null ? lambdaContext.getAwsRequestId() : null;
2629
this.logger = new DurableLogger(

sdk/src/main/java/software/amazon/lambda/durable/operation/CallbackOperation.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33
package software.amazon.lambda.durable.operation;
44

5-
import org.slf4j.Logger;
6-
import org.slf4j.LoggerFactory;
75
import software.amazon.awssdk.services.lambda.model.CallbackOptions;
86
import software.amazon.awssdk.services.lambda.model.OperationAction;
97
import software.amazon.awssdk.services.lambda.model.OperationType;
@@ -18,8 +16,6 @@
1816
/** Durable operation for creating and waiting on external callbacks. */
1917
public class CallbackOperation<T> extends BaseDurableOperation<T> implements DurableCallbackFuture<T> {
2018

21-
private static final Logger logger = LoggerFactory.getLogger(CallbackOperation.class);
22-
2319
private final CallbackConfig config;
2420

2521
private String callbackId;

sdk/src/main/java/software/amazon/lambda/durable/operation/ChildContextOperation.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static software.amazon.lambda.durable.model.OperationSubType.RUN_IN_CHILD_CONTEXT;
66

77
import java.nio.charset.StandardCharsets;
8+
import java.util.concurrent.ExecutorService;
89
import java.util.function.Function;
910
import software.amazon.awssdk.services.lambda.model.ContextOptions;
1011
import software.amazon.awssdk.services.lambda.model.ErrorObject;
@@ -34,6 +35,7 @@ public class ChildContextOperation<T> extends BaseDurableOperation<T> {
3435
private static final int LARGE_RESULT_THRESHOLD = 256 * 1024;
3536

3637
private final Function<DurableContext, T> function;
38+
private final ExecutorService userExecutor;
3739
private boolean replayChildContext;
3840
private T reconstructedResult;
3941

@@ -46,6 +48,7 @@ public ChildContextOperation(
4648
DurableContext durableContext) {
4749
super(operationId, name, OperationType.CONTEXT, resultTypeToken, resultSerDes, durableContext);
4850
this.function = function;
51+
this.userExecutor = getContext().getDurableConfig().getExecutorService();
4952
}
5053

5154
@Override
@@ -93,7 +96,7 @@ private void executeChildContext() {
9396
// registerActiveThread is idempotent (no-op if already registered).
9497
registerActiveThread(contextId);
9598

96-
getContext().getDurableConfig().getExecutorService().execute(() -> {
99+
userExecutor.execute(() -> {
97100
setCurrentThreadContext(new ThreadContext(contextId, ThreadType.CONTEXT));
98101
try {
99102
var childContext = getContext().createChildContext(contextId);

0 commit comments

Comments
 (0)