Package org.hotswap.agent.config
Class PluginManager
- java.lang.Object
-
- org.hotswap.agent.config.PluginManager
-
public class PluginManager extends Object
The main agent plugin manager, well known singleton controller.- Author:
- Jiri Bubnik
-
-
Field Summary
Fields Modifier and Type Field Description protected HotswapTransformerhotswapTransformerstatic StringPLUGIN_PACKAGEprotected Schedulerschedulerprotected Watcherwatcher
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseClassLoader(ClassLoader classLoader)Remove any classloader reference and close all plugin instances associated with classloader.HotswapTransformergetHotswapTransformer()Returns the hotswap transformer service.static PluginManagergetInstance()Get the singleton instance of the plugin manager.InstrumentationgetInstrumentation()<T> TgetPlugin(Class<T> clazz, ClassLoader classLoader)Returns a plugin instance by its type and classLoader.ObjectgetPlugin(String clazz, ClassLoader classLoader)Returns a plugin instance by its type and classLoader.PluginConfigurationgetPluginConfiguration(ClassLoader classLoader)PluginRegistrygetPluginRegistry()Returns the plugin registry service.SchedulergetScheduler()Returns the scheduler service.WatchergetWatcher()Returns the watcher service.voidhotswap(Map<Class<?>,byte[]> reloadMap)Redefine the supplied set of classes using the supplied bytecode.voidinit(Instrumentation instrumentation)Initialize the singleton plugin manager.voidinitClassLoader(ClassLoader classLoader)voidinitClassLoader(ClassLoader classLoader, ProtectionDomain protectionDomain)booleanisPluginInitialized(String pluginClassName, ClassLoader classLoader)Check if plugin is initialized in classLoader.voidregisterClassLoaderInitListener(ClassLoaderInitListener classLoaderInitListener)voidsetPluginRegistry(PluginRegistry pluginRegistry)Sets the plugin registry service.voidscheduleHotswap(Map<Class<?>,byte[]> reloadMap, int timeout)Redefine the supplied set of classes using the supplied bytecode in scheduled command.
-
-
-
Field Detail
-
PLUGIN_PACKAGE
public static final String PLUGIN_PACKAGE
- See Also:
- Constant Field Values
-
hotswapTransformer
protected HotswapTransformer hotswapTransformer
-
watcher
protected Watcher watcher
-
scheduler
protected Scheduler scheduler
-
-
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 pluginclassLoader- 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 pluginclassLoader- 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)
-
initClassLoader
public void initClassLoader(ClassLoader classLoader, ProtectionDomain protectionDomain)
-
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
-
getPluginConfiguration
public PluginConfiguration getPluginConfiguration(ClassLoader classLoader)
-
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...)
-
-