org.erights.e.extern.timer
Class TimerThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.erights.e.extern.timer.TimerThread
All Implemented Interfaces:
Runnable

class TimerThread
extends Thread

Thread to handle timeouts and clocks.

Author:
Chip Morningstar

Field Summary
private static int FUDGE
           
private  Object myLock
           
private  boolean myRunning
          Flag to control execution
private  TimerQEntry myTopEntry
          queue of pending timer events
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
(package private) TimerThread()
          Package level constructor
 
Method Summary
(package private)  boolean cancelTimeout(TimerWatcher target)
          Cancel a previously scheduled timer event.
private  void insertEntry(TimerQEntry newEntry)
          Insert a new event into the timer queue (in order).
private  void orderEntries()
          Sort the timer queue entries in order of time.
 void run()
          Run the timer thread until told to stop.
private  void runloop()
          The actual guts of the timer thread: Look for the next event on the timer queue.
(package private)  void setAlarm(long absMillis, TimerWatcher target)
          Set a timeout event to happen.
(package private)  void setClock(TimerWatcher target, long deltaMillis)
          Set a timeout event to happen.
(package private)  void shutdown()
          Stop the thread.
private  void wakeup()
          Wake up the sleeping runloop.
 
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
 

Field Detail

myLock

private final Object myLock

myTopEntry

private TimerQEntry myTopEntry
queue of pending timer events


myRunning

private boolean myRunning
Flag to control execution


FUDGE

private static final int FUDGE
Constructor Detail

TimerThread

TimerThread()
Package level constructor

Method Detail

cancelTimeout

boolean cancelTimeout(TimerWatcher target)
Cancel a previously scheduled timer event.

Parameters:
target - Object whose event this is.

insertEntry

private void insertEntry(TimerQEntry newEntry)
Insert a new event into the timer queue (in order).

Parameters:
newEntry - A TimerQEntry describing the new event.

orderEntries

private void orderEntries()
Sort the timer queue entries in order of time. Called when one or more entries are altered.


run

public void run()
Run the timer thread until told to stop.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
See Also:
java.lang.Thread#start(), java.lang.Thread#stop(), java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String), java.lang.Runnable#run()

runloop

private void runloop()
The actual guts of the timer thread: Look for the next event on the timer queue. Wait until the indicated time. Process the event and any others that may now be relevent. Repeat.


setAlarm

void setAlarm(long absMillis,
              TimerWatcher target)
Set a timeout event to happen.

Parameters:
absMillis - When the event should happen
target - Object which will handle the timeout event when it occurs

setClock

void setClock(TimerWatcher target,
              long deltaMillis)
Set a timeout event to happen.

Parameters:
target - Object which will handle the timeout event when it occurs
deltaMillis - Distance into the future for event to happen

shutdown

void shutdown()
Stop the thread.


wakeup

private void wakeup()
Wake up the sleeping runloop.



comments?