From 13adc2269d4a0110a0d1145951b9f7ef16eda3d7 Mon Sep 17 00:00:00 2001 From: RanVaknin <50976344+RanVaknin@users.noreply.github.com> Date: Tue, 2 Sep 2025 14:03:04 -0700 Subject: [PATCH 1/4] Adding thread context package --- bom/pom.xml | 5 +++ pom.xml | 1 + thread-context/pom.xml | 33 ++++++++++++++ .../awssdk/threadcontext/ThreadStorage.java | 45 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 thread-context/pom.xml create mode 100644 thread-context/src/main/java/software/amazon/awssdk/threadcontext/ThreadStorage.java diff --git a/bom/pom.xml b/bom/pom.xml index ede5b9251007..51494631af0f 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -252,6 +252,11 @@ endpoints-spi ${awsjavasdk.version} + + software.amazon.awssdk + thread-context + ${awsjavasdk.version} + software.amazon.awssdk diff --git a/pom.xml b/pom.xml index 42dbdbfc01bb..fd1409a27f37 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ test/crt-unavailable-tests test/architecture-tests test/s3-tests + thread-context ${scm.github.url} diff --git a/thread-context/pom.xml b/thread-context/pom.xml new file mode 100644 index 000000000000..e942f7e0a335 --- /dev/null +++ b/thread-context/pom.xml @@ -0,0 +1,33 @@ + + + + + 4.0.0 + + software.amazon.awssdk + aws-sdk-java-pom + 2.33.2-SNAPSHOT + + thread-context + AWS Java SDK :: Thread Context + + Provides thread-local context storage utilities for sharing data across components. + + https://aws.amazon.com/sdkforjava + + \ No newline at end of file diff --git a/thread-context/src/main/java/software/amazon/awssdk/threadcontext/ThreadStorage.java b/thread-context/src/main/java/software/amazon/awssdk/threadcontext/ThreadStorage.java new file mode 100644 index 000000000000..f7223a74f70c --- /dev/null +++ b/thread-context/src/main/java/software/amazon/awssdk/threadcontext/ThreadStorage.java @@ -0,0 +1,45 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.awssdk.threadcontext; + +import java.util.HashMap; +import java.util.Map; + +public final class ThreadStorage { + private static final ThreadLocal> storage = ThreadLocal.withInitial(HashMap::new); + + private ThreadStorage() {} + + public static void put(String key, String value) { + storage.get().put(key, value); + } + + public static String get(String key) { + return storage.get().get(key); + } + + public static String remove(String key) { + return storage.get().remove(key); + } + + public static void clear() { + storage.get().clear(); + } + + public static boolean containsKey(String key) { + return storage.get().containsKey(key); + } +} From 828dc504b6c255e9e09d3ea62496b926af382b9a Mon Sep 17 00:00:00 2001 From: RanVaknin <50976344+RanVaknin@users.noreply.github.com> Date: Tue, 2 Sep 2025 14:04:23 -0700 Subject: [PATCH 2/4] Fix ordering in pom --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fd1409a27f37..f5577c128f95 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,7 @@ archetypes third-party v2-migration + thread-context test/http-client-tests test/protocol-tests test/protocol-tests-core @@ -95,7 +96,6 @@ test/crt-unavailable-tests test/architecture-tests test/s3-tests - thread-context ${scm.github.url} From a6d60ec2c25eef7132100495651c0115e3130936 Mon Sep 17 00:00:00 2001 From: RanVaknin <50976344+RanVaknin@users.noreply.github.com> Date: Tue, 2 Sep 2025 14:17:23 -0700 Subject: [PATCH 3/4] Add changelog --- .changes/next-release/feature-AWSSDKforJavav2-2e7c0a3.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/next-release/feature-AWSSDKforJavav2-2e7c0a3.json diff --git a/.changes/next-release/feature-AWSSDKforJavav2-2e7c0a3.json b/.changes/next-release/feature-AWSSDKforJavav2-2e7c0a3.json new file mode 100644 index 000000000000..4b0c2020e6f1 --- /dev/null +++ b/.changes/next-release/feature-AWSSDKforJavav2-2e7c0a3.json @@ -0,0 +1,6 @@ +{ + "type": "feature", + "category": "AWS SDK for Java v2", + "contributor": "", + "description": "Adding a small utility class to store data on thread local that can be used across components." +} From b5bcbc50954a6373e25979a152fb433a81e67523 Mon Sep 17 00:00:00 2001 From: RanVaknin <50976344+RanVaknin@users.noreply.github.com> Date: Tue, 2 Sep 2025 14:53:12 -0700 Subject: [PATCH 4/4] Add requirements for publishing new package --- .brazil.json | 1 + aws-sdk-java/pom.xml | 5 ++ pom.xml | 1 + test/architecture-tests/pom.xml | 5 ++ test/tests-coverage-reporting/pom.xml | 5 ++ thread-context/pom.xml | 41 +++++++++++ .../threadcontext/ThreadStorageTest.java | 70 +++++++++++++++++++ 7 files changed, 128 insertions(+) create mode 100644 thread-context/src/test/java/software/amazon/awssdk/threadcontext/ThreadStorageTest.java diff --git a/.brazil.json b/.brazil.json index 7d240cb9bf5c..6acd1ba723b6 100644 --- a/.brazil.json +++ b/.brazil.json @@ -32,6 +32,7 @@ "s3-transfer-manager": { "packageName": "AwsJavaSdk-S3-TransferManager" }, "s3-event-notifications": { "packageName": "AwsJavaSdk-S3-EventNotifications" }, "sdk-core": { "packageName": "AwsJavaSdk-Core" }, + "thread-context": { "packageName": "AwsJavaSdk-ThreadContext" }, "url-connection-client": { "packageName": "AwsJavaSdk-HttpClient-UrlConnectionClient" }, "utils": { "packageName": "AwsJavaSdk-Core-Utils" }, "imds": { "packageName": "AwsJavaSdk-Imds" }, diff --git a/aws-sdk-java/pom.xml b/aws-sdk-java/pom.xml index 81f8e827a9ff..ac745e71fead 100644 --- a/aws-sdk-java/pom.xml +++ b/aws-sdk-java/pom.xml @@ -813,6 +813,11 @@ Amazon AutoScaling, etc). swf ${awsjavasdk.version} + + software.amazon.awssdk + thread-context + ${awsjavasdk.version} + software.amazon.awssdk textract diff --git a/pom.xml b/pom.xml index f5577c128f95..2e942d5f56e0 100644 --- a/pom.xml +++ b/pom.xml @@ -659,6 +659,7 @@ protocols regions sdk-core + thread-context http-client-spi apache-client netty-nio-client diff --git a/test/architecture-tests/pom.xml b/test/architecture-tests/pom.xml index 7b255deff4d5..ac97eb8cbc38 100644 --- a/test/architecture-tests/pom.xml +++ b/test/architecture-tests/pom.xml @@ -61,6 +61,11 @@ software.amazon.awssdk ${awsjavasdk.version} + + thread-context + software.amazon.awssdk + ${awsjavasdk.version} + s3 software.amazon.awssdk diff --git a/test/tests-coverage-reporting/pom.xml b/test/tests-coverage-reporting/pom.xml index 39e84897ced9..d730618895a0 100644 --- a/test/tests-coverage-reporting/pom.xml +++ b/test/tests-coverage-reporting/pom.xml @@ -242,6 +242,11 @@ software.amazon.awssdk ${awsjavasdk.version} + + thread-context + software.amazon.awssdk + ${awsjavasdk.version} +