calypso.util
Class ListenerList

java.lang.Object
  |
  +--calypso.util.ListenerList

public class ListenerList
extends java.lang.Object

ListenersList is a thread-safe, reentrant class which contains a list of EventListeners and enforce some policy on event dispatching.

This class guarantees that events delivering is correctly accomplished even if listeners are removed from or added to the list during event dispatching. Added listeners, though, will not receive the current event.

Event listeners are returned LIFO.

User of this class must enclose event dispatching between startDelivering()/stopDelivering() calls and pass the state object to the nextListener call.

    ListenerListState state = eventListeners.startDelivering();

    SomeEventListener el = (SomeEventListener)eventListeners.nextListener(state);
    while (null != el) {
      el.someEvent();
      el = (SomeEventListener)eventListeners.nextListener(state);
    }

    eventListeners.stopDelivering(state);
 


Constructor Summary
ListenerList()
          Construct an array of listeners with the specifed size.
ListenerList(int aSize)
          Construct an array of listeners with the specifed size.
 
Method Summary
 void addListener(java.util.EventListener aListener)
          Set a new event listener for the class of events this ListenersList is mantaining.
 java.util.EventListener nextListener(ListenerListState aState)
          Return the next EventListener in the array.
 void removeListener(java.util.EventListener aListener)
          Remove a listener from the list of listeners this ListenersList is mantaining. Existing and valid state object are updated to reflect this change.
 ListenerListState startDelivering()
          A user of this class is starting event delivery.
 void stopDelivering(ListenerListState aState)
          A user completed or aborted event delivering.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListenerList

public ListenerList(int aSize)
Construct an array of listeners with the specifed size.

The array size is doubled every time an element is added to a full array.

Parameters:
aSize - the required size

ListenerList

public ListenerList()
Construct an array of listeners with the specifed size.

The array size is doubled every time an element is added to a full array.

Method Detail

addListener

public void addListener(java.util.EventListener aListener)
Set a new event listener for the class of events this ListenersList is mantaining.
Parameters:
aListener - a listener for the specific set of events

removeListener

public void removeListener(java.util.EventListener aListener)
Remove a listener from the list of listeners this ListenersList is mantaining.

Existing and valid state object are updated to reflect this change.

Parameters:
aListener - a listener for the specific set of events

startDelivering

public ListenerListState startDelivering()
A user of this class is starting event delivery.

The state object represents the state of the list for that user and has to be passed in every nextListener call.

Parameters:
aListener - a listener for the specific set of events
Returns:
ListenerListState the state of the list for the caller

stopDelivering

public void stopDelivering(ListenerListState aState)
A user completed or aborted event delivering.

Returns:
aState the state of the list for the caller

nextListener

public java.util.EventListener nextListener(ListenerListState aState)
Return the next EventListener in the array.

Listeners are returned with a last-in/first-out (LIFO) policy.

Returns:
aState the state of the list for the caller