JMACS

org.jmacs.util
Class Timer

java.lang.Object
  extended by org.jmacs.util.Timer

public class Timer
extends Object

timer which defines a cycle--in terms of its period and some reference boundary--and which is able to sleep until the next boundary of that cycle. This is NOT thread safe.

Version:
$Id: Timer.java 2089 2007-08-15 15:07:05Z rob $
Author:
Rob Dickens

Nested Class Summary
static class Timer.Params
          immutable parameters.
 
Constructor Summary
Timer()
          creates new instance.
Timer(long refBoundaryMillis, long periodMillis)
          creates new instance.
Timer(Timer.Params params)
          creates new instance.
 
Method Summary
 long getLagMillis()
          returns this property.
 long getLastBoundaryMillis()
          in case sleep not called.
 Timer.Params getParams()
          returns parameters.
 long getPeriodMillis()
          returns period/ms.
 void setLagMillis(long lagMillis)
          where (current time + lagMillis) is used in place of the value obtained from the system clock.
 void setParams(long refBoundaryMillis, long periodMillis)
          sets parameters.
 void setParams(Timer.Params params)
          sets parameters.
 void setPeriodMillis(long periodMillis)
          sets new period/ms.
 void setRefBoundaryMillis(long refBoundaryMillis)
          sets new reference boundary/ms.
 long sleep()
          until the next boundary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Timer

public Timer()
creates new instance. The reference boundary will be set to 'the epoch'--0000 hours on 1970-01-01--and period to 1 second.


Timer

public Timer(long refBoundaryMillis,
             long periodMillis)
creates new instance.


Timer

public Timer(Timer.Params params)
creates new instance.

Method Detail

sleep

public long sleep()
           throws InterruptedException
until the next boundary.

Returns:
time of boundary (when woke up)
Throws:
InterruptedException

getLastBoundaryMillis

public long getLastBoundaryMillis()
in case sleep not called.


getPeriodMillis

public long getPeriodMillis()
returns period/ms.


getParams

public Timer.Params getParams()
returns parameters.


setRefBoundaryMillis

public void setRefBoundaryMillis(long refBoundaryMillis)
sets new reference boundary/ms.


setPeriodMillis

public void setPeriodMillis(long periodMillis)
sets new period/ms.


setParams

public void setParams(long refBoundaryMillis,
                      long periodMillis)
sets parameters.


setParams

public void setParams(Timer.Params params)
sets parameters.


setLagMillis

public void setLagMillis(long lagMillis)
where (current time + lagMillis) is used in place of the value obtained from the system clock.


getLagMillis

public long getLagMillis()
returns this property.


JMACS

jmacs.org