public class DefaultPluginManager extends Object implements PluginController, PluginAccessor, PluginSystemLifecycle
PluginLoaders and records the
state of plugins in a
PluginPersistentStateStore.
This class is responsible for enabling and disabling plugins and plugin
modules and reflecting these state changes in the PluginPersistentStateStore.
An interesting quirk in the design is that
installPlugin(com.atlassian.plugin.PluginArtifact) explicitly stores
the plugin via a PluginInstaller, whereas
uninstall(Plugin) relies on the underlying
PluginLoader to remove the plugin if
necessary.PluginAccessor.Descriptor| Modifier and Type | Method and Description |
|---|---|
protected void |
addPlugin(PluginLoader loader,
Plugin plugin)
Deprecated.
Since 2.0.2, use
#addPlugins(PluginLoader,Collection instead |
protected void |
addPlugins(PluginLoader loader,
Collection<Plugin> pluginsToInstall)
Update the local plugin state and enable state aware modules.
|
void |
disablePlugin(String key)
Disables the plugin with the given key.
|
protected void |
disablePluginInternal(String key,
boolean persistDisabledState) |
void |
disablePluginModule(String completeKey)
Disable a plugin module by key.
|
protected void |
disablePluginModuleState(ModuleDescriptor<?> module,
PluginPersistentStateStore stateStore) |
protected void |
disablePluginState(Plugin plugin,
PluginPersistentStateStore stateStore) |
void |
disablePluginWithoutPersisting(String key)
Disables the plugin with the given key without persisting the disabled state.
|
void |
earlyStartup() |
void |
enablePlugin(String key)
Deprecated.
since 2.5.0, use {#link enablePlugins(String... keys)} instead
|
void |
enablePluginModule(String completeKey)
Enable a plugin module by key.
|
protected void |
enablePluginModuleState(ModuleDescriptor<?> module,
PluginPersistentStateStore stateStore) |
void |
enablePlugins(String... keys)
Enable a set of plugins by key.
|
protected void |
enablePluginState(Plugin plugin,
PluginPersistentStateStore stateStore) |
PluginsClassLoader |
getClassLoader()
Retrieve the class loader responsible for loading classes and resources from plugins.
|
Class<?> |
getDynamicPluginClass(String className)
Retrieve a class from a currently loaded (and active) dynamically loaded plugin.
|
InputStream |
getDynamicResourceAsStream(String name)
Retrieve a resource from a currently loaded (and active) dynamically loaded plugin.
|
<D extends ModuleDescriptor<?>> |
getEnabledModuleDescriptorsByClass(Class<D> descriptorClazz)
This method has been reverted to pre PLUG-40 to fix performance issues
that were encountered during load testing.
|
<D extends ModuleDescriptor<?>> |
getEnabledModuleDescriptorsByClass(Class<D> descriptorClazz,
boolean verbose)
Get all enabled module descriptors that have a specific descriptor class.
|
<M> List<ModuleDescriptor<M>> |
getEnabledModuleDescriptorsByType(String type)
Deprecated.
since 0.17, use
getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)
with an appropriate predicate instead. |
<M> List<M> |
getEnabledModulesByClass(Class<M> moduleClass)
Retrieve all plugin modules that implement or extend a specific class.
|
<M> List<M> |
getEnabledModulesByClassAndDescriptor(Class<ModuleDescriptor<M>>[] descriptorClasses,
Class<M> moduleClass)
Deprecated.
since 0.17, use
getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)
with an appropriate predicate instead. |
<M> List<M> |
getEnabledModulesByClassAndDescriptor(Class<ModuleDescriptor<M>> descriptorClass,
Class<M> moduleClass)
Deprecated.
since 0.17, use
getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)
with an appropriate predicate instead. |
Plugin |
getEnabledPlugin(String pluginKey)
Retrieve a given plugin if it is enabled.
|
ModuleDescriptor<?> |
getEnabledPluginModule(String completeKey)
Retrieve an enabled plugin module by complete module key.
|
Collection<Plugin> |
getEnabledPlugins()
Get all of the currently enabled plugins.
|
<M> Collection<ModuleDescriptor<M>> |
getModuleDescriptors(ModuleDescriptorPredicate<M> moduleDescriptorPredicate)
Gets all module descriptors of installed modules that match the given predicate.
|
<M> Collection<M> |
getModules(ModuleDescriptorPredicate<M> moduleDescriptorPredicate)
Gets all installed modules that match the given predicate.
|
Plugin |
getPlugin(String key)
Retrieve a given plugin (whether enabled or not).
|
ModuleDescriptor<?> |
getPluginModule(String completeKey)
Retrieve any plugin module by complete module key.
|
InputStream |
getPluginResourceAsStream(String pluginKey,
String resourcePath)
Retrieve a resource from a currently loaded (and active) plugin.
|
PluginRestartState |
getPluginRestartState(String key)
Gets the state of the plugin upon restart.
|
Collection<Plugin> |
getPlugins()
Gets all of the currently installed plugins.
|
Collection<Plugin> |
getPlugins(PluginPredicate pluginPredicate)
Gets all installed plugins that match the given predicate.
|
protected PluginPersistentState |
getState() |
protected PluginPersistentStateStore |
getStore() |
void |
init()
Initialise the plugin system.
|
String |
installPlugin(PluginArtifact pluginArtifact)
Installs a plugin and returns the plugin key
|
Set<String> |
installPlugins(PluginArtifact... pluginArtifacts)
Installs multiple plugins and returns the list of plugin keys.
|
boolean |
isPluginEnabled(String key)
This method checks to see if the plugin is enabled based on the state
manager and the plugin.
|
boolean |
isPluginModuleEnabled(String completeKey)
Whether or not a given plugin module is currently enabled.
|
boolean |
isSystemPlugin(String key) |
void |
lateStartup() |
protected void |
notifyModuleDisabled(ModuleDescriptor<?> module) |
protected void |
notifyModuleEnabled(ModuleDescriptor<?> module) |
protected void |
notifyPluginDisabled(Plugin plugin) |
protected void |
notifyPluginEnabled(Plugin plugin)
Called on all clustered application nodes, rather than
enablePlugin(String) to just update the local state, state aware
modules and loaders, but not affect the global plugin state. |
protected void |
notifyUninstallPlugin(Plugin plugin) |
void |
onPluginContainerUnavailable(PluginContainerUnavailableEvent event) |
void |
onPluginModuleAvailable(PluginModuleAvailableEvent event) |
void |
onPluginModuleUnavailable(PluginModuleUnavailableEvent event) |
void |
onPluginRefresh(PluginRefreshedEvent event) |
protected void |
onUpdateRequiresRestartState(String pluginKey,
PluginRestartState pluginRestartState) |
protected void |
removeStateFromStore(PluginPersistentStateStore stateStore,
Plugin plugin) |
void |
revertRestartRequiredChange(String pluginKey)
Restores the state of any plugin requiring a restart that had been removed, upgraded, or installed.
|
int |
scanForNewPlugins()
Search all loaders and add any new plugins you find.
|
void |
setDescriptorParserFactory(DescriptorParserFactory descriptorParserFactory)
Deprecated.
Since 2.0.0.beta2
|
void |
setPluginInstaller(PluginInstaller pluginInstaller)
Set the plugin installation strategy for this manager
|
void |
shutdown()
Fires the shutdown event
|
void |
uninstall(Plugin plugin)
Uninstalls the given plugin, emitting disabled and uninstalled events as it does so.
|
protected void |
uninstallNoEvent(Plugin plugin)
Preforms an uninstallation without broadcasting the uninstallation event.
|
protected void |
unloadPlugin(Plugin plugin)
Unload a plugin.
|
protected void |
updatePlugin(Plugin oldPlugin,
Plugin newPlugin)
Replace an already loaded plugin with another version.
|
void |
warmRestart()
Restart all plugins by disabling and enabling them in the order they were loaded (by plugin loader)
|
public DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager)
public DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager, PluginExceptionInterception pluginExceptionInterception)
public DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager, boolean verifyRequiredPlugins)
@ExperimentalApi public DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager, PluginPredicate delayLoadOf)
@ExperimentalApi public DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager, PluginExceptionInterception pluginExceptionInterception, PluginPredicate delayLoadOf)
public DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager, PluginExceptionInterception pluginExceptionInterception, boolean verifyRequiredPlugins)
@ExperimentalApi public DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager, PluginExceptionInterception pluginExceptionInterception, boolean verifyRequiredPlugins, PluginPredicate delayLoadOf)
public void init()
throws PluginParseException,
NotificationException
PluginSystemLifecycleinit in interface PluginSystemLifecyclePluginParseException - If parsing the plugins failed.NotificationException - If any of the Event Listeners throw an exception on the Framework startup events.@ExperimentalApi
public void earlyStartup()
throws PluginParseException,
NotificationException
@ExperimentalApi
public void lateStartup()
throws PluginParseException,
NotificationException
public void shutdown()
shutdown in interface PluginSystemLifecycleIllegalStateException - if already shutdown or already in the
process of shutting down.public final void warmRestart()
PluginSystemLifecyclewarmRestart in interface PluginSystemLifecyclepublic void onPluginModuleAvailable(PluginModuleAvailableEvent event)
public void onPluginModuleUnavailable(PluginModuleUnavailableEvent event)
public void onPluginContainerUnavailable(PluginContainerUnavailableEvent event)
public void onPluginRefresh(PluginRefreshedEvent event)
public void setPluginInstaller(PluginInstaller pluginInstaller)
pluginInstaller - the plugin installation strategy to usePluginInstallerprotected final PluginPersistentStateStore getStore()
public String installPlugin(PluginArtifact pluginArtifact) throws PluginParseException
PluginControllerinstallPlugin in interface PluginControllerpluginArtifact - The plugin artifact to installPluginParseException - if the plugin is not a valid pluginpublic Set<String> installPlugins(PluginArtifact... pluginArtifacts) throws PluginParseException
PluginControllerinstallPlugins in interface PluginControllerpluginArtifacts - The list of plugin artifacts to installPluginParseException - if any plugin is not a valid pluginpublic int scanForNewPlugins()
throws PluginParseException
PluginControllerscanForNewPlugins in interface PluginControllerPluginParseExceptionprotected void onUpdateRequiresRestartState(String pluginKey, PluginRestartState pluginRestartState)
public void uninstall(Plugin plugin) throws PluginException
uninstall in interface PluginControllerplugin - the plugin to uninstall.PluginException - If the plugin or loader doesn't support
uninstallationprotected void uninstallNoEvent(Plugin plugin)
plugin - The plugin to uninstallpublic void revertRestartRequiredChange(String pluginKey) throws PluginException
PluginControllerrevertRestartRequiredChange in interface PluginControllerpluginKey - The plugin key to revertPluginException - If the revert cannot be completedprotected void removeStateFromStore(PluginPersistentStateStore stateStore, Plugin plugin)
protected void unloadPlugin(Plugin plugin) throws PluginException
plugin - the plugin to removePluginException - if the plugin cannot be uninstalledprotected void notifyUninstallPlugin(Plugin plugin)
protected PluginPersistentState getState()
@Deprecated protected void addPlugin(PluginLoader loader, Plugin plugin) throws PluginParseException
#addPlugins(PluginLoader,Collection...) insteadPluginParseExceptionprotected void addPlugins(@Nullable PluginLoader loader, Collection<Plugin> pluginsToInstall) throws PluginParseException
If there is an existing plugin with the same key, the version strings of
the existing plugin and the plugin provided to this method will be parsed
and compared. If the installed version is newer than the provided
version, it will not be changed. If the specified plugin's version is the
same or newer, the existing plugin state will be saved and the plugin
will be unloaded before the provided plugin is installed. If the existing
plugin cannot be unloaded a PluginException will be thrown.
loader - the loader used to load this plugin. This should only be null when called
internally from init(), in which case the loader is looked up per plugin in
candidatePluginsToPluginLoader.pluginsToInstall - the plugins to addPluginParseException - if the plugin cannot be parsedprotected void updatePlugin(Plugin oldPlugin, Plugin newPlugin) throws PluginException
oldPlugin - Plugin to replacenewPlugin - New plugin to installPluginException - if the plugin cannot be updatedpublic Collection<Plugin> getPlugins()
PluginAccessorgetPlugins in interface PluginAccessorPlugins.public Collection<Plugin> getPlugins(PluginPredicate pluginPredicate)
PluginAccessorgetPlugins in interface PluginAccessorpluginPredicate - the PluginPredicate to match.Plugins that match the given predicate.PluginAccessor.getPlugins(com.atlassian.plugin.predicate.PluginPredicate)public Collection<Plugin> getEnabledPlugins()
PluginAccessorgetEnabledPlugins in interface PluginAccessorPlugins.PluginAccessor.getEnabledPlugins()public <M> Collection<M> getModules(ModuleDescriptorPredicate<M> moduleDescriptorPredicate)
PluginAccessorgetModules in interface PluginAccessormoduleDescriptorPredicate - the ModuleDescriptorPredicate to match.ModuleDescriptor.getModule() that match the given predicate.PluginAccessor.getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)public <M> Collection<ModuleDescriptor<M>> getModuleDescriptors(ModuleDescriptorPredicate<M> moduleDescriptorPredicate)
PluginAccessorgetModuleDescriptors in interface PluginAccessormoduleDescriptorPredicate - the ModuleDescriptorPredicate to match.ModuleDescriptors that match the given predicate.PluginAccessor.getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)public Plugin getPlugin(String key)
PluginAccessorgetPlugin in interface PluginAccessorkey - The plugin key. Cannot be null.public Plugin getEnabledPlugin(String pluginKey)
PluginAccessorgetEnabledPlugin in interface PluginAccessorpublic ModuleDescriptor<?> getPluginModule(String completeKey)
PluginAccessorNote: the module may or may not be disabled.
getPluginModule in interface PluginAccessorpublic ModuleDescriptor<?> getEnabledPluginModule(String completeKey)
PluginAccessorgetEnabledPluginModule in interface PluginAccessorpublic <M> List<M> getEnabledModulesByClass(Class<M> moduleClass)
PluginAccessorgetEnabledModulesByClass in interface PluginAccessorPluginAccessor.getEnabledModulesByClass(Class)@Deprecated public <M> List<M> getEnabledModulesByClassAndDescriptor(Class<ModuleDescriptor<M>>[] descriptorClasses, Class<M> moduleClass)
getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)
with an appropriate predicate instead.PluginAccessorgetEnabledModulesByClassAndDescriptor in interface PluginAccessordescriptorClasses - @NotNullmoduleClass - @NotNullPluginAccessor.getEnabledModulesByClassAndDescriptor(Class[], Class)@Deprecated public <M> List<M> getEnabledModulesByClassAndDescriptor(Class<ModuleDescriptor<M>> descriptorClass, Class<M> moduleClass)
getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)
with an appropriate predicate instead.PluginAccessorgetEnabledModulesByClassAndDescriptor in interface PluginAccessordescriptorClass - @NotNullmoduleClass - @NotNullPluginAccessor.getEnabledModulesByClassAndDescriptor(Class, Class)public <D extends ModuleDescriptor<?>> List<D> getEnabledModuleDescriptorsByClass(Class<D> descriptorClazz)
getEnabledModuleDescriptorsByClass in interface PluginAccessordescriptorClazz - module descriptor classModuleDescriptors that implement or extend the given class.PluginAccessor.getEnabledModuleDescriptorsByClass(Class)public <D extends ModuleDescriptor<?>> List<D> getEnabledModuleDescriptorsByClass(Class<D> descriptorClazz, boolean verbose)
PluginAccessorgetEnabledModuleDescriptorsByClass in interface PluginAccessordescriptorClazz - module descriptor classverbose - log verbose messages flagModuleDescriptors that implement or extend the given class.@Deprecated public <M> List<ModuleDescriptor<M>> getEnabledModuleDescriptorsByType(String type) throws PluginParseException, IllegalArgumentException
getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)
with an appropriate predicate instead.PluginAccessorgetEnabledModuleDescriptorsByType in interface PluginAccessorModuleDescriptors that are of a given type.PluginParseExceptionIllegalArgumentExceptionPluginAccessor.getEnabledModuleDescriptorsByType(String)public void enablePlugins(String... keys)
enablePlugins in interface PluginControllerkeys - The plugin keys. Must not be null.@Deprecated public void enablePlugin(String key)
PluginControllerenablePlugin in interface PluginControllerkey - The plugin key.protected void enablePluginState(Plugin plugin, PluginPersistentStateStore stateStore)
protected void notifyPluginEnabled(Plugin plugin)
enablePlugin(String) to just update the local state, state aware
modules and loaders, but not affect the global plugin state.plugin - the plugin being enabledpublic void disablePlugin(String key)
PluginControllerCalling this method will persist the disabled state so that the plugin will also be disabled on next startup. This would normally be used when a user manually disables a plugin.
If you extend DefaultPluginManager and override this method, you will also need to override PluginController.disablePluginWithoutPersisting(String).
disablePlugin in interface PluginControllerkey - The plugin key.PluginController.disablePluginWithoutPersisting(String)public void disablePluginWithoutPersisting(String key)
PluginControllerCalling this method will NOT persist the disabled state so that the framework will try to enable the plugin on next startup. This is used when a plugin has errors on startup.
If you extend DefaultPluginManager and override PluginController.disablePlugin(String), you will also need to override this method.
disablePluginWithoutPersisting in interface PluginControllerkey - The plugin key.PluginController.disablePlugin(String)protected void disablePluginInternal(String key, boolean persistDisabledState)
protected void disablePluginState(Plugin plugin, PluginPersistentStateStore stateStore)
protected void notifyPluginDisabled(Plugin plugin)
public void disablePluginModule(String completeKey)
PluginControllerdisablePluginModule in interface PluginControllercompleteKey - The "complete key" of the plugin module.protected void disablePluginModuleState(ModuleDescriptor<?> module, PluginPersistentStateStore stateStore)
protected void notifyModuleDisabled(ModuleDescriptor<?> module)
public void enablePluginModule(String completeKey)
PluginControllerenablePluginModule in interface PluginControllercompleteKey - The "complete key" of the plugin module.protected void enablePluginModuleState(ModuleDescriptor<?> module, PluginPersistentStateStore stateStore)
protected void notifyModuleEnabled(ModuleDescriptor<?> module)
public boolean isPluginModuleEnabled(String completeKey)
PluginAccessorisPluginModuleEnabled in interface PluginAccessorPluginAccessor.isPluginEnabled(String)public boolean isPluginEnabled(String key)
isPluginEnabled in interface PluginAccessorkey - The plugin keypublic InputStream getDynamicResourceAsStream(String name)
PluginAccessorgetDynamicResourceAsStream in interface PluginAccessorname - the path to the resource to retrievepublic Class<?> getDynamicPluginClass(String className) throws ClassNotFoundException
PluginAccessorgetDynamicPluginClass in interface PluginAccessorclassName - the name of the class to retrieveClassNotFoundException - thrown if no classes by that name could be found in any of the enabled dynamic pluginspublic PluginsClassLoader getClassLoader()
PluginAccessorgetClassLoader in interface PluginAccessorpublic InputStream getPluginResourceAsStream(String pluginKey, String resourcePath)
PluginAccessorgetPluginResourceAsStream in interface PluginAccessorpublic boolean isSystemPlugin(String key)
isSystemPlugin in interface PluginAccessorpublic PluginRestartState getPluginRestartState(String key)
PluginAccessorgetPluginRestartState in interface PluginAccessorkey - The plugin key@Deprecated public void setDescriptorParserFactory(DescriptorParserFactory descriptorParserFactory)
Copyright © 2014 Atlassian. All rights reserved.