Skip to content

Commit dab06dc

Browse files
committed
Remove individual getters for refactored OperationContext record in execution manager.
1 parent e7b18e1 commit dab06dc

4 files changed

Lines changed: 11 additions & 25 deletions

File tree

sdk/src/main/java/com/amazonaws/lambda/durable/execution/ExecutionManager.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,6 @@ public OperationContext getCurrentContext() {
213213
return currentContext.get();
214214
}
215215

216-
/** Returns the ThreadType for the current thread, or null if not registered. */
217-
public ThreadType getCurrentThreadType() {
218-
var ctx = currentContext.get();
219-
return ctx != null ? ctx.threadType() : null;
220-
}
221-
222-
/** Returns the context ID for the current thread, or null if not registered. */
223-
public String getCurrentContextId() {
224-
var ctx = currentContext.get();
225-
return ctx != null ? ctx.contextId() : null;
226-
}
227-
228216
public void deregisterActiveThread(String threadId) {
229217
// Skip if already suspended
230218
if (suspendExecutionFuture.isDone()) {

sdk/src/main/java/com/amazonaws/lambda/durable/operation/StepOperation.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,10 @@ private void handleStepFailure(Throwable error, int attempt) {
296296
@Override
297297
public T get() {
298298
// Get current context from ThreadLocal (not thread name)
299-
var currentContextId = executionManager.getCurrentContextId();
300-
var currentThreadType = executionManager.getCurrentThreadType();
299+
var currentContext = executionManager.getCurrentContext();
301300

302301
// Nested steps are not supported - calling a step from within another step breaks replay consistency
303-
if (currentThreadType == ThreadType.STEP) {
302+
if (currentContext.threadType() == ThreadType.STEP) {
304303
throw new IllegalStateException("Nested step calling is not supported. Cannot call get() on step '" + name
305304
+ "' from within another step's execution.");
306305
}
@@ -314,15 +313,15 @@ public T get() {
314313
phaser.register();
315314

316315
// Deregister current context - allows suspension
317-
logger.debug("StepOperation.get() attempting to deregister context: {}", currentContextId);
318-
executionManager.deregisterActiveThread(currentContextId);
316+
logger.debug("StepOperation.get() attempting to deregister context: {}", currentContext.contextId());
317+
executionManager.deregisterActiveThread(currentContext.contextId());
319318

320319
// Block until operation completes
321320
logger.trace("Waiting for operation to finish {} (Phaser: {})", operationId, phaser);
322321
phaser.arriveAndAwaitAdvance(); // Wait for phase 0
323322

324323
// Reactivate current context
325-
executionManager.registerActiveThread(currentContextId, currentThreadType);
324+
executionManager.registerActiveThread(currentContext.contextId(), currentContext.threadType());
326325

327326
// Complete phase 1
328327
phaser.arriveAndDeregister();

sdk/src/main/java/com/amazonaws/lambda/durable/operation/WaitOperation.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,18 @@ public Void get() {
9797
phaser.register();
9898

9999
// Get current context from ThreadLocal
100-
var currentContextId = executionManager.getCurrentContextId();
101-
var currentThreadType = executionManager.getCurrentThreadType();
100+
var currentContext = executionManager.getCurrentContext();
102101

103102
// Deregister current thread - THIS is where suspension can happen!
104103
// If no other threads are active, this will throw SuspendExecutionException
105-
executionManager.deregisterActiveThread(currentContextId);
104+
executionManager.deregisterActiveThread(currentContext.contextId());
106105

107106
// Complete the wait phaser immediately (we don't actually wait in Lambda)
108107
// The backend handles the wait duration
109108
phaser.arriveAndAwaitAdvance(); // Phase 0 -> 1
110109

111110
// Reactivate current thread
112-
executionManager.registerActiveThread(currentContextId, currentThreadType);
111+
executionManager.registerActiveThread(currentContext.contextId(), currentContext.threadType());
113112

114113
// Complete phase 1
115114
phaser.arriveAndDeregister();

sdk/src/test/java/com/amazonaws/lambda/durable/operation/StepOperationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.mockito.Mockito.*;
77

88
import com.amazonaws.lambda.durable.execution.ExecutionManager;
9+
import com.amazonaws.lambda.durable.execution.OperationContext;
910
import com.amazonaws.lambda.durable.execution.ThreadType;
1011
import com.amazonaws.lambda.durable.logging.DurableLogger;
1112
import com.amazonaws.lambda.durable.serde.JacksonSerDes;
@@ -19,7 +20,7 @@ void getThrowsIllegalStateExceptionWhenCalledFromStepContext() {
1920
var executionManager = mock(ExecutionManager.class);
2021
var phaser = new Phaser(1);
2122
when(executionManager.startPhaser(any())).thenReturn(phaser);
22-
when(executionManager.getCurrentThreadType()).thenReturn(ThreadType.STEP);
23+
when(executionManager.getCurrentContext()).thenReturn(new OperationContext("1-step", ThreadType.STEP));
2324

2425
var operation = new StepOperation<>(
2526
"1",
@@ -42,8 +43,7 @@ void getDoesNotThrowWhenCalledFromHandlerContext() {
4243
var phaser = new Phaser(1);
4344
phaser.arriveAndDeregister(); // Advance to phase 1 to skip blocking
4445
when(executionManager.startPhaser(any())).thenReturn(phaser);
45-
when(executionManager.getCurrentThreadType()).thenReturn(ThreadType.CONTEXT);
46-
when(executionManager.getCurrentContextId()).thenReturn("handler");
46+
when(executionManager.getCurrentContext()).thenReturn(new OperationContext("handler", ThreadType.CONTEXT));
4747
when(executionManager.getOperation("1"))
4848
.thenReturn(software.amazon.awssdk.services.lambda.model.Operation.builder()
4949
.id("1")

0 commit comments

Comments
 (0)