public class DefaultEventStudio extends Object implements EventStudio
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.
| Modifier and Type | Field and Description |
|---|---|
static String |
HIDDEN_STATION
A reserved station name that is used to hide the station abstraction.
|
MAX_QUEUE_SIZE_PROP| Constructor and Description |
|---|
DefaultEventStudio() |
| Modifier and Type | Method and Description |
|---|---|
<T> void |
add(Class<T> eventClass,
Listener<T> listener)
Adds a
Listener to the hidden station listening for the given event class, hiding the station abstraction. |
<T> void |
add(Class<T> eventClass,
Listener<T> listener,
int priority,
ReferenceStrength strength)
Adds a
Listener (with the given priority and strength ) to the hidden station listening for the given event class, hiding the station abstraction. |
<T> void |
add(Class<T> eventClass,
Listener<T> listener,
String station)
Adds the given
Listener, listening for the given event class, to the given station using default priority(0) ad default strength ReferenceStrength.STRONG. |
<T> void |
add(Class<T> eventClass,
Listener<T> listener,
String station,
int priority,
ReferenceStrength strength)
Adds the given
Listener, listening for the given event class, to the given station using the given priority (low values mean higher priority) and strength. |
<T> void |
add(Listener<T> listener)
Adds a
Listener to the hidden station, hiding the station abstraction. |
<T> void |
add(Listener<T> listener,
int priority,
ReferenceStrength strength)
Adds a
Listener (with the given priority and strength ) to the hidden station, hiding the station abstraction. |
<T> void |
add(Listener<T> listener,
String station)
Adds the given
Listener to the given station using default priority(0) ad default strength ReferenceStrength.STRONG. |
<T> void |
add(Listener<T> listener,
String station,
int priority,
ReferenceStrength strength)
Adds the given
Listener to the given station using the given priority (low values mean higher priority) and strength. |
void |
addAnnotatedListeners(Object bean)
Discovers annotated method on the the given bean and adds them as
Listeners |
void |
broadcast(Object event)
Boradcast the event to the hidden station
|
void |
broadcast(Object event,
String station)
Broadcasts the given event to the given station.
|
void |
broadcastToEveryStation(Object event)
Broadcasts the given event to every station.
|
void |
clear()
Clears the hidden station
|
void |
clear(String station)
Clear the given station removing the whole station from the
EventStudio which means that Listeners and Supervisor will not be notified anymore. |
<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.
|
<T> boolean |
remove(Class<T> eventClass,
Listener<T> listener,
String station)
Removes the first occurrence of the given
Listener listening for the given event, from the given station |
<T> boolean |
remove(Listener<T> listener)
Removes the given listener from the hidden station, hiding the station abstraction.
|
<T> boolean |
remove(Listener<T> listener,
String station)
Removes the first occurrence of the given
Listener from the given station. |
void |
supervisor(Supervisor supervisor)
Adds a
Supervisor to the hidden station, hiding the station abstraction. |
void |
supervisor(Supervisor supervisor,
String station)
Sets a
Supervisor for the given station. |
public static final String HIDDEN_STATION
EventStudio
can be used as a more traditional Event Bus with pub/sub pattern.public <T> void add(Listener<T> listener, String station, int priority, ReferenceStrength strength)
EventStudioListener to the given station using the given priority (low values mean higher priority) and strength.add in interface EventStudiopublic <T> void add(Listener<T> listener, String station)
EventStudioListener to the given station using default priority(0) ad default strength ReferenceStrength.STRONG.add in interface EventStudiopublic <T> void add(Class<T> eventClass, Listener<T> listener, String station)
EventStudioListener, listening for the given event class, to the given station using default priority(0) ad default strength ReferenceStrength.STRONG.
This add method is useful when a listener can listen for a hierarchy of events.add in interface EventStudioEventStudio.add(Class, Listener, String, int, ReferenceStrength)public <T> void add(Class<T> eventClass, Listener<T> listener, String station, int priority, ReferenceStrength strength)
EventStudioListener, 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");
...
}
}
add in interface EventStudiopublic void addAnnotatedListeners(Object bean)
EventStudioListenersaddAnnotatedListeners in interface EventStudioEventListener,
EventStationpublic <T> void add(Class<T> eventClass, Listener<T> listener, int priority, ReferenceStrength strength)
Listener (with the given priority and strength ) to the hidden station listening for the given event class, hiding the station abstraction.public <T> void add(Listener<T> listener, int priority, ReferenceStrength strength)
Listener (with the given priority and strength ) to the hidden station, hiding the station abstraction.public <T> void add(Listener<T> listener)
Listener to the hidden station, hiding the station abstraction.EventStudio.add(Listener, String),
HIDDEN_STATIONpublic <T> void add(Class<T> eventClass, Listener<T> listener)
Listener to the hidden station listening for the given event class, hiding the station abstraction.public void supervisor(Supervisor supervisor)
Supervisor to the hidden station, hiding the station abstraction.supervisor - EventStudio.supervisor(Supervisor, String),
HIDDEN_STATIONpublic void supervisor(Supervisor supervisor, String station)
EventStudioSupervisor for the given station. It will be notified of every event broadcasted to the station prior its delivery to the proper Listeners allowing
event inspection.
Supervisors cannot be removed but they can be replaces. See Supervisor.SLACKER
supervisor in interface EventStudiopublic <T> boolean remove(Listener<T> listener, String station)
EventStudioListener from the given station.remove in interface EventStudiopublic <T> boolean remove(Class<T> eventClass, Listener<T> listener, String station)
EventStudioListener listening for the given event, from the given stationremove in interface EventStudiopublic <T> boolean remove(Listener<T> listener)
EventStudio.remove(Listener, String),
HIDDEN_STATIONpublic <T> boolean remove(Class<T> eventClass, Listener<T> listener)
EventStudio.remove(Listener, String),
HIDDEN_STATIONpublic void clear(String station)
EventStudioEventStudio which means that Listeners and Supervisor will not be notified anymore. A
station with the same name can be recreated.clear in interface EventStudiopublic void clear()
EventStudio.clear(String),
HIDDEN_STATIONpublic void broadcast(Object event, String station)
EventStudioListeners listening the given station and bound to the event class will be notified.broadcast in interface EventStudiopublic void broadcast(Object event)
public void broadcastToEveryStation(Object event)
EventStudioListeners bound to the event class (no matter the station they are listening) will be notified.broadcastToEveryStation in interface EventStudioCopyright © 2020 Sober Lemur S.a.s. di Vacondio Andrea. All rights reserved.