Clearspace API (2.5.29) Core Javadocs

com.jivesoftware.base.plugin
Class PluginManagerImpl

java.lang.Object
  extended by com.jivesoftware.base.plugin.PluginManagerImpl
All Implemented Interfaces:
com.jivesoftware.base.event.v2.EventSource, com.jivesoftware.base.plugin.PluginManager, JiveManager

public class PluginManagerImpl
extends Object
implements JiveManager, com.jivesoftware.base.plugin.PluginManager, com.jivesoftware.base.event.v2.EventSource

Loads and manages plugins. The plugins directory is monitored for any new plugins, and they are dynamically loaded.

See Also:
Plugin

Field Summary
protected  Map<String,String> brokenPlugins
           
protected  Map<Locale,List<ResourceBundle>> bundleCache
           
protected  Map<String,com.jivesoftware.base.plugin.PluginClassLoader> classloaders
           
protected  Collection<com.jivesoftware.base.plugin.PluginConfigurator> configurators
           
protected  List<String> customURLMapperList
           
protected  Set<String> devPlugins
           
protected  com.jivesoftware.base.event.v2.EventDispatcher eventDispatcher
           
protected  AtomicBoolean initialized
           
protected static PluginManagerImpl instance
           
protected  com.jivesoftware.community.license.ClearspaceLicenseManager licenseManager
           
protected  com.jivesoftware.base.plugin.dao.PluginDAO pluginDAO
           
protected  File pluginDirectory
           
protected  Map<Plugin<?>,File> pluginDirs
           
protected  Set<PluginListener> pluginListeners
           
protected  Map<Object,PluginMetaDataImpl> pluginMeta
           
protected  Map<String,JiveProperties<String,String>> pluginProperties
           
protected  com.jivesoftware.base.plugin.dao.PluginPropertyDAO pluginPropertyDAO
           
protected  Map<String,Plugin<?>> plugins
           
protected  com.jivesoftware.util.task.TaskEngine taskEngine
           
protected  com.jivesoftware.community.upgrade.UpgradeManager upgradeManager
           
 
Constructor Summary
protected PluginManagerImpl()
          Constructs a new plugin manager.
 
Method Summary
 void addPluginListener(PluginListener listener)
          Registers a plugin applicationLifeCycleListener.
protected  File createLocalCache(com.jivesoftware.base.plugin.dao.PluginDbBean bean)
          Pulls the plugin jar file from the database outputs it to the pluginDirectory and expands the jar file.
protected  boolean createPluginCacheDirectories(List<com.jivesoftware.base.plugin.dao.PluginDbBean> pluginBeans)
          Checks the existing plugins to see if there are any plugins that need to be installed.
protected  ClassLoader createPluginChainingClassloader()
          Creates a classloader that will also look for classes under the plugin directories.
 void deleteBrokenPlugin(String pluginName)
          Removes a plugin that was flagged as broken.
 void destroy()
          Shuts down all running plugins.
 Map<String,String> getBrokenPlugins()
          Returns a list of broken plugins, mapped to what the cause of the breakage was.
 Collection<ClassLoader> getClassLoaders()
          Returns a collection of all plugin classloaders.
protected  Set<String> getDevPlugins()
          Returns a set of all the plugins that have been specified with -DpluginDirs system property
static PluginManagerImpl getInstance()
          This method had to be created in order to perform operations on plugins that must happen before spring initializes inside of the JiveApplicationContextLoader
 Plugin<?> getPlugin(String name)
          Returns a plugin by name or null if a plugin with that name does not exist.
protected  List<com.jivesoftware.base.plugin.dao.PluginDbBean> getPluginBeans()
          Returns beans for all the plugins that need to have their spring config loaded with the parent context.
 com.jivesoftware.base.plugin.PluginClassLoader getPluginClassloader(Plugin<?> plugin)
          Returns the classloader of a plugin.
protected  com.jivesoftware.base.plugin.PluginClassLoader getPluginClassloader(String pluginName, File pluginDir)
           
protected  File getPluginDirectory()
          Returns the directory {jiveHome}/plugins.
protected  File getPluginDirectory(Plugin<?> plugin)
          Returns the plugin's directory.
protected  Map<String,Plugin<?>> getPluginMap()
          Returns a map of plugin name plugin entries.
 com.jivesoftware.base.plugin.PluginMetaData getPluginMetaData(Plugin<?> plugin)
          Returns meta data assosiated with the plugin.
 com.jivesoftware.base.plugin.PluginMetaData getPluginMetaData(String name)
          Returns meta data associated with the plugin.
protected  JiveProperties<String,String> getPluginProperties(String pluginName)
          Returns a object for storing and receving property setting for a plugin.
 ResourceBundle getPluginResourceBundle(Plugin<?> plugin, Locale locale)
          Acquires a plugins resource bundle which should be stored in /plugin_i18n in the plugin's classloader.
 List<ResourceBundle> getPluginResourceBundles(Locale l)
          Returns all of the plugin resource bundles that match the specified locale.
 Collection<Plugin<?>> getPlugins()
          Returns a Collection of all installed plugins.
protected  com.jivesoftware.base.plugin.dao.PluginDAO getSpringUnManagedDAO()
           
protected  int handleUpgradeTasks(File pluginDir, Plugin<?> p)
          If an upgrade.xml was specified in the plugin all upgrade tasks will be performed if the jiveVersion value for the plugin is less than the tasks specified in the upgrade.xml
 void init()
          Starts plugins and the plugin monitoring service.
 com.jivesoftware.base.plugin.PluginResultList installPlugin(File file)
          Installs or updates an existing plugin.
 boolean isInitialized()
          Returns true if the plugin framework has been initialized an is running.
 boolean isPluginBroken(String plugin)
          Returns true if the specified plugin is flagged as broken during load time.
 boolean isPluginDownloaded(String pluginFilename)
          Returns true if the specified filename, that belongs to a plugin, exists.
protected  void isValidVersion(String pluginName, org.dom4j.Document pluginXML, File pluginDir)
          Checks to see if the clearspace version is ok to use with this plugin.
 Class<?> loadClass(Plugin<?> plugin, String className)
          Loads a class from the classloader of a plugin.
protected  void loadDevPlugins()
           
 List<com.jivesoftware.base.plugin.ConfiguratorResult> loadPlugin(File pluginDir, com.jivesoftware.base.plugin.dao.PluginDbBean pluginDbBean)
          Loads a plug-in module into the container.
 void preInit()
           
 void processSpringConfigs(List<String> springPaths)
          Process plugins to configure plugin caches that need to be configured first, and populate plugin's spring paths.
protected  void registerPlugin(Plugin<?> plugin, File pluginDir)
          Registers the plugin as an installed plugin.
 void removePluginListener(PluginListener listener)
          Unregisters a plugin applicationLifeCycleListener.
 void setConfigurators(Collection<com.jivesoftware.base.plugin.PluginConfigurator> configurators)
          Set the list of plugin configuration objects that will be used to configure the plugins.
 void setDispatcher(com.jivesoftware.base.event.v2.EventDispatcher eventDispatcher)
           
 void setLicenseManager(com.jivesoftware.community.license.ClearspaceLicenseManager licenseManager)
           
 void setPluginDAO(com.jivesoftware.base.plugin.dao.PluginDAO pluginDAO)
           
 void setPluginPropertyDAO(com.jivesoftware.base.plugin.dao.PluginPropertyDAO pluginPropertyDAO)
           
 void setTaskEngine(com.jivesoftware.util.task.TaskEngine taskEngine)
           
 void setUpgradeManager(com.jivesoftware.community.upgrade.UpgradeManager upgradeManager)
           
 com.jivesoftware.base.plugin.PluginResultList uninstallPlugin(Plugin<?> plugin)
          Removes a plugin from the system.
 com.jivesoftware.base.plugin.PluginResultList unloadPlugin(String pluginName)
          Unloads a plugin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pluginDirectory

protected File pluginDirectory

plugins

protected Map<String,Plugin<?>> plugins

brokenPlugins

protected Map<String,String> brokenPlugins

pluginMeta

protected Map<Object,PluginMetaDataImpl> pluginMeta

classloaders

protected Map<String,com.jivesoftware.base.plugin.PluginClassLoader> classloaders

pluginDirs

protected Map<Plugin<?>,File> pluginDirs

devPlugins

protected Set<String> devPlugins

pluginListeners

protected Set<PluginListener> pluginListeners

pluginProperties

protected Map<String,JiveProperties<String,String>> pluginProperties

bundleCache

protected Map<Locale,List<ResourceBundle>> bundleCache

customURLMapperList

protected List<String> customURLMapperList

initialized

protected AtomicBoolean initialized

upgradeManager

protected com.jivesoftware.community.upgrade.UpgradeManager upgradeManager

configurators

protected Collection<com.jivesoftware.base.plugin.PluginConfigurator> configurators

taskEngine

protected com.jivesoftware.util.task.TaskEngine taskEngine

licenseManager

protected com.jivesoftware.community.license.ClearspaceLicenseManager licenseManager

pluginPropertyDAO

protected com.jivesoftware.base.plugin.dao.PluginPropertyDAO pluginPropertyDAO

pluginDAO

protected com.jivesoftware.base.plugin.dao.PluginDAO pluginDAO

instance

protected static final PluginManagerImpl instance

eventDispatcher

protected com.jivesoftware.base.event.v2.EventDispatcher eventDispatcher
Constructor Detail

PluginManagerImpl

protected PluginManagerImpl()
Constructs a new plugin manager.

Method Detail

getInstance

public static PluginManagerImpl getInstance()
This method had to be created in order to perform operations on plugins that must happen before spring initializes inside of the JiveApplicationContextLoader

Returns:
An instance of PluginManagerImpl

init

public void init()
Starts plugins and the plugin monitoring service.


destroy

public void destroy()
Shuts down all running plugins.

Specified by:
destroy in interface JiveManager

setConfigurators

public void setConfigurators(Collection<com.jivesoftware.base.plugin.PluginConfigurator> configurators)
Set the list of plugin configuration objects that will be used to configure the plugins.

Parameters:
configurators - list of PluginConfigurators

isInitialized

public boolean isInitialized()
Returns true if the plugin framework has been initialized an is running.

Specified by:
isInitialized in interface com.jivesoftware.base.plugin.PluginManager
Returns:
True if the plugin framework is initialized.

installPlugin

public com.jivesoftware.base.plugin.PluginResultList installPlugin(File file)
                                                            throws com.jivesoftware.base.plugin.PluginException
Installs or updates an existing plugin.

Specified by:
installPlugin in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
file - the input file that contains the new plugin definition.
Returns:
The results from installing the plugin.
Throws:
PluginException - Thrown if there are issues installing the plugin.

isPluginDownloaded

public boolean isPluginDownloaded(String pluginFilename)
Returns true if the specified filename, that belongs to a plugin, exists.

Parameters:
pluginFilename - the filename of the plugin to create or update.
Returns:
true if the specified filename, that belongs to a plugin, exists.

getPlugins

public Collection<Plugin<?>> getPlugins()
Returns a Collection of all installed plugins.

Specified by:
getPlugins in interface com.jivesoftware.base.plugin.PluginManager
Returns:
a Collection of all installed plugins.

getClassLoaders

public Collection<ClassLoader> getClassLoaders()
Returns a collection of all plugin classloaders.

Specified by:
getClassLoaders in interface com.jivesoftware.base.plugin.PluginManager
Returns:
a collection of all plugin classloaders.

getPlugin

public Plugin<?> getPlugin(String name)
Returns a plugin by name or null if a plugin with that name does not exist. The name is the name of the directory that the plugin is in such as "broadcast".

Specified by:
getPlugin in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
name - the name of the plugin.
Returns:
the plugin.

getPluginMetaData

public com.jivesoftware.base.plugin.PluginMetaData getPluginMetaData(String name)
Returns meta data associated with the plugin.

Specified by:
getPluginMetaData in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
name - The name of the plugin.
Returns:
meta data associated with the plugin.

getPluginMetaData

public com.jivesoftware.base.plugin.PluginMetaData getPluginMetaData(Plugin<?> plugin)
Returns meta data assosiated with the plugin.

Specified by:
getPluginMetaData in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
plugin - The plugin to acquire meta data for
Returns:
meta data associated with the plugin.

getPluginDirectory

protected File getPluginDirectory(Plugin<?> plugin)
Returns the plugin's directory.

Parameters:
plugin - the plugin.
Returns:
the plugin's directory.

createPluginCacheDirectories

protected boolean createPluginCacheDirectories(List<com.jivesoftware.base.plugin.dao.PluginDbBean> pluginBeans)
Checks the existing plugins to see if there are any plugins that need to be installed. returns true if plugins caches are created properly, false otherwise


createLocalCache

protected File createLocalCache(com.jivesoftware.base.plugin.dao.PluginDbBean bean)
                         throws IOException
Pulls the plugin jar file from the database outputs it to the pluginDirectory and expands the jar file.

Parameters:
bean - The db bean for the plugin.
Returns:
Throws:
IOException - Thrown if there are problems creating the plugin's cache directory

getPluginProperties

protected JiveProperties<String,String> getPluginProperties(String pluginName)
Returns a object for storing and receving property setting for a plugin. Property stored in this object will be persisted and updated across the cluster.

Parameters:
pluginName - The name of the plugin to get a properties object for.
Returns:
Object for storing and receiving plugin properties.

getPluginResourceBundles

public List<ResourceBundle> getPluginResourceBundles(Locale l)
Returns all of the plugin resource bundles that match the specified locale.

Specified by:
getPluginResourceBundles in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
l - The locale to acquire plugin resource bundles for.
Returns:
All the plugin resource bundles that match the locale.
See Also:
getPluginResourceBundle(com.jivesoftware.base.plugin.Plugin, java.util.Locale)

loadPlugin

public List<com.jivesoftware.base.plugin.ConfiguratorResult> loadPlugin(File pluginDir,
                                                                        com.jivesoftware.base.plugin.dao.PluginDbBean pluginDbBean)
                                                                 throws com.jivesoftware.base.plugin.PluginException
Loads a plug-in module into the container. Loading consists of the following steps:

Parameters:
pluginDir - the plugin directory.
Returns:
Throws:
PluginException - Thrown if there are issues installing the plugin.

unloadPlugin

public com.jivesoftware.base.plugin.PluginResultList unloadPlugin(String pluginName)
Unloads a plugin. The name should be the name of the plugin directory and not the name as given by the plugin meta-data. This method only removes the plugin but does not delete the plugin JAR file. Therefore, if the plugin JAR still exists after this method is called, the plugin will be started again the next time the plugin monitor process runs. This is useful for "restarting" plugins.

This method is called automatically when a plugin's JAR file is deleted.

Parameters:
pluginName - the name of the plugin to unload.

registerPlugin

protected void registerPlugin(Plugin<?> plugin,
                              File pluginDir)
Registers the plugin as an installed plugin.

Parameters:
plugin - The plugin object.
pluginDir - The directory where the plugin lives.

isValidVersion

protected void isValidVersion(String pluginName,
                              org.dom4j.Document pluginXML,
                              File pluginDir)
                       throws com.jivesoftware.base.plugin.PluginException
Checks to see if the clearspace version is ok to use with this plugin. This will compare plugin.xml's maxServerVersion and minServerVersion elements with the clearspace server version.

Parameters:
pluginName - The name of the plugin.
pluginXML - The plugin's configuration.
pluginDir - The directory where the plugin lives.
Throws:
PluginException - Thrown if the version of the plugin is illegal.

getPluginResourceBundle

public ResourceBundle getPluginResourceBundle(Plugin<?> plugin,
                                              Locale locale)
Acquires a plugins resource bundle which should be stored in /plugin_i18n in the plugin's classloader.

Specified by:
getPluginResourceBundle in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
plugin - The plugin to acquire a resource bundle for.
locale - The locale of the resource bundle.
Returns:
The resource bundle for a plugin.

handleUpgradeTasks

protected int handleUpgradeTasks(File pluginDir,
                                 Plugin<?> p)
If an upgrade.xml was specified in the plugin all upgrade tasks will be performed if the jiveVersion value for the plugin is less than the tasks specified in the upgrade.xml

Parameters:
pluginDir - The directory where the plugin exists.
p - The plugin object.
Returns:
The number of tasks performed.

preInit

public void preInit()
             throws com.jivesoftware.base.plugin.PluginException
Throws:
com.jivesoftware.base.plugin.PluginException

processSpringConfigs

public void processSpringConfigs(List<String> springPaths)
                          throws IOException
Process plugins to configure plugin caches that need to be configured first, and populate plugin's spring paths.

Parameters:
springPaths - This path will be populated with all spring plugin paths
Throws:
IOException

createPluginChainingClassloader

protected ClassLoader createPluginChainingClassloader()
Creates a classloader that will also look for classes under the plugin directories.

Returns:
A classloader that also contains plugin directories.

getPluginBeans

protected List<com.jivesoftware.base.plugin.dao.PluginDbBean> getPluginBeans()
Returns beans for all the plugins that need to have their spring config loaded with the parent context.

Returns:
beans for all the plugins that need to have their spring config loaded with the parent context.

getSpringUnManagedDAO

protected com.jivesoftware.base.plugin.dao.PluginDAO getSpringUnManagedDAO()

getPluginClassloader

protected com.jivesoftware.base.plugin.PluginClassLoader getPluginClassloader(String pluginName,
                                                                              File pluginDir)

loadDevPlugins

protected void loadDevPlugins()

loadClass

public Class<?> loadClass(Plugin<?> plugin,
                          String className)
                   throws ClassNotFoundException,
                          IllegalAccessException,
                          InstantiationException
Loads a class from the classloader of a plugin.

Parameters:
plugin - the plugin.
className - the name of the class to load.
Returns:
the class.
Throws:
ClassNotFoundException - if the class was not found.
IllegalAccessException - if not allowed to access the class.
InstantiationException - if the class could not be created.

getPluginClassloader

public com.jivesoftware.base.plugin.PluginClassLoader getPluginClassloader(Plugin<?> plugin)
Returns the classloader of a plugin.

Specified by:
getPluginClassloader in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
plugin - the plugin.
Returns:
the classloader of the plugin.

addPluginListener

public void addPluginListener(PluginListener listener)
Registers a plugin applicationLifeCycleListener. Plugin Listeners allow a notification of when a plugin is loaded and unloaded.

Specified by:
addPluginListener in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
listener - The plugin to register.
See Also:
PluginListener

removePluginListener

public void removePluginListener(PluginListener listener)
Unregisters a plugin applicationLifeCycleListener. The plugin applicationLifeCycleListener will not longer be notified when plugins are loaded and unloaded.

Specified by:
removePluginListener in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
listener - the plugin to remove as a applicationLifeCycleListener.

isPluginBroken

public boolean isPluginBroken(String plugin)
Returns true if the specified plugin is flagged as broken during load time.

Specified by:
isPluginBroken in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
plugin - Name of plugin to check.
Returns:
True if the specified plugin is broken.

getBrokenPlugins

public Map<String,String> getBrokenPlugins()
Returns a list of broken plugins, mapped to what the cause of the breakage was.

Specified by:
getBrokenPlugins in interface com.jivesoftware.base.plugin.PluginManager
Returns:
Map of broken plugin names to what broken them.

deleteBrokenPlugin

public void deleteBrokenPlugin(String pluginName)
Removes a plugin that was flagged as broken. This will delete the plugin from the database and/or the file system, but since the plugin is not actually installed, it doesn't need to do anything else.

Specified by:
deleteBrokenPlugin in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
pluginName - Name of the plugin to delete. Can be a filename or "short" name of plugin.

uninstallPlugin

public com.jivesoftware.base.plugin.PluginResultList uninstallPlugin(Plugin<?> plugin)
Removes a plugin from the system. This will delete the plugin from the jiveHome/plugins directory.

Specified by:
uninstallPlugin in interface com.jivesoftware.base.plugin.PluginManager
Parameters:
plugin - The plugin too delete.

getDevPlugins

protected Set<String> getDevPlugins()
Returns a set of all the plugins that have been specified with -DpluginDirs system property

Returns:
a set of all the plugins that have been specified with -DpluginDirs system property

getPluginMap

protected Map<String,Plugin<?>> getPluginMap()
Returns a map of plugin name plugin entries.

Returns:
a map of plugin name plugin entries.

getPluginDirectory

protected File getPluginDirectory()
Returns the directory {jiveHome}/plugins.

Returns:
the directory {jiveHome}/plugins.

setUpgradeManager

public void setUpgradeManager(com.jivesoftware.community.upgrade.UpgradeManager upgradeManager)

setTaskEngine

public void setTaskEngine(com.jivesoftware.util.task.TaskEngine taskEngine)

setLicenseManager

public void setLicenseManager(com.jivesoftware.community.license.ClearspaceLicenseManager licenseManager)

setPluginPropertyDAO

public void setPluginPropertyDAO(com.jivesoftware.base.plugin.dao.PluginPropertyDAO pluginPropertyDAO)

setPluginDAO

public void setPluginDAO(com.jivesoftware.base.plugin.dao.PluginDAO pluginDAO)

setDispatcher

public void setDispatcher(com.jivesoftware.base.event.v2.EventDispatcher eventDispatcher)
Specified by:
setDispatcher in interface com.jivesoftware.base.event.v2.EventSource

Clearspace Project Page

Copyright © 1999-2007 Jive Software.