org.rhq.enterprise.server.plugin.pc
Class ServerPluginManager

java.lang.Object
  extended by org.rhq.enterprise.server.plugin.pc.ServerPluginManager
Direct Known Subclasses:
AlertSenderPluginManager, BundleServerPluginManager, ContentServerPluginManager, DriftServerPluginManager, EntitlementServerPluginManager, PackageTypePluginManager, PerspectiveServerPluginManager

public class ServerPluginManager
extends Object

Provides functionality to manage plugins for a plugin container. Plugin containers can install their own plugin managers that are extensions to this class if they need to. Most of the methods here are protected; they are meant for the plugin container's use only. Usually, anything an external client needs will be done through a delegation method found on the plugin container.

Author:
John Mazzitelli

Constructor Summary
ServerPluginManager(AbstractTypeServerPluginContainer pc)
          Creates a plugin manager for the given plugin container.
 
Method Summary
protected  ServerPluginComponent createServerPluginComponent(ServerPluginEnvironment environment)
          This will create a new ServerPluginComponent instance for that is used to initialize and shutdown a particular server plugin.
protected  void disablePlugin(String pluginName)
           
protected  void enablePlugin(String pluginName)
           
protected  org.apache.commons.logging.Log getLog()
           
 AbstractTypeServerPluginContainer getParentPluginContainer()
          Returns the plugin container that whose plugins are managed by this manager.
protected  org.rhq.core.domain.plugin.ServerPlugin getPlugin(ServerPluginEnvironment pluginEnv)
          Given a plugin environment, return its ServerPlugin representation, which should also include the plugin configuration and scheduled jobs configuration.
 ServerPluginEnvironment getPluginEnvironment(String pluginName)
          Given a plugin name, this returns that plugin's environment.
 Collection<ServerPluginEnvironment> getPluginEnvironments()
          Returns the ServerPluginEnvironments for every plugin this manager has loaded.
protected  ServerPluginComponent getServerPluginComponent(String pluginName)
          Returns the main plugin component instance that is responsible for initializing and managing the plugin.
protected  ServerPluginContext getServerPluginContext(ServerPluginEnvironment env)
           
protected  void initialize()
          Initializes the plugin manager to prepare it to start loading plugins.
protected  Object instantiatePluginClass(ServerPluginEnvironment environment, String className)
          Instantiates a class with the given name within the given environment's classloader using the class' no-arg constructor.
protected  boolean isPluginEnabled(String pluginName)
           
protected  boolean isPluginLoaded(String pluginName)
           
protected  void loadPlugin(ServerPluginEnvironment env, boolean enabled)
          Informs the plugin manager that a plugin with the given environment needs to be loaded.
protected  Class<?> loadPluginClass(ServerPluginEnvironment environment, String className, boolean initialize)
          Loads a class with the given name within the given environment's classloader.
protected  ServerPluginEnvironment rebuildServerPluginEnvironment(ServerPluginEnvironment env)
          Given a plugin environment, this will rebuild a new one with up-to-date information.
protected  void reloadPlugin(String pluginName, boolean enabled)
          This will reload a plugin allowing you to enable or disable it.
protected  void shutdown()
          Shuts down this manager.
protected  void startPlugin(String pluginName)
           
protected  void startPlugins()
           
protected  void stopPlugin(String pluginName)
           
protected  void stopPlugins()
           
protected  void unloadPlugin(String pluginName)
          Informs the plugin manager that a plugin with the given name is to be unloaded.
protected  void unloadPlugin(String pluginName, boolean keepClassLoader)
          Informs the plugin manager that a plugin with the given name is to be unloaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerPluginManager

public ServerPluginManager(AbstractTypeServerPluginContainer pc)
Creates a plugin manager for the given plugin container.

Parameters:
pc - the plugin manager's owning plugin container
Method Detail

getParentPluginContainer

public AbstractTypeServerPluginContainer getParentPluginContainer()
Returns the plugin container that whose plugins are managed by this manager.

Returns:
the plugin container that owns this plugin manager

getPluginEnvironments

public Collection<ServerPluginEnvironment> getPluginEnvironments()
Returns the ServerPluginEnvironments for every plugin this manager has loaded. The returned collection is a copy and not backed by this manager.

Returns:
environments for all the plugins

getPluginEnvironment

public ServerPluginEnvironment getPluginEnvironment(String pluginName)
Given a plugin name, this returns that plugin's environment.

The plugin's name is defined in its plugin descriptor - specifically the XML root node's "name" attribute (e.g. <server-plugin name="thePluginName").

Parameters:
pluginName - the plugin whose environment is to be returned
Returns:
given plugin's environment

initialize

protected void initialize()
                   throws Exception
Initializes the plugin manager to prepare it to start loading plugins.

Throws:
Exception - if failed to initialize

shutdown

protected void shutdown()
Shuts down this manager. This should be called only after all of its plugins have been unloaded.


loadPlugin

protected void loadPlugin(ServerPluginEnvironment env,
                          boolean enabled)
                   throws Exception
Informs the plugin manager that a plugin with the given environment needs to be loaded. Once this method returns, the plugin's components are ready to be created and used, unless enabled is false, in which case the plugin will not be initialized.

Parameters:
env - the environment of the plugin to be loaded
enabled - true if the plugin should be initialized; false if the plugin's existence should be noted but it should not be initialized or started
Throws:
Exception - if the plugin manager cannot load the plugin or deems the plugin invalid. Typically, this method will not throw an exception unless enabled is true - loading a disabled plugin is trivial and should not fail or throw an exception.

startPlugins

protected void startPlugins()

startPlugin

protected void startPlugin(String pluginName)

stopPlugins

protected void stopPlugins()

stopPlugin

protected void stopPlugin(String pluginName)

unloadPlugin

protected void unloadPlugin(String pluginName)
                     throws Exception
Informs the plugin manager that a plugin with the given name is to be unloaded. The component's shutdown method will be called.

Parameters:
pluginName - the name of the plugin to be unloaded
Throws:
Exception - if the plugin manager cannot unload the plugin

unloadPlugin

protected void unloadPlugin(String pluginName,
                            boolean keepClassLoader)
                     throws Exception
Informs the plugin manager that a plugin with the given name is to be unloaded. Once this method returns, the plugin's components should not be created or used. If keepClassLoader is true, this is the same as unloadPlugin(String). You want to keep the classloader if you are only temporarily unloading the plugin, and will load it back soon. Subclasses of this plugin manager class will normally not override this method; instead, they will typically want to override unloadPlugin(String).

Parameters:
pluginName - the name of the plugin to be unloaded
keepClassLoader - if true the classloader is not destroyed
Throws:
Exception - if the plugin manager cannot unload the plugin

reloadPlugin

protected void reloadPlugin(String pluginName,
                            boolean enabled)
                     throws Exception
This will reload a plugin allowing you to enable or disable it. This will start the plugin component if you enable it. This will stop the plugin component if you disable it. This will ensure any new plugin configuration will be re-loaded.

Parameters:
pluginName - the name of the loaded plugin that is to be enabled or disabled
enabled - true if you want to enable the plugin; false if you want to disable it
Throws:
Exception - if the plugin was never loaded before or the reload failed

enablePlugin

protected void enablePlugin(String pluginName)
                     throws Exception
Throws:
Exception

disablePlugin

protected void disablePlugin(String pluginName)
                      throws Exception
Throws:
Exception

isPluginLoaded

protected boolean isPluginLoaded(String pluginName)

isPluginEnabled

protected boolean isPluginEnabled(String pluginName)

getServerPluginComponent

protected ServerPluginComponent getServerPluginComponent(String pluginName)
Returns the main plugin component instance that is responsible for initializing and managing the plugin. This will return null if a plugin has not defined a plugin component.

Parameters:
pluginName - the name of the plugin whose plugin component is to be returned
Returns:
the plugin component instance that initialized and is managing a plugin. Will return null if the plugin has not defined a plugin component. null is also returned if the plugin is not initialized yet.

getLog

protected org.apache.commons.logging.Log getLog()

getServerPluginContext

protected ServerPluginContext getServerPluginContext(ServerPluginEnvironment env)

rebuildServerPluginEnvironment

protected ServerPluginEnvironment rebuildServerPluginEnvironment(ServerPluginEnvironment env)
                                                          throws Exception
Given a plugin environment, this will rebuild a new one with up-to-date information. This means the descriptor will be reparsed.

Parameters:
env - the original environment
Returns:
the new environment that has been rebuild from the original but has newer data
Throws:
Exception - if the environment could not be rebuilt - probably due to an invalid descriptor in the plugin jar or the plugin jar is now missing

getPlugin

protected org.rhq.core.domain.plugin.ServerPlugin getPlugin(ServerPluginEnvironment pluginEnv)
Given a plugin environment, return its ServerPlugin representation, which should also include the plugin configuration and scheduled jobs configuration.

Parameters:
pluginEnv -
Returns:
the ServerPlugin object for the given plugin

createServerPluginComponent

protected ServerPluginComponent createServerPluginComponent(ServerPluginEnvironment environment)
                                                     throws Exception
This will create a new ServerPluginComponent instance for that is used to initialize and shutdown a particular server plugin. If there is no plugin component configured for the given plugin, null is returned. The new object will be loaded in the plugin's specific classloader.

Parameters:
environment - the environment in which the plugin will execute
Returns:
a new object loaded in the proper plugin classloader that can initialize/shutdown the plugin, or null if there is no plugin component to be associated with the given plugin
Throws:
Exception - if failed to create the instance

loadPluginClass

protected Class<?> loadPluginClass(ServerPluginEnvironment environment,
                                   String className,
                                   boolean initialize)
                            throws Exception
Loads a class with the given name within the given environment's classloader. The class will only be initialized if initialize is true.

Parameters:
environment - the environment that has the classloader where the class will be loaded
className - the class to load
initialize - whether the class must be initialized
Returns:
the new class that has been loaded
Throws:
Exception - if failed to load the class

instantiatePluginClass

protected Object instantiatePluginClass(ServerPluginEnvironment environment,
                                        String className)
                                 throws Exception
Instantiates a class with the given name within the given environment's classloader using the class' no-arg constructor.

Parameters:
environment - the environment that has the classloader where the class will be loaded
className - the class to instantiate
Returns:
the new object that is an instance of the given class
Throws:
Exception - if failed to instantiate the class


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.