Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
ObservationManager | 33 | 0 | - | 0 | 0 |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.observation; | |
21 | ||
22 | import org.xwiki.component.annotation.Role; | |
23 | import org.xwiki.observation.event.Event; | |
24 | ||
25 | /** | |
26 | * The main orchestrator for event notification. To receive events create a component implementing the | |
27 | * {@link EventListener} interface. Your component will be automatically registered when this Observation Manager | |
28 | * component is loaded. To send events to all registered listeners, call one of the {@link #notify} methods. | |
29 | * | |
30 | * @version $Id: dab8e74945d6e2aa831907a2a04a06fe60e29f58 $ | |
31 | */ | |
32 | @Role | |
33 | public interface ObservationManager | |
34 | { | |
35 | /** | |
36 | * Manually add a listener. | |
37 | * | |
38 | * @param eventListener the listener to register | |
39 | */ | |
40 | void addListener(EventListener eventListener); | |
41 | ||
42 | /** | |
43 | * Remove a listener from the list of registered listeners. The removed listener will no longer receive events. | |
44 | * | |
45 | * @param listenerName the name of the listener to remove (must match {@link EventListener#getName()} | |
46 | */ | |
47 | void removeListener(String listenerName); | |
48 | ||
49 | /** | |
50 | * Adds an Event to an already registered listener. | |
51 | * | |
52 | * @param listenerName the name of the listener to which the event must be added (must match | |
53 | * {@link EventListener#getName()} | |
54 | * @param event the event to add to the matching listener | |
55 | */ | |
56 | void addEvent(String listenerName, Event event); | |
57 | ||
58 | /** | |
59 | * Removes an Event to an already registered listener. | |
60 | * | |
61 | * @param listenerName the name of the listener to which the event must be removed (must match | |
62 | * {@link EventListener#getName()} | |
63 | * @param event the event to remove to the matching listener | |
64 | */ | |
65 | void removeEvent(String listenerName, Event event); | |
66 | ||
67 | /** | |
68 | * @param listenerName the name of the listener | |
69 | * @return the registered listener's instance or null if no listener is registered under that name | |
70 | */ | |
71 | EventListener getListener(String listenerName); | |
72 | ||
73 | /** | |
74 | * Call the registered listeners matching the passed Event. The definition of <em>source</em> and <em>data</em> is | |
75 | * purely up to the communicating classes. | |
76 | * | |
77 | * @param event the event to pass to the registered listeners | |
78 | * @param source the source of the event (or <code>null</code>) | |
79 | * @param data the additional data related to the event (or <code>null</code>) | |
80 | */ | |
81 | void notify(Event event, Object source, Object data); | |
82 | ||
83 | /** | |
84 | * Convenience front-end where the additional data parameter is <code>null</code>. | |
85 | * | |
86 | * @param event the event to pass to the registered listeners | |
87 | * @param source the source of the event (or <code>null</code>) | |
88 | * @see #notify(org.xwiki.observation.event.Event, Object, Object) | |
89 | */ | |
90 | void notify(Event event, Object source); | |
91 | } |