x10
Class UnitEventDispatcher

java.lang.Object
  extended byjava.lang.Thread
      extended byx10.UnitEventDispatcher
All Implemented Interfaces:
java.lang.Runnable

public class UnitEventDispatcher
extends java.lang.Thread

UnitEventDispatcher is a threaded dispatcher that calls each registered UnitListener when an event comes in. This object is single-threaded, so all UnitListeners are notified by the same thread. This is important to note so that UnitListeners do not "hog" the thread. UnitListeners should quickly return from handling events as to not delay subsequent listeners from receiving the event.

This class can be reused by other Controller implementations.


Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
UnitEventDispatcher()
          UnitEventDispatcher constructs an unstarted dispatcher.
 
Method Summary
 void addUnitListener(UnitListener listener)
          addUnitListener adds the specified UnitListener to the list of listeners that are notified by the dispatcher.
 void dispatchUnitEvent(UnitEvent event)
          dispatchUnitEvent adds the specified UnitEvent to the queue of events to be dispatched.
 void kill()
          kill terminates the dispatcher thread.
 void removeUnitListener(UnitListener listener)
          removeUnitListener removes the specified listener.
 void run()
          run blocks until an event comes in, and then dispatches it to all registered listeners.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnitEventDispatcher

public UnitEventDispatcher()
UnitEventDispatcher constructs an unstarted dispatcher.

Method Detail

run

public void run()
run blocks until an event comes in, and then dispatches it to all registered listeners.


dispatchUnitEvent

public void dispatchUnitEvent(UnitEvent event)
dispatchUnitEvent adds the specified UnitEvent to the queue of events to be dispatched.

Parameters:
event - the UnitEvent to be dispatched

addUnitListener

public void addUnitListener(UnitListener listener)
addUnitListener adds the specified UnitListener to the list of listeners that are notified by the dispatcher.

Parameters:
listener - the listener to add.

removeUnitListener

public void removeUnitListener(UnitListener listener)
removeUnitListener removes the specified listener. This cuts the specified listener off from receiving any subsequent events.

Parameters:
listener - the listener to be removed.

kill

public void kill()
kill terminates the dispatcher thread. This typically occurs when the system is shutting down.



Copyright ©2000-2005 Wade Wassenberg.
On the web: http://x10.homelinux.org.
Send bug reports to x10@wass.homelinux.net.
Last Modified June 1, 2005