public class RealTimeTickSource extends AbstractTickSource
System.nanoTime(), the upper
bound is Integer.MAX_VALUE.
Ticks are generated at a fixed tick-to-tick interval, regardless of the
duration of handling ticks. If the handling of ticks for all is not finished
until the next tick, one or more subsequent ticks will be fired immediately.
Ticks start at 0 and are processed in single-threaded mode.
If the last tick listener has been removed from this source, it shuts itself
down via stop(), if it's not set to keepAlive mode using
setKeepAlive(boolean).| Modifier and Type | Field and Description |
|---|---|
static long |
BUSY_WAITING_THRESHOLD
The threshold below which busy waiting is employed.
|
static long |
MILLISECOND_THRESHOLD
The threshold above which a different implementation of the internal timer
is used, which is only considering milliseconds.
|
listeners| Constructor and Description |
|---|
RealTimeTickSource(long nanoSecondsPerTick)
Creates a running real time tick source with ticks generated at the given
interval.
|
RealTimeTickSource(long nanoSecondsPerTick,
boolean start)
Creates a tick source with ticks generated at the given interval.
|
| Modifier and Type | Method and Description |
|---|---|
void |
removeListener(TickListener listener)
If the last tick listener has been removed from this source, it shuts
itself down via
stop(), if it's not set to keepAlive mode using
setKeepAlive(boolean). |
void |
reset() |
void |
setKeepAlive(boolean keepAlive)
Sets the keepAlive mode of this tick source.
|
void |
start()
Starts generating tick events, starting from 0.
|
void |
stop()
Stops generating tick events.
|
addListener, doTick, getCurrentTickpublic static final long BUSY_WAITING_THRESHOLD
BUSY_WAITING_THRESHOLD are implemented
with busy waiting. Intervals above are implemented by synchronized
waiting.
On the current development machine, this threshold had to be at least a
value of 4.2 ms to ensure the real-time tests passing, which is why 15 ms
have been chosen as a margin. Above 10 ms of threshold, an constat error
rate of less than 1 % was measured.public static final long MILLISECOND_THRESHOLD
public RealTimeTickSource(long nanoSecondsPerTick)
nanoSecondsPerTick - the interval of ticks in nanosecondspublic RealTimeTickSource(long nanoSecondsPerTick,
boolean start)
nanoSecondsPerTick - the interval of ticks in nanosecondsstart - whether the tick source should be started upon creationpublic void setKeepAlive(boolean keepAlive)
stop() upon the
removal of the last tick listener. If keepAlive is true, the source stays
active.keepAlive - whether the keepAlive mode should be onpublic void reset()
reset in interface TickSourcereset in class AbstractTickSourcepublic void removeListener(TickListener listener)
stop(), if it's not set to keepAlive mode using
setKeepAlive(boolean).removeListener in interface TickSourceremoveListener in class AbstractTickSourcepublic void start()
public void stop()
Copyright © 2015. All rights reserved.