java.lang.Object
org.pdfsam.eventstudio.DefaultEventStudio
- All Implemented Interfaces:
EventStudio
Default implementation of
EventStudio. 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 with StaticStudio where 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
DefaultEventStudio where the station name parameter is missing from the parameters list and the HIDDEN_STATION is used, providing a more
traditional event bus pub/sub pattern.
- Author:
- Andrea Vacondio
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA 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 -
Method Summary
Modifier and TypeMethodDescription<T> voidAdds 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> 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> voidAdds 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> 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.voidaddAnnotatedListeners(Object bean) Discovers annotated method on the given bean and adds them asListenersvoidBroadcast the event to the hidden stationvoidBroadcasts the given event to the given station.voidbroadcastToEveryStation(Object event) Broadcasts the given event to every station.voidclear()Clears the hidden stationvoidClear the given station removing the whole station from theEventStudiowhich means thatListeners andSupervisorwill not be notified anymore.<T> booleanRemoves the given listener listening on the given event, from the hidden station, hiding the station abstraction.<T> booleanRemoves the first occurrence of the givenListenerlistening for the given event, from the given station<T> booleanRemoves the given listener from the hidden station, hiding the station abstraction.<T> booleanRemoves 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 Details
-
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:
-
-
Constructor Details
-
DefaultEventStudio
public DefaultEventStudio()
-
-
Method Details
-
add
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
Description copied from interface:EventStudioAdds the givenListenerto the given station using default priority(0) ad default strengthReferenceStrength.STRONG.- Specified by:
addin interfaceEventStudio
-
add
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 adds method is useful when a listener can listen for a hierarchy of events.- Specified by:
addin interfaceEventStudio- See Also:
-
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 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"); ... } }- Specified by:
addin interfaceEventStudio
-
addAnnotatedListeners
Description copied from interface:EventStudioDiscovers annotated method on the given bean and adds them asListeners- Specified by:
addAnnotatedListenersin interfaceEventStudio- See Also:
-
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.- See Also:
-
add
Adds aListener(with the given priority and strength ) to the hidden station, hiding the station abstraction.- See Also:
-
add
Adds aListenerto the hidden station, hiding the station abstraction.- See Also:
-
add
Adds aListenerto the hidden station listening for the given event class, hiding the station abstraction.- See Also:
-
supervisor
Adds aSupervisorto the hidden station, hiding the station abstraction.- See Also:
-
supervisor
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
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
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
Removes the given listener from the hidden station, hiding the station abstraction.- Returns:
- true if the listener was found and removed
- See Also:
-
remove
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:
-
clear
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:
-
broadcast
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
Broadcast the event to the hidden station- See Also:
-
broadcastToEveryStation
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
-