public class OneShotTimer extends Timer
AsyncEvent that is driven by a Clock.
It will fire once,
when the clock time reaches the time-out time, unless restarted after
expiration.
When the timer is disabled at the expiration of the indicated time,
the firing is lost (skipped).
After expiration, the OneShotTimer becomes
not-active and disabled.
When the clock time has
already passed the time-out time, it will fire immediately after it is
started or after it is rescheduled while active.
Semantics details are described in the Timer pseudocode
and compact graphic representation of state transitions.
Caution: This class is explicitly unsafe for multithreading when being changed. Code that mutates instances of this class should synchronize at a higher level.
| Constructor and Description |
|---|
OneShotTimer(HighResolutionTime<?> time,
AsyncBaseEventHandler handler)
The equivalent of calling
OneShotTimer(HighResolutionTime, AsyncBaseEventHandler, TimeDispatcher)
with arguments (time, handler, null). |
OneShotTimer(HighResolutionTime<?> time,
AsyncBaseEventHandler handler,
TimeDispatcher dispatcher)
Creates an instance of
OneShotTimer, based on the given
clock, that will execute its fire method
according to the given time. |
OneShotTimer(HighResolutionTime<?> time,
AsyncEventHandler handler)
Deprecated.
since RTSJ 2.0
|
OneShotTimer(HighResolutionTime<?> time,
Clock clock,
AsyncEventHandler handler)
Deprecated.
since RTSJ 2.0
|
| Modifier and Type | Method and Description |
|---|---|
void |
fire()
This should not be called for application code, except for
emulation.
|
bindTo, createReleaseParameters, destroy, disable, enable, getClock, getDispatcher, getEffectiveStartTime, getEffectiveStartTime, getFireTime, getFireTime, getStart, handledBy, isActive, isRunning, reschedule, setDispatcher, start, start, start, start, stopaddHandler, removeHandler, setHandler, unbindToaddHandler, handledBy, hasHandlers, removeHandler, setHandler@Deprecated public OneShotTimer(HighResolutionTime<?> time, Clock clock, AsyncEventHandler handler) throws StaticIllegalArgumentException, StaticUnsupportedOperationException, IllegalAssignmentError
OneShotTimer, based on the given
clock, that will execute its
fire method according to the given time.
The Clock association of the parameter time
is ignored.time - The time used to determine when to fire the event.
A time value of null is equivalent to a
RelativeTime of 0, and in this case
the Timer fires
immediately upon a call to start().clock - The clock on which to base this timer, overriding
the clock associated with the parameter time.
When null, the system Realtime clock is used.
The clock associated with the parameter time is always
ignored.handler - The AsyncEventHandler that will be
released when fire is invoked.
When null, no handler is associated with this
Timer and nothing will happen when this event fires
unless a handler is subsequently associated with the timer using the
addHandler() or setHandler() method.StaticIllegalArgumentException - when time
is a RelativeTime instance less than zero.StaticUnsupportedOperationException - when the Chronograph
associated with time is not a Clock.IllegalAssignmentError - when this OneShotTimer
cannot hold references to time, handler,
or clock.public OneShotTimer(HighResolutionTime<?> time, AsyncBaseEventHandler handler, TimeDispatcher dispatcher) throws StaticIllegalArgumentException, StaticUnsupportedOperationException, IllegalAssignmentError
OneShotTimer, based on the given
clock, that will execute its fire method
according to the given time. The Clock association of
the parameter time is ignored.time - The time used to determine when to fire the event.
A time value of null is equivalent to a
RelativeTime of 0, and in this case the
Timer fires immediately upon a call to start().handler - The default handler to use for this event.
When null, no handler is associated with the
timer and nothing will happen when this event fires unless a
handler is subsequently associated with the timer
using the addHandler() or setHandler() method.dispatcher - The dispatcher used to interface between
this timer and its associated clock. When
null, the system default dispatcher is used.StaticIllegalArgumentException - when time is a
RelativeTime instance less than zero.StaticUnsupportedOperationException - when the Chronograph
associated with time is not a Clock.IllegalAssignmentError - when this OneShotTimer
cannot hold references to time, handler,
or clock.@Deprecated public OneShotTimer(HighResolutionTime<?> time, AsyncEventHandler handler)
OneShotTimer(HighResolutionTime, AsyncBaseEventHandler, TimeDispatcher)
with arguments (time, handler, null).time - Time to release its handlers.handler - Handler to be released.public OneShotTimer(HighResolutionTime<?> time, AsyncBaseEventHandler handler)
OneShotTimer(HighResolutionTime, AsyncBaseEventHandler, TimeDispatcher)
with arguments (time, handler, null).time - Time to release its handlers.handler - Handler to be released.public void fire()
this is enabled, it releases all handlers and then
calls Timer.stop(). When distabled, but active, it only
calls Timer.stop(). Otherwise it does nothing.fire in class AsyncEventOneShotTimer and
PeriodicTimer have slightly different semantics.