public class SntpConnector extends NetTimeConnector<SntpConfiguration>
Connects to a modern time server using the NTP-protocol.
This class needs a socket connection via the port 123. The exact configuration can be set in the constructors but can also be changed at runtime. It is recommended not to connect to the NTP-server during or near a leap second because the NTP-protocol only repeats such a timestamp causing ambivalences.
| Constructor and Description |
|---|
SntpConnector()
Creates a new instance which is configured by a
ServiceLoader. |
SntpConnector(SntpConfiguration ntc)
Creates a new instance which is configured by given argument.
|
SntpConnector(String server)
Creates a new instance which uses a default configuration
using the specified NTP4-server.
|
| Modifier and Type | Method and Description |
|---|---|
long |
currentTimeInMicros()
Returns the current time in microseconds since the Unix epoch
[1970-01-01T00:00:00,000000Z].
|
long |
currentTimeInMillis()
Returns the current time in milliseconds since the Unix epoch
[1970-01-01T00:00:00,000Z].
|
SntpMessage |
getLastReply()
Returns the last received message of the NTP-server.
|
connect, currentTime, getLastConnectionTime, getLastOffsetInMicros, getNetTimeConfiguration, isLogEnabled, isRunning, reconfigure, setLogWriterinLocalView, inPlatformView, inZonalView, inZonalViewpublic SntpConnector()
Creates a new instance which is configured by a
ServiceLoader.
IllegalStateException - if no configuration could be foundServiceLoaderpublic SntpConnector(SntpConfiguration ntc)
Creates a new instance which is configured by given argument.
ntc - SNTP-configurationpublic SntpConnector(String server)
Creates a new instance which uses a default configuration using the specified NTP4-server.
Example:
SntpConnector clock = new SntpConnector("ptbtime1.ptb.de");
clock.connect();
System.out.println(clock.currentTime());
server - NTP4-serverpublic long currentTimeInMillis()
Returns the current time in milliseconds since the Unix epoch [1970-01-01T00:00:00,000Z].
UTC leap seconds are never counted.
public long currentTimeInMicros()
Returns the current time in microseconds since the Unix epoch [1970-01-01T00:00:00,000000Z].
UTC leap seconds are never counted.
public SntpMessage getLastReply()
Returns the last received message of the NTP-server.
null if not yet receivedNetTimeConnector.connect()Copyright © 2014–2016. All rights reserved.