Package net.i2p.util
Class Clock
java.lang.Object
net.i2p.util.Clock
- All Implemented Interfaces:
Timestamper.UpdateListener
- Direct Known Subclasses:
RouterClock
Alternate location for determining the time which takes into account an offset.
This offset will ideally be periodically updated so as to serve as the difference
between the local computer's current time and the time as known by some reference
(such as an NTP synchronized clock).
Protected members are used in the subclass RouterClock,
which has access to a router's transports (particularly peer clock skews)
to second-guess the sanity of clock adjustments.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected final I2PAppContext
protected final boolean
protected long
protected long
protected boolean
static final long
after we've started up and shifted the clock, don't allow shifts of more than 10 minutesstatic final long
if the clock is skewed by 3+ days, forget itstatic final long
if the clock skewed changes by less than this, ignore the update (so we don't slide all over the place) -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
protected void
fireOffsetChanged
(long delta) static Clock
protected Log
getLog()
we fetch it on demand to avoid circular dependencies (logging uses the clock)long
This is a dummy, see RouterClock and RouterTimestamper for the real thingboolean
long
now()
Retrieve the current time synchronized with whatever reference clock is in use.void
void
setNow
(long realTime) void
setNow
(long realTime, int stratum) Warning - overridden in RouterClockvoid
setOffset
(long offsetMs) Specify how far away from the "correct" time the computer is - a positive value means that the system time is slow, while a negative value means the system time is fast.void
setOffset
(long offsetMs, boolean force) Specify how far away from the "correct" time the computer is - a positive value means that the system time is slow, while a negative value means the system time is fast.
-
Field Details
-
_context
-
_isSystemClockBad
protected final boolean _isSystemClockBad -
_startedOn
protected long _startedOn -
_statCreated
protected boolean _statCreated -
_offset
protected volatile long _offset -
_alreadyChanged
protected boolean _alreadyChanged -
MAX_OFFSET
public static final long MAX_OFFSETif the clock is skewed by 3+ days, forget it- See Also:
-
MAX_LIVE_OFFSET
public static final long MAX_LIVE_OFFSETafter we've started up and shifted the clock, don't allow shifts of more than 10 minutes- See Also:
-
MIN_OFFSET_CHANGE
public static final long MIN_OFFSET_CHANGEif the clock skewed changes by less than this, ignore the update (so we don't slide all over the place)- See Also:
-
-
Constructor Details
-
Clock
-
-
Method Details
-
getInstance
-
getTimestamper
This is a dummy, see RouterClock and RouterTimestamper for the real thing -
getLog
we fetch it on demand to avoid circular dependencies (logging uses the clock) -
setOffset
public void setOffset(long offsetMs) Specify how far away from the "correct" time the computer is - a positive value means that the system time is slow, while a negative value means the system time is fast.- Parameters:
offsetMs
- the delta from System.currentTimeMillis() (NOT the delta from now())
-
setOffset
public void setOffset(long offsetMs, boolean force) Specify how far away from the "correct" time the computer is - a positive value means that the system time is slow, while a negative value means the system time is fast. Warning - overridden in RouterClock- Parameters:
offsetMs
- the delta from System.currentTimeMillis() (NOT the delta from now())
-
getOffset
public long getOffset() -
getUpdatedSuccessfully
public boolean getUpdatedSuccessfully() -
setNow
public void setNow(long realTime) -
setNow
public void setNow(long realTime, int stratum) Warning - overridden in RouterClock- Specified by:
setNow
in interfaceTimestamper.UpdateListener
- Parameters:
stratum
- ignored- Since:
- 0.7.12
-
now
public long now()Retrieve the current time synchronized with whatever reference clock is in use. -
addUpdateListener
-
removeUpdateListener
-
fireOffsetChanged
protected void fireOffsetChanged(long delta)
-