Available: | Confluence 3.3 and later. |
Every time something important happens within Confluence (a page is added or modified, the configuration is changed, etc.), an 'event' is triggered. Listeners allow you to extend Confluence by installing code that responds to those events.
SpaceModifiedEvent
that itself causes a SpaceModifiedEvent
to be generated, you are responsible for preventing the start of an infinite loop.InitializingBean
and DisposableBean
.
The afterPropertiesSet()
and destroy()
methods on these interfaces will be called when the module is enabled or disabled,Listeners are a kind of Confluence plugin modules.
Events 2.0
Starting from Confluence 3.3, you can benefit from annotation-based event listeners.
Annotation-based event listeners let you annotate methods to be called for specific event types. The annotated methods must take a single parameter specifying the type of event that should trigger the method.
To use the annotation-based event listeners, you must register your listener as a component and start listening to EventPublisher
.
1 2@Named public class EventListener implements DisposableBean { @ConfluenceImport private EventPublisher eventPublisher; @Inject public EventListener(EventPublisher eventPublisher) { eventPublisher.register(this); //just for example } // Unregister the listener if the plugin is uninstalled or disabled. public void destroy() throws Exception { eventPublisher.unregister(this); } }
You can check Writing advanced Confluence blueprint for an example of a simple listener.
All events within Confluence extend from com.atlassian.com.event.events.ConfluenceEvent. In general, we use the following convention for naming each type of ConfluenceEvent
:
<Object><Operation>Event
For example, we have the following event types relating to space events: SpaceCreateEvent
, SpaceUpdateEvent
, and SpaceRemoveEvent
. In the previous description, space would correspond to <Object> and create, update, or remove would correspond to <Operation>.
Occasionally, an operation is so singular that its meaning will be obvious without use of this naming convention; for example, a LoginEvent
or ConfigurationEvent
.
There are a few legacy ways to register event listener:
Rate this page: