com.zynaptic.reaction.util
Class FixedUpMonotonicClock
java.lang.Object
com.zynaptic.reaction.util.FixedUpMonotonicClock
- All Implemented Interfaces:
- MonotonicClockSource
public final class FixedUpMonotonicClock
- extends java.lang.Object
- implements MonotonicClockSource
Implements a monotonic clock source derived from the standard Java wallclock.
This monotonic clock variant uses the standard Java millisecond clock which
is susceptible to changes made to the underlying wallclock. It works around
potential changes to the wallclock time by maintaining a clock offset which
is updated when the wallclock is observed to go backwards or jump too far
into the future.
To minimise timing errors when such discontinuities occur, a sleepy thread
makes regular calls to getMsTime, since timed calls to
the thread sleep method are assumed to be independent of the
wallclock time. This places an upper limit on the interval between requests
to getMsTime.
|
Method Summary |
long |
getMsTime()
Gets the elapsed time since the monotonic clock source was initialised. |
void |
init()
Initialises the monotonic clock source. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FixedUpMonotonicClock
public FixedUpMonotonicClock()
getMsTime
public final long getMsTime()
- Description copied from interface:
MonotonicClockSource
- Gets the elapsed time since the monotonic clock source was initialised.
This method is called in order to obtain the current time, defined as the
integer number of milliseconds since the monotonic clock source was
initialised.
- Specified by:
getMsTime in interface MonotonicClockSource
- Returns:
- Returns the monotonic time since the clock was initialised,
specified in milliseconds. Returns invalid data if the clock has
not been initialised.
init
public final void init()
- Description copied from interface:
MonotonicClockSource
- Initialises the monotonic clock source. This method is called on startup by
the reactor in order to initialise the timebase clock. It resets the
current clock time value to 0 and then sets the timer counter running.
- Specified by:
init in interface MonotonicClockSource