Package rea.events
Class EventBroadcast<T extends UpdateEvent>
java.lang.Object
rea.events.EventBroadcast<T>
- Type Parameters:
T
- the type of event that can be listened to.
Event broadcast to registered listeners.
Listeners can be added and removed using the
addListener(rea.events.UpdateListener<T>)
and removeListener(rea.events.UpdateListener<T>)
methods.
Listeners are automatically removed if they throw an exception.
Events are broadcast to all listeners using the broadcast(T)
method.- Author:
- José Paulo Leal
jpleal@fc.up.pt
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Set
<UpdateListener<T>> The listeners registered to receive events. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(UpdateListener<T> listener) Add a listener to the list of listeners.void
Broadcast an event to all listeners.Get all the currently registered listeners.void
removeListener
(UpdateListener<T> listener) Remove a listener from the list of listeners.
-
Field Details
-
listeners
Set<UpdateListener<T extends UpdateEvent>> listenersThe listeners registered to receive events.
-
-
Constructor Details
-
EventBroadcast
public EventBroadcast()Create an instance of this class. No particular initializations are performed.
-
-
Method Details
-
addListener
Add a listener to the list of listeners.- Parameters:
listener
- the listener to add.
-
removeListener
Remove a listener from the list of listeners.- Parameters:
listener
- the listener to remove.
-
getListeners
Get all the currently registered listeners. Listeners are automatically removed if they throw an exception.- Returns:
- set of listeners.
-
broadcast
Broadcast an event to all listeners. If the events is not handled by a listener, the listener is removed.- Parameters:
event
- the event to broadcast.
-