Crowd 2.0 : Event Listeners
This page last changed on Oct 15, 2008 by doflynn.
On this page: If you are familiar with writing a listener for Confluence, writing a listener plugin for Crowd should be almost identical. In Crowd, events are thrown for almost all operations that occur to a user. (If you need more or find a spot we haven't thought of, please let us know!.) The Listener Plugin ModuleBelow is an example atlassian-plugin.xml that will configure your event Listeners: <atlassian-plugin name="Example Listeners" key="crowd.listeners.core" system="false"> <plugin-info> <description>This contains example listeners</description> <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/> <version>1.0</version> </plugin-info> <listener name="Reset Password Listener" key="resetpasswordlistener" class="com.atlassian.crowd.event.listener.ResetPasswordListener"> <description>Will handle reset password events, sending out a principal their new password.</description> </listener> </atlassian-plugin> The Event Listener ClassYour event listener must implement the com.atlassian.event.EventListener interface: package com.atlassian.event; /** * Defines a listener for Crowd events. */ public interface EventListener { /** * Perform some action as a response to an event. The EventManager will * ensure that this is only called if the class of the event matches one of the * classes returned by getHandledEventClasses * * @param event some event triggered within Crowd */ void handleEvent(Event event); /** * Determine which event classes this listener is interested in. * * <p>The EventManager performs rudimentary filtering of events by their class. If * you want to receive only a subset of events passing through the system, return * an array of the Classes you wish to listen for from this method. * * <p>Listening for a class will also listen for all its subclasses. (And listening * for an interface will listen for any implementation of that interface) * * <p>Returning an empty array will allow you to receive every event. * * @return An array of the event classes that this event listener is interested in, * or an empty array if the listener should receive all events. <b>Must not</b> * return null. */ Class[] getHandledEventClasses(); } Events and Event TypesMost event types in Crowd currently extend com.atlassian.crowd.event.DirectoryEvent. If you want to see the current list of available events, please take a look at Crowd's JavaDoc. Generally Crowd uses the following naming scheme for events: For example: Limitations of EventsPlease take note of the following limitations:
Examples of Event ListenersWe would suggest looking at the current Crowd source. Currently there are only a few listeners implemented in Crowd, but more will come. The above example of a module descriptor defines a ResetPasswordListener. Please look at this listener if you need a practical example. RELATED TOPICS |
![]() |
Document generated by Confluence on Jul 30, 2009 01:30 |