Skip to content

Commit 30c2be8

Browse files
committed
Add thread context module
1 parent b5bcbc5 commit 30c2be8

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

thread-context/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
</dependencyManagement>
4444

4545
<dependencies>
46+
<dependency>
47+
<groupId>software.amazon.awssdk</groupId>
48+
<artifactId>annotations</artifactId>
49+
<version>${awsjavasdk.version}</version>
50+
</dependency>
4651
<dependency>
4752
<groupId>org.junit.jupiter</groupId>
4853
<artifactId>junit-jupiter</artifactId>

thread-context/src/main/java/software/amazon/awssdk/threadcontext/ThreadStorage.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,35 @@
1717

1818
import java.util.HashMap;
1919
import java.util.Map;
20+
import software.amazon.awssdk.annotations.SdkProtectedApi;
2021

22+
/**
23+
* Utility for thread-local context storage.
24+
*/
25+
@SdkProtectedApi
2126
public final class ThreadStorage {
22-
private static final ThreadLocal<Map<String, String>> storage = ThreadLocal.withInitial(HashMap::new);
27+
private static final ThreadLocal<Map<String, String>> STORAGE = ThreadLocal.withInitial(HashMap::new);
2328

24-
private ThreadStorage() {}
29+
private ThreadStorage() {
30+
}
2531

2632
public static void put(String key, String value) {
27-
storage.get().put(key, value);
33+
STORAGE.get().put(key, value);
2834
}
2935

3036
public static String get(String key) {
31-
return storage.get().get(key);
37+
return STORAGE.get().get(key);
3238
}
3339

3440
public static String remove(String key) {
35-
return storage.get().remove(key);
41+
return STORAGE.get().remove(key);
3642
}
3743

3844
public static void clear() {
39-
storage.get().clear();
45+
STORAGE.get().clear();
4046
}
4147

4248
public static boolean containsKey(String key) {
43-
return storage.get().containsKey(key);
49+
return STORAGE.get().containsKey(key);
4450
}
4551
}

0 commit comments

Comments
 (0)