snaq.util
Class EventDispatcher<L extends EventListener,E extends EventObject>
java.lang.Object
java.lang.Thread
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
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 |
EventDispatcher
public EventDispatcher(List<L> listeners,
EventNotifier<L,E> notifier)
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