-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathStepContextImpl.java
More file actions
71 lines (65 loc) · 2.5 KB
/
StepContextImpl.java
File metadata and controls
71 lines (65 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package software.amazon.lambda.durable.context;
import com.amazonaws.services.lambda.runtime.Context;
import org.slf4j.LoggerFactory;
import software.amazon.lambda.durable.DurableConfig;
import software.amazon.lambda.durable.StepContext;
import software.amazon.lambda.durable.execution.ExecutionManager;
import software.amazon.lambda.durable.execution.ThreadType;
import software.amazon.lambda.durable.logging.DurableLogger;
/**
* Context available inside a step operation's user function.
*
* <p>Provides access to the current retry attempt number and a logger that includes execution metadata. Extends
* {@link BaseContext} for thread lifecycle management.
*/
public class StepContextImpl extends BaseContextImpl implements StepContext {
private volatile DurableLogger logger;
private final int attempt;
/**
* Creates a new StepContext instance for use in step operations.
*
* @param executionManager Manages durable execution state and operations
* @param durableConfig Configuration for durable execution behavior
* @param lambdaContext AWS Lambda runtime context
* @param stepOperationId Unique identifier for this context instance that equals to step operation id
* @param stepOperationName the name of the step operation
* @param attempt the current retry attempt number (0-based)
*/
protected StepContextImpl(
ExecutionManager executionManager,
DurableConfig durableConfig,
Context lambdaContext,
String stepOperationId,
String stepOperationName,
int attempt) {
super(executionManager, durableConfig, lambdaContext, stepOperationId, stepOperationName, ThreadType.STEP);
this.attempt = attempt;
}
/** Returns the current retry attempt number (0-based). */
@Override
public int getAttempt() {
return attempt;
}
@Override
public DurableLogger getLogger() {
// lazy initialize logger
if (logger == null) {
synchronized (this) {
if (logger == null) {
logger = new DurableLogger(LoggerFactory.getLogger(StepContext.class), this);
}
}
}
return logger;
}
/** Closes the logger for this context. */
@Override
public void close() {
if (logger != null) {
logger.close();
}
super.close();
}
}