Package org.ros.time
Class NtpTimeProvider
java.lang.Object
org.ros.time.NtpTimeProvider
- All Implemented Interfaces:
TimeProvider
Provides NTP synchronized wallclock (actual) time.
- Author:
- damonkohler@google.com (Damon Kohler)
-
Constructor Summary
ConstructorsConstructorDescriptionNtpTimeProvider(InetAddress host, ScheduledExecutorService scheduledExecutorService) -
Method Summary
Modifier and TypeMethodDescriptionorg.ros.message.TimevoidsetUpdateTimeSampleSize(int sampleSize) Sets how many samples will be taken from the NTP server when callingupdateTime().voidstartPeriodicUpdates(long period, TimeUnit unit) Starts periodically updating the current time offset periodically.voidStops periodically updating the current time offset.voidUpdate the current time offset from the configured NTP host.
-
Constructor Details
-
NtpTimeProvider
- Parameters:
host- the NTP host to use
-
-
Method Details
-
updateTime
Update the current time offset from the configured NTP host.- Throws:
IOException- : if ntpClient.getTime() fails too often.
-
startPeriodicUpdates
Starts periodically updating the current time offset periodically.The first time update happens immediately.
Note that errors thrown while periodically updating time will be logged but not rethrown.
- Parameters:
period- time between updatesunit- unit of period
-
stopPeriodicUpdates
public void stopPeriodicUpdates()Stops periodically updating the current time offset. -
getCurrentTime
public org.ros.message.Time getCurrentTime()- Specified by:
getCurrentTimein interfaceTimeProvider- Returns:
- the current time of the system using rostime
-
setUpdateTimeSampleSize
public void setUpdateTimeSampleSize(int sampleSize) Sets how many samples will be taken from the NTP server when callingupdateTime().- Parameters:
sampleSize- Number of samples to take. It has to be > 0.
-