From f65e40307855976a33dda27c75024a3b8099c9ea Mon Sep 17 00:00:00 2001 From: Stuart McCulloch Date: Thu, 19 Dec 2024 14:35:50 +0000 Subject: [PATCH] Move provider initialization-on-demand types to ContextProviders --- .../java/datadog/context/ContextBinder.java | 7 ------- .../java/datadog/context/ContextManager.java | 7 ------- .../java/datadog/context/ContextProviders.java | 18 ++++++++++++++++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/components/context/src/main/java/datadog/context/ContextBinder.java b/components/context/src/main/java/datadog/context/ContextBinder.java index bfcc85a887a..db461788942 100644 --- a/components/context/src/main/java/datadog/context/ContextBinder.java +++ b/components/context/src/main/java/datadog/context/ContextBinder.java @@ -24,11 +24,4 @@ public interface ContextBinder { static void register(ContextBinder binder) { ContextProviders.customBinder = binder; } - - final class Provided { - static final ContextBinder INSTANCE = - null != ContextProviders.customBinder - ? ContextProviders.customBinder - : new WeakMapContextBinder(); - } } diff --git a/components/context/src/main/java/datadog/context/ContextManager.java b/components/context/src/main/java/datadog/context/ContextManager.java index aa571a3a8ba..409bc8d1c94 100644 --- a/components/context/src/main/java/datadog/context/ContextManager.java +++ b/components/context/src/main/java/datadog/context/ContextManager.java @@ -31,11 +31,4 @@ public interface ContextManager { static void register(ContextManager manager) { ContextProviders.customManager = manager; } - - final class Provided { - static final ContextManager INSTANCE = - null != ContextProviders.customManager - ? ContextProviders.customManager - : new ThreadLocalContextManager(); - } } diff --git a/components/context/src/main/java/datadog/context/ContextProviders.java b/components/context/src/main/java/datadog/context/ContextProviders.java index e43d989bedc..6895446947a 100644 --- a/components/context/src/main/java/datadog/context/ContextProviders.java +++ b/components/context/src/main/java/datadog/context/ContextProviders.java @@ -6,11 +6,25 @@ final class ContextProviders { static volatile ContextManager customManager; static volatile ContextBinder customBinder; + private static final class ProvidedManager { + static final ContextManager INSTANCE = + null != ContextProviders.customManager + ? ContextProviders.customManager + : new ThreadLocalContextManager(); + } + + private static final class ProvidedBinder { + static final ContextBinder INSTANCE = + null != ContextProviders.customBinder + ? ContextProviders.customBinder + : new WeakMapContextBinder(); + } + static ContextManager manager() { - return ContextManager.Provided.INSTANCE; // may be overridden by instrumentation + return ProvidedManager.INSTANCE; // may be overridden by instrumentation } static ContextBinder binder() { - return ContextBinder.Provided.INSTANCE; // may be overridden by instrumentation + return ProvidedBinder.INSTANCE; // may be overridden by instrumentation } }