snaq.util
Class EventDispatcher<L extends EventListener,E extends EventObject>

java.lang.Object
  extended by java.lang.Thread
      extended by snaq.util.EventDispatcher<L,E>
All Implemented Interfaces:
Runnable

public class EventDispatcher<L extends EventListener,E extends EventObject>
extends Thread

Utility class to perform asynchronous event dispatch. it provides a simple mechanism to allow dispatch of events using the single method call dispatchEvent(EventObject), which schedules the event to be propagated to the registered listeners in a seperate thread. The mechanism of actual event notification is specified using an implementation of EventNotifier.

The EventListener list provided on creation should ideally be an instance of CopyOnWriteArrayList, which allows safe iteration without making a copy. If this type is not used, a copy of of the listeners is taken each time an event dispatch is performed, synchronizing on the list instance during the copy.

Author:
Giles Winstanley

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
EventDispatcher(List<L> listeners, EventNotifier<L,E> notifier)
           
 
Method Summary
 void dispatchEvent(E event)
          Schedules the specified event for listener notification.
 void halt()
          Halts this thread (use instead of Thread.stop()).
 void run()
           
 void start()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EventDispatcher

public EventDispatcher(List<L> listeners,
                       EventNotifier<L,E> notifier)
Method Detail

start

public void start()
Overrides:
start in class Thread

halt

public void halt()
Halts this thread (use instead of Thread.stop()).


dispatchEvent

public void dispatchEvent(E event)
Schedules the specified event for listener notification.


run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread