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,
AsyncBaseEventHandler 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)
Deprecated.
since RTSJ 2.0
|
Modifier and Type | Method and Description |
---|---|
void |
bindTo(String happening)
Deprecated.
since RTSJ 2.0
|
ReleaseParameters<?> |
createReleaseParameters()
createReleaseParameters creates the default release parameters
for this event.
|
void |
destroy()
Deprecated.
since RTSJ 2.0
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
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.
|
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
@Deprecated protected Timer(HighResolutionTime<?> time, Clock clock, AsyncEventHandler handler)
StaticIllegalArgumentException
- if time is a negative
RelativeTime.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.protected Timer(HighResolutionTime<?> time, AsyncBaseEventHandler handler, TimeDispatcher dispatcher)
time
based
on the Clock
associated with time
and is dispatched
by the specified dispatcher
.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
.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.public TimeDispatcher getDispatcher()
getDispatcher
in interface ActiveEvent<Timer,TimeDispatcher>
getDispatcher
in interface Releasable<Timer,TimeDispatcher>
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>
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>
StaticIllegalStateException
- if this timer is destroyed.disabled
- true to make this timer active but disabled.public void start(PhasingPolicy phasingPolicy) throws LateStartException, StaticIllegalArgumentException
PhasingPolicy
.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
.phasingPolicy
- Determines what happens when the start is too late.public void start(boolean disabled, PhasingPolicy phasingPolicy) throws LateStartException, StaticIllegalArgumentException
PhasingPolicy
and the
specified disabled state.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
.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.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.@Deprecated 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, ArithmeticException
StaticIllegalStateException
- when the timer is not active or has
been destroyed.ArithmeticException
- when the result does not fit in the
normalized format.this
actually started.public AbsoluteTime getEffectiveStartTime(AbsoluteTime dest) throws StaticIllegalStateException, 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.StaticIllegalStateException
- when the timer is not active or has
been destroyed.ArithmeticException
- when the result does not fit in the
normalized format.dest
- An object used to store the time this
actually started.public AbsoluteTime getFireTime()
StaticIllegalStateException
- if this timer has been destroyed or
it is not active.public AbsoluteTime getFireTime(AbsoluteTime dest)
StaticIllegalStateException
- if this timer has been destroyed or
it is not active.dest
- the AbsoluteTime which will be updated and returned if
not null. If dest is null, a new instance of AbsoluteTime will be
returned.public void reschedule(HighResolutionTime<?> time)
StaticIllegalStateException
- if this timer has been destroyed.time
- the new time parameter.public void fire() throws MITViolationException, ArrivalTimeQueueOverflowException
fire
in class AsyncEvent
MITViolationException
ArrivalTimeQueueOverflowException
protected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the Java™ virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
JamaicaVM: Realtime code requires special care when using finalize:
NOTE: The use of finalize() is strongly discouraged for realtime or safety-critical code. This method should only be used for debugging purposes. If used as a last resort to reclaim non-memory resources, finalize() should indicate the resource leak with a loud error message.
There is no guarantee that finalize() will be called, the memory management may decide not to reclaim this object's memory or to delay the call to finalize() to an unspecified point in time. It is therefore recommended never to use the finalize method to release any resources (files, network connections, non-Java memory, etc.) since releasing of these resource may be delayed perpetually.
The order of finalization is not specified, i.e., the finalize method of any two objects that become unreachable may be called in an arbitrary order. It therefore has to be assumed that when finalize() is called on an object, that the finalize() method of any object that is only reachable through this object() has been called as well or is called simultaneously by another thread.
The presence of a finalize-method in any sub-class of Object causes the reclamation of the memory of this object to be delayed until the finalize() method has been executed. The finalize() method is typically executed by the finalizer thread (that may run at a low priority) or by a call to Runtime.runFinalization().
Any code sequence that creates instances of a class that defines a finalize() method must therefore ensure that sufficient CPU time is allocated to the finalizer thread or that Runtime.runFinalization() is called regularly such that the finalize() methods can be executed and the object's memory can be reclaimed.
The finalize method itself should never block or run for long times since it would otherwise block the finalizer thread or the thread that called Runtime.runFinalization() and prevent the execution other finalize() method and consequently prevent the reclamation of these object's memory.
For objects that are allocated in a javax.realtime.memory.ScopedMemory, the finalize() methods will be called when this scoped memory is exited by the last thread. Unlike HeapMemory, which is controlled by the garbage collector, ScopedMemory provides a defined execution point for the finalize() mehods and it is therefore safer to use finalize() here.
finalize
in class AsyncBaseEvent
Throwable
- the Exception
raised by this methodWeakReference
,
PhantomReference
@Deprecated public void bindTo(String happening) throws UnsupportedOperationException
bindTo
in class AsyncEvent
UnsupportedOperationException
- everytime, since this
operation is not supported.happening
- to which to bind.