public abstract class Timer extends AsyncEvent implements ActiveEvent<Timer,TimeDispatcher>
abstract super class of PeriodicTimer or OneShotTimer. These timers are asynchronous events that fire at a given time.
Modifier | Constructor and Description |
---|---|
protected |
Timer(HighResolutionTime<?> time,
AsyncEventHandler handler,
TimeDispatcher dispatcher)
Creates a timer that fires according to the given
time based
on the Clock associated with time and is dispatched
by the specified dispatcher . |
protected |
Timer(HighResolutionTime<?> time,
Clock clock,
AsyncEventHandler handler)
Constructor to create a timer with the given time, clock and
handler.
|
Modifier and Type | Method and Description |
---|---|
void |
bindTo(java.lang.String happening)
Should not be called, since this was only meant for binding
happenings to normal instances AsyncEvent, not to special
subclasses.
|
ReleaseParameters<?> |
createReleaseParameters()
createReleaseParameters creates the default release parameters
for this event.
|
void |
destroy()
destroy destroys this timer, i.e., stops it from counting.
|
protected void |
finalize() |
void |
fire()
fires this event unless firing is disabled and reschedules
the timer in case it is periodic.
|
Clock |
getClock()
getClock returns the clock this timer was based on.
|
TimeDispatcher |
getDispatcher()
Obtain the current dispatcher for this event.
|
AbsoluteTime |
getEffectiveStartTime()
Returns a newly-created time representing the time when the timer
actually started, or when the timer has been rescheduled, the
effective start time after the reschedule.
|
AbsoluteTime |
getEffectiveStartTime(AbsoluteTime dest)
Updates
dest to represent the time when the timer actually
started, or when the timer has been rescheduled, the effective start
time after the reschedule. |
AbsoluteTime |
getFireTime()
getFireTime returns the time at which this timer is expected to
fire or skip firing (because it is disabled) next.
|
AbsoluteTime |
getFireTime(AbsoluteTime dest)
getFireTime returns the time at which this timer is expected to
fire or skip firing (because it is disabled) next.
|
HighResolutionTime<?> |
getStart()
Gets the start time of this
Timer . |
boolean |
isActive()
Determines the activation state of this event, i.e., it has been started
but not yet stopped again.
|
boolean |
isRunning()
isRunning returns true if this timer has been started (it is
active) and it has not been disabled.
|
void |
reschedule(HighResolutionTime<?> time)
reschedule changes the time for this event.
|
TimeDispatcher |
setDispatcher(TimeDispatcher dispatcher)
Change the current dispatcher for this event.
|
protected void |
setStartTime(HighResolutionTime<?> time)
Sets the time when this timer should fire.
|
void |
start()
start this timer, i.e., make it active and enabled
|
void |
start(boolean disabled)
start this timer, i.e., make it active.
|
void |
start(boolean disabled,
PhasingPolicy phasingPolicy)
Starts the timer with the specified
PhasingPolicy and the
specified disabled state. |
void |
start(PhasingPolicy phasingPolicy)
Starts the timer with the specified
PhasingPolicy . |
boolean |
stop()
stop stops this active timer changing its state to not-active and
disabled.
|
addHandler, handledBy, removeHandler, setHandler, unbindTo
addHandler, disable, enable, handledBy, hasHandlers, removeHandler, setHandler
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
disable, enable
protected Timer(HighResolutionTime<?> time, Clock clock, AsyncEventHandler handler)
time
- The time when this timer should fire. May be null, in
this case this is equal to new RelativeTime(0, 0) and the firing
will occur immediately after a call to start().clock
- the clock this timer should be based upon. May be
null to use the default System.getRealtimeClock().handler
- The handler that will be released when this timer
fires. May be null to have no handler until one will be added via
addHandler.StaticIllegalArgumentException
- if time is a negative
RelativeTime.protected Timer(HighResolutionTime<?> time, AsyncEventHandler handler, TimeDispatcher dispatcher)
time
based
on the Clock
associated with time
and is dispatched
by the specified dispatcher
.time
- The parameter 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 object used to interface between
this timer
and its associated clock. When
null
, the system default dispatcher is used.StaticIllegalArgumentException
- when time
is a
negative RelativeTime
value.StaticUnsupportedOperationException
- when time
has a
Chronograph
is not a clock
.IllegalAssignmentError
- when this Timer
cannot hold references to
handler
and clock
.public TimeDispatcher getDispatcher()
getDispatcher
in interface ActiveEvent<Timer,TimeDispatcher>
getDispatcher
in interface Releasable<Timer,TimeDispatcher>
java.lang.UnsupportedOperationException
- always, since it is not yet
implemented.public TimeDispatcher setDispatcher(TimeDispatcher dispatcher)
dispatcher
is null
, the default dispatcher is restored.setDispatcher
in interface ActiveEvent<Timer,TimeDispatcher>
java.lang.UnsupportedOperationException
- always, since it is not yet
implemented.public boolean isRunning()
isRunning
in interface ActiveEvent<Timer,TimeDispatcher>
isRunning
in class AsyncBaseEvent
public boolean isActive()
ActiveEvent
isActive
in interface ActiveEvent<Timer,TimeDispatcher>
true
when active, false
otherwise.public void start()
start
in interface ActiveEvent<Timer,TimeDispatcher>
public void start(boolean disabled)
start
in interface ActiveEvent<Timer,TimeDispatcher>
disabled
- true to make this timer active but disabled.StaticIllegalStateException
- if this timer is destroyed.public void start(PhasingPolicy phasingPolicy) throws LateStartException, StaticIllegalArgumentException
PhasingPolicy
.phasingPolicy
- Determines what happens when the start is too late.LateStartException
- when this method is called after its absolute
start time and the phasingPolicy
is
PhasingPolicy.STRICT_PHASING
.StaticIllegalArgumentException
- when the start time of this timer
is not an absolute time, or phasingPolicy
is
null
or, when this in not a periodic timer,
ADJUST_FORWARD
or ADJUST_BACKWARD
.public void start(boolean disabled, PhasingPolicy phasingPolicy) throws LateStartException, StaticIllegalArgumentException
PhasingPolicy
and the
specified disabled state.disabled
- It determines the mode of start: true
for
enabled and false
for disabled for consistency with
start(boolean)
.phasingPolicy
- It determines what happens when the start is too late.LateStartException
- when this method is called after its absolute
start time and the phasingPolicy
is
PhasingPolicy.STRICT_PHASING
.StaticIllegalArgumentException
- when the start time of this timer
is not an absolute time, or phasingPolicy
is
null
or, when this in not a periodic timer,
ADJUST_FORWARD
or ADJUST_BACKWARD
.public boolean stop()
stop
in interface ActiveEvent<Timer,TimeDispatcher>
StaticIllegalStateException
- if this timer is destroyed.public ReleaseParameters<?> createReleaseParameters()
createReleaseParameters
in class AsyncEvent
StaticIllegalStateException
- if this timer is destroyed.public void destroy()
StaticIllegalStateException
- if this timer has been destroyed.public Clock getClock()
StaticIllegalStateException
- if this timer has been destroyed.public HighResolutionTime<?> getStart()
Timer
. Note that the start time
uses copy semantics, so changes made to the value returned by this
method do not affect the start time of this Timer
.Timer
, ensuring the content has
the original values.public AbsoluteTime getEffectiveStartTime() throws StaticIllegalStateException, java.lang.ArithmeticException
this
actually started.StaticIllegalStateException
- when the timer is not active or has
been destroyed.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public AbsoluteTime getEffectiveStartTime(AbsoluteTime dest) throws StaticIllegalStateException, java.lang.ArithmeticException
dest
to represent the time when the timer actually
started, or when the timer has been rescheduled, the effective start
time after the reschedule.
When dest
is null
, behaves as if
getEffectiveStartTime()
had been called.dest
- An object used to store the time this
actually started.StaticIllegalStateException
- when the timer is not active or has
been destroyed.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public AbsoluteTime getFireTime()
StaticIllegalStateException
- if this timer has been destroyed or
it is not active.public AbsoluteTime getFireTime(AbsoluteTime dest)
dest
- the AbsoluteTime which will be updated and returned if
not null. If dest is null, a new instance of AbsoluteTime will be
returned.StaticIllegalStateException
- if this timer has been destroyed or
it is not active.public void reschedule(HighResolutionTime<?> time)
time
- the new time parameter.StaticIllegalStateException
- if this timer has been destroyed.public void fire()
fire
in class AsyncEvent
protected void finalize() throws java.lang.Throwable
finalize
in class AsyncBaseEvent
java.lang.Throwable
public void bindTo(java.lang.String happening) throws java.lang.UnsupportedOperationException
bindTo
in class AsyncEvent
happening
- to which to bind.java.lang.UnsupportedOperationException
- everytime, since this
operation is not supported.protected void setStartTime(HighResolutionTime<?> time)
time
- The time when this timer should fire, may be null, in this case
this is equal to new RelativeTime(0, 0) and the firing will occur immediately
after a call to start().aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2024 aicas GmbH. All Rights Reserved.