Skip to content

Commit

Permalink
Switch from SetOne to AtomicRef
Browse files Browse the repository at this point in the history
  • Loading branch information
tvernum committed Apr 2, 2024
1 parent b9c3893 commit 07089c6
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
package org.elasticsearch.common.logging;

import org.apache.logging.log4j.core.util.ContextDataProvider;
import org.apache.lucene.util.SetOnce;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
* An implementation of log4j2's {@link ContextDataProvider} that can be configured at runtime
Expand All @@ -31,10 +31,11 @@
*/
public class DynamicContextDataProvider implements ContextDataProvider {

private static final SetOnce<List<? extends LoggingDataProvider>> DATA_PROVIDERS = new SetOnce<>();
// This is not a set-once because some integration tests may try to set it twice
private static final AtomicReference<List<? extends LoggingDataProvider>> DATA_PROVIDERS = new AtomicReference<>();

public static void setDataProviders(List<? extends LoggingDataProvider> dataProviders) {
DynamicContextDataProvider.DATA_PROVIDERS.set(List.copyOf(dataProviders));
DynamicContextDataProvider.DATA_PROVIDERS.compareAndSet(null, List.copyOf(dataProviders));
}

@Override
Expand Down

0 comments on commit 07089c6

Please sign in to comment.