Class HelperClassManager<T>

  • Type Parameters:
    T - the type of the helper interface
    Direct Known Subclasses:
    HelperClassManager.ForAnyClassLoader, HelperClassManager.ForSingleClassLoader

    @Deprecated
    public abstract class HelperClassManager<T>
    extends java.lang.Object
    Deprecated.
    Use indy plugins instead. As the whole package the indy plugin is defined it is loaded from IndyPluginClassLoader, a separate helper class manager is not needed anymore.
    This class helps to overcome the fact that the agent classes can't access the classes they want to instrument.

    For example, when the agent wants to access the classes of the Servlet API it can't, as the agent is loaded by the bootstrap classloader and the Servlet API is loaded by a child classloader.

    This class creates a helper classloader whose parent is the classloader of the classes the agent needs to have access to. The classes loaded by this helper classloader are called helper classes. These helper classes can access the desired classes, as they are defined by a parent classloader.

    As the agent, which is loaded by the bootstrap classloader can't directly access the helper classes, the agent defines a helper interface, which is implemented by the helper class. Therefore, the agent does not need to have access to the implementation type, but can just refer to the interface.

    Because the helper classes are also available from the bootstrap classloader, the classloaders created in this class have child-first semantics. This makes sure that the loaded classes indeed have access to the types the helper classes refer to.

    Note: trying to load the helper class implementations from the bootstrap classloader leads to NoClassDefFoundErrors.

    • Field Detail

      • implementation

        protected final java.lang.String implementation
        Deprecated.
      • additionalHelpers

        protected final java.lang.String[] additionalHelpers
        Deprecated.
    • Constructor Detail

      • HelperClassManager

        protected HelperClassManager​(ElasticApmTracer tracer,
                                     java.lang.String implementation,
                                     java.lang.String[] additionalHelpers)
        Deprecated.
    • Method Detail

      • getForClassLoaderOfClass

        @Nullable
        public T getForClassLoaderOfClass​(java.lang.Class<?> classOfTargetClassLoader)
        Deprecated.
      • doGetForClassLoaderOfClass

        @Nullable
        protected abstract T doGetForClassLoaderOfClass​(java.lang.Class<?> classOfTargetClassLoader)
                                                 throws java.lang.Exception
        Deprecated.
        Implementations of this method are expected to load helper classes lazily, meaning when invoked for the first time. By delaying the helper class loading only to when actually required (normally from the injected code) we ensure proper classpath is already in place.
        Parameters:
        classOfTargetClassLoader - a class loaded by the class loader we want to load the helper class from
        Returns:
        helper instance
        Throws:
        java.lang.Exception - most likely related to first time loading error