org.avis.util
Class ListenerList<E>

java.lang.Object
  extended by org.avis.util.ListenerList<E>

public class ListenerList<E>
extends Object

A generic event listener list. The list is thread safe, but does not guarantee immediate visibility of changes: i.e. if thread1 executes a remove () and thread2 executes a fire () immediately after, thread2 will not necessarily see the result of the remove ().

Author:
Matthew Phillips

Constructor Summary
ListenerList(Class<E> listenerType, String method, Class<?>... paramTypes)
          Create a new instance.
ListenerList(Class<E> listenerType, String method, Class<?> eventType)
          Create a new instance.
 
Method Summary
 void add(E listener)
           
 List<E> asList()
           
 void fire(Object... args)
          Fire an event.
 void fire(Object event)
          Fire an event.
 boolean hasListeners()
          Test if any listeners are in this list.
 void remove(E listener)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListenerList

public ListenerList(Class<E> listenerType,
                    String method,
                    Class<?> eventType)
             throws IllegalArgumentException
Create a new instance.

Parameters:
listenerType - The type of the listener interface.
method - The name of the method to call on the interface.
eventType - The type of the single event parameter.
Throws:
IllegalArgumentException - if the listener method could not be found.

ListenerList

public ListenerList(Class<E> listenerType,
                    String method,
                    Class<?>... paramTypes)
             throws IllegalArgumentException
Create a new instance.

Parameters:
listenerType - The type of the listener interface.
method - The name of the method to call on the interface.
paramTypes - The paramter types of the listener method.
Throws:
IllegalArgumentException - if the listener method could not be found.
Method Detail

asList

public List<E> asList()

add

public void add(E listener)

remove

public void remove(E listener)

fire

public void fire(Object event)
Fire an event.

Parameters:
event - The event parameter.

fire

public void fire(Object... args)
Fire an event.

Parameters:
args - The event parameters.

hasListeners

public boolean hasListeners()
Test if any listeners are in this list.



Copyright © 2008 Matthew Phillips. All Rights Reserved.