kaos.metrics
Class TaskTimer

java.lang.Object
  extended by java.lang.Thread
      extended by kaos.metrics.TaskTimer
All Implemented Interfaces:
java.lang.Runnable

public class TaskTimer
extends java.lang.Thread

This is a generic timer used by other classes. An instance of TaskTimer is given a callback (any object implementing the TimerCallBack interface) which is called everytime the timer expires. The length of the timer is a millisecond value set in the constructor or directly. The timer uses a separate thread for execution by extending the default Thread.

See Also:
TimerCallBack

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static long MINIMUM_TIMER_INTERVAL
          The minimum allowed value of the timer interval.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TaskTimer()
          Default constructor creates a TaskTimer with not established call back objects.
TaskTimer(long pTimerInterval)
          Construct a TaskTimer object with the specified timer setting.
TaskTimer(java.lang.String pThreadName, long pTimerInterval)
          Construct a TaskTimer object with the specified timer name and timer setting.
TaskTimer(TimerCallBack pCallBack)
          Construct a TaskTimer object with the specified call back.
TaskTimer(TimerCallBack pCallBack, java.lang.String pThreadName, long pTimerInterval)
          Construct a TaskTimer object with the specified call back, name, and timer setting.
 
Method Summary
 void addTimerCallBack(TimerCallBack pCallBack)
          Adds an object that will be called each iteration of the timer.
 long getTimerInterval()
           
 void killTimer()
          Stops the timer and clears all references to call back items.
 void removeTimerCallBack(TimerCallBack pCallBack)
          Removes an existing timer call back object from the available call back list.
 void run()
          Main timer loop runs until shutdown command is received.
 void setTimerInterval(long pTimerInterval)
          Set the timer interval.
 void stopTimer()
          This stops the timer, after the current interval expires.
 
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
 

Field Detail

MINIMUM_TIMER_INTERVAL

public static final long MINIMUM_TIMER_INTERVAL
The minimum allowed value of the timer interval. The timer must call each call back object each interval of the timer and therefore must have enough time to make the appropriate calls. Since the timer value is milliseconds a minimum value assures the timer doesn't spend all it's time making calls to the TimerCallBack objects.

See Also:
Constant Field Values
Constructor Detail

TaskTimer

public TaskTimer()
Default constructor creates a TaskTimer with not established call back objects.


TaskTimer

public TaskTimer(long pTimerInterval)
Construct a TaskTimer object with the specified timer setting.

Parameters:
pTimerInterval - millisecond interval value.

TaskTimer

public TaskTimer(java.lang.String pThreadName,
                 long pTimerInterval)
Construct a TaskTimer object with the specified timer name and timer setting.

Parameters:
pThreadName - name for this thread.
pTimerInterval - millisecond interval value.

TaskTimer

public TaskTimer(TimerCallBack pCallBack,
                 java.lang.String pThreadName,
                 long pTimerInterval)
Construct a TaskTimer object with the specified call back, name, and timer setting.

Parameters:
pCallBack - Object implementing the TimerCallBack interface that is to be called each time the timer expires.
pThreadName - name for this thread.
pTimerInterval - millisecond interval value.

TaskTimer

public TaskTimer(TimerCallBack pCallBack)
Construct a TaskTimer object with the specified call back.

Parameters:
pCallBack - Object implementing the TimerCallBack interface that is to be called each time the timer expires.
Method Detail

getTimerInterval

public long getTimerInterval()
Returns:
The current timer interval setting.

setTimerInterval

public void setTimerInterval(long pTimerInterval)
Set the timer interval.

Parameters:
pTimerInterval - Interval value in milliseconds, if less than MINIMUM_TIMER_INTERVAL then timer will be set equal to the minimum.

addTimerCallBack

public void addTimerCallBack(TimerCallBack pCallBack)
Adds an object that will be called each iteration of the timer.

Parameters:
pCallBack - Object to be called each time the timer expires.

removeTimerCallBack

public void removeTimerCallBack(TimerCallBack pCallBack)
Removes an existing timer call back object from the available call back list.

Parameters:
pCallBack - Object to be called each time the timer expires.

run

public void run()
Main timer loop runs until shutdown command is received. The thread will sleep for the designated timer interval and then call back to all registered objects.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

stopTimer

public void stopTimer()
This stops the timer, after the current interval expires.


killTimer

public void killTimer()
Stops the timer and clears all references to call back items.