public class Clock extends Object implements Timestamper.UpdateListener
Modifier and Type | Class and Description |
---|---|
static interface |
Clock.ClockUpdateListener |
Modifier and Type | Field and Description |
---|---|
protected boolean |
_alreadyChanged |
protected I2PAppContext |
_context |
protected boolean |
_isSystemClockBad |
protected long |
_offset |
protected long |
_startedOn |
protected boolean |
_statCreated |
static long |
MAX_LIVE_OFFSET
after we've started up and shifted the clock, don't allow shifts of more than 10 minutes
|
static long |
MAX_OFFSET
if the clock is skewed by 3+ days, forget it
|
static long |
MIN_OFFSET_CHANGE
if the clock skewed changes by less than this, ignore the update (so we don't slide all over the place)
|
Constructor and Description |
---|
Clock(I2PAppContext context) |
Modifier and Type | Method and Description |
---|---|
void |
addUpdateListener(Clock.ClockUpdateListener lsnr) |
protected void |
fireOffsetChanged(long delta) |
static Clock |
getInstance() |
protected Log |
getLog()
we fetch it on demand to avoid circular dependencies (logging uses the clock)
|
long |
getOffset() |
Timestamper |
getTimestamper()
This is a dummy, see RouterClock and RouterTimestamper for the real thing
|
boolean |
getUpdatedSuccessfully() |
long |
now()
Retrieve the current time synchronized with whatever reference clock is in
use.
|
void |
removeUpdateListener(Clock.ClockUpdateListener lsnr) |
void |
setNow(long realTime) |
void |
setNow(long realTime,
int stratum)
Warning - overridden in RouterClock
|
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.
|
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.
|
protected final I2PAppContext _context
protected final boolean _isSystemClockBad
protected long _startedOn
protected boolean _statCreated
protected volatile long _offset
protected boolean _alreadyChanged
public static final long MAX_OFFSET
public static final long MAX_LIVE_OFFSET
public static final long MIN_OFFSET_CHANGE
public Clock(I2PAppContext context)
public static Clock getInstance()
public Timestamper getTimestamper()
protected Log getLog()
public void setOffset(long offsetMs)
offsetMs
- the delta from System.currentTimeMillis() (NOT the delta from now())public void setOffset(long offsetMs, boolean force)
offsetMs
- the delta from System.currentTimeMillis() (NOT the delta from now())public long getOffset()
public boolean getUpdatedSuccessfully()
public void setNow(long realTime)
public void setNow(long realTime, int stratum)
setNow
in interface Timestamper.UpdateListener
stratum
- ignoredpublic long now()
public void addUpdateListener(Clock.ClockUpdateListener lsnr)
public void removeUpdateListener(Clock.ClockUpdateListener lsnr)
protected void fireOffsetChanged(long delta)