Package net.i2p.router
Class RouterClock
java.lang.Object
net.i2p.util.Clock
net.i2p.router.RouterClock
- All Implemented Interfaces:
Timestamper.UpdateListener
public class RouterClock extends Clock
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).
RouterClock is a subclass of Clock with access to router transports.
Configuration permitting, it will block clock offset changes
which would increase peer clock skew.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RouterClock.ClockShiftListener
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_STRATUM
Fields inherited from class net.i2p.util.Clock
_alreadyChanged, _context, _isSystemClockBad, _offset, _startedOn, _statCreated, MAX_LIVE_OFFSET, MAX_OFFSET, MIN_OFFSET_CHANGE
-
Constructor Summary
Constructors Constructor Description RouterClock(RouterContext context)
Does not start. -
Method Summary
Modifier and Type Method Description void
addShiftListener(RouterClock.ClockShiftListener lsnr)
long
getDeltaOffset()
Deprecated.Timestamper
getTimestamper()
The RouterTimestamperlong
now()
Retrieve the current time synchronized with whatever reference clock is in use.void
removeShiftListener(RouterClock.ClockShiftListener lsnr)
void
setNow(long realTime, int stratum)
Warning - overridden in RouterClockvoid
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.void
start()
Cannot be stopped, but RouterTimestamper registers a shutdown task.Methods inherited from class net.i2p.util.Clock
addUpdateListener, fireOffsetChanged, getInstance, getLog, getOffset, getUpdatedSuccessfully, removeUpdateListener, setNow, setOffset
-
Field Details
-
DEFAULT_STRATUM
public static final int DEFAULT_STRATUM- See Also:
- Constant Field Values
-
-
Constructor Details
-
RouterClock
Does not start. Caller MUST call start()
-
-
Method Details
-
start
public void start()Cannot be stopped, but RouterTimestamper registers a shutdown task.- Since:
- 0.9.20
-
getTimestamper
The RouterTimestamper- Overrides:
getTimestamper
in classClock
-
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. -
setNow
public void setNow(long realTime, int stratum)Description copied from class:Clock
Warning - overridden in RouterClock- Specified by:
setNow
in interfaceTimestamper.UpdateListener
- Overrides:
setNow
in classClock
- Parameters:
stratum
- used to determine whether we should ignore- Since:
- 0.7.12
-
now
public long now()Retrieve the current time synchronized with whatever reference clock is in use. Do really simple clock slewing, like NTP but without jitter prevention. Slew the clock toward the desired offset, but only up to a maximum slew rate, and never let the clock go backwards because of slewing. Take care to only access the volatile variables once for speed and to avoid having another thread change them This is called about a zillion times a second, so we can do the slewing right here rather than in some separate thread to keep it simple. Avoiding backwards clocks when updating in a thread would be hard too. -
addShiftListener
-
removeShiftListener
-
getDeltaOffset
Deprecated.
-