Holger's
Java API

com.antelmann.calendar
Class NTPTime

java.lang.Object
  extended by com.antelmann.calendar.NTPTime
All Implemented Interfaces:
TimeSystem

public class NTPTime
extends Object
implements TimeSystem

works based on a NTPClient instance adding reliability by using multiple servers if one fails.

Author:
Holger Antelmann
See Also:
NTPClient

Field Summary
 
Fields inherited from interface com.antelmann.calendar.TimeSystem
SYSTEM_TIME
 
Constructor Summary
NTPTime()
          immediately activates the instance and schedules updates in the interval given.
NTPTime(boolean activateNow)
          Interval is 12h.
NTPTime(boolean activateNow, long updateIntervalMillis)
          immediately activates the instance and schedules updates in the interval given.
NTPTime(boolean activateNow, long updateIntervalMillis, Logger logger)
           
NTPTime(boolean activateNow, long updateIntervalMillis, NTPClient client)
           
NTPTime(boolean activateNow, long updateIntervalMillis, NTPClient client, Logger logger)
           
 
Method Summary
 void activate()
          activates the embedded timer for automatic updates
 boolean addServer(String server)
           
 long currentTimeMillis()
          returns the current time
 void deactivate()
          deactivates the embedded timer for automatic updates
protected  void finalize()
           
 Logger getLogger()
           
 NTPClient getNtpClient()
          returns the clock in use
 String[] getServerNames()
           
 long getUpdateIntervalMillis()
           
 boolean isActivated()
           
 boolean removeServer(String server)
           
 void setUpdateIntervalMillis(long updateIntervalMillis)
          must be called while the instance is deactivated.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NTPTime

public NTPTime()
immediately activates the instance and schedules updates in the interval given. Interval is 24h.


NTPTime

public NTPTime(boolean activateNow)
Interval is 12h.


NTPTime

public NTPTime(boolean activateNow,
               long updateIntervalMillis)
        throws IllegalArgumentException
immediately activates the instance and schedules updates in the interval given.

Parameters:
updateIntervalMillis - must represent more than a minute
Throws:
IllegalArgumentException - if the interval represents less than a minute

NTPTime

public NTPTime(boolean activateNow,
               long updateIntervalMillis,
               Logger logger)
        throws IllegalArgumentException
Throws:
IllegalArgumentException

NTPTime

public NTPTime(boolean activateNow,
               long updateIntervalMillis,
               NTPClient client)
        throws IllegalArgumentException
Throws:
IllegalArgumentException

NTPTime

public NTPTime(boolean activateNow,
               long updateIntervalMillis,
               NTPClient client,
               Logger logger)
        throws IllegalArgumentException
Parameters:
activateNow - if true, the instance is immediately activated
updateIntervalMillis - must represent more than a minute
client - the NTPClient that is to be used with this instance
logger - used to log the scheduled delta updates for the ntp clock
Throws:
IllegalArgumentException - if the interval represents less than 5 minutes
Method Detail

isActivated

public boolean isActivated()

getUpdateIntervalMillis

public long getUpdateIntervalMillis()

setUpdateIntervalMillis

public void setUpdateIntervalMillis(long updateIntervalMillis)
                             throws IllegalStateException,
                                    IllegalArgumentException
must be called while the instance is deactivated.

Throws:
IllegalStateException - if this instance is currently activated
IllegalArgumentException - if the interval represents less than 5 minutes
See Also:
isActivated()

activate

public void activate()
activates the embedded timer for automatic updates


deactivate

public void deactivate()
deactivates the embedded timer for automatic updates


finalize

protected void finalize()
Overrides:
finalize in class Object

currentTimeMillis

public long currentTimeMillis()
returns the current time

Specified by:
currentTimeMillis in interface TimeSystem
Returns:
the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

getNtpClient

public NTPClient getNtpClient()
returns the clock in use


getLogger

public Logger getLogger()

getServerNames

public String[] getServerNames()

addServer

public boolean addServer(String server)

removeServer

public boolean removeServer(String server)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads