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.

public class EventMulticast<T extends UpdateEvent> extends Object
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 Details

  • Constructor Details

    • EventMulticast

      public EventMulticast()
      Create an instance of this class. No particular initializations are performed.
  • Method Details

    • getListeners

      public Map<Character,UpdateListener<T>> getListeners()
      Get all the currently registered listeners.
      Returns:
      map of listeners keyed by characters.
    • addListener

      public void addListener(Character character, UpdateListener<T> listener)
      Add a listener for a given character.
      Parameters:
      character - to add listener for
      listener - the listener to add
    • removeListener

      protected void removeListener(Character character)
      Remove a listener for a given and character
      Parameters:
      character - to remove listener for
    • unicast

      public void unicast(Character character, T event)
      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

      public void multicast(Set<Character> characters, T event)
      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.