C - generic configuration typepublic abstract class NetTimeConnector<C extends NetTimeConfiguration> extends AbstractClock
Represents an abstract connection object to an internet time server.
A socket connection can be established by connect() and then the difference
between the local computer clock using SystemClock.MONOTONIC and the net time
can be queried. Next time queries of this clock are based on this difference
and the local clock - until the next CONNECT.
SystemClock.MONOTONIC| Modifier and Type | Method and Description |
|---|---|
void |
connect()
Queries a time server for the current time.
|
Moment |
currentTime()
Yields the current time after a connection has been established
at least once.
|
Moment |
getLastConnectionTime()
Yields the time of last connection.
|
long |
getLastOffsetInMicros()
Yields the last offset between net time and local time in
microseconds.
|
C |
getNetTimeConfiguration()
Yields the current configuration parameters.
|
boolean |
isLogEnabled()
Determines if the internal logging is enabled.
|
boolean |
isRunning()
The clock is running as soon as there was established a connection
at least once.
|
boolean |
reconfigure()
Queries the configuration parameters to be used for the next
connection.
|
void |
setLogWriter(PrintWriter out)
Installs a logging stream for any messages during connection.
|
inLocalView, inPlatformView, inZonalView, inZonalViewpublic Moment currentTime()
Yields the current time after a connection has been established at least once.
If there was no connection yet then this method just displays the time of clock construction. Note that this method is still sensible for any local clock change triggered by the underlying operating system. If an application needs a fresh internet time then following code can be used instead (causing network traffic):
NetTimeConnector<?> clock = ...; clock.connect(); Moment currentTime = clock.getLastConnectionTime();
isRunning()public boolean isRunning()
The clock is running as soon as there was established a connection at least once.
If there is not yet any connection then this clock will only display the time of its construction.
connect()public final void connect()
throws IOException
Queries a time server for the current time.
The result can then be achieved by the method currentTime()
which is based on the network offset calculated in last connection.
A connection to the server only happens in this method and not in
the method currentTime().
IOException - if connection fails or in case of any
inconsistent server answerscurrentTime()public final boolean reconfigure()
Queries the configuration parameters to be used for the next connection.
The configuration will be determined by a ServiceLoader.
If not available then this connector will just choose the configuration
which was given during construction of this instance. Any possible
IllegalStateException will be logged to the error console.
This method delegates to loadNetTimeConfiguration().
true if successful else falseloadNetTimeConfiguration()public C getNetTimeConfiguration()
Yields the current configuration parameters.
reconfigure()public void setLogWriter(PrintWriter out)
Installs a logging stream for any messages during connection.
out - output stream (null disables logging)public boolean isLogEnabled()
Determines if the internal logging is enabled.
true if there is any installed log writer
else falsesetLogWriter(PrintWriter)public Moment getLastConnectionTime()
Yields the time of last connection.
null if there was not
any connection yetconnect()public long getLastOffsetInMicros()
Yields the last offset between net time and local time in microseconds.
0 if there was not any
connection yet)connect()Copyright © 2014–2016. All rights reserved.