Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first step toward using standard MPConfig property names #7794

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,18 @@ private ThreadContextProvider findConflictingProvider(ThreadContextProvider prov
* @param defaultValue value to use if not found in MicroProfile Config.
* @return default value.
*/
<T> T getDefault(String mpConfigPropName, T defaultValue) {
<T> T getDefault(String mpConfigPropName, String oldName, T defaultValue) { // TODO remove the old name after spec change
MPConfigAccessor accessor = cmProvider.mpConfigAccessor;
if (accessor != null) {
Object mpConfig = mpConfigRef.get();
if (mpConfig == Boolean.FALSE) // not initialized yet
if (!mpConfigRef.compareAndSet(Boolean.FALSE, mpConfig = accessor.getConfig()))
mpConfig = mpConfigRef.get();

if (mpConfig != null)
if (mpConfig != null) {
defaultValue = accessor.get(mpConfig, oldName, defaultValue); // TODO remove this line after spec change
defaultValue = accessor.get(mpConfig, mpConfigPropName, defaultValue);
}
}
return defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public class ManagedExecutorBuilderImpl implements ManagedExecutor.Builder {

@Override
public ManagedExecutor build() {
Set<String> cleared = this.cleared == null ? contextManager.getDefault("ManagedExecutor/cleared", DEFAULT_CLEARED) : this.cleared;
int maxAsync = this.maxAsync == UNDEFINED ? contextManager.getDefault("ManagedExecutor/maxAsync", -1) : this.maxAsync;
int maxQueued = this.maxQueued == UNDEFINED ? contextManager.getDefault("ManagedExecutor/maxQueued", -1) : this.maxQueued;
Set<String> propagated = this.propagated == null ? contextManager.getDefault("ManagedExecutor/propagated", DEFAULT_PROPAGATED) : this.propagated;
Set<String> cleared = this.cleared == null ? contextManager.getDefault("mp.context.ManagedExecutor.cleared", "ManagedExecutor/cleared", DEFAULT_CLEARED) : this.cleared;
int maxAsync = this.maxAsync == UNDEFINED ? contextManager.getDefault("mp.context.ManagedExecutor.maxAsync", "ManagedExecutor/maxAsync", -1) : this.maxAsync;
int maxQueued = this.maxQueued == UNDEFINED ? contextManager.getDefault("mp.context.ManagedExecutor.maxQueued", "ManagedExecutor/maxQueued", -1) : this.maxQueued;
Set<String> propagated = this.propagated == null ? contextManager.getDefault("mp.context.ManagedExecutor.propagated", "ManagedExecutor/propagated", DEFAULT_PROPAGATED) : this.propagated;

// For detection of unknown and overlapping types,
HashSet<String> unknown = new HashSet<String>(cleared);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public class ThreadContextBuilderImpl implements ThreadContext.Builder {

@Override
public ThreadContext build() {
Set<String> cleared = this.cleared == null ? contextManager.getDefault("ThreadContext/cleared", DEFAULT_CLEARED) : this.cleared;
Set<String> propagated = this.propagated == null ? contextManager.getDefault("ThreadContext/propagated", DEFAULT_PROPAGATED) : this.propagated;
Set<String> unchanged = this.unchanged == null ? contextManager.getDefault("ThreadContext/unchanged", DEFAULT_UNCHANGED) : this.unchanged;
Set<String> cleared = this.cleared == null ? contextManager.getDefault("mp.context.ThreadContext.cleared", "ThreadContext/cleared", DEFAULT_CLEARED) : this.cleared;
Set<String> propagated = this.propagated == null ? contextManager.getDefault("mp.context.ThreadContext.propagated", "ThreadContext/propagated", DEFAULT_PROPAGATED) : this.propagated;
Set<String> unchanged = this.unchanged == null ? contextManager.getDefault("mp.context.ThreadContext.unchanged", "ThreadContext/unchanged", DEFAULT_UNCHANGED) : this.unchanged;

// For detection of unknown and overlapping types,
HashSet<String> unknown = new HashSet<String>(cleared);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ManagedExecutor/maxAsync=2
ManagedExecutor/maxQueued=3
ManagedExecutor/cleared=Transaction
ManagedExecutor/propagated=City,Application
ThreadContext/cleared=
ThreadContext/propagated=State
ThreadContext/unchanged=Remaining
mp.context.ManagedExecutor.maxAsync=2
mp.context.ManagedExecutor.maxQueued=3
mp.context.ManagedExecutor.cleared=Transaction
mp.context.ManagedExecutor.propagated=City,Application
mp.context.ThreadContext.cleared=
mp.context.ThreadContext.propagated=State
mp.context.ThreadContext.unchanged=Remaining
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ public void testMPConfigDefaultsMaxQueued() throws Exception {
@Test
public void testMPConfigSpecifiesDefaultAsyncAndQueuedMaximumsForManagedExecutor() throws Exception {
// Defaults:
// ManagedExecutor/maxAsync=2
// ManagedExecutor/maxQueued=3
// mp.context.ManagedExecutor.maxAsync=2
// mp.context.ManagedExecutor.maxQueued=3
ManagedExecutor executor = ManagedExecutor.builder().build();

// schedule 2 tasks to block and wait for them to start
Expand Down Expand Up @@ -271,8 +271,8 @@ public void testMPConfigSpecifiesDefaultAsyncAndQueuedMaximumsForManagedExecutor
@Test
public void testMPConfigSpecifiesDefaultContextPropagationForManagedExecutor() throws Exception {
// Defaults:
// ManagedExecutor/cleared=Transaction
// ManagedExecutor/propagated=City,Application
// mp.context.ManagedExecutor.cleared=Transaction
// mp.context.ManagedExecutor.propagated=City,Application
ManagedExecutor executor = ManagedExecutor.builder()
.maxAsync(10)
.build();
Expand Down Expand Up @@ -304,9 +304,9 @@ public void testMPConfigSpecifiesDefaultContextPropagationForManagedExecutor() t
@Test
public void testMPConfigSpecifiesDefaultContextPropagationForThreadContext() throws Exception {
// Defaults:
// ThreadContext/cleared=
// ThreadContext/propagated=State
// ThreadContext/unchanged=Remaining
// mp.context.ThreadContext.cleared=
// mp.context.ThreadContext.propagated=State
// mp.context.ThreadContext.unchanged=Remaining
ThreadContext threadContext = ThreadContext.builder().build();

CurrentLocation.setLocation("Owatonna", "Minnesota");
Expand Down