Class EventManager

  extended by java.lang.Thread
      extended by
All Implemented Interfaces:
java.lang.Runnable, EventHandler

public class EventManager
extends java.lang.Thread
implements EventHandler

This implements an event manager for timer events. Timer events are a way to have events occur some time in the future. They are an alternative to using separate threads which issue sleep requests themselves.

Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
Field Summary
Fields inherited from class java.lang.Thread
Constructor Summary
Method Summary
 void handleTimerEvent(java.lang.Object rock, long time)
          Handle an timer event.
static void main(java.lang.String[] args)
 java.lang.Object recallTimer(java.lang.Object timer)
          This recalls a previously registered timer event.
 java.lang.Object registerTimer( newEvent)
          This is like the above registerTimer, except it takes an event object with the deliver time filled in.
 java.lang.Object registerTimer(long ms, EventHandler handler, java.lang.Object data)
          registerTimer inserts a new timer event into the queue.
 void run()
 void stopEventManager()
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, 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


public EventManager()
Method Detail


public java.lang.Object registerTimer(long ms,
                                      EventHandler handler,
                                      java.lang.Object data)
registerTimer inserts a new timer event into the queue. The queue is always sorted by time, in increasing order. That is, things farther into the future are further down in the queue. ms is milliseconds in the future, handler is the object that will handle the event, and data is a "rock" that is passed to the handler to do with what it will. This returns an opaque object which can be used to recall the timer before it is delivered.


public void stopEventManager()


public java.lang.Object registerTimer( newEvent)
This is like the above registerTimer, except it takes an event object with the deliver time filled in. If deliver time is before the current time, the event is "immediately" delivered. Do a binary search to figure out where the event goes.


public java.lang.Object recallTimer(java.lang.Object timer)
This recalls a previously registered timer event.


public void run()
Specified by:
run in interface java.lang.Runnable
run in class java.lang.Thread


public void handleTimerEvent(java.lang.Object rock,
                             long time)
Description copied from interface: EventHandler
Handle an timer event. Data is the rock the register wanted passed to the handleEvent routine, and time is the time the event was scheduled to be delivered. The handler can compare that time to the current time, if it wants, to see whether or not it's falling behind.

Specified by:
handleTimerEvent in interface EventHandler


public static void main(java.lang.String[] args)