Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Rosjava Core Gradle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CeTI
ROS
ROS Java Packages
Rosjava Core Gradle
Commits
deaeafa7
Commit
deaeafa7
authored
8 years ago
by
Julian Cerruti
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #244 from jubeira/fix/ntp_provider_logging
Avoid flooding log with error messages on NTP sync failure
parents
c746aed1
8c895e48
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
rosjava/src/main/java/org/ros/time/NtpTimeProvider.java
+17
-5
17 additions, 5 deletions
rosjava/src/main/java/org/ros/time/NtpTimeProvider.java
with
17 additions
and
5 deletions
rosjava/src/main/java/org/ros/time/NtpTimeProvider.java
+
17
−
5
View file @
deaeafa7
...
...
@@ -44,7 +44,7 @@ public class NtpTimeProvider implements TimeProvider {
private
static
final
boolean
DEBUG
=
false
;
private
static
final
Log
log
=
LogFactory
.
getLog
(
NtpTimeProvider
.
class
);
private
static
final
int
SAMPLE_SIZE
=
11
;
private
int
sampleSize
=
11
;
private
final
InetAddress
host
;
private
final
ScheduledExecutorService
scheduledExecutorService
;
...
...
@@ -76,11 +76,11 @@ public class NtpTimeProvider implements TimeProvider {
public
void
updateTime
()
throws
IOException
{
List
<
Long
>
offsets
=
Lists
.
newArrayList
();
int
failures
=
0
;
for
(
int
i
=
0
;
i
<
SAMPLE_SIZE
;
i
++)
{
for
(
int
i
=
0
;
i
<
sampleSize
;
i
++)
{
try
{
offsets
.
add
(
computeOffset
());
}
catch
(
IOException
e
)
{
if
(
++
failures
>
SAMPLE_SIZE
/
2
)
{
if
(++
failures
>
sampleSize
/
2
)
{
throw
e
;
}
}
...
...
@@ -97,7 +97,9 @@ public class NtpTimeProvider implements TimeProvider {
try
{
time
=
ntpClient
.
getTime
(
host
);
}
catch
(
IOException
e
)
{
if
(
DEBUG
)
{
log
.
error
(
"Failed to read time from NTP server: "
+
host
.
getHostName
(),
e
);
}
throw
e
;
}
time
.
computeDetails
();
...
...
@@ -147,4 +149,14 @@ public class NtpTimeProvider implements TimeProvider {
Time
currentTime
=
wallTimeProvider
.
getCurrentTime
();
return
currentTime
.
add
(
Duration
.
fromMillis
(
offset
));
}
/**
* Sets how many samples will be taken from the NTP server
* when calling {@link #updateTime()}.
* @param sampleSize Number of samples to take. It has to be > 0.
*/
public
void
setUpdateTimeSampleSize
(
int
sampleSize
)
{
Preconditions
.
checkArgument
(
sampleSize
>
0
);
this
.
sampleSize
=
sampleSize
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment