public class DefaultPluginManager extends Object implements PluginController, PluginAccessor, SplitStartupPluginSystemLifecycle
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
installPlugins(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.
| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultPluginManager.Builder<T extends DefaultPluginManager.Builder<?>> |
PluginAccessor.Descriptor| Modifier and Type | Method and Description |
|---|---|
ModuleDescriptor<?> |
addDynamicModule(Plugin maybePluginInternal,
org.dom4j.Element module)
Add a new module described by
element to the plugin specified. |
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.
|
void |
disablePluginWithoutPersisting(String key)
Disables the plugin with the given key without persisting the disabled state.
|
void |
earlyStartup()
Perform the first part of startup.
|
void |
enablePluginModule(String completeKey)
Enable a plugin module by key.
|
void |
enablePlugins(String... keys)
Enable a set of plugins by key.
|
PluginsClassLoader |
getClassLoader()
Retrieve the class loader responsible for loading classes and resources from plugins.
|
Iterable<ModuleDescriptor<?>> |
getDynamicModules(Plugin maybePluginInternal)
Retrieve all currently registered dynamic modules i.e.
|
Class<?> |
getDynamicPluginClass(String className) |
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.
|
<M> List<M> |
getEnabledModulesByClass(Class<M> moduleClass)
Retrieve all plugin modules that implement or extend a specific class.
|
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.
|
static String |
getLateStartupEnableRetryProperty() |
static String |
getMinimumPluginVersionsFileProperty() |
<M> Collection<ModuleDescriptor<M>> |
getModuleDescriptors(Predicate<ModuleDescriptor<M>> moduleDescriptorPredicate)
Gets all module descriptors of installed modules that match the given predicate.
|
<M> Collection<M> |
getModules(Predicate<ModuleDescriptor<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.
|
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(Predicate<Plugin> pluginPredicate)
Gets all installed plugins that match the given predicate.
|
static String |
getStartupOverrideFileProperty() |
protected PluginPersistentState |
getState() |
void |
init()
Initialise the plugin system.
|
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()
Perform the second part of startup.
|
static DefaultPluginManager.Builder<? extends DefaultPluginManager.Builder<?>> |
newBuilder() |
protected void |
notifyModuleDisabled(ModuleDescriptor<?> module) |
protected void |
notifyModuleEnabled(ModuleDescriptor<?> module) |
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) |
void |
removeDynamicModule(Plugin maybePluginInternal,
ModuleDescriptor<?> module)
Remove a module that was dynamically added to plugin..
|
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 |
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.
|
void |
uninstallPlugins(Collection<Plugin> plugins)
Uninstall multiple plugin, disabling it first.
|
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)
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetActiveModuleDescriptorsByClass, getModuleDescriptors, getModules, getPluginspublic 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, Predicate<Plugin> delayLoadOf)
@ExperimentalApi public DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager, PluginExceptionInterception pluginExceptionInterception, Predicate<Plugin> delayLoadOf)
public DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager, PluginExceptionInterception pluginExceptionInterception, boolean verifyRequiredPlugins)
public DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager, PluginExceptionInterception pluginExceptionInterception, boolean verifyRequiredPlugins, Predicate<Plugin> delayLoadOf)
protected DefaultPluginManager(DefaultPluginManager.Builder<? extends DefaultPluginManager.Builder> builder)
@Internal public static String getStartupOverrideFileProperty()
@Internal public static String getLateStartupEnableRetryProperty()
@Internal public static String getMinimumPluginVersionsFileProperty()
public static DefaultPluginManager.Builder<? extends DefaultPluginManager.Builder<?>> newBuilder()
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
SplitStartupPluginSystemLifecycleearlyStartup in interface SplitStartupPluginSystemLifecyclePluginParseException - If parsing the plugins failed.NotificationException - If any of the Event Listeners throw an exception on the Framework startup events.PluginSystemLifecycle.init()@ExperimentalApi
public void lateStartup()
throws PluginParseException,
NotificationException
SplitStartupPluginSystemLifecycleSplitStartupPluginSystemLifecycle.earlyStartup(), and calling both earlyStartup and lateStartup is
equivalent to calling PluginSystemLifecycle.init().lateStartup in interface SplitStartupPluginSystemLifecyclePluginParseException - If parsing the plugins failed.NotificationException - If any of the Event Listeners throw an exception on the Framework startup events.PluginSystemLifecycle.init()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 usePluginInstallerpublic 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 uninstallationpublic void uninstallPlugins(Collection<Plugin> plugins) throws PluginException
PluginControlleruninstallPlugins in interface PluginControllerplugins - The plugins to uninstall.PluginException - if there was some problem uninstalling a plugin.protected 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()
protected 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(Predicate<Plugin> pluginPredicate)
PluginAccessorgetPlugins in interface PluginAccessorpluginPredicate - the Predicate describing which plugins to match.Plugins that match the given predicate.PluginAccessor.getPlugins(Predicate)public Collection<Plugin> getEnabledPlugins()
PluginAccessorgetEnabledPlugins in interface PluginAccessorPlugins.PluginAccessor.getEnabledPlugins()public <M> Collection<M> getModules(Predicate<ModuleDescriptor<M>> moduleDescriptorPredicate)
PluginAccessorgetModules in interface PluginAccessormoduleDescriptorPredicate - describes which modules to matchModuleDescriptor.getModule() that match the given predicate.PluginAccessor.getModules(Predicate)public <M> Collection<ModuleDescriptor<M>> getModuleDescriptors(Predicate<ModuleDescriptor<M>> moduleDescriptorPredicate)
PluginAccessorgetModuleDescriptors in interface PluginAccessormoduleDescriptorPredicate - describes which modules to matchModuleDescriptors that match the given predicate.PluginAccessor.getModuleDescriptors(Predicate)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)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 void enablePlugins(String... keys)
enablePlugins in interface PluginControllerkeys - The plugin keys. Must not be null.public 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).
Mandatory dependent plugins will also be disabled. Optionally dependent plugins will be disabled then enabled. Dynamically dependent plugins will not be disabled.
disablePlugin in interface PluginControllerkey - The plugin key.PluginController.disablePluginWithoutPersisting(String),
Plugin.getDependencies()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.
Mandatory dependent plugins will also be disabled. Optionally dependent plugins will be disabled then enabled. Dynamically dependent plugins will not be disabled.
disablePluginWithoutPersisting in interface PluginControllerkey - The plugin key.PluginController.disablePlugin(String),
Plugin.getDependencies()protected void disablePluginInternal(String key, boolean persistDisabledState)
public void disablePluginModule(String completeKey)
PluginControllerdisablePluginModule in interface PluginControllercompleteKey - The "complete key" of the plugin module.protected void notifyModuleDisabled(ModuleDescriptor<?> module)
public void enablePluginModule(String completeKey)
PluginControllerenablePluginModule in interface PluginControllercompleteKey - The "complete key" of the plugin module.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
ClassNotFoundExceptionpublic PluginsClassLoader getClassLoader()
PluginAccessorgetClassLoader in interface PluginAccessorpublic boolean isSystemPlugin(String key)
isSystemPlugin in interface PluginAccessorpublic PluginRestartState getPluginRestartState(String key)
PluginAccessorgetPluginRestartState in interface PluginAccessorkey - The plugin keypublic ModuleDescriptor<?> addDynamicModule(Plugin maybePluginInternal, org.dom4j.Element module)
PluginControllerelement to the plugin specified.
Module will be enabled if the following conditions are met:
ModuleDescriptor.isEnabledByDefault() returns trueaddDynamicModule in interface PluginControllermaybePluginInternal - to add the module tomodule - to addPluginController.removeDynamicModule(Plugin, ModuleDescriptor),
PluginAccessor.getDynamicModules(Plugin)public Iterable<ModuleDescriptor<?>> getDynamicModules(Plugin maybePluginInternal)
PluginAccessorplugin via
PluginController.addDynamicModule(Plugin, org.dom4j.Element) during the lifetime of
this plugin, but not removed via PluginController.removeDynamicModule(Plugin, ModuleDescriptor).getDynamicModules in interface PluginAccessormaybePluginInternal - to queryPluginController.addDynamicModule(Plugin, org.dom4j.Element),
PluginController.removeDynamicModule(Plugin, ModuleDescriptor)public void removeDynamicModule(Plugin maybePluginInternal, ModuleDescriptor<?> module)
PluginControllerremoveDynamicModule in interface PluginControllermaybePluginInternal - to remove the module frommodule - to removePluginController.addDynamicModule(Plugin, org.dom4j.Element),
PluginAccessor.getDynamicModules(Plugin)Copyright © 2019 Atlassian. All rights reserved.