- All Known Implementing Classes:
DefaultEventStudio
public interface EventStudio
An
EventStudio is a thread-safe central place allowing broadcast of events to Listeners 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.. )
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescription<T> voidAdds 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(Class<T> eventClass, Listener<T> listener, String station, int priority, ReferenceStrength strength, boolean once) Adds the givenListener, listening for the given event class, to the given station.<T> voidAdds 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.<T> voidadd(Listener<T> listener, String station, int priority, ReferenceStrength strength, boolean once) Adds the givenListenerto the given station using the given priority (low values mean higher priority), strength and once flag.voidaddAnnotatedListeners(Object bean) Discovers annotated method on the given bean and adds them asListenersvoidBroadcasts the given event to the given station.voidbroadcastToEveryStation(Object event) Broadcasts the given event to every station.voidClear the given station removing the whole station from theEventStudiowhich means thatListeners andSupervisorwill not be notified anymore.<T> voidclearEnqueuedEvents(Class<T> eventClass, String station) Removes all the enqueued events of the given class from the given station.<T> booleanRemoves the first occurrence of the givenListenerlistening for the given event, from the given station<T> booleanRemoves the first occurrence of the givenListenerfrom the given station.<T> voidsupervisor(Supervisor supervisor, String station) Sets aSupervisorfor the given station.
-
Field Details
-
MAX_QUEUE_SIZE_PROP
- See Also:
-
-
Method Details
-
add
Adds the givenListenerto the given station using default priority(0) ad default strengthReferenceStrength.STRONG. -
add
Adds the givenListenerto the given station using the given priority (low values mean higher priority) and strength. -
add
<T> void add(Listener<T> listener, String station, int priority, ReferenceStrength strength, boolean once) Adds the givenListenerto the given station using the given priority (low values mean higher priority), strength and once flag.- Parameters:
once- the listener will be executed once and then removed
-
add
Adds the givenListener, listening for the given event class, to the given station using default priority(0) ad default strengthReferenceStrength.STRONG. This adds method is useful when a listener can listen for a hierarchy of events.- See Also:
-
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 adds 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"); ... } } -
add
<T> void add(Class<T> eventClass, Listener<T> listener, String station, int priority, ReferenceStrength strength, boolean once) Adds the givenListener, listening for the given event class, to the given station. This adds method is useful when a listener can listen for a hierarchy of events.- Parameters:
once- the listener will be executed once and then removed- See Also:
-
addAnnotatedListeners
Discovers annotated method on the given bean and adds them asListeners- See Also:
-
supervisor
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
Removes the first occurrence of the givenListenerfrom the given station.- Returns:
- true if the listener was successfully removed
-
remove
Removes the first occurrence of the givenListenerlistening for the given event, from the given station- Returns:
- true if the listener was successfully removed
-
clear
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. -
clearEnqueuedEvents
Removes all the enqueued events of the given class from the given station. This is useful when a listener is added to a station, and it should not be notified of events that have been broadcasted before its registration. -
broadcast
Broadcasts the given event to the given station.Listeners listening the given station and bound to the event class will be notified. -
broadcastToEveryStation
Broadcasts the given event to every station.Listeners bound to the event class (no matter the station they are listening) will be notified.
-