Class FieldBackedProvider

  • All Implemented Interfaces:
    InstrumentationContextProvider

    public class FieldBackedProvider
    extends Object
    implements InstrumentationContextProvider
    InstrumentationContextProvider which stores context in a field that is injected into a class and falls back to global map if field was not injected.

    This is accomplished by

    1. Injecting a Dynamic Interface that provides getter and setter for context field
    2. Applying Dynamic Interface to a type needing context, implementing interface methods and adding context storage field
    3. Injecting a Dynamic Class created from FieldBackedProvider.ContextStoreImplementationTemplate to use injected field or fall back to a static map
    4. Rewriting calls to the context-store to access the specific dynamic FieldBackedProvider.ContextStoreImplementationTemplate

    Example:
    InstrumentationContext.get(Runnable.class, RunnableState.class)")
    is rewritten to:
    FieldBackedProvider$ContextStore$Runnable$RunnableState12345.getContextStore(runnableRunnable.class, RunnableState.class)

    • Constructor Detail

      • FieldBackedProvider

        public FieldBackedProvider​(Class<?> instrumenterClass,
                                   Map<String,​String> contextStore)
    • Method Detail

      • instrumentationTransformer

        public net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable instrumentationTransformer​(net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable builder)
        Description copied from interface: InstrumentationContextProvider
        Hook to provide an agent builder after advice is applied to target class. Used to implement context-store lookup.
        Specified by:
        instrumentationTransformer in interface InstrumentationContextProvider
      • resetContextMatchers

        public static void resetContextMatchers()
        Clear set that prevents multiple matchers for same context class.
      • additionalInstrumentation

        public net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable additionalInstrumentation​(net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable builder)
        Description copied from interface: InstrumentationContextProvider
        Hook to define additional instrumentation. Run at instrumentation advice is hooked up.
        Specified by:
        additionalInstrumentation in interface InstrumentationContextProvider