@FunctionalInterface public interface Realtime extends Runnable, CompilableControlFlow
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_AFAP_INTERRUPT_LATENCY
Default upper bound on the number of events that may be generates
by a fast driver before checking the executing thread's interrupt
status.
|
static long |
DEFAULT_SLEEP_TIME_MS
Default number of milliseconds to sleep in an event-generating
thread that has outrun real time.
|
Modifier and Type | Method and Description |
---|---|
static Realtime |
adHoc(Realtime r)
Helper method that enables lambda notation for instances of this
class in any context.
|
default Runnable |
afap()
Creates a driver for this object that generates events as fast as
possible.
|
default Runnable |
afap(int interruptLatency)
Creates a driver for this object that generates events as fast as
possible.
|
default Realtime |
andThen(Realtime other)
Creates a wrapper that performs, for each event, the
reactions of this object and another in sequence.
|
default Realtime |
asAsynchronousSwingEvent()
Creates a wrapper that executes this event asynchronously in the
Swing event thread.
|
default <V,L> void |
compileControlFlow(CompilationContext<V,L> context) |
default Realtime |
every(int slowdown)
Creates a wrapper that passes only every n-th event to this
object, starting with the first event.
|
default Realtime |
every(int slowdown,
int initialCountdown)
Creates a wrapper that passes only every n-th event to this
object, starting after a given number of initially skipped
events.
|
default Runnable |
frequently(float freq)
Creates a driver for this object that generates events
with a given asymptotic real-time frequency.
|
default Runnable |
frequently(float freq,
long sleepTimeMS)
Creates a driver for this object that generates events
with a given asymptotic real-time frequency.
|
default Runnable |
frequently(float freq,
long sleepTimeMS,
int sleepTimeNS)
Creates a driver for this object that generates events with a
given asymptotic real-time frequency.
|
void |
run()
Processes an event.
|
static Realtime |
sequence(Realtime... elems)
Creates a wrapper that performs, for each event, the
reactions of an arbitrary number of objects in sequence.
|
default Runnable |
times(long n) |
default Runnable |
times(long n,
int interruptLatency) |
static final long DEFAULT_SLEEP_TIME_MS
static final int DEFAULT_AFAP_INTERRUPT_LATENCY
void run()
Any implementation of this method should complete promptly and normally. In particular it must not block indefinitely.
static Realtime adHoc(Realtime r)
r
- the object to returndefault Realtime andThen(Realtime other)
other
- the other object to react to each event after this
object.IllegalArgumentException
- if other == null
.static Realtime sequence(Realtime... elems)
elems
- the array of objects to react to each event in
sequence.IllegalArgumentException
- if other == null
.default Realtime every(int slowdown)
slowdown
- the number of events for the wrapper that result
in a single event for the wrapped object.IllegalArgumentException
- if slowdown < 1
.default Realtime every(int slowdown, int initialCountdown)
slowdown
- the number of events for the wrapper that result
in a single event for the wrapped object.initialCountdown
- the number of events to skip
initially. Note that this number may exceed the value of .IllegalArgumentException
- if slowdown < 1
or
initialCountdown < 0
.default Runnable frequently(float freq)
This method is a shorthand for frequently(freq,
DEFAULT_SLEEP_TIME_MS, 0)
.
default Runnable frequently(float freq, long sleepTimeMS)
This method is a shorthand for frequently(freq,
sleepTimeMS, 0)
.
frequently(float, long, int)
default Runnable frequently(float freq, long sleepTimeMS, int sleepTimeNS)
run()
of
the wrapped object has completed, it is immediately reinvoked.
After each burst, the executing thread sleeps for a given amount
of time.
The number of events in a burst is determined by the amount of real time elapsed since the start of the previous burst, and the specified frequency. Thus the frequency is obeyed asymptotically, and the latency of each individual event is bounded by the given sleep time.
The driver continues to operate until its executing thread is interrupted; then it completes normally after finishing the current burst, and clears the interrupt status.
freq
- the real-time frequency of events.sleepTimeMS
- the number of milliseconds to sleep between
bursts.sleepTimeNS
- the number of additional nanoseconds to sleep
between bursts.IllegalArgumentException
- if !(freq >= 0)
or
sleepTimeMS < 0
or sleepTimeNS < 0
.Thread.Thread(Runnable)
default Realtime asAsynchronousSwingEvent()
SwingUtilities.invokeLater(java.lang.Runnable)
default Runnable afap()
This method is a shorthand for afap(DEFAULT_AFAP_INTERRUPT_LATENCY)
.
afap(int)
default Runnable afap(int interruptLatency)
The driver continues to operate until its executing thread is interrupted; then it completes normally after no more than a given number of events, and clears the interrupt status.
interruptLatency
- the number of events that may be
generated before the interrupt status of the executing thread is
checked, or zero to disable interrupt checking altogether.IllegalArgumentException
- if interruptLatency < 0
.Thread.Thread(Runnable)
default Runnable times(long n)
default Runnable times(long n, int interruptLatency)
default <V,L> void compileControlFlow(CompilationContext<V,L> context)
compileControlFlow
in interface CompilableControlFlow