com.atlassian.plugin.manager
Class DefaultPluginManager

java.lang.Object
  extended by com.atlassian.plugin.manager.DefaultPluginManager
All Implemented Interfaces:
PluginAccessor, PluginController, PluginSystemLifecycle
Direct Known Subclasses:
DefaultPluginManager

public class DefaultPluginManager
extends java.lang.Object
implements PluginController, PluginAccessor, PluginSystemLifecycle

This implementation delegates the initiation and classloading of plugins to a list of 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(com.atlassian.plugin.Plugin) relies on the underlying PluginLoader to remove the plugin if necessary.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.plugin.PluginAccessor
PluginAccessor.Descriptor
 
Constructor Summary
DefaultPluginManager(PluginPersistentStateStore store, java.util.List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager)
           
 
Method Summary
protected  void addPlugin(PluginLoader loader, Plugin plugin)
          Deprecated. Since 2.0.2, use #addPlugins(PluginLoader,Collection...) instead
protected  void addPlugins(PluginLoader loader, java.util.Collection<Plugin> pluginsToInstall)
          Update the local plugin state and enable state aware modules.
 void disablePlugin(java.lang.String key)
          Disable a plugin by key.
 void disablePluginModule(java.lang.String completeKey)
          Disable a plugin module by key.
protected  void disablePluginModuleState(ModuleDescriptor<?> module, PluginPersistentStateStore stateStore)
           
protected  void disablePluginState(Plugin plugin, PluginPersistentStateStore stateStore)
           
 void enablePlugin(java.lang.String key)
          Enable a plugin by key.
 void enablePluginModule(java.lang.String completeKey)
          Enable a plugin module by key.
protected  void enablePluginModuleState(ModuleDescriptor<?> module, PluginPersistentStateStore stateStore)
           
protected  void enablePluginState(Plugin plugin, PluginPersistentStateStore stateStore)
           
 PluginsClassLoader getClassLoader()
          Retrieve the class loader responsible for loading classes and resources from plugins.
 java.lang.Class<?> getDynamicPluginClass(java.lang.String className)
          Retrieve a class from a currently loaded (and active) dynamically loaded plugin.
 java.io.InputStream getDynamicResourceAsStream(java.lang.String name)
          Retrieve a resource from a currently loaded (and active) dynamically loaded plugin.
<D extends ModuleDescriptor<?>>
java.util.List<D>
getEnabledModuleDescriptorsByClass(java.lang.Class<D> descriptorClazz)
          Get all enabled module descriptors that have a specific descriptor class.
<D extends ModuleDescriptor<?>>
java.util.List<D>
getEnabledModuleDescriptorsByClass(java.lang.Class<D> descriptorClazz, boolean verbose)
          This method has been reverted to pre PLUG-40 to fix performance issues that were encountered during load testing.
<M> java.util.List<ModuleDescriptor<M>>
getEnabledModuleDescriptorsByType(java.lang.String type)
          Deprecated. since 0.17, use getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
<M> java.util.List<M>
getEnabledModulesByClass(java.lang.Class<M> moduleClass)
          Retrieve all plugin modules that implement or extend a specific class.
<M> java.util.List<M>
getEnabledModulesByClassAndDescriptor(java.lang.Class<ModuleDescriptor<M>>[] descriptorClasses, java.lang.Class<M> moduleClass)
          Deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
<M> java.util.List<M>
getEnabledModulesByClassAndDescriptor(java.lang.Class<ModuleDescriptor<M>> descriptorClass, java.lang.Class<M> moduleClass)
          Deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
 Plugin getEnabledPlugin(java.lang.String pluginKey)
          Retrieve a given plugin if it is enabled.
 ModuleDescriptor<?> getEnabledPluginModule(java.lang.String completeKey)
          Retrieve an enabled plugin module by complete module key.
 java.util.Collection<Plugin> getEnabledPlugins()
          Get all of the currently enabled plugins.
<M> java.util.Collection<ModuleDescriptor<M>>
getModuleDescriptors(ModuleDescriptorPredicate<M> moduleDescriptorPredicate)
          Gets all module descriptors of installed modules that match the given predicate.
<M> java.util.Collection<M>
getModules(ModuleDescriptorPredicate<M> moduleDescriptorPredicate)
          Gets all installed modules that match the given predicate.
 Plugin getPlugin(java.lang.String key)
          Retrieve a given plugin (whether enabled or not).
 ModuleDescriptor<?> getPluginModule(java.lang.String completeKey)
          Retrieve any plugin module by complete module key.
 java.io.InputStream getPluginResourceAsStream(java.lang.String pluginKey, java.lang.String resourcePath)
          Retrieve a resource from a currently loaded (and active) plugin.
 PluginRestartState getPluginRestartState(java.lang.String key)
          Gets the state of the plugin upon restart.
 java.util.Collection<Plugin> getPlugins()
          Gets all of the currently installed plugins.
 java.util.Collection<Plugin> getPlugins(PluginPredicate pluginPredicate)
          Gets all installed plugins that match the given predicate.
protected  PluginPersistentState getState()
           
protected  PluginPersistentStateStore getStore()
           
 void init()
          Initialize all plugins in all loaders
 java.lang.String installPlugin(PluginArtifact pluginArtifact)
          Installs a plugin and returns the plugin key
 boolean isPluginEnabled(java.lang.String key)
          This method checks to see if the plugin is enabled based on the state manager and the plugin.
 boolean isPluginModuleEnabled(java.lang.String completeKey)
          Whether or not a given plugin module is currently enabled.
 boolean isSystemPlugin(java.lang.String key)
           
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 onPluginRefresh(PluginRefreshedEvent event)
           
protected  void removeStateFromStore(PluginPersistentStateStore stateStore, Plugin plugin)
           
 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)
          Uninstall the 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPluginManager

public DefaultPluginManager(PluginPersistentStateStore store,
                            java.util.List<PluginLoader> pluginLoaders,
                            ModuleDescriptorFactory moduleDescriptorFactory,
                            PluginEventManager pluginEventManager)
Method Detail

init

public void init()
          throws PluginParseException
Initialize all plugins in all loaders

Specified by:
init in interface PluginSystemLifecycle
Throws:
PluginParseException
java.lang.IllegalStateException - if already initialized or already in the process of initialization.

shutdown

public void shutdown()
Fires the shutdown event

Specified by:
shutdown in interface PluginSystemLifecycle
Throws:
java.lang.IllegalStateException - if already shutdown or already in the process of shutting down.
Since:
2.0.0

onPluginRefresh

public void onPluginRefresh(PluginRefreshedEvent event)

setPluginInstaller

public void setPluginInstaller(PluginInstaller pluginInstaller)
Set the plugin installation strategy for this manager

Parameters:
pluginInstaller - the plugin installation strategy to use
See Also:
PluginInstaller

getStore

protected final PluginPersistentStateStore getStore()

installPlugin

public java.lang.String installPlugin(PluginArtifact pluginArtifact)
                               throws PluginParseException
Description copied from interface: PluginController
Installs a plugin and returns the plugin key

Specified by:
installPlugin in interface PluginController
Throws:
PluginParseException - if the plugin is not a valid plugin

scanForNewPlugins

public int scanForNewPlugins()
                      throws PluginParseException
Description copied from interface: PluginController
Search all loaders and add any new plugins you find.

Specified by:
scanForNewPlugins in interface PluginController
Returns:
The number of new plugins found.
Throws:
PluginParseException

uninstall

public void uninstall(Plugin plugin)
               throws PluginException
Description copied from interface: PluginController
Uninstall the plugin, disabling it first.

Specified by:
uninstall in interface PluginController
Parameters:
plugin -
Throws:
PluginException - If the plugin or loader doesn't support uninstallation

removeStateFromStore

protected void removeStateFromStore(PluginPersistentStateStore stateStore,
                                    Plugin plugin)

unloadPlugin

protected void unloadPlugin(Plugin plugin)
                     throws PluginException
Unload a plugin. Called when plugins are added locally, or remotely in a clustered application.

Parameters:
plugin - the plugin to remove
Throws:
PluginException - if th eplugin cannot be uninstalled

notifyUninstallPlugin

protected void notifyUninstallPlugin(Plugin plugin)

getState

protected PluginPersistentState getState()

addPlugin

@Deprecated
protected void addPlugin(PluginLoader loader,
                                    Plugin plugin)
                  throws PluginParseException
Deprecated. Since 2.0.2, use #addPlugins(PluginLoader,Collection...) instead

Throws:
PluginParseException

addPlugins

protected void addPlugins(PluginLoader loader,
                          java.util.Collection<Plugin> pluginsToInstall)
                   throws PluginParseException
Update the local plugin state and enable state aware modules.

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.

Parameters:
loader - the loader used to load this plugin
pluginsToInstall - the plugins to add
Throws:
PluginParseException - if the plugin cannot be parsed
Since:
2.0.2

updatePlugin

protected void updatePlugin(Plugin oldPlugin,
                            Plugin newPlugin)
                     throws PluginException
Replace an already loaded plugin with another version. Relevant stored configuration for the plugin will be preserved.

Parameters:
oldPlugin - Plugin to replace
newPlugin - New plugin to install
Throws:
PluginException - if the plugin cannot be updated

getPlugins

public java.util.Collection<Plugin> getPlugins()
Description copied from interface: PluginAccessor
Gets all of the currently installed plugins.

Specified by:
getPlugins in interface PluginAccessor
Returns:
a collection of installed Plugins.

getPlugins

public java.util.Collection<Plugin> getPlugins(PluginPredicate pluginPredicate)
Description copied from interface: PluginAccessor
Gets all installed plugins that match the given predicate.

Specified by:
getPlugins in interface PluginAccessor
Parameters:
pluginPredicate - the PluginPredicate to match.
Returns:
a collection of Plugins that match the given predicate.
Since:
0.17
See Also:
PluginAccessor.getPlugins(com.atlassian.plugin.predicate.PluginPredicate)

getEnabledPlugins

public java.util.Collection<Plugin> getEnabledPlugins()
Description copied from interface: PluginAccessor
Get all of the currently enabled plugins.

Specified by:
getEnabledPlugins in interface PluginAccessor
Returns:
a collection of installed and enabled Plugins.
See Also:
PluginAccessor.getEnabledPlugins()

getModules

public <M> java.util.Collection<M> getModules(ModuleDescriptorPredicate<M> moduleDescriptorPredicate)
Description copied from interface: PluginAccessor
Gets all installed modules that match the given predicate.

Specified by:
getModules in interface PluginAccessor
Parameters:
moduleDescriptorPredicate - the ModuleDescriptorPredicate to match.
Returns:
a collection of modules as per ModuleDescriptor.getModule() that match the given predicate.
Since:
0.17
See Also:
PluginAccessor.getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)

getModuleDescriptors

public <M> java.util.Collection<ModuleDescriptor<M>> getModuleDescriptors(ModuleDescriptorPredicate<M> moduleDescriptorPredicate)
Description copied from interface: PluginAccessor
Gets all module descriptors of installed modules that match the given predicate.

Specified by:
getModuleDescriptors in interface PluginAccessor
Parameters:
moduleDescriptorPredicate - the ModuleDescriptorPredicate to match.
Returns:
a collection of ModuleDescriptors that match the given predicate.
Since:
0.17
See Also:
PluginAccessor.getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)

getPlugin

public Plugin getPlugin(java.lang.String key)
Description copied from interface: PluginAccessor
Retrieve a given plugin (whether enabled or not).

Specified by:
getPlugin in interface PluginAccessor
Returns:
The enabled plugin, or null if that plugin does not exist.

getEnabledPlugin

public Plugin getEnabledPlugin(java.lang.String pluginKey)
Description copied from interface: PluginAccessor
Retrieve a given plugin if it is enabled.

Specified by:
getEnabledPlugin in interface PluginAccessor
Returns:
The enabled plugin, or null if that plugin does not exist or is disabled.

getPluginModule

public ModuleDescriptor<?> getPluginModule(java.lang.String completeKey)
Description copied from interface: PluginAccessor
Retrieve any plugin module by complete module key.

Note: the module may or may not be disabled.

Specified by:
getPluginModule in interface PluginAccessor

getEnabledPluginModule

public ModuleDescriptor<?> getEnabledPluginModule(java.lang.String completeKey)
Description copied from interface: PluginAccessor
Retrieve an enabled plugin module by complete module key.

Specified by:
getEnabledPluginModule in interface PluginAccessor

getEnabledModulesByClass

public <M> java.util.List<M> getEnabledModulesByClass(java.lang.Class<M> moduleClass)
Description copied from interface: PluginAccessor
Retrieve all plugin modules that implement or extend a specific class.

Specified by:
getEnabledModulesByClass in interface PluginAccessor
Returns:
List of modules that implement or extend the given class.
See Also:
PluginAccessor.getEnabledModulesByClass(Class)

getEnabledModulesByClassAndDescriptor

@Deprecated
public <M> java.util.List<M> getEnabledModulesByClassAndDescriptor(java.lang.Class<ModuleDescriptor<M>>[] descriptorClasses,
                                                                              java.lang.Class<M> moduleClass)
Deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Description copied from interface: PluginAccessor
Retrieve all plugin modules that implement or extend a specific class, and has a descriptor class as one of descriptorClazz

Specified by:
getEnabledModulesByClassAndDescriptor in interface PluginAccessor
Parameters:
descriptorClasses - @NotNull
moduleClass - @NotNull
Returns:
List of modules that implement or extend the given class. Empty list if none found
See Also:
PluginAccessor.getEnabledModulesByClassAndDescriptor(Class[], Class)

getEnabledModulesByClassAndDescriptor

@Deprecated
public <M> java.util.List<M> getEnabledModulesByClassAndDescriptor(java.lang.Class<ModuleDescriptor<M>> descriptorClass,
                                                                              java.lang.Class<M> moduleClass)
Deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Description copied from interface: PluginAccessor
Retrieve all plugin modules that implement or extend a specific class, and has a descriptor class as the descriptorClazz

Specified by:
getEnabledModulesByClassAndDescriptor in interface PluginAccessor
Parameters:
descriptorClass - @NotNull
moduleClass - @NotNull
Returns:
List of modules that implement or extend the given class. Empty list if none found
See Also:
PluginAccessor.getEnabledModulesByClassAndDescriptor(Class, Class)

getEnabledModuleDescriptorsByClass

public <D extends ModuleDescriptor<?>> java.util.List<D> getEnabledModuleDescriptorsByClass(java.lang.Class<D> descriptorClazz)
Description copied from interface: PluginAccessor
Get all enabled module descriptors that have a specific descriptor class.

Specified by:
getEnabledModuleDescriptorsByClass in interface PluginAccessor
Parameters:
descriptorClazz - module descriptor class
Returns:
List of ModuleDescriptors that implement or extend the given class.

getEnabledModuleDescriptorsByClass

public <D extends ModuleDescriptor<?>> java.util.List<D> getEnabledModuleDescriptorsByClass(java.lang.Class<D> descriptorClazz,
                                                                                            boolean verbose)
This method has been reverted to pre PLUG-40 to fix performance issues that were encountered during load testing. This should be reverted to the state it was in at 54639 when the fundamental issue leading to this slowdown has been corrected (that is, slowness of PluginClassLoader).

Specified by:
getEnabledModuleDescriptorsByClass in interface PluginAccessor
Parameters:
descriptorClazz - module descriptor class
verbose - log verbose messages flag
Returns:
List of ModuleDescriptors that implement or extend the given class.
See Also:
PluginAccessor.getEnabledModuleDescriptorsByClass(Class)

getEnabledModuleDescriptorsByType

@Deprecated
public <M> java.util.List<ModuleDescriptor<M>> getEnabledModuleDescriptorsByType(java.lang.String type)
                                                                      throws PluginParseException,
                                                                             java.lang.IllegalArgumentException
Deprecated. since 0.17, use getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Description copied from interface: PluginAccessor
Get all enabled module descriptors that have a specific descriptor type.

Specified by:
getEnabledModuleDescriptorsByType in interface PluginAccessor
Returns:
List of ModuleDescriptors that are of a given type.
Throws:
PluginParseException
java.lang.IllegalArgumentException
See Also:
PluginAccessor.getEnabledModuleDescriptorsByType(String)

enablePlugin

public void enablePlugin(java.lang.String key)
Description copied from interface: PluginController
Enable a plugin by key.

Specified by:
enablePlugin in interface PluginController

enablePluginState

protected void enablePluginState(Plugin plugin,
                                 PluginPersistentStateStore stateStore)

notifyPluginEnabled

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.

Parameters:
plugin - the plugin being enabled

disablePlugin

public void disablePlugin(java.lang.String key)
Description copied from interface: PluginController
Disable a plugin by key.

Specified by:
disablePlugin in interface PluginController

disablePluginState

protected void disablePluginState(Plugin plugin,
                                  PluginPersistentStateStore stateStore)

notifyPluginDisabled

protected void notifyPluginDisabled(Plugin plugin)

disablePluginModule

public void disablePluginModule(java.lang.String completeKey)
Description copied from interface: PluginController
Disable a plugin module by key.

Specified by:
disablePluginModule in interface PluginController

disablePluginModuleState

protected void disablePluginModuleState(ModuleDescriptor<?> module,
                                        PluginPersistentStateStore stateStore)

notifyModuleDisabled

protected void notifyModuleDisabled(ModuleDescriptor<?> module)

enablePluginModule

public void enablePluginModule(java.lang.String completeKey)
Description copied from interface: PluginController
Enable a plugin module by key.

Specified by:
enablePluginModule in interface PluginController

enablePluginModuleState

protected void enablePluginModuleState(ModuleDescriptor<?> module,
                                       PluginPersistentStateStore stateStore)

notifyModuleEnabled

protected void notifyModuleEnabled(ModuleDescriptor<?> module)

isPluginModuleEnabled

public boolean isPluginModuleEnabled(java.lang.String completeKey)
Description copied from interface: PluginAccessor
Whether or not a given plugin module is currently enabled. This also checks if the plugin it is contained within is enabled also

Specified by:
isPluginModuleEnabled in interface PluginAccessor
See Also:
PluginAccessor.isPluginEnabled(String)

isPluginEnabled

public boolean isPluginEnabled(java.lang.String key)
This method checks to see if the plugin is enabled based on the state manager and the plugin.

Specified by:
isPluginEnabled in interface PluginAccessor
Parameters:
key - The plugin key
Returns:
True if the plugin is enabled

getDynamicResourceAsStream

public java.io.InputStream getDynamicResourceAsStream(java.lang.String name)
Description copied from interface: PluginAccessor
Retrieve a resource from a currently loaded (and active) dynamically loaded plugin. Will return the first resource found, so plugins with overlapping resource names will behave eratically.

Specified by:
getDynamicResourceAsStream in interface PluginAccessor
Parameters:
name - the path to the resource to retrieve
Returns:
the dynamically loaded resource that matches that path, or null if no such resource is found

getDynamicPluginClass

public java.lang.Class<?> getDynamicPluginClass(java.lang.String className)
                                         throws java.lang.ClassNotFoundException
Description copied from interface: PluginAccessor
Retrieve a class from a currently loaded (and active) dynamically loaded plugin. Will return the first class found, so plugins with overlapping class names will behave eratically.

Specified by:
getDynamicPluginClass in interface PluginAccessor
Parameters:
className - the name of the class to retrieve
Returns:
the dynamically loaded class that matches that name
Throws:
java.lang.ClassNotFoundException - thrown if no classes by that name could be found in any of the enabled dynamic plugins

getClassLoader

public PluginsClassLoader getClassLoader()
Description copied from interface: PluginAccessor
Retrieve the class loader responsible for loading classes and resources from plugins.

Specified by:
getClassLoader in interface PluginAccessor
Returns:
the class loader

getPluginResourceAsStream

public java.io.InputStream getPluginResourceAsStream(java.lang.String pluginKey,
                                                     java.lang.String resourcePath)
Description copied from interface: PluginAccessor
Retrieve a resource from a currently loaded (and active) plugin. For statically loaded plugins, this just means pulling the resource from the PluginManager's classloader. For dynamically loaded plugins, this means retrieving the resource from the plugin's private classloader.

Specified by:
getPluginResourceAsStream in interface PluginAccessor

isSystemPlugin

public boolean isSystemPlugin(java.lang.String key)
Specified by:
isSystemPlugin in interface PluginAccessor
Returns:
true if the plugin is a system plugin.

getPluginRestartState

public PluginRestartState getPluginRestartState(java.lang.String key)
Description copied from interface: PluginAccessor
Gets the state of the plugin upon restart. Only useful for plugins that contain module descriptors with the \@RestartRequired annotation, and therefore, cannot be dynamically installed, upgraded, or removed at runtime

Specified by:
getPluginRestartState in interface PluginAccessor
Parameters:
key - The plugin key
Returns:
The state of the plugin on restart

setDescriptorParserFactory

@Deprecated
public void setDescriptorParserFactory(DescriptorParserFactory descriptorParserFactory)
Deprecated. Since 2.0.0.beta2



Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.