Skip to content

Commit 13adc22

Browse files
committed
Adding thread context package
1 parent 5dac489 commit 13adc22

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@
252252
<artifactId>endpoints-spi</artifactId>
253253
<version>${awsjavasdk.version}</version>
254254
</dependency>
255+
<dependency>
256+
<groupId>software.amazon.awssdk</groupId>
257+
<artifactId>thread-context</artifactId>
258+
<version>${awsjavasdk.version}</version>
259+
</dependency>
255260
<!-- Services -->
256261
<dependency>
257262
<groupId>software.amazon.awssdk</groupId>

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<module>test/crt-unavailable-tests</module>
9696
<module>test/architecture-tests</module>
9797
<module>test/s3-tests</module>
98+
<module>thread-context</module>
9899
</modules>
99100
<scm>
100101
<url>${scm.github.url}</url>

thread-context/pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License").
6+
~ You may not use this file except in compliance with the License.
7+
~ A copy of the License is located at
8+
~
9+
~ http://aws.amazon.com/apache2.0
10+
~
11+
~ or in the "license" file accompanying this file. This file is distributed
12+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
~ express or implied. See the License for the specific language governing
14+
~ permissions and limitations under the License.
15+
-->
16+
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>software.amazon.awssdk</groupId>
23+
<artifactId>aws-sdk-java-pom</artifactId>
24+
<version>2.33.2-SNAPSHOT</version>
25+
</parent>
26+
<artifactId>thread-context</artifactId>
27+
<name>AWS Java SDK :: Thread Context</name>
28+
<description>
29+
Provides thread-local context storage utilities for sharing data across components.
30+
</description>
31+
<url>https://aws.amazon.com/sdkforjava</url>
32+
33+
</project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.threadcontext;
17+
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
21+
public final class ThreadStorage {
22+
private static final ThreadLocal<Map<String, String>> storage = ThreadLocal.withInitial(HashMap::new);
23+
24+
private ThreadStorage() {}
25+
26+
public static void put(String key, String value) {
27+
storage.get().put(key, value);
28+
}
29+
30+
public static String get(String key) {
31+
return storage.get().get(key);
32+
}
33+
34+
public static String remove(String key) {
35+
return storage.get().remove(key);
36+
}
37+
38+
public static void clear() {
39+
storage.get().clear();
40+
}
41+
42+
public static boolean containsKey(String key) {
43+
return storage.get().containsKey(key);
44+
}
45+
}

0 commit comments

Comments
 (0)