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

java.lang.Object
  extended by org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer

public class MasterServerPluginContainer
extends Object

The container responsible for managing all the plugin containers for all the different plugin types.

Author:
John Mazzitelli

Constructor Summary
MasterServerPluginContainer()
           
 
Method Summary
protected  ClassLoaderManager createClassLoaderManager(Map<URL,? extends ServerPluginDescriptorType> plugins, ClassLoader rootClassLoader, File tmpDir)
          Creates the manager that will be responsible for instantiating plugin classloaders.
protected  List<AbstractTypeServerPluginContainer> createPluginContainers()
          Creates the individual plugin containers that can be used to deploy different plugin types.
protected  ClassLoader createRootServerPluginClassLoader()
          Create the root classloader that will be the ancester to all plugin classloaders.
 ClassLoaderManager getClassLoaderManager()
          Returns the manager that is responsible for created classloaders for plugins.
protected  EnhancedScheduler getClusteredScheduler()
          Most jobs need to be scheduled using the clustered scheduler so they can be run on different machines in the RHQ cluster in order to balance the load across the cluster.
 MasterServerPluginContainerConfiguration getConfiguration()
          Returns the configuration that this object was initialized with.
protected  List<org.rhq.core.domain.plugin.PluginKey> getDisabledPluginKeys()
          This will return a list of plugin keys that represent all the plugins that are to be disabled.
protected  EnhancedScheduler getNonClusteredScheduler()
          Some schedule jobs may want to run on all machines in the RHQ cluster.
<T extends AbstractTypeServerPluginContainer>
T
getPluginContainerByClass(Class<T> clazz)
          Get the plugin container of the given class.
protected  AbstractTypeServerPluginContainer getPluginContainerByDescriptor(ServerPluginDescriptorType descriptor)
          Given a plugin's descriptor, this will return the plugin container that can manage the plugin.
<T extends AbstractTypeServerPluginContainer>
T
getPluginContainerByPlugin(org.rhq.core.domain.plugin.PluginKey pluginKey)
          Given the key of a deployed plugin, this returns the plugin container that is hosting that plugin.
 AbstractTypeServerPluginContainer getPluginContainerByPluginType(ServerPluginType pluginType)
          Given a server plugin type, this will return the plugin container that can manage that type of plugin.
 List<ServerPluginType> getServerPluginTypes()
          This will return all known server plugins types.
 void initialize(MasterServerPluginContainerConfiguration config)
          Starts the master plugin container, which will load all plugins and begin managing them.
protected  void initializeNonClusteredScheduler()
          Some schedule jobs may want to run on all machines in the RHQ cluster.
 void loadPlugin(URL pluginUrl, boolean enabled)
          Loads a plugin into the appropriate plugin container.
protected  Map<URL,? extends ServerPluginDescriptorType> preloadAllPlugins()
          Finds all plugins and parses their descriptors.
 void scheduleAllPluginJobs()
          Asks that all plugin containers schedule jobs now, if needed.
 void shutdown()
          Stops all plugins and cleans up after them.
protected  void shutdownNonClusteredScheduler()
          This will stop the internal, non-clustered scheduler running in the master plugin container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MasterServerPluginContainer

public MasterServerPluginContainer()
Method Detail

initialize

public void initialize(MasterServerPluginContainerConfiguration config)
Starts the master plugin container, which will load all plugins and begin managing them.

Parameters:
config - the master configuration

shutdown

public void shutdown()
Stops all plugins and cleans up after them.


loadPlugin

public void loadPlugin(URL pluginUrl,
                       boolean enabled)
                throws Exception
Loads a plugin into the appropriate plugin container.

Parameters:
pluginUrl - the location where the new plugin is found
enabled - indicates if the plugin should be enabled as soon as its loaded
Throws:
Exception - if the plugin's descriptor could not be parsed or could not be loaded into the plugin container

scheduleAllPluginJobs

public void scheduleAllPluginJobs()
Asks that all plugin containers schedule jobs now, if needed. Note that this is separate from the initialize(MasterServerPluginContainerConfiguration) method because it is possible that the master plugin container has been initialized before the scheduler is started. In this case, the caller must wait for the scheduler to be started before this method is called to schedule jobs.


getConfiguration

public MasterServerPluginContainerConfiguration getConfiguration()
Returns the configuration that this object was initialized with. If this plugin container was not initialized or has been shutdown, this will return null.

Returns:
the configuration

getClassLoaderManager

public ClassLoaderManager getClassLoaderManager()
Returns the manager that is responsible for created classloaders for plugins.

Returns:
classloader manager

getServerPluginTypes

public List<ServerPluginType> getServerPluginTypes()
This will return all known server plugins types. These are the types of plugins that are supported by a server plugin container. You can obtain the server plugin container that manages a particular server plugin type via getPluginContainerByPluginType(ServerPluginType).

Returns:
all known server plugin types

getPluginContainerByClass

public <T extends AbstractTypeServerPluginContainer> T getPluginContainerByClass(Class<T> clazz)
Get the plugin container of the given class. This method provides a strongly typed return value, based on the type of plugin container the caller wants returned.

Parameters:
clazz - the class name of the plugin container that the caller wants
Returns:
the plugin container of the given class (null if none found)

getPluginContainerByPlugin

public <T extends AbstractTypeServerPluginContainer> T getPluginContainerByPlugin(org.rhq.core.domain.plugin.PluginKey pluginKey)
Given the key of a deployed plugin, this returns the plugin container that is hosting that plugin. If there is no plugin with the given key or that plugin is not loaded in any plugin container (e.g. when it is disabled), then null is returned.

Parameters:
pluginKey -
Returns:
the plugin container that is managing the named plugin or null

getPluginContainerByPluginType

public AbstractTypeServerPluginContainer getPluginContainerByPluginType(ServerPluginType pluginType)
Given a server plugin type, this will return the plugin container that can manage that type of plugin. If the server plugin type is unknown to the master, or if the master plugin is not started, this will return null.

Parameters:
pluginType - the type of server plugin whose PC is to be returned
Returns:
a plugin container that can handle the given type of server plugin

getPluginContainerByDescriptor

protected AbstractTypeServerPluginContainer getPluginContainerByDescriptor(ServerPluginDescriptorType descriptor)
Given a plugin's descriptor, this will return the plugin container that can manage the plugin.

Parameters:
descriptor - descriptor to identify a plugin whose container is to be returned
Returns:
a plugin container that can handle the plugin with the given descriptor

preloadAllPlugins

protected Map<URL,? extends ServerPluginDescriptorType> preloadAllPlugins()
                                                                   throws Exception
Finds all plugins and parses their descriptors. This is only called during this master plugin container's initialization. If a plugin fails to preload, it will be ignored - other plugins will still preload.

Returns:
a map of plugins, keyed on the plugin jar URL whose values are the parsed descriptors
Throws:
Exception - on catastrophic failure. Note that if a plugin failed to load, that plugin will simply be ignored and no exception will be thrown

getDisabledPluginKeys

protected List<org.rhq.core.domain.plugin.PluginKey> getDisabledPluginKeys()
This will return a list of plugin keys that represent all the plugins that are to be disabled. If a plugin jar is found on the filesystem, its plugin key should be checked with this "blacklist" - if its key is found, that plugin should be disabled.

Returns:
names of "blacklisted" plugins that should not be started (i.e. loaded as a disabled plugin)

createPluginContainers

protected List<AbstractTypeServerPluginContainer> createPluginContainers()
Creates the individual plugin containers that can be used to deploy different plugin types.

This is protected to allow subclasses to override the PCs that are created by this service (mainly to support tests).

Returns:
the new plugin containers created by this method

createRootServerPluginClassLoader

protected ClassLoader createRootServerPluginClassLoader()
Create the root classloader that will be the ancester to all plugin classloaders.

Returns:
the root server plugin classloader

createClassLoaderManager

protected ClassLoaderManager createClassLoaderManager(Map<URL,? extends ServerPluginDescriptorType> plugins,
                                                      ClassLoader rootClassLoader,
                                                      File tmpDir)
Creates the manager that will be responsible for instantiating plugin classloaders.

Parameters:
plugins - maps plugin URLs with their parsed descriptors
rootClassLoader - the classloader at the top of the classloader hierarchy
tmpDir - where the classloaders can write out the jars that are embedded in the plugin jars
Returns:
the classloader manager instance

initializeNonClusteredScheduler

protected void initializeNonClusteredScheduler()
                                        throws Exception
Some schedule jobs may want to run on all machines in the RHQ cluster. We can't use our normal persistent, clustered scheduler for these jobs. Instead, each master plugin container running in each RHQ server will have their own internal scheduler that can be used to run jobs for this purpose.

Throws:
Exception - if failed to initialize the internal scheduler

shutdownNonClusteredScheduler

protected void shutdownNonClusteredScheduler()
This will stop the internal, non-clustered scheduler running in the master plugin container. This tells all jobs to shut down.


getNonClusteredScheduler

protected EnhancedScheduler getNonClusteredScheduler()
                                              throws Exception
Some schedule jobs may want to run on all machines in the RHQ cluster. We can't use our normal persistent, clustered scheduler for these jobs. Instead, each master plugin container running in each RHQ server will have their own internal scheduler that can be used to run jobs for this purpose.

Throws:
Exception - if failed to obtain the internal scheduler
See Also:
getClusteredScheduler()

getClusteredScheduler

protected EnhancedScheduler getClusteredScheduler()
Most jobs need to be scheduled using the clustered scheduler so they can be run on different machines in the RHQ cluster in order to balance the load across the cluster. Use this scheduler when scheduling those jobs.

Returns:
the clustered scheduler
See Also:
getNonClusteredScheduler()


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