Package rea.events
Class EventMulticast<T extends UpdateEvent>
java.lang.Object
rea.events.EventMulticast<T>
- Type Parameters:
T
- the type of event to be notified about.
Event multicast to groups of registered listeners.
Each listener is associated to player and can be added and removed using the
addListener(rea.components.Character, rea.events.UpdateListener<T>)
and removeListener(rea.components.Character)
methods.
Listeners are automatically removed if they throw an exception.
Events are multicast to listeners using the multicast(java.util.Set<rea.components.Character>, T)
method,
specifying a set of players to multicast to.
Alternatively, events can be unicast to a single player using
the unicast(rea.components.Character, T)
method.- Author:
- José Paulo Leal
jpleal@fc.up.pt
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Map
<Character, UpdateListener<T>> The listeners registered to receive events. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(Character character, UpdateListener<T> listener) Add a listener for a given character.Get all the currently registered listeners.void
Multicast an event to listeners assigned by giben characters.protected void
removeListener
(Character character) Remove a listener for a given and charactervoid
Unicast an event to a listener assigned by a given character.
-
Field Details
-
listeners
Map<Character,UpdateListener<T extends UpdateEvent>> listenersThe listeners registered to receive events. To support multicast, listeners are associated to a character.
-
-
Constructor Details
-
EventMulticast
public EventMulticast()Create an instance of this class. No particular initializations are performed.
-
-
Method Details
-
getListeners
Get all the currently registered listeners.- Returns:
- map of listeners keyed by characters.
-
addListener
Add a listener for a given character.- Parameters:
character
- to add listener forlistener
- the listener to add
-
removeListener
Remove a listener for a given and character- Parameters:
character
- to remove listener for
-
unicast
Unicast an event to a listener assigned by a given character. If an event is not handled by a listener, the listener is removed.- Parameters:
character
- the character to unicast to.event
- the event to unicast.
-
multicast
Multicast an event to listeners assigned by giben characters. If an event is not handled by a listener, the listener is removed.- Parameters:
characters
- the characters to multicast to.event
- the event to multicast.
-