public final class ContextTrampoline extends Object
ContextTrampoline provides methods for accessing and manipulating the context from
instrumented bytecode.
ContextTrampoline avoids tight coupling with the concrete implementation of the
context by accessing and manipulating the context through the ContextStrategy interface.
Both ContextTrampoline and ContextStrategy are loaded by the bootstrap
classloader so that they can be used from classes loaded by the bootstrap classloader. A concrete
implementation of ContextStrategy will be loaded by the system classloader. This allows
for using the same context implementation as the instrumented application.
ContextTrampoline is implemented as a static class to allow for easy and fast use from
instrumented bytecode. We cannot use dependency injection for the instrumented bytecode.
| Modifier and Type | Method and Description |
|---|---|
static void |
attachContextForThread(Thread thread)
Attaches the context that was previously saved for the specified thread.
|
static void |
saveContextForThread(Thread thread)
Saves the context that is associated with the current scope.
|
static void |
setContextStrategy(ContextStrategy contextStrategy)
Sets the concrete strategy for accessing and manipulating the context.
|
static Runnable |
wrapInCurrentContext(Runnable runnable)
Wraps a
Runnable so that it executes with the context that is associated with the
current scope. |
public static void setContextStrategy(ContextStrategy contextStrategy)
NB: The agent is responsible for setting the context strategy once before any other method of this class is called.
contextStrategy - the concrete strategy for accessing and manipulating the contextpublic static Runnable wrapInCurrentContext(Runnable runnable)
Runnable so that it executes with the context that is associated with the
current scope.runnable - a Runnable objectRunnable objectContextStrategy.wrapInCurrentContext(java.lang.Runnable)public static void saveContextForThread(Thread thread)
The context will be attached when entering the specified thread's Thread.run()
method.
thread - a Thread object