Class PluginManager
- java.lang.Object
-
- org.jivesoftware.openfire.container.PluginManager
-
public class PluginManager extends Object
Manages plugins. Thepluginsdirectory 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.
minServerVersiondefinition.- Author:
- Matt Tucker
- See Also:
Plugin,XMPPServer.getPluginManager()
- installed - the plugin archive file is present in the
-
-
Constructor Summary
Constructors Constructor Description PluginManager(Path pluginDir)Constructs a new plugin manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddPluginListener(PluginListener listener)Registers a PluginListener, which will now start receiving events regarding plugin creation and destruction.voidaddPluginManagerListener(PluginManagerListener listener)Registers 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.StringgetAuthor(Plugin plugin)Deprecated.Moved toPluginMetadataHelper.getAuthor(Plugin).StringgetCanonicalName(Plugin plugin)Returns the canonical name for a loaded plugin.StringgetDatabaseKey(Plugin plugin)Deprecated.intgetDatabaseVersion(Plugin plugin)Deprecated.StringgetDescription(Plugin plugin)Deprecated.StringgetLicense(Plugin plugin)Deprecated.Moved toPluginMetadataHelper.getLicense(Plugin).StringgetLoadWarning(String canonicalPluginName)Returns a human-readable, localized message related to a failure while trying to load a plugin.PluginMetadatagetMetadata(String canonicalName)Returns metadata for an extracted plugin, or null when the plugin is extracted nor loaded.Map<String,PluginMetadata>getMetadataExtractedPlugins()Returns metadata for all extracted plugins, mapped by their canonical name.StringgetMinServerVersion(Plugin plugin)Deprecated.StringgetName(Plugin plugin)Deprecated.Moved toPluginMetadataHelper.getName(Plugin).PlugingetPlugin(String canonicalName)Deprecated.in Openfire 4.4 in favour ofgetPluginByName(String)Optional<Plugin>getPluginByName(String pluginName)Returns a loaded plugin by the name contained in the plugin.xml <name/> tag, ignoring case.PluginClassLoadergetPluginClassloader(Plugin plugin)Returns the classloader of a plugin.FilegetPluginDirectory(Plugin plugin)Deprecated.Use #getPluginPath() instead.PathgetPluginPath(Plugin plugin)Returns the plugin's directory.Collection<Plugin>getPlugins()Returns a Collection of all loaded plugins.PathgetPluginsDirectory()Returns the directory that contains all plugins.StringgetVersion(Plugin plugin)Deprecated.Moved toPluginMetadataHelper.getVersion(Plugin).booleaninstallPlugin(InputStream in, String pluginFilename)Installs or updates an existing plugin.booleanisExecuted()Returns 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.booleanisLoaded(String canonicalName)Returns true if the plugin by the specified name is loaded.booleanisMonitorTaskRunning()ClassloadClass(Plugin plugin, String className)Loads a class from the classloader of a plugin.booleanreloadPlugin(String pluginName)voidremovePluginListener(PluginListener listener)Deregisters a PluginListener, which will no longer receive events.voidremovePluginManagerListener(PluginManagerListener listener)Deregisters a PluginManagerListener, which will no longer receive events.voidshutdown()Shuts down all running plugins.voidstart()Starts plugins and the plugin monitoring service.static booleanvalidMagicNumbers(BufferedInputStream bin)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.
-
-
-
Constructor Detail
-
PluginManager
public PluginManager(Path pluginDir)
Constructs a new plugin manager.- Parameters:
pluginDir- the directory containing all Openfire plugins, typically OPENFIRE_HOME/plugins/
-
-
Method Detail
-
start
public void start()
Starts plugins and the plugin monitoring service.
-
shutdown
public void shutdown()
Shuts down all running plugins.
-
getPluginsDirectory
public Path getPluginsDirectory()
Returns the directory that contains all plugins. This typically is OPENFIRE_HOME/plugins.- Returns:
- The directory that contains all plugins.
-
installPlugin
public boolean installPlugin(InputStream in, String pluginFilename)
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
public boolean isInstalled(String canonicalName)
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
public boolean isExtracted(String canonicalName)
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
public boolean isLoaded(String canonicalName)
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
public Map<String,PluginMetadata> 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
public PluginMetadata getMetadata(String canonicalName)
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
public Collection<Plugin> 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
public String getCanonicalName(Plugin plugin)
Returns the canonical name for a loaded plugin.- Parameters:
plugin- A plugin (cannot be null).- Returns:
- The canonical name for the plugin (never null).
-
getPlugin
@Deprecated public Plugin getPlugin(String canonicalName)
Deprecated.in Openfire 4.4 in favour ofgetPluginByName(String)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".- Parameters:
canonicalName- the name of the plugin.- Returns:
- the plugin.
-
getPluginByName
public Optional<Plugin> getPluginByName(String pluginName)
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
-
getPluginDirectory
@Deprecated public File getPluginDirectory(Plugin plugin)
Deprecated.Use #getPluginPath() instead.- Parameters:
plugin- the plugin to get the directory for- Returns:
- the plugin's directory
-
getPluginPath
public Path getPluginPath(Plugin plugin)
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
public void deletePlugin(String pluginName)
Delete a plugin, which removes the plugin.jar/war file after which the plugin is unloaded.- Parameters:
pluginName- the plugin to delete
-
reloadPlugin
public boolean reloadPlugin(String pluginName)
-
getLoadWarning
public String getLoadWarning(String canonicalPluginName)
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.
-
loadClass
public Class loadClass(Plugin plugin, String className) throws ClassNotFoundException
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.
-
getName
@Deprecated public String getName(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getName(Plugin).- Parameters:
plugin- the plugin to get the name for- Returns:
- the name of the plugin, as defined in the plugin.xml
-
getDescription
@Deprecated public String getDescription(Plugin plugin)
Deprecated.- Parameters:
plugin- the plugin to get the description for- Returns:
- the description of the plugin
-
getAuthor
@Deprecated public String getAuthor(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getAuthor(Plugin).- Parameters:
plugin- the plugin to get the author for- Returns:
- the author of the plugin
-
getVersion
@Deprecated public String getVersion(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getVersion(Plugin).- Parameters:
plugin- the plugin to get the version for- Returns:
- the version of the plugin
-
getMinServerVersion
@Deprecated public String getMinServerVersion(Plugin plugin)
Deprecated.- Parameters:
plugin- the plugin to get the minimum server version for- Returns:
- the minimum server version for the plugin
-
getDatabaseKey
@Deprecated public String getDatabaseKey(Plugin plugin)
Deprecated.- Parameters:
plugin- the plugin to get the database key for- Returns:
- the database key for the plugin
-
getDatabaseVersion
@Deprecated public int getDatabaseVersion(Plugin plugin)
Deprecated.- Parameters:
plugin- the plugin to get the database version for- Returns:
- the database version for the plugin
-
getLicense
@Deprecated public String getLicense(Plugin plugin)
Deprecated.Moved toPluginMetadataHelper.getLicense(Plugin).- Parameters:
plugin- the plugin to get the licence for- Returns:
- the licence for the plugin
-
getPluginClassloader
public PluginClassLoader getPluginClassloader(Plugin plugin)
Returns the classloader of a plugin.- Parameters:
plugin- the plugin.- Returns:
- the classloader of the plugin.
-
validMagicNumbers
public static boolean validMagicNumbers(BufferedInputStream bin) throws IOException
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
public void addPluginListener(PluginListener listener)
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
public void removePluginListener(PluginListener listener)
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
public void addPluginManagerListener(PluginManagerListener listener)
Registers a PluginManagerListener, which will now start receiving events regarding plugin management.- Parameters:
listener- the listener to be notified (cannot be null).
-
removePluginManagerListener
public void removePluginManagerListener(PluginManagerListener listener)
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()
-
-