Class PluginManager
java.lang.Object
org.jivesoftware.openfire.container.PluginManager
Manages plugins.
The
plugins directory is monitored for any new plugins, and they are dynamically loaded.
An instance of this class can be obtained using: XMPPServer.getInstance().getPluginManager()
These states are defined for plugin management:
- installed - the plugin archive file is present in the
pluginsdirectory. - extracted - the plugin archive file has been extracted.
- loaded - the plugin has (successfully) been initialized.
minServerVersion definition.- Author:
- Matt Tucker
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPluginListener(PluginListener listener) Registers a PluginListener, which will now start receiving events regarding plugin creation and destruction.voidRegisters a PluginManagerListener, which will now start receiving events regarding plugin management.voiddeletePlugin(String pluginName) Delete a plugin, which removes the plugin.jar/war file after which the plugin is unloaded.getCanonicalName(Plugin plugin) Returns the canonical name for a loaded plugin.getLoadWarning(String canonicalPluginName) Returns a human-readable, localized message related to a failure while trying to load a plugin.getMetadata(String canonicalName) Returns metadata for an extracted plugin, or null when the plugin is extracted nor loaded.Returns metadata for all extracted plugins, mapped by their canonical name.getPluginByCanonicalName(String canonicalName) Returns a loaded plugin by its canonical name ornullif a plugin with that name does not exist.getPluginByName(String pluginName) Returns a loaded plugin by the name contained in the plugin.xml <name/> tag, ignoring case.getPluginClassloader(Plugin plugin) Returns the classloader of a plugin.getPluginPath(Plugin plugin) Returns the plugin's directory.Returns a Collection of all loaded plugins.Returns the directory that contains all plugins.booleanChecks if there were any problems while loading plugins.booleaninstallPlugin(InputStream in, String pluginFilename) Installs or updates an existing plugin.booleanReturns true if at least one attempt to load plugins has been done.booleanisExtracted(String canonicalName) Returns true if the plugin by the specified name is extracted.booleanisInstalled(String canonicalName) Returns true if the plugin by the specified name is installed.booleanReturns true if the plugin by the specified name is loaded.booleanClass<?>Loads a class from the classloader of a plugin.booleanreloadPlugin(String pluginName) voidremovePluginListener(PluginListener listener) Deregisters a PluginListener, which will no longer receive events.voidDeregisters a PluginManagerListener, which will no longer receive events.voidshutdown()Shuts down all running plugins.voidstart()Starts plugins and the plugin monitoring service.static booleanVerifies that the first few bytes of the input stream correspond to any of the known 'magic numbers' that are known to represent a JAR archive.
-
Constructor Details
-
PluginManager
Constructs a new plugin manager.- Parameters:
pluginDir- the directory containing all Openfire plugins, typically OPENFIRE_HOME/plugins/
-
-
Method Details
-
start
public void start()Starts plugins and the plugin monitoring service. -
shutdown
public void shutdown()Shuts down all running plugins. -
getPluginsDirectory
Returns the directory that contains all plugins. This typically is OPENFIRE_HOME/plugins.- Returns:
- The directory that contains all plugins.
-
installPlugin
Installs or updates an existing plugin.- Parameters:
in- the input stream that contains the new plugin definition.pluginFilename- the filename of the plugin to create or update.- Returns:
- true if the plugin was successfully installed or updated.
-
isInstalled
Returns true if the plugin by the specified name is installed. Specifically, this checks if the plugin archive file is present in thepluginsdirectory. Note that an installed plugin is not per definition an extracted plugin, and an extracted plugin is not per definition a loaded plugin. A plugin that's extracted might, for instance, fail to load, due to restrictions imposed by itsminServerVersiondefinition.- Parameters:
canonicalName- the canonical filename of the plugin (cannot be null).- Returns:
- true if the plugin is installed, otherwise false.
-
isExtracted
Returns true if the plugin by the specified name is extracted. Specifically, this checks if thepluginsdirectory contains a subdirectory that matches the canonical name of the plugin. Note that an installed plugin is not per definition an extracted plugin, and an extracted plugin is not per definition a loaded plugin. A plugin that's extracted might, for instance, fail to load, due to restrictions imposed by itsminServerVersiondefinition.- Parameters:
canonicalName- the canonical filename of the plugin (cannot be null).- Returns:
- true if the plugin is extracted, otherwise false.
-
isLoaded
Returns true if the plugin by the specified name is loaded. Specifically, this checks if an instance was created for the plugin class file. Note that an installed plugin is not per definition an extracted plugin, and an extracted plugin is not per definition a loaded plugin. A plugin that's extracted might, for instance, fail to load, due to restrictions imposed by itsminServerVersiondefinition.- Parameters:
canonicalName- the canonical filename of the plugin (cannot be null).- Returns:
- true if the plugin is extracted, otherwise false.
-
getMetadataExtractedPlugins
Returns metadata for all extracted plugins, mapped by their canonical name. The collection is alphabetically sorted, by plugin name. Note that an installed plugin is not per definition an extracted plugin, and an extracted plugin is not per definition a loaded plugin. A plugin that's extracted might, for instance, fail to load, due to restrictions imposed by itsminServerVersiondefinition.- Returns:
- A collection of metadata (possibly empty, never null).
-
getMetadata
Returns metadata for an extracted plugin, or null when the plugin is extracted nor loaded. Note that an installed plugin is not per definition an extracted plugin, and an extracted plugin is not per definition a loaded plugin. A plugin that's extracted might, for instance, fail to load, due to restrictions imposed by itsminServerVersiondefinition.- Parameters:
canonicalName- the canonical name (lower case JAR/WAR file without exception) of the plugin- Returns:
- A collection of metadata (possibly empty, never null).
-
getPlugins
Returns a Collection of all loaded plugins. The returned collection will not include plugins that have been downloaded, but not loaded.- Returns:
- a Collection of all loaded plugins.
-
getCanonicalName
Returns the canonical name for a loaded plugin.- Parameters:
plugin- A plugin (cannot be null).- Returns:
- The canonical name for the plugin (never null).
-
getPluginByCanonicalName
Returns a loaded plugin by its canonical name ornullif a plugin with that name does not exist. The canonical name is the lowercase-name of the plugin archive, without the file extension. For example: "broadcast". Note that the canonical name of the plugin is sensitive to filenames outside of the plugin's author direct control. Prefer usinggetPluginByName(String).- Parameters:
canonicalName- the name of the plugin.- Returns:
- the plugin.
-
getPluginByName
Returns a loaded plugin by the name contained in the plugin.xml <name/> tag, ignoring case. For example: "broadcast".- Parameters:
pluginName- the name of the plugin.- Returns:
- the plugin, if found
- Since:
- Openfire 4.4
-
getPluginPath
Returns the plugin's directory.- Parameters:
plugin- the plugin.- Returns:
- the plugin's directory.
- Since:
- Openfire 4.1
-
isExecuted
public boolean isExecuted()Returns true if at least one attempt to load plugins has been done. A true value does not mean that available plugins have been loaded nor that plugins to be added in the future are already loaded. :)- Returns:
- true if at least one attempt to load plugins has been done.
-
deletePlugin
Delete a plugin, which removes the plugin.jar/war file after which the plugin is unloaded.- Parameters:
pluginName- the plugin to delete
-
reloadPlugin
-
getLoadWarning
Returns a human-readable, localized message related to a failure while trying to load a plugin. When the last time that this plugin was loaded was successful (or when a plugin of this name was never attempted to be loaded at all), this method returns null.- Parameters:
canonicalPluginName- The canonical name of a plugin- Returns:
- An optional human-readable, localized failure message.
-
hasLoadWarnings
public boolean hasLoadWarnings()Checks if there were any problems while loading plugins.- Returns:
- true when at least one plugin has failed to load, otherwise false.
-
loadClass
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.
-
getPluginClassloader
Returns the classloader of a plugin.- Parameters:
plugin- the plugin.- Returns:
- the classloader of the plugin.
-
validMagicNumbers
Verifies that the first few bytes of the input stream correspond to any of the known 'magic numbers' that are known to represent a JAR archive. This method uses the mark/reset functionality of InputStream. This ensures that the input stream is reset back to its original position after execution of this method.- Parameters:
bin- The input to read (cannot be null).- Returns:
- true if the stream first few bytes are equal to any of the known magic number sequences, otherwise false.
- Throws:
IOException
-
addPluginListener
Registers a PluginListener, which will now start receiving events regarding plugin creation and destruction. When the listener was already registered, this method will have no effect.- Parameters:
listener- the listener to be notified (cannot be null).
-
removePluginListener
Deregisters a PluginListener, which will no longer receive events. When the listener was never added, this method will have no effect.- Parameters:
listener- the listener to be removed (cannot be null).
-
addPluginManagerListener
Registers a PluginManagerListener, which will now start receiving events regarding plugin management.- Parameters:
listener- the listener to be notified (cannot be null).
-
removePluginManagerListener
Deregisters a PluginManagerListener, which will no longer receive events. When the listener was never added, this method will have no effect.- Parameters:
listener- the listener to be notified (cannot be null).
-
isMonitorTaskRunning
public boolean isMonitorTaskRunning()
-