@Internal @ParametersAreNonnullByDefault public class ComponentManager extends Object implements Shutdown
ComponentContainer
, which includes:
ComponentContainer.ContainerLevel
getComponent(Class)
.
Plugins developers should use ComponentAccessor
for this, instead.
This class is a stateful singleton that lasts for the entire uptime of Jira, but the container it manages will come
and go as Jira goes through different stages of its lifecycle.Modifier and Type | Class and Description |
---|---|
static class |
ComponentManager.PluginSystemState |
static interface |
ComponentManager.State
The state of the
ComponentManager . |
Modifier and Type | Method and Description |
---|---|
boolean |
componentsAvailable()
Determines whether components have already been instantiated regardless of which container is in use.
|
void |
createBootstrapContainer()
Creates the
ComponentContainer that contains the minimal components required to bootstrap Jira. |
void |
createFullContainer()
Creates the
ComponentContainer that contains the full set of Jira components. |
<T> T |
createRequestScopedComponent(Class<T> componentClass)
Creates a request-scoped component of the given class.
|
void |
discardContainer()
Gets rid of the
ComponentContainer and resets the state to ComponentManagerStateImpl.NOT_STARTED . |
void |
earlyStartPluginSystem()
Early-starts the plugin system (including Plugins 1 components) and instantiates the components in the
container.
|
void |
extendBootstrapContainerForDisplayingErrors()
Extends the bootstrap container by adding the extra components needed for displaying startup errors (or warnings)
on the Johnson page.
|
void |
extendBootstrapContainerForSetup()
Extends the bootstrap container by adding the extra components needed for the admin to set up Jira.
|
<T> T |
getComponent(Class<T> componentClass)
Retrieves and returns a component which is an instance of given class.
|
<T> T |
getComponentInstanceOfType(Class<T> type)
Retrieves and returns a component which is an instance of given class.
|
<T> List<T> |
getComponents(Class<T> type)
Returns the components of the given type.
|
<T> List<T> |
getComponentsOfType(Class<T> type)
Returns all the components inside Pico that are instances of the given class.
|
<T> Map<String,T> |
getComponentsOfTypeMap(Class<T> type)
Returns all the components currently inside Pico which are instances of the given class, mapping them to their
component key.
|
static ComponentManager |
getInstance()
Retuns a singleton instance of this class.
|
<T> T |
getOSGiComponentInstanceOfType(Class<T> clazz)
Deprecated.
since 6.0 - please use the jira-api
ComponentAccessor.getOSGiComponentInstanceOfType(Class) instead |
ComponentManager.PluginSystemState |
getPluginSystemState()
Returns the state of the plugin system.
|
ComponentManager.State |
getState()
Returns the
ComponentManager.State of this instance. |
void |
lateStartPluginSystem()
Start delayed plugins (if any).
|
<T> T |
loadComponent(Class<T> componentClass,
Collection<Object> dependencies)
Instantiates a component from its class and dependent classes/instances.
|
void |
registerComponent(Class<?> interfaceClass,
Class<?> componentClass)
Registers a component of the given class, optionally using the given interface as the key.
|
void |
restart()
Stops the plugin system, replaces any container with a new full container, and restarts the plugin system (early
and late).
|
void |
shutdown()
Stops the plugin system and discards the
ComponentContainer . |
void |
stopPluginSystem()
Publishes a
ComponentManagerShutdownEvent and shuts down the plugin system. |
void |
unregisterComponent(Class<?> interfaceClass,
Class<?> componentClass)
Unregisters a component of the given class, optionally using the given interface as the key.
|
@Nonnull public static ComponentManager getInstance()
public void createBootstrapContainer()
ComponentContainer
that contains the minimal components required to bootstrap Jira.
This is done before we know whether Jira has been set up or will otherwise start up properly.IllegalStateException
- if a container already existspublic void extendBootstrapContainerForSetup()
IllegalStateException
- if there's no container, it's not initialised, or it's not in bootstrap modecreateBootstrapContainer()
public void extendBootstrapContainerForDisplayingErrors()
IllegalStateException
- if there's an unextended container but it's either uninitialised or not in bootstrap modecreateBootstrapContainer()
public void createFullContainer()
ComponentContainer
that contains the full set of Jira components.IllegalStateException
- if a container already existspublic void earlyStartPluginSystem()
ComponentManagerStateImpl.STARTED
state and
publishes a ComponentManagerStartedEvent
.public void lateStartPluginSystem()
SplitStartupPluginSystemLifecycle.lateStartup()
public boolean componentsAvailable()
public void stopPluginSystem()
ComponentManagerShutdownEvent
and shuts down the plugin system.public void discardContainer()
ComponentContainer
and resets the state to ComponentManagerStateImpl.NOT_STARTED
.public void shutdown()
ComponentContainer
.shutdown
in interface Shutdown
stopPluginSystem()
,
discardContainer()
@Nonnull public ComponentManager.State getState()
ComponentManager.State
of this instance.public ComponentManager.PluginSystemState getPluginSystemState()
@Nullable public <T> T getComponentInstanceOfType(Class<T> type)
In practise, this is the same as getComponent(Class)
except it will try to find a unique component that
implements/extends the given Class even if the Class is not an actual component key.
Please note that this method only gets components from JIRA's core Pico Containter. That is, it retrieves
core components and components declared in Plugins1 plugins, but not components declared in Plugins2 plugins.
Plugins2 components can be retrieved via the getOSGiComponentInstanceOfType(Class)
method, but only if
they are public.
NOTE to Jira devs: don't use this method for general purpose component retrieval. Use ComponentAccessor instead.
type
- the class by which to find the componentgetOSGiComponentInstanceOfType(Class)
,
ComponentContainer#getComponent(Class))
@Nullable public <T> T getComponent(Class<T> componentClass)
In practise, this is the same as getComponentInstanceOfType(Class)
except it will fail faster if the
given Class is not a known component key (it also has a shorter and more meaningful name).
Please note that this method only gets components from JIRA's core Pico Container. That is, it retrieves
core components and components declared in Plugins1 plugins, but not components declared in Plugins2 plugins.
Plugins2 components can be retrieved via the getOSGiComponentInstanceOfType(Class)
method, but only if
they are public.
NOTE to Jira DEVS: Stop using this method for general purpose component retrieval; use ComponentAccessor please.
componentClass
- class to find a component instance bygetOSGiComponentInstanceOfType(Class)
,
ComponentContainer.getComponent(Class)
@Nullable public <T> T getOSGiComponentInstanceOfType(Class<T> clazz)
ComponentAccessor.getOSGiComponentInstanceOfType(Class)
instead
Plugin developers should prefer the API method ComponentAccessor.getOSGiComponentInstanceOfType(Class)
.
It is important to note that this only works for public components. That is components with public="true"
declared in their XML configuration. This means that they are available for other plugins to
import.
A use case for this is when for example for the dashboards plugin. In several areas in JIRA we may want to
render gadgets via the GadgetViewFactory
. Whilst the interface for this
component is available in JIRA core, the implementation is provided by the dashboards OSGi bundle. This method
will allow us to access it.
NOTE to JIRA DEVS : Stop using this method for general purpose component retrieval. Use ComponentAccessor please.
clazz
- class to find an OSGi component instance forgetComponentInstanceOfType(Class)
public <T> List<T> getComponents(Class<T> type)
T
- the component typetype
- the component typeIllegalStateException
- if the container does not existpublic <T> List<T> getComponentsOfType(Class<T> type)
type
- the class for which to searchpublic <T> Map<String,T> getComponentsOfTypeMap(Class<T> type)
type
- the type for which to searchpublic void registerComponent(@Nullable Class<?> interfaceClass, Class<?> componentClass)
interfaceClass
- the interface to use as the keycomponentClass
- the component classpublic void unregisterComponent(@Nullable Class<?> interfaceClass, Class<?> componentClass)
interfaceClass
- the interface to use as the keycomponentClass
- the component classpublic <T> T createRequestScopedComponent(Class<T> componentClass)
T
- the type of the componentcomponentClass
- the class of component to instantiate@Nullable public <T> T loadComponent(Class<T> componentClass, Collection<Object> dependencies)
public void restart()
Copyright © 2002-2022 Atlassian. All Rights Reserved.