networkClock
Class NetworkClockController

java.lang.Object
  extended by networkClock.NetworkClockController
All Implemented Interfaces:
NetworkClockInterface

public class NetworkClockController
extends java.lang.Object
implements NetworkClockInterface

Controller class of component NetworkClock.

Provides a clock, which can be synchronized with a SNTP server (See RFC 2030 for further information).

Can retrieve SNTP messages from a SNTP server at regular intervals and calculate the local clock's offset each time. The local clock's offset calculation is implemented according to the SNTP algorithm specified in RFC 2030.

The method getTime() can be used to generate timestamps (The typical accuracy of a SNTP client/server exchange is fractions of a second).

The System's time is never changed.

Uses Adam Buckley's class NtpMessage as message format.

Author:
Karl-Peter Fuchs
See Also:
NtpMessage

Field Summary
private static InternalInformationPortController internalInformationPort
          Reference on component InternalInformationPort.
private static long localClockOffset
          The local clock's offset (compared to the SNTP server) (accuracy: ~10ms).
private static java.util.logging.Logger LOGGER
          Logger used to log and display information.
private static java.net.InetAddress timeServerHost
          The SNTP server's address.
private static java.net.DatagramSocket timeServerSocket
          Datagram socket to communicate with SNTP server.
private static boolean useSynchronizedClock
          Indicates whether to synchronize clock (with SNTP server) or not.
 
Constructor Summary
NetworkClockController()
          Generates a new NetworkClock component which provides a clock, synchronized with a SNTP server.
 
Method Summary
 long getTime()
          Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT (The typical accuracy of a SNTP client/server exchange is fractions of a second.)
 void initialize()
          Initializes the this component.
private static void synchronizeClocks()
          Retrieves an SNTP message from a SNTP server and calculates the local clock's offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

internalInformationPort

private static InternalInformationPortController internalInformationPort
Reference on component InternalInformationPort. Used to display and/or log data and read general settings.


LOGGER

private static final java.util.logging.Logger LOGGER
Logger used to log and display information.


localClockOffset

private static long localClockOffset
The local clock's offset (compared to the SNTP server) (accuracy: ~10ms).


timeServerSocket

private static java.net.DatagramSocket timeServerSocket
Datagram socket to communicate with SNTP server.


timeServerHost

private static java.net.InetAddress timeServerHost
The SNTP server's address. A list of servers can be found here . Supports URLs and IPv4 Addresses.


useSynchronizedClock

private static boolean useSynchronizedClock
Indicates whether to synchronize clock (with SNTP server) or not.

Constructor Detail

NetworkClockController

public NetworkClockController()
Generates a new NetworkClock component which provides a clock, synchronized with a SNTP server.

Method Detail

initialize

public void initialize()
Initializes the this component.


synchronizeClocks

private static void synchronizeClocks()
Retrieves an SNTP message from a SNTP server and calculates the local clock's offset. The local clock's offset calculation is implemented according to the SNTP algorithm specified in RFC 2030.


getTime

public long getTime()
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT (The typical accuracy of a SNTP client/server exchange is fractions of a second.)

Specified by:
getTime in interface NetworkClockInterface
Returns:
The number of milliseconds since January 1, 1970, 00:00:00 GMT.