Skip to content

Commit

Permalink
Move provider initialization-on-demand types to ContextProviders
Browse files Browse the repository at this point in the history
  • Loading branch information
mcculls committed Dec 20, 2024
1 parent 3417e48 commit f65e403
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit f65e403

Please sign in to comment.