-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBaseContextImpl.java
More file actions
112 lines (98 loc) · 3.61 KB
/
Copy pathBaseContextImpl.java
File metadata and controls
112 lines (98 loc) · 3.61 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// 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.Logger;
import software.amazon.lambda.durable.DurableConfig;
import software.amazon.lambda.durable.execution.ExecutionManager;
import software.amazon.lambda.durable.execution.ThreadType;
import software.amazon.lambda.durable.logging.DurableLogger;
public abstract class BaseContextImpl implements BaseContext {
private final ExecutionManager executionManager;
private final DurableConfig durableConfig;
private final Context lambdaContext;
private final String contextId;
private final String contextName;
private final ThreadType threadType;
/**
* Creates a new BaseContext instance.
*
* @param executionManager the execution manager for thread coordination and state management
* @param durableConfig the durable execution configuration
* @param lambdaContext the AWS Lambda runtime context
* @param contextId the context ID, null for root context, set for child contexts
* @param contextName the human-readable name for this context
* @param threadType the type of thread this context runs on
*/
protected BaseContextImpl(
ExecutionManager executionManager,
DurableConfig durableConfig,
Context lambdaContext,
String contextId,
String contextName,
ThreadType threadType) {
this.executionManager = executionManager;
this.durableConfig = durableConfig;
this.lambdaContext = lambdaContext;
this.contextId = contextId;
this.contextName = contextName;
this.threadType = threadType;
}
// =============== accessors ================
/**
* Returns the AWS Lambda runtime context.
*
* @return the Lambda context
*/
@Override
public Context getLambdaContext() {
return lambdaContext;
}
/**
* Returns metadata about the current durable execution.
*
* <p>The execution context provides information that remains constant throughout the execution lifecycle, such as
* the durable execution ARN. This is useful for tracking execution progress, correlating logs, and referencing this
* execution in external systems.
*
* @return the execution context
*/
@Override
public String getExecutionArn() {
return executionManager.getDurableExecutionArn();
}
/**
* Returns the configuration for durable execution behavior.
*
* @return the durable configuration
*/
@Override
public DurableConfig getDurableConfig() {
return durableConfig;
}
// ============= internal utilities ===============
/** Gets the context ID for this context. Null for root context, set for child contexts. */
@Override
public String getContextId() {
return contextId;
}
/** Gets the context name for this context. Null for root context. */
@Override
public String getContextName() {
return contextName;
}
public ExecutionManager getExecutionManager() {
return executionManager;
}
/** Returns a durable logger for this context. */
public DurableLogger getLogger() {
return DurableLogger.INSTANCE;
}
/** Returns a durable logger for this context. */
public DurableLogger getLogger(Logger delegate) {
return new DurableLogger(delegate);
}
public static void setCurrentContext(BaseContext context) {
CONTEXT.set(context);
}
}