com.monad.homerun.util
Class HRTimer

java.lang.Object
  extended by com.monad.homerun.util.HRTimer

public class HRTimer
extends java.lang.Object

HRTimer is a simple system-wide timer facility using a singleton Timer, with additional instrumentation.


Method Summary
 void addDelayedTask(java.util.TimerTask task, long delay, long period)
          Adds a repeating task with an initial delay
 void addOneOffTask(java.util.TimerTask task, long delay)
          Adds a task to be executed only once
 void addTask(java.util.TimerTask task, long period)
          Adds a repeating task to the timer
 void cancelTask(java.util.TimerTask task)
          Cancels a regsitered task
static HRTimer getInstance()
          Resturns an instance of an HRTimer
 int getNumOneOffTasks()
          Returns the current number of non-repeatable tasks
 int getNumRepeatTasks()
          Returns the current number of repeatable tasks
 int getNumTasks()
          Returns the number of active tasks
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static HRTimer getInstance()
Resturns an instance of an HRTimer

Returns:
timer the timer instance

addTask

public void addTask(java.util.TimerTask task,
                    long period)
Adds a repeating task to the timer

Parameters:
task - the timer task to add
period - the time interval between task executions

addOneOffTask

public void addOneOffTask(java.util.TimerTask task,
                          long delay)
Adds a task to be executed only once

Parameters:
task - the task to perform
delay - initial time interval before execution

addDelayedTask

public void addDelayedTask(java.util.TimerTask task,
                           long delay,
                           long period)
Adds a repeating task with an initial delay

Parameters:
task - the task to add
delay - the intial delay before first execution
period - the interval between task executions

cancelTask

public void cancelTask(java.util.TimerTask task)
Cancels a regsitered task

Parameters:
task - the task to be cancelled

getNumTasks

public int getNumTasks()
Returns the number of active tasks

Returns:
num the number of current tasks

getNumRepeatTasks

public int getNumRepeatTasks()
Returns the current number of repeatable tasks

Returns:
num the number of repreatable tasks

getNumOneOffTasks

public int getNumOneOffTasks()
Returns the current number of non-repeatable tasks

Returns:
num the number of non-repreatable tasks


Copyright © 2006-2009 Richard Rodgers. All Rights Reserved.