public abstract class Clock extends java.lang.Object implements Chronograph
Clock.getTime()
, and it can have events
queued on it which will be fired when their appointed time is reached.
Note that while all Clock
implementations use
representations of time derived from HighResolutionTime
,
which expresses its time in milliseconds and nanoseconds, a
particular Clock
may track time that is not delimited in
seconds or not related to wall clock time in any particular fashion
(e.g., revolutions or event detections). In this case, the
Clock
's timebase should be mapped to milliseconds and
nanoseconds in a manner that is computationally appropriate.
Constructor and Description |
---|
Clock()
Constructor for the abstract class.
|
Modifier and Type | Method and Description |
---|---|
RelativeTime |
getDrivePrecision()
Gets the precision of the clock for driving events, the nominal interval
between ticks that can trigger an event.
|
abstract 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 difference between the epoch of this clock from the Epoch.
|
RelativeTime |
getQueryPrecision()
Obtains the precision with which time can be read, i.e.,
the nominal interval between ticks.
|
static Clock |
getRealtimeClock()
There is always at least one clock object available:
the system realtime clock.
|
abstract RelativeTime |
getResolution()
Deprecated.
since RTSJ 2.0
|
AbsoluteTime |
getTime()
Determines the current time.
|
abstract AbsoluteTime |
getTime(AbsoluteTime dest)
Obtains the current time.
|
static Clock |
getUniversalClock()
A means of obtaining the Universal Time, which has no summer or winter
time.
|
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.
|
abstract void |
wait(java.lang.Long milliseconds,
int nanoseconds) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getEpochOffset, getQueryPrecision, isUpdated, lastSynchronized, lastSynchronized
public static Clock getRealtimeClock()
CLOCK_MONOTONIC
. It is the default Clock
.Clock
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() throws StaticUnsupportedOperationException, UninitializedStateException
CLOCK_REALTIME
,
when the timezone is set to UTC.StaticUnsupportedOperationException
- when the system does
not support UTC.UninitializedStateException
- when UTC time is not yet available.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
RelativeTime
value equal to
zero. For other clocks, it is a value representing the difference between
zero on that clock and zero on the UTC measured on the UTC, where
a positive epoc is later than the EPOC.getEpochOffset
in interface Chronograph
RelativeTime
object in the current
execution context with the UTC as its chronograph and containing
the time when this chronograph was zero.StaticUnsupportedOperationException
- when the chronograph
does not have the concept of date.UninitializedStateException
- when UTC time is not yet available.public RelativeTime getDrivePrecision()
getDrivePrecision(RelativeTime)
with null
as its
argument.public abstract RelativeTime getDrivePrecision(RelativeTime dest)
Chronograph.getQueryPrecision(RelativeTime)
.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()
Chronograph
Chronograph.getQueryPrecision(RelativeTime)
with
null
as an argument.getQueryPrecision
in interface Chronograph
public AbsoluteTime getTime()
Chronograph
getTime
in interface Chronograph
AbsoluteTime
in the
current allocation context, representing the current time.
The returned object has the chronograph from this
.public abstract AbsoluteTime getTime(AbsoluteTime dest)
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
chronographs'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
dest
- 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.void
to
AbsoluteTime
., RTSJ 2.0 When dest is null
, a new object is allocated,
when not chronograph is overwritten with this
.public abstract void wait(java.lang.Long milliseconds, int nanoseconds)
@Deprecated public abstract void setResolution(RelativeTime resolution)
this
.
For some hardware clocks setting resolution is
impossible and when this method is called on those clocks,
then an StaticUnsupportedOperationException
is thrown.resolution
- The new resolution of this
, when the
requested value is supported by this
clock.
When resolution
is smaller than the minimum
resolution supported by this
clock then it
throws StaticIllegalArgumentException
. When the
requested resolution
is not available and it
is larger than the minimum resolution, then the clock will
be set to the closest resolution that the clock supports,
via truncation. The value of the resolution
parameter is not altered. The clock association of the
resolution
parameter is ignored.StaticIllegalArgumentException
- when resolution
is null
, or when the
requested resolution
is smaller than the minimum
resolution supported by this clock.StaticUnsupportedOperationException
- when the
clock does not support setting its resolution.@Deprecated public abstract RelativeTime getResolution()
RelativeTime
object representing
the resolution of this
.
The returned object is associated with this
clock.getDrivePrecision()
,
getQueryPrecision()