Jive API (3.0.13) Core Javadocs

com.jivesoftware.base.plugin
Class PluginManagerImpl

java.lang.Object
  extended by com.jivesoftware.base.plugin.PluginManagerImpl
All Implemented Interfaces:
JiveManager

@Transactional(readOnly=true,
               propagation=SUPPORTS)
public class PluginManagerImpl
extends Object
implements JiveManager

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<String,List<UpgradeTaskException>> brokenPluginUpgradeExceptions
           
protected  Map<Locale,List<ResourceBundle>> bundleCache
           
protected  Map<String,PluginClassLoader> classloaders
           
protected  Collection<PluginConfigurator> configurators
           
protected  List<String> customURLMapperList
           
protected  Set<String> devPlugins
           
protected  EventDispatcher eventDispatcher
           
protected  AtomicBoolean initialized
           
protected static PluginManagerImpl instance
           
protected  JiveLicenseManager licenseManager
           
protected  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  PluginPropertyDAO pluginPropertyDAO
           
protected  Map<String,Plugin<?>> plugins
           
protected  TaskEngine taskEngine
           
protected  UpgradeManager upgradeManager
           
 
Constructor Summary
protected PluginManagerImpl()
          Constructs a new plugin manager.
 
Method Summary
 void addPluginListener(PluginListener listener)
          Registers a plugin applicationLifeCycleListener.
 void addUpgradeException(String pluginName, UpgradeTaskException exception)
          Register an encountered plugin upgrade exception.
protected  File createLocalCache(PluginDbBean bean)
          Pulls the plugin jar file from the database outputs it to the pluginDirectory and expands the jar file.
protected  boolean createPluginCacheDirectories(List<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 com.jivesoftware.community.lifecycle.spring.JiveContextLoader
 Plugin<?> getPlugin(String name)
          Returns a plugin by name or null if a plugin with that name does not exist.
protected  List<PluginDbBean> getPluginBeans()
          Returns beans for all the plugins that need to have their spring config loaded with the parent context.
 PluginClassLoader getPluginClassloader(Plugin<?> plugin)
          Returns the classloader of a plugin.
protected  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.
 PluginMetaData getPluginMetaData(Plugin<?> plugin)
          Returns meta data assosiated with the 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  PluginDAO getSpringUnManagedDAO()
           
 List<UpgradeTaskException> getUpgradeExceptions(String pluginName)
          Return a list of plugin upgrade exceptions for the given plugin.
 void handle(ApplicationStateChangeEvent ev)
           
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
 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<ConfiguratorResult> loadPlugin(File pluginDir, 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<PluginConfigurator> configurators)
          Set the list of plugin configuration objects that will be used to configure the plugins.
 void setDispatcher(EventDispatcher eventDispatcher)
           
 void setLicenseManager(JiveLicenseManager licenseManager)
           
 void setPluginDAO(PluginDAO pluginDAO)
           
 void setPluginPropertyDAO(PluginPropertyDAO pluginPropertyDAO)
           
 void setTaskEngine(TaskEngine taskEngine)
           
 void setUpgradeManager(UpgradeManager upgradeManager)
           
 PluginResultList uninstallPlugin(Plugin<?> plugin)
          Removes a plugin from the system.
 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

brokenPluginUpgradeExceptions

protected Map<String,List<UpgradeTaskException>> brokenPluginUpgradeExceptions

pluginMeta

protected Map<Object,PluginMetaDataImpl> pluginMeta

classloaders

protected Map<String,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 UpgradeManager upgradeManager

configurators

protected Collection<PluginConfigurator> configurators

taskEngine

protected TaskEngine taskEngine

licenseManager

protected JiveLicenseManager licenseManager

pluginPropertyDAO

protected PluginPropertyDAO pluginPropertyDAO

pluginDAO

protected PluginDAO pluginDAO

instance

protected static final PluginManagerImpl instance

eventDispatcher

protected 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 com.jivesoftware.community.lifecycle.spring.JiveContextLoader

Returns:
An instance of PluginManagerImpl

destroy

public void destroy()
Shuts down all running plugins.

Specified by:
destroy in interface JiveManager

setConfigurators

public void setConfigurators(Collection<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.

Returns:
True if the plugin framework is initialized.

installPlugin

@Transactional(readOnly=false,
               propagation=REQUIRED,
               rollbackFor=)
public PluginResultList installPlugin(File file)
                               throws PluginException
Installs or updates an existing plugin.

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.

Returns:
a Collection of all installed plugins.

getClassLoaders

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

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".

Parameters:
name - the name of the plugin.
Returns:
the plugin.

getPluginMetaData

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

Parameters:
name - The name of the plugin.
Returns:
meta data associated with the plugin.

getPluginMetaData

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

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<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(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.

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<ConfiguratorResult> loadPlugin(File pluginDir,
                                           PluginDbBean pluginDbBean)
                                    throws 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 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)
                       throws PluginException
Registers the plugin as an installed plugin.

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

isValidVersion

protected void isValidVersion(String pluginName,
                              org.dom4j.Document pluginXML,
                              File pluginDir)
                       throws 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.

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 PluginException
Throws:
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()
                                               throws PluginException
Creates a classloader that will also look for classes under the plugin directories.

Returns:
A classloader that also contains plugin directories.
Throws:
PluginException

getPluginBeans

protected List<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 PluginDAO getSpringUnManagedDAO()

getPluginClassloader

protected 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 PluginClassLoader getPluginClassloader(Plugin<?> plugin)
Returns the classloader of a plugin.

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.

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.

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.

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.

Returns:
Map of broken plugin names to what broken them.

getUpgradeExceptions

public List<UpgradeTaskException> getUpgradeExceptions(String pluginName)
Return a list of plugin upgrade exceptions for the given plugin.

Parameters:
pluginName -
Returns:

addUpgradeException

public void addUpgradeException(String pluginName,
                                UpgradeTaskException exception)
Register an encountered plugin upgrade exception.

Parameters:
pluginName -
exception -

deleteBrokenPlugin

@Transactional(readOnly=false,
               propagation=REQUIRED)
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.

Parameters:
pluginName - Name of the plugin to delete. Can be a filename or "short" name of plugin.

uninstallPlugin

@Transactional(readOnly=false,
               propagation=REQUIRED)
public PluginResultList uninstallPlugin(Plugin<?> plugin)
Removes a plugin from the system. This will delete the plugin from the jiveHome/plugins directory.

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(UpgradeManager upgradeManager)

setTaskEngine

public void setTaskEngine(TaskEngine taskEngine)

setLicenseManager

public void setLicenseManager(JiveLicenseManager licenseManager)

setPluginPropertyDAO

public void setPluginPropertyDAO(PluginPropertyDAO pluginPropertyDAO)

setPluginDAO

public void setPluginDAO(PluginDAO pluginDAO)

setDispatcher

public void setDispatcher(EventDispatcher eventDispatcher)

handle

public void handle(ApplicationStateChangeEvent ev)

Jive Product Page

Copyright © 1999-2007 Jive Software.