ch.aplu.util
Class BaseAlarmTimer

java.lang.Object
  extended by ch.aplu.util.BaseAlarmTimer
Direct Known Subclasses:
HiResAlarmTimer, LoResAlarmTimer

public abstract class BaseAlarmTimer
extends java.lang.Object

Abstract base class for HiResAlarmTimer and LoResAlarmTimer. See HiResAlarmTimer or LoResAlarmTimer for more details.


Method Summary
 void addTimerListener(TimerListener timerListener)
          Register a TimerListener to fire callbacks when the time interval expires (current time reaches 0 or the timer is stopped).
 long getTime()
          Return the current time in microseconds (us).
 boolean isRunning()
          Return true if the timer is running (current time > 0 and not stopped).
 void resume()
          Restart the timer from its current time.
 void start()
          Set the timer to the preset alarm time and start it.
 void start(long alarmTime)
          Set the timer to the given preset alarm time and start it.
 void stop()
          Stop the timer and store the current time.
 void stopEvents()
          Force to stop the callback calls by terminating the timer's polling thread.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTime

public long getTime()
Return the current time in microseconds (us).


start

public void start()
Set the timer to the preset alarm time and start it. The timer runs backward.


start

public void start(long alarmTime)
Set the timer to the given preset alarm time and start it. The timer runs backward.


stop

public void stop()
Stop the timer and store the current time.


resume

public void resume()
Restart the timer from its current time. The timer runs backward.


isRunning

public boolean isRunning()
Return true if the timer is running (current time > 0 and not stopped).


addTimerListener

public void addTimerListener(TimerListener timerListener)
Register a TimerListener to fire callbacks when the time interval expires (current time reaches 0 or the timer is stopped). The accuracy of the event is about 1 ms, but may vary due to multitasking/multithreading of the operation system and Java. The preset time of the AlarmTimer must exceed 10 ms. Be aware that the callback method must return before the preset time has elapsed. If timerListener = null, the internal thread of a previously registered timer listener is canceled.


stopEvents

public void stopEvents()
Force to stop the callback calls by terminating the timer's polling thread.