-
- All Known Implementing Classes:
DefaultEventStudio
public interface EventStudioAnEventStudiois a thread-safe central place allowing broadcast of events toListeners to registered on a Station. Stations are created internally as soon as a listener is added but it's up to the user to clear a station when it's not needed anymore.Listeners can be added multiple times either to different or the same station and they will be called as many times as they have been added.As a general rule null parameters are not allowed (either station names, listeners, supervisors.. )
- Author:
- Andrea Vacondio
-
-
Field Summary
Fields Modifier and Type Field Description static StringMAX_QUEUE_SIZE_PROP
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> voidadd(Class<T> eventClass, Listener<T> listener, String station)Adds the givenListener, listening for the given event class, to the given station using default priority(0) ad default strengthReferenceStrength.STRONG.<T> voidadd(Class<T> eventClass, Listener<T> listener, String station, int priority, ReferenceStrength strength)Adds the givenListener, listening for the given event class, to the given station using the given priority (low values mean higher priority) and strength.<T> voidadd(Listener<T> listener, String station)Adds the givenListenerto the given station using default priority(0) ad default strengthReferenceStrength.STRONG.<T> voidadd(Listener<T> listener, String station, int priority, ReferenceStrength strength)Adds the givenListenerto the given station using the given priority (low values mean higher priority) and strength.voidaddAnnotatedListeners(Object bean)Discovers annotated method on the the given bean and adds them asListenersvoidbroadcast(Object event, String station)Broadcasts the given event to the given station.voidbroadcastToEveryStation(Object event)Broadcasts the given event to every station.voidclear(String station)Clear the given station removing the whole station from theEventStudiowhich means thatListeners andSupervisorwill not be notified anymore.<T> booleanremove(Class<T> eventClass, Listener<T> listener, String station)Removes the first occurrence of the givenListenerlistening for the given event, from the given station<T> booleanremove(Listener<T> listener, String station)Removes the first occurrence of the givenListenerfrom the given station.<T> voidsupervisor(Supervisor supervisor, String station)Sets aSupervisorfor the given station.
-
-
-
Field Detail
-
MAX_QUEUE_SIZE_PROP
static final String MAX_QUEUE_SIZE_PROP
- See Also:
- Constant Field Values
-
-
Method Detail
-
add
<T> void add(Listener<T> listener, String station)
Adds the givenListenerto the given station using default priority(0) ad default strengthReferenceStrength.STRONG.
-
add
<T> void add(Listener<T> listener, String station, int priority, ReferenceStrength strength)
Adds the givenListenerto the given station using the given priority (low values mean higher priority) and strength.
-
add
<T> void add(Class<T> eventClass, Listener<T> listener, String station)
Adds the givenListener, listening for the given event class, to the given station using default priority(0) ad default strengthReferenceStrength.STRONG. This add method is useful when a listener can listen for a hierarchy of events.
-
add
<T> void add(Class<T> eventClass, Listener<T> listener, String station, int priority, ReferenceStrength strength)
Adds the givenListener, listening for the given event class, to the given station using the given priority (low values mean higher priority) and strength. This add method is useful when a listener can listen for a hierarchy of events:class BroadListener{@code <T extends ParentEvent> implements Listener<T>} { void onEvent(ParentEvent e){ LOG.debug(e); } } class X { public void init() { EventStudio studio = .... studio.add(ChildEvent.class, new BroadListener{@code <ChildEvent>}(), "mystation"); studio.add(AnotherChildEvent.class, new BroadListener{@code <AnotherChildEvent>()}, "mystation"); ... } }
-
addAnnotatedListeners
void addAnnotatedListeners(Object bean)
Discovers annotated method on the the given bean and adds them asListeners- Parameters:
bean-- See Also:
EventListener,EventStation
-
supervisor
<T> void supervisor(Supervisor supervisor, String station)
Sets aSupervisorfor the given station. It will be notified of every event broadcasted to the station prior its delivery to the properListeners allowing event inspection.Supervisors cannot be removed but they can be replaces. SeeSupervisor.SLACKER
-
remove
<T> boolean remove(Listener<T> listener, String station)
Removes the first occurrence of the givenListenerfrom the given station.- Returns:
- true if the listener was successfully removed
-
remove
<T> boolean remove(Class<T> eventClass, Listener<T> listener, String station)
Removes the first occurrence of the givenListenerlistening for the given event, from the given station- Returns:
- true if the listener was successfully removed
-
clear
void clear(String station)
Clear the given station removing the whole station from theEventStudiowhich means thatListeners andSupervisorwill not be notified anymore. A station with the same name can be recreated.
-
broadcast
void broadcast(Object event, String station)
Broadcasts the given event to the given station.Listeners listening the given station and bound to the event class will be notified.
-
-