The StateAware interface can be implemented by plugin modules which need to know when they are enabled or disabled.
To be notified of enablement/disablement, implement the following in your Macro Plugins, Event Listener Plugins or Component Plugins:
public class YourMacro extends BaseMacro implements com.atlassian.plugin.StateAware |
This has two methods you must implement:
public void enabled()
{
// Your enablement code goes here.
}
public void disabled()
{
// Your disablement code goes here.
}
|
These methods are called in the following circumstances:
enabled()disabled()Each method is only called once at each logical enablement/disablement event. Please note that the module class's constructor is not a reliable place to put initialisation code either, as the classes are often constructed or destructed more often than they are disabled/enabled. However, once enabled, the same class will remain in memory until it is disabled.
Not all module types have been tested, but the following have the following status:
Module Type |
Confluence バージョン |
Working |
|---|---|---|
2.3.3 |
|
|
2.3.3 |
|
|
2.3.3 |
|
|
2.3.3 |
|
The component module type for OSGi (version 2) plugins doesn't support the StateAware interface, as they are implemented differently than non-OSGi (version 1) plugins. To achieve the same effect, you can use the two Spring lifecycle interfaces: InitializingBean and DisposableBean. The init() and destroy() methods on these interfaces will be called when the module is enabled or disabled, exactly like StateAware.
Making this change to a component in an existing plugin will be backwards compatible. That is, a component module in a legacy plugin which implements InitializingBean will have its init() method called when it is enabled, exactly the same as such a component in an OSGi plugin. For more information about the component module type in OSGi plugins, see Component Plugin Module.