Class PluginManager


  • public class PluginManager
    extends Object
    The main agent plugin manager, well known singleton controller.
    Author:
    Jiri Bubnik
    • Method Detail

      • getInstance

        public static PluginManager getInstance()
        Get the singleton instance of the plugin manager.
      • getPlugin

        public Object getPlugin​(String clazz,
                                ClassLoader classLoader)
        Returns a plugin instance by its type and classLoader.
        Parameters:
        clazz - type name of the plugin (IllegalArgumentException class is not known to the classLoader)
        classLoader - classloader of the plugin
        Returns:
        plugin instance or null if not found
      • getPlugin

        public <T> T getPlugin​(Class<T> clazz,
                               ClassLoader classLoader)
        Returns a plugin instance by its type and classLoader.
        Type Parameters:
        T - type of the plugin to return correct instance.
        Parameters:
        clazz - type of the plugin
        classLoader - classloader of the plugin
        Returns:
        the plugin or null if not found.
      • isPluginInitialized

        public boolean isPluginInitialized​(String pluginClassName,
                                           ClassLoader classLoader)
        Check if plugin is initialized in classLoader.
        Parameters:
        pluginClassName - type of the plugin
        classLoader - classloader of the plugin
        Returns:
        true/false
      • init

        public void init​(Instrumentation instrumentation)
        Initialize the singleton plugin manager.
        • Create new resource watcher using WatcherFactory and start it in separate thread.
        • Create new scheduler and start it in separate thread.
        • Scan for plugins
        • Register HotswapTransformer with the javaagent instrumentation class
        Parameters:
        instrumentation - javaagent instrumentation.
      • registerClassLoaderInitListener

        public void registerClassLoaderInitListener​(ClassLoaderInitListener classLoaderInitListener)
      • initClassLoader

        public void initClassLoader​(ClassLoader classLoader)
      • closeClassLoader

        public void closeClassLoader​(ClassLoader classLoader)
        Remove any classloader reference and close all plugin instances associated with classloader. This method is called typically after webapp undeploy.
        Parameters:
        classLoader - the classloader to cleanup
      • getPluginRegistry

        public PluginRegistry getPluginRegistry()
        Returns the plugin registry service.
      • setPluginRegistry

        public void setPluginRegistry​(PluginRegistry pluginRegistry)
        Sets the plugin registry service.
      • getHotswapTransformer

        public HotswapTransformer getHotswapTransformer()
        Returns the hotswap transformer service.
      • getWatcher

        public Watcher getWatcher()
        Returns the watcher service.
      • getScheduler

        public Scheduler getScheduler()
        Returns the scheduler service.
      • hotswap

        public void hotswap​(Map<Class<?>,​byte[]> reloadMap)
        Redefine the supplied set of classes using the supplied bytecode. This method operates on a set in order to allow interdependent changes to more than one class at the same time (a redefinition of class A can require a redefinition of class B).
        Parameters:
        reloadMap - class -> new bytecode
        See Also:
        Instrumentation.redefineClasses(java.lang.instrument.ClassDefinition...)
      • getInstrumentation

        public Instrumentation getInstrumentation()
        Returns:
        the instrumentation
      • scheduleHotswap

        public void scheduleHotswap​(Map<Class<?>,​byte[]> reloadMap,
                                    int timeout)
        Redefine the supplied set of classes using the supplied bytecode in scheduled command. Actual hotswap is postponed by timeout This method operates on a set in order to allow interdependent changes to more than one class at the same time (a redefinition of class A can require a redefinition of class B).
        Parameters:
        reloadMap - class -> new bytecode
        See Also:
        Instrumentation.redefineClasses(java.lang.instrument.ClassDefinition...)