public abstract class Clock extends Object implements Chronograph
A clock provides means to determine the current time (now) with a given resolution.
Constructor and Description |
---|
Clock()
Constructor to be called by subclasses of Clock.
|
Modifier and Type | Method and Description |
---|---|
RelativeTime |
getDrivePrecision()
Returns the resolution for driving events from this clock, i.e.
|
RelativeTime |
getDrivePrecision(RelativeTime dest)
Gets the precision of the clock for driving events, the nominal interval
between ticks that can trigger an event.
|
RelativeTime |
getEpochOffset()
Determines the time on the UTC clock when this chronograph was
zero.
|
RelativeTime |
getQueryPrecision(RelativeTime dest)
Obtains the precision with which time can be read, i.e., the nominal
interval between ticks.
|
static Clock |
getRealtimeClock()
Returns the default RealtimeClock.
|
abstract RelativeTime |
getResolution()
Deprecated.
since RTSJ 2.0
|
AbsoluteTime |
getTime()
Determines the current time.
|
abstract AbsoluteTime |
getTime(AbsoluteTime time)
Obtain the current time.
|
static Clock |
getUniversalClock()
Returns the default UniversalClock.
|
static void |
setRealtimeClock(Clock clock)
Sets the system default realtime clock.
|
abstract void |
setResolution(RelativeTime resolution)
Deprecated.
since RTSJ 2.0
|
static void |
setUniversalClock(Clock clock)
Sets the system default universal clock.
|
boolean |
wait(Object rendezvous,
HighResolutionTime<?> deadline)
Generic wait function that waits for a waiting for a deadlime.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getEpochOffset, getQueryPrecision, isUpdated, lastSynchronized, lastSynchronized
public Clock()
Since this class is abstract, this constructor cannot be called from a class that is not a sub-class of Clock, it should therefore better be protected.
public static Clock getRealtimeClock()
For JamaicaVM, on systems that have a timer that is synchronized with the external world, this returns a RealtimeClock that is synchronized with the external world. On systems whose timer is not synchronized with the external world, the time of the returned RealtimeClock may be different to the time used by the external world (e.g., the epoch may start at system boot time).
public static void setRealtimeClock(Clock clock)
clock
- To be used for the realtime clock. When null
, the
default realtime clock is set to the original system default.public static Clock getUniversalClock()
For JamaicaVM, on systems that have a timer that is synchronized with the external world, this returns a UniversalClock that is synchronized with the external world. On systems whose timer is not synchronized with the external world, the time of the returned UniversalClock may be different to the time used by the external world (e.g., the epoch may start at system boot time).
public static void setUniversalClock(Clock clock)
clock
- To be used for the universal clock. When null
, the
default universal clock is set to the original system default.public RelativeTime getEpochOffset() throws StaticUnsupportedOperationException, UninitializedStateException
getEpochOffset
in interface Chronograph
UninitializedStateException
- when UTC time is not yet available.StaticUnsupportedOperationException
RelativeTime
object in the current
execution context with the realtime clock as its chronograph
and containing time when this chronograph was zero.@Deprecated public abstract RelativeTime getResolution()
StaticUnsupportedOperationException
- when getting the time
resolution is not supported for the given clock.public AbsoluteTime getTime()
Chronograph
getTime
in interface Chronograph
AbsoluteTime
in the
current allocation context, representing the current time.
The returned object has this
its chronograph.public abstract AbsoluteTime getTime(AbsoluteTime time)
AbsoluteTime
is changed at some time between the invocation of the
method and the return of the method. This method will return an absolute
time value that represents this chronograph's notion of the absolute time.
For chronographs that do not measure calendar time, this absolute time may
not represent a wall clock time.getTime
in interface Chronograph
time
- The instance of AbsoluteTime
object which will be
updated in place.AbsoluteTime
passed as parameter, or a new
object when dest
is null
. The returned object
represents the current time and is associated with this
chronograph.@Deprecated public abstract void setResolution(RelativeTime resolution)
StaticIllegalArgumentException
- if parameter is null or
represents a negative or zero interval.StaticUnsupportedOperationException
- when setting the time
resolution is not supported for the given clock.resolution
- the new resolution.public RelativeTime getDrivePrecision()
public RelativeTime getDrivePrecision(RelativeTime dest)
Chronograph.getQueryPrecision(RelativeTime)
. This
base implementation does nothing for compatibility and must be
overridden in subclasses.dest
- To return the relative time value in dest
.
When dest
is null
, it allocates a new
RelativeTime
instance to hold the returned value.dest
set to values representing the drive precision.public RelativeTime getQueryPrecision(RelativeTime dest)
getQueryPrecision
in interface Chronograph
dest
- To return the relative time value in dest
.
When dest
is null
, it allocates a new
RelativeTime
instance to hold the returned value.dest
, when dest
is not
null
, or in a newly created object otherwise.public boolean wait(Object rendezvous, HighResolutionTime<?> deadline) throws InterruptedException
rendezvous
object to hold the
schedulable until the time has elapsed. The caller must be
synchronized on rendezvous
. This is used
to implement both RealtimeThread.sleep(javax.realtime.Clock, javax.realtime.HighResolutionTime<?>)
and
RealtimeThread.waitForNextRelease()
InterruptedException
rendezvous
- an object to wait on until time has passed thus
letting the current thread to continue.deadline
- The time when the wait should endtrue
when deadline
is reached and
false
when interrupted before deadline
aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2025 aicas GmbH. All Rights Reserved.