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

java.lang.Object
  extended by org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer
Direct Known Subclasses:
AlertServerPluginContainer, BundleServerPluginContainer, ContentServerPluginContainer, DriftServerPluginContainer, EntitlementServerPluginContainer, GenericServerPluginContainer, PackageTypeServerPluginContainer, PerspectiveServerPluginContainer

public abstract class AbstractTypeServerPluginContainer
extends Object

The abstract superclass for all plugin containers of the different plugin types.

Author:
John Mazzitelli

Constructor Summary
AbstractTypeServerPluginContainer(MasterServerPluginContainer master)
          Instantiates the plugin container.
 
Method Summary
protected  ServerPluginManager createPluginManager()
          This will be called when its time for this plugin container to create its plugin manager.
protected  org.apache.commons.logging.Log getLog()
          Returns the logger that can be used to log messages.
 MasterServerPluginContainer getMasterServerPluginContainer()
          Returns the master plugin container that is responsible for managing this instance.
 Long getPluginLoadTime(org.rhq.core.domain.plugin.PluginKey pluginKey)
          Given a plugin key, this returns the time (in epoch milliseconds) when that plugin was loaded into this plugin container.
 ServerPluginManager getPluginManager()
          Returns the object that manages the plugins.
abstract  ServerPluginType getSupportedServerPluginType()
          Each plugin container will tell the master which plugins it can support via this method; this method returns the type of plugin that the plugin container can process.
 void initialize()
          The initialize method that prepares the plugin container.
 ControlResults invokePluginControl(org.rhq.core.domain.plugin.PluginKey pluginKey, String controlName, org.rhq.core.domain.configuration.Configuration params)
          Invokes a control operation on a given plugin and returns the results.
 boolean isPluginEnabled(org.rhq.core.domain.plugin.PluginKey pluginKey)
          Determines if the given plugin is enabled in the plugin container.
 boolean isPluginLoaded(org.rhq.core.domain.plugin.PluginKey pluginKey)
          Determines if the given plugin is loaded in the plugin container.
 void loadPlugin(ServerPluginEnvironment env, boolean enabled)
          Informs the plugin container that it has a plugin that it must begin to start managing.
 void reloadPlugin(org.rhq.core.domain.plugin.PluginKey pluginKey, boolean enabled)
          Informs the plugin container that a plugin should be reloaded and any of its resources should be started if being enabled.
 void scheduleAllPluginJobs()
          If a plugin has scheduled jobs, this method will schedule them now.
protected  void scheduleJob(ScheduledJobDefinition schedule, org.rhq.core.domain.plugin.PluginKey pluginKey)
          Schedules a job for periodic execution.
 void schedulePluginJobs(org.rhq.core.domain.plugin.PluginKey pluginKey)
           
 void shutdown()
          The shutdown method that will stop and unload all plugins.
 void start()
          This method informs the plugin container that all of its plugins have been loaded.
 void stop()
          This will inform the plugin container that it must stop doing its work.
 void unloadPlugin(org.rhq.core.domain.plugin.PluginKey pluginKey)
          Informs the plugin container that a plugin should be unloaded and any of its resources should be released.
 void unschedulePluginJobs(org.rhq.core.domain.plugin.PluginKey pluginKey)
          Unschedules any plugin jobs that are currently scheduled for the named plugin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTypeServerPluginContainer

public AbstractTypeServerPluginContainer(MasterServerPluginContainer master)
Instantiates the plugin container. All subclasses must support this and only this constructor.

Parameters:
master - the master plugin container that is creating this instance.
Method Detail

getSupportedServerPluginType

public abstract ServerPluginType getSupportedServerPluginType()
Each plugin container will tell the master which plugins it can support via this method; this method returns the type of plugin that the plugin container can process. Only one plugin container can support a plugin type.

Returns:
the type of plugin that this plugin container instance can support

getMasterServerPluginContainer

public MasterServerPluginContainer getMasterServerPluginContainer()
Returns the master plugin container that is responsible for managing this instance.

Returns:
this plugin container's master

getPluginManager

public ServerPluginManager getPluginManager()
Returns the object that manages the plugins.

Returns:
the plugin manager for this container

isPluginLoaded

public boolean isPluginLoaded(org.rhq.core.domain.plugin.PluginKey pluginKey)
Determines if the given plugin is loaded in the plugin container. The plugin may be loaded but not enabled.

Parameters:
pluginKey -
Returns:
true if the plugin is loaded in this plugin container; false otherwise

isPluginEnabled

public boolean isPluginEnabled(org.rhq.core.domain.plugin.PluginKey pluginKey)
Determines if the given plugin is enabled in the plugin container. true implies the plugin is also loaded. If false is returned, it is either because the plugin is loaded but disabled, or the plugin is just not loaded. Use isPluginLoaded(PluginKey) to know if the plugin is loaded or not.

Parameters:
pluginKey -
Returns:
true if the plugin is enabled in this plugin container; false otherwise

getPluginLoadTime

public Long getPluginLoadTime(org.rhq.core.domain.plugin.PluginKey pluginKey)
Given a plugin key, this returns the time (in epoch milliseconds) when that plugin was loaded into this plugin container.

Parameters:
pluginKey - identifies the plugin whose load time is to be returned
Returns:
the epoch millis timestamp when the plugin was loaded; null if the plugin is not loaded

initialize

public void initialize()
                throws Exception
The initialize method that prepares the plugin container. This should get the plugin container ready to accept plugins. Subclasses are free to perform additional tasks by overriding this method.

Throws:
Exception - if the plugin container failed to initialize for some reason

start

public void start()
This method informs the plugin container that all of its plugins have been loaded. Once this is called, the plugin container can assume all plugins that it will ever know about have been loadPlugin(ServerPluginEnvironment, boolean) loaded}.


stop

public void stop()
This will inform the plugin container that it must stop doing its work. Once called, the plugin container must assume that soon it will be asked to shutdown().


shutdown

public void shutdown()
The shutdown method that will stop and unload all plugins. Subclasses are free to perform additional tasks by overriding this method.


loadPlugin

public void loadPlugin(ServerPluginEnvironment env,
                       boolean enabled)
                throws Exception
Informs the plugin container that it has a plugin that it must begin to start managing.

Parameters:
env - the plugin environment, including the plugin jar and its descriptor
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 failed to load the plugin

unloadPlugin

public void unloadPlugin(org.rhq.core.domain.plugin.PluginKey pluginKey)
                  throws Exception
Informs the plugin container that a plugin should be unloaded and any of its resources should be released.

Parameters:
pluginKey - identifies the plugin that should be shutdown
Throws:
Exception - if failed to unload the plugin

reloadPlugin

public void reloadPlugin(org.rhq.core.domain.plugin.PluginKey pluginKey,
                         boolean enabled)
                  throws Exception
Informs the plugin container that a plugin should be reloaded and any of its resources should be started if being enabled.

Parameters:
pluginKey - identifies the plugin that should be reloaded
enabled - indicates if the plugin should be enabled or disabled after being loaded
Throws:
Exception - if failed to unload the plugin

scheduleAllPluginJobs

public void scheduleAllPluginJobs()
                           throws Exception
If a plugin has scheduled jobs, this method will schedule them now. This particular method implementation schedules the global jobs as defined in the plugin descriptors. Subclasses are free to extend this method to schedule additional plugin jobs, but must ensure they call this method so the global scheduled jobs get added to the scheduler. Note that this is separate from the start() method because it is possible that the plugin container has been started before the scheduler has. In this case, the caller must wait for the scheduler to be started before this method is called to schedule jobs.

Throws:
Exception - if failed to schedule jobs

schedulePluginJobs

public void schedulePluginJobs(org.rhq.core.domain.plugin.PluginKey pluginKey)
                        throws Exception
Throws:
Exception

unschedulePluginJobs

public void unschedulePluginJobs(org.rhq.core.domain.plugin.PluginKey pluginKey)
                          throws Exception
Unschedules any plugin jobs that are currently scheduled for the named plugin. Subclasses are free to extend this method to unschedule those additional plugin jobs they created, but must ensure they call this method so the global scheduled jobs get removed from the scheduler. Note that this is separate from the stop() method because we never want to unschedule jobs since other plugin containers on other servers may be running and able to process the jobs. This method should only be called when a plugin is being disabled or removed.

Parameters:
pluginKey -
Throws:
Exception - if failed to unschedule jobs

invokePluginControl

public ControlResults invokePluginControl(org.rhq.core.domain.plugin.PluginKey pluginKey,
                                          String controlName,
                                          org.rhq.core.domain.configuration.Configuration params)
                                   throws Exception
Invokes a control operation on a given plugin and returns the results. This method blocks until the plugin component completes the invocation.

Parameters:
pluginKey - identifies the plugin whose control operation is to be invoked
controlName - identifies the name of the control operation to invoke
params - parameters to pass to the control operation; may be null
Returns:
the results of the invocation
Throws:
Exception - if failed to obtain the plugin component and invoke the control. This usually means an abnormal error occurred - if the control operation merely failed to do what it needed to do, the error will be reported in the returned results, not as a thrown exception.

createPluginManager

protected ServerPluginManager createPluginManager()
This will be called when its time for this plugin container to create its plugin manager. Subclasses are free to override this if they need their own specialized plugin manager.

Returns:
the plugin manager for use by this plugin container

getLog

protected org.apache.commons.logging.Log getLog()
Returns the logger that can be used to log messages. A convienence object so all subclasses don't have to explicitly declare and create their own.

Returns:
this instance's logger object

scheduleJob

protected void scheduleJob(ScheduledJobDefinition schedule,
                           org.rhq.core.domain.plugin.PluginKey pluginKey)
                    throws Exception
Schedules a job for periodic execution. Note that if the schedule indicates the job is not enabled, this method returns immediately as a no-op.

Parameters:
schedule - instructs how the job should be scheduled
pluginKey - the key of the plugin scheduling the job
Throws:
Exception - if failed to schedule the job


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