Holger's Java API

## com.antelmann.calendar
Class AbstractTimeSystem

    java.lang.Object
      com.antelmann.calendar.AbstractTimeSystem

All Implemented Interfaces:
  TimeSystem

Direct Known Subclasses:
  NTPClient

    public abstract class AbstractTimeSystem

extends Object
implements TimeSystem

the basis for a custom TimeSystem based on an offset value (delta) relative to the system time.

Author:
  Holger Antelmann

Field Summary

Fields inherited from interface com.antelmann.calendar.TimeSystem
`SYSTEM_TIME`

Constructor Summary
`AbstractTimeSystem()`

Method Summary
`long` `adjustDelta()` adjusts the delta value used for `getTime()` through using the server time
`long` `adjustedTimeMills()`
`protected abstract long` `aquireDelta()` returns the current difference between system time and the time of this implementation in milliseconds.
`TimerTask` `createTimerTask(Logger logger)` creates a TimerTask that will adjust the delta and log the result to the given logger.
`long` `currentTimeMillis()` returns the system time adjusted by the delta value.
`long` `getDelta()` returns the stored difference between system time and atomic time in milliseconds.
`long` `getLastDeltaAdjustmentTime()` returns the system time when `adjustDelta()` has been successfully called last time.
`long` `getLastRoundTripDelay()` returns the time of the time it took to adjust the delta the last time the adjustment was made.
`protected void` `setDelta(long delta)` manually sets the value used to adjust system time
`void` `setLastRoundTripDelay(long lastRoundTripDelay)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### AbstractTimeSystem

    public AbstractTimeSystem()

Method Detail

### currentTimeMillis

    public long currentTimeMillis()

  returns the system time adjusted by the delta value. This is generally the proper method to be called by the application.

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

### adjustedTimeMills

    public long adjustedTimeMills()
                           throws IOException

  Throws:
    `IOException`

### aquireDelta

    protected abstract long aquireDelta()
                                 throws IOException

  returns the current difference between system time and the time of this implementation in milliseconds. A negative number indicates that the system clock is behind. Calling this method does not affect the delta value of this instance.

  Throws:
    `IOException`
  See Also:
    `adjustDelta()`

### getDelta

    public long getDelta()

  returns the stored difference between system time and atomic time in milliseconds. A negative number indicates that the system clock is behind.

  See Also:
    `adjustDelta()`, `setDelta(long)`

### setDelta

    protected void setDelta(long delta)

  manually sets the value used to adjust system time

  See Also:
    `adjustDelta()`

### getLastDeltaAdjustmentTime

    public long getLastDeltaAdjustmentTime()

  returns the system time when `adjustDelta()` has been successfully called last time. If no successful adjustment has taken place, yet, the method returns 0.

  See Also:
    `adjustDelta()`

### getLastRoundTripDelay

    public long getLastRoundTripDelay()

  returns the time of the time it took to adjust the delta the last time the adjustment was made. If no successful adjustment has taken place, yet, the method returns -1.

### setLastRoundTripDelay

    public void setLastRoundTripDelay(long lastRoundTripDelay)

### adjustDelta

    public long adjustDelta()
                     throws IOException

  adjusts the delta value used for `getTime()` through using the server time

  Throws:
    `IOException`
  See Also:
    `currentTimeMillis()`, `getDelta()`, `setDelta(long)`, `getLastDeltaAdjustmentTime()`, `getLastRoundTripDelay()`

### createTimerTask

    public TimerTask createTimerTask(Logger logger)

  creates a TimerTask that will adjust the delta and log the result to the given logger. The logger may be null.

  See Also:
    `adjustDelta()`, `Timer`

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