java.lang.Object
net.i2p.time.Timestamper
net.i2p.router.time.RouterTimestamper
- All Implemented Interfaces:
Runnable
Periodically query a series of NTP servers and update any associated listeners. It tries the NTP servers in order, contacting them using SNTP (UDP port 123).
Nested Class Summary
Nested classes/interfaces inherited from class Timestamper
Timestamper.UpdateListenerModifier and TypeClassDescriptionstatic interfaceInterface to receive update notifications for when we query the time Only used by Clock.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty key for how many SNTP servers are queried at once.static final StringProperty key that turns time synchronization off.static final StringProperty key holding the country of our last public IP address.static final StringProperty key for the milliseconds between time queries.static final StringProperty key naming the SNTP servers to query.Constructor Summary
ConstructorsConstructorDescriptionDoes not start.Does not start.RouterTimestamper(I2PAppContext ctx, Timestamper.UpdateListener lsnr, boolean daemon) Does not start.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidRegister a listener to be notified of time updates.booleanWhether NTP is disabled.getListener(int index) Time update listener at the given index.intNumber of registered time update listeners.intHow often to query the NTP servers, in ms.getServer(int index) NTP server at the given index in the configured list.intNumber of NTP servers in the configured list.voidUnregister a listener from time update notifications.voidrun()Run the main SNTP query loop, updating the time periodically.voidStart the SNTP query thread, unless disabled or already initialized.voidUpdate the time immediately.voidWait until the initial time synchronization completes, or the timeout is reached.
Field Details
PROP_QUERY_FREQUENCY
Property key for the milliseconds between time queries.- See Also:
PROP_SERVER_LIST
Property key naming the SNTP servers to query.- See Also:
PROP_DISABLED
Property key that turns time synchronization off.- See Also:
PROP_CONCURRING_SERVERS
Property key for how many SNTP servers are queried at once.- See Also:
PROP_IP_COUNTRY
Property key holding the country of our last public IP address.- See Also:
Constructor Details
RouterTimestamper
Does not start. Caller MUST call startTimestamper().- Parameters:
ctx- the application context used to read properties and locate the router
RouterTimestamper
Does not start. Caller MUST call startTimestamper().- Parameters:
ctx- the application context used to read properties and locate the routerlsnr- listener notified of each time update, or null to register none yet
RouterTimestamper
Does not start. Caller MUST call startTimestamper().- Parameters:
ctx- the application context used to read properties and locate the routerlsnr- listener notified of each time update, or null to register none yetdaemon- true to run the query thread as a daemon the JVM may abandon at shutdown
Method Details
getServerCount
public int getServerCount()Number of NTP servers in the configured list.- Returns:
- the server count
getServer
NTP server at the given index in the configured list.- Parameters:
index- zero-based position within the configured server list- Returns:
- the NTP server address at that position in the configured list
getQueryFrequencyMs
public int getQueryFrequencyMs()How often to query the NTP servers, in ms.- Returns:
- the query frequency ms
getIsDisabled
public boolean getIsDisabled()Whether NTP is disabled.- Returns:
- true when NTP is switched off at startup, either by configuration or because the VM comm system is in use
addListener
Register a listener to be notified of time updates.- Parameters:
lsnr- the listener to add; adding the same listener twice registers it once
removeListener
Unregister a listener from time update notifications.- Parameters:
lsnr- the listener to remove; absent listeners are ignored
getListenerCount
public int getListenerCount()Number of registered time update listeners.- Returns:
- the listener count
getListener
Time update listener at the given index.- Parameters:
index- zero-based position within the registered listener list- Returns:
- the registered time update listener at that position
startTimestamper
public void startTimestamper()Start the SNTP query thread, unless disabled or already initialized.waitForInitialization
public void waitForInitialization()Wait until the initial time synchronization completes, or the timeout is reached.- Overrides:
waitForInitializationin classTimestamper
timestampNow
run
public void run()Run the main SNTP query loop, updating the time periodically.- Specified by:
runin interfaceRunnable- Overrides:
runin classTimestamper