- java.lang.Object
-
- org.pdfsam.eventstudio.DefaultEventStudio
-
- All Implemented Interfaces:
EventStudio
public class DefaultEventStudio extends Object implements EventStudio
Default implementation ofEventStudio. It doesn't enforce a Singleton pattern and it's up to the user to decide how to use it and how many EventStudio the application needs. A singleton implementation with lazy initialization is provided withStaticStudiowhere the typical usage is:import static org.eventstudio.StaticStudio.eventStudio; public class Foo{ void doSomethingAndNotify(){ ..... eventStudio.broadcast(new ImFinished(), "station"); } }Hidden Station: The hidden station is a pre-built station with "hidden.station" name that is used to hide the station abstraction. Helper method are provided by
DefaultEventStudiowhere the station name parameter is missing from the parameters list and theHIDDEN_STATIONis used, providing a more traditional event bus pub/sub pattern.- Author:
- Andrea Vacondio
-
-
Field Summary
Fields Modifier and Type Field Description static StringHIDDEN_STATIONA reserved station name that is used to hide the station abstraction.-
Fields inherited from interface org.pdfsam.eventstudio.EventStudio
MAX_QUEUE_SIZE_PROP
-
-
Constructor Summary
Constructors Constructor Description DefaultEventStudio()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> voidadd(Class<T> eventClass, Listener<T> listener)Adds aListenerto the hidden station listening for the given event class, hiding the station abstraction.<T> voidadd(Class<T> eventClass, Listener<T> listener, int priority, ReferenceStrength strength)Adds aListener(with the given priority and strength ) to the hidden station listening for the given event class, hiding the station abstraction.<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)Adds aListenerto the hidden station, hiding the station abstraction.<T> voidadd(Listener<T> listener, int priority, ReferenceStrength strength)Adds aListener(with the given priority and strength ) to the hidden station, hiding the station abstraction.<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)Boradcast the event to the hidden stationvoidbroadcast(Object event, String station)Broadcasts the given event to the given station.voidbroadcastToEveryStation(Object event)Broadcasts the given event to every station.voidclear()Clears the hidden stationvoidclear(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)Removes the given listener listening on the given event, from the hidden station, hiding the station abstraction.<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)Removes the given listener from the hidden station, hiding the station abstraction.<T> booleanremove(Listener<T> listener, String station)Removes the first occurrence of the givenListenerfrom the given station.voidsupervisor(Supervisor supervisor)Adds aSupervisorto the hidden station, hiding the station abstraction.voidsupervisor(Supervisor supervisor, String station)Sets aSupervisorfor the given station.
-
-
-
Field Detail
-
HIDDEN_STATION
public static final String HIDDEN_STATION
A reserved station name that is used to hide the station abstraction. Using the provided helper methods the station concept remains totally hidden andEventStudiocan be used as a more traditional Event Bus with pub/sub pattern.- See Also:
- Constant Field Values
-
-
Method Detail
-
add
public <T> void add(Listener<T> listener, String station, int priority, ReferenceStrength strength)
Description copied from interface:EventStudioAdds the givenListenerto the given station using the given priority (low values mean higher priority) and strength.- Specified by:
addin interfaceEventStudio
-
add
public <T> void add(Listener<T> listener, String station)
Description copied from interface:EventStudioAdds the givenListenerto the given station using default priority(0) ad default strengthReferenceStrength.STRONG.- Specified by:
addin interfaceEventStudio
-
add
public <T> void add(Class<T> eventClass, Listener<T> listener, String station)
Description copied from interface:EventStudioAdds 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.- Specified by:
addin interfaceEventStudio- See Also:
EventStudio.add(Class, Listener, String, int, ReferenceStrength)
-
add
public <T> void add(Class<T> eventClass, Listener<T> listener, String station, int priority, ReferenceStrength strength)
Description copied from interface:EventStudioAdds 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"); ... } }- Specified by:
addin interfaceEventStudio
-
addAnnotatedListeners
public void addAnnotatedListeners(Object bean)
Description copied from interface:EventStudioDiscovers annotated method on the the given bean and adds them asListeners- Specified by:
addAnnotatedListenersin interfaceEventStudio- See Also:
EventListener,EventStation
-
add
public <T> void add(Class<T> eventClass, Listener<T> listener, int priority, ReferenceStrength strength)
Adds aListener(with the given priority and strength ) to the hidden station listening for the given event class, hiding the station abstraction.
-
add
public <T> void add(Listener<T> listener, int priority, ReferenceStrength strength)
Adds aListener(with the given priority and strength ) to the hidden station, hiding the station abstraction.
-
add
public <T> void add(Listener<T> listener)
Adds aListenerto the hidden station, hiding the station abstraction.- See Also:
EventStudio.add(Listener, String),HIDDEN_STATION
-
add
public <T> void add(Class<T> eventClass, Listener<T> listener)
Adds aListenerto the hidden station listening for the given event class, hiding the station abstraction.
-
supervisor
public void supervisor(Supervisor supervisor)
Adds aSupervisorto the hidden station, hiding the station abstraction.- Parameters:
supervisor-- See Also:
EventStudio.supervisor(Supervisor, String),HIDDEN_STATION
-
supervisor
public void supervisor(Supervisor supervisor, String station)
Description copied from interface:EventStudioSets 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- Specified by:
supervisorin interfaceEventStudio
-
remove
public <T> boolean remove(Listener<T> listener, String station)
Description copied from interface:EventStudioRemoves the first occurrence of the givenListenerfrom the given station.- Specified by:
removein interfaceEventStudio- Returns:
- true if the listener was successfully removed
-
remove
public <T> boolean remove(Class<T> eventClass, Listener<T> listener, String station)
Description copied from interface:EventStudioRemoves the first occurrence of the givenListenerlistening for the given event, from the given station- Specified by:
removein interfaceEventStudio- Returns:
- true if the listener was successfully removed
-
remove
public <T> boolean remove(Listener<T> listener)
Removes the given listener from the hidden station, hiding the station abstraction.- Returns:
- true if the listener was found and removed
- See Also:
EventStudio.remove(Listener, String),HIDDEN_STATION
-
remove
public <T> boolean remove(Class<T> eventClass, Listener<T> listener)
Removes the given listener listening on the given event, from the hidden station, hiding the station abstraction.- Returns:
- true if the listener was found and removed
- See Also:
EventStudio.remove(Listener, String),HIDDEN_STATION
-
clear
public void clear(String station)
Description copied from interface:EventStudioClear 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.- Specified by:
clearin interfaceEventStudio
-
clear
public void clear()
Clears the hidden station- See Also:
EventStudio.clear(String),HIDDEN_STATION
-
broadcast
public void broadcast(Object event, String station)
Description copied from interface:EventStudioBroadcasts the given event to the given station.Listeners listening the given station and bound to the event class will be notified.- Specified by:
broadcastin interfaceEventStudio
-
broadcast
public void broadcast(Object event)
Boradcast the event to the hidden station
-
broadcastToEveryStation
public void broadcastToEveryStation(Object event)
Description copied from interface:EventStudioBroadcasts the given event to every station.Listeners bound to the event class (no matter the station they are listening) will be notified.- Specified by:
broadcastToEveryStationin interfaceEventStudio
-
-