-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ectit/ocelot/core/instrumentation/correlation/log/adapters/JBossLogmanagerMDCAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package rocks.inspectit.ocelot.core.instrumentation.correlation.log.adapters; | ||
|
||
import rocks.inspectit.ocelot.config.model.tracing.TraceIdMDCInjectionSettings; | ||
import rocks.inspectit.ocelot.core.utils.WeakMethodReference; | ||
|
||
/** | ||
* Provides access to JBoss Logmanagers ThreadContext. | ||
* | ||
* @author boris_unckel | ||
*/ | ||
public class JBossLogmanagerMDCAdapter extends AbstractStaticMapMDCAdapter { | ||
|
||
/** | ||
* The name of the MDC class of JBoss Logmanager. | ||
*/ | ||
public static final String MDC_CLASS = "org.jboss.logmanager.MDC"; | ||
|
||
private JBossLogmanagerMDCAdapter(WeakMethodReference put, WeakMethodReference get, WeakMethodReference remove) { | ||
super(put, get, remove); | ||
} | ||
|
||
/** | ||
* Creates an Adapater given a JBoss Logmanager MDC class. | ||
* | ||
* @param mdcClazz the org.jboss.logmanager.MDC class | ||
* | ||
* @return an adapter for setting values on the given MDC. | ||
*/ | ||
public static JBossLogmanagerMDCAdapter get(Class<?> mdcClazz) { | ||
try { | ||
WeakMethodReference put = WeakMethodReference.create(mdcClazz, "put", String.class, String.class); | ||
WeakMethodReference get = WeakMethodReference.create(mdcClazz, "get", String.class); | ||
WeakMethodReference remove = WeakMethodReference.create(mdcClazz, "remove", String.class); | ||
return new JBossLogmanagerMDCAdapter(put, get, remove); | ||
} catch (NoSuchMethodException e) { | ||
throw new IllegalArgumentException("JBoss MDC class did not contain expected methods", e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isEnabledForConfig(TraceIdMDCInjectionSettings settings) { | ||
return settings.isJbossLogmanagerEnabled(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...t/ocelot/core/instrumentation/correlation/log/adapters/JBossLogmanagerMDCAdapterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package rocks.inspectit.ocelot.core.instrumentation.correlation.log.adapters; | ||
|
||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import rocks.inspectit.ocelot.core.instrumentation.correlation.log.MDCAccess; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class JBossLogmanagerMDCAdapterTest { | ||
|
||
private static class DummyMDC { | ||
|
||
private static Map<String, String> backingMap = new HashMap<>(); | ||
|
||
public static String get(String key) { | ||
return backingMap.get(key); | ||
} | ||
|
||
public static String put(String key, String value) { | ||
return backingMap.put(key, value); | ||
} | ||
|
||
public static String remove(String key) { | ||
return backingMap.remove(key); | ||
} | ||
} | ||
|
||
@Nested | ||
public static class Set { | ||
|
||
@Test | ||
void verifyMDCAccess() { | ||
DummyMDC.put("my_key", "default"); | ||
JBossLogmanagerMDCAdapter adapter = JBossLogmanagerMDCAdapter.get(DummyMDC.class); | ||
|
||
MDCAccess.Undo undo = adapter.set("my_key", "overridden"); | ||
assertThat(DummyMDC.get("my_key")).isEqualTo("overridden"); | ||
|
||
undo.close(); | ||
assertThat(DummyMDC.get("my_key")).isEqualTo("default"); | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters