Class EventMulticaster

All Implemented Interfaces:

public class EventMulticaster extends Object implements EventListener
A class which implements efficient and thread-safe multicast event dispatching for generic events.

This class will manage an immutable structure consisting of a chain of event listeners and will dispatch events to those listeners. Because the structure is immutable, it is safe to use this API to add/remove listeners during the process of an event dispatch operation.

An example of how this class could be used to implement a new component which fires "action" events:

public MyComponent extends Component
   EventListener listener;
   public void addPropertyValueListener(PropertyListener l)
   public void removePropertyListener(PropertyListener l)
   public void someMethod()
     // When event occurs which causes "onEvent".
     EventListener listener=this.listener;
     if ( listener!=null )
       listener.onEvent(new SomeEvent(...));

Christopher Mindus
  • Field Details

  • Constructor Details

    • EventMulticaster

      protected EventMulticaster(EventListener a, EventListener b)
      Creates an event multicaster instance which chains listener-a with listener-b.
      a - listener-a.
      b - listener-b.
  • Method Details

    • remove

      protected EventListener remove(EventListener old)
      Removes a listener from this multicaster and returns the resulting multicast listener.
      old - the listener to be removed.
    • populate

      public void populate(ArrayList<EventListener> listeners)
      Populates the array with listeners.
    • onEvent

      public void onEvent(GEvent event)
      Called when the event is fired.
      Specified by:
      onEvent in interface EventListener
      event - The event.
    • add

      public static EventListener add(EventListener a, EventListener b)
      Adds listener-a with listener-b and returns the resulting multicast listener.
      a - listener-a.
      b - listener-b.
    • remove

      public static EventListener remove(EventListener l, EventListener old)
      Removes the old listener from listener-l and returns the resulting multicast listener.
      l - listener-l.
      old - the listener being removed.
    • addInternal

      protected static EventListener addInternal(EventListener a, EventListener b)
      Returns the resulting multicast listener from adding listener-a and listener-b together.
      1. If listener-a is null, it returns listener-b.
      2. If listener-b is null, it returns listener-a.
      3. If neither are null, then it creates and returns a new EventMulticaster instance which chains a with b.
      a - event-listener-a.
      b - event-listener-b.
    • removeInternal

      protected static EventListener removeInternal(EventListener l, EventListener old)
      Returns the resulting multicast listener after removing the old listener from listener-l.
      1. If listener-l equals the old listener OR listener-l is null, returns null.
      2. If listener-l is an instance of EventMulticaster, then it removes the old listener from it.
      3. Returns listener l.
      l - the listener being removed from.
      old - the listener being removed.