Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Commit c3b095b

Browse files
committed
patch version bump, readying for release.
1 parent 4237745 commit c3b095b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

rosjava/src/main/java/org/ros/time/NtpTimeProvider.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,27 @@ public NtpTimeProvider(InetAddress host, ScheduledExecutorService scheduledExecu
6363
this.scheduledExecutorService = scheduledExecutorService;
6464
wallTimeProvider = new WallTimeProvider();
6565
ntpClient = new NTPUDPClient();
66+
ntpClient.setDefaultTimeout(500); // timeout to 500ms
6667
offset = 0;
6768
scheduledFuture = null;
6869
}
6970

7071
/**
7172
* Update the current time offset from the configured NTP host.
7273
*
73-
* @throws IOException
74+
* @throws IOException : if ntpClient.getTime() fails too often.
7475
*/
7576
public void updateTime() throws IOException {
7677
List<Long> offsets = Lists.newArrayList();
78+
int failures = 0;
7779
for (int i = 0; i < SAMPLE_SIZE; i++) {
78-
offsets.add(computeOffset());
80+
try {
81+
offsets.add(computeOffset());
82+
} catch (IOException e) {
83+
if ( ++failures > SAMPLE_SIZE/2 ) {
84+
throw e;
85+
}
86+
}
7987
}
8088
offset = CollectionMath.median(offsets);
8189
log.info(String.format("NTP time offset: %d ms", offset));

rosjava/src/test/java/org/ros/time/NtpTimeProviderTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,14 @@ public void testNtpUbuntuCom() throws InterruptedException {
4545
nodeMainExecutor.execute(new AbstractNodeMain() {
4646
@Override
4747
public GraphName getDefaultNodeName() {
48-
return GraphName.of("node");
48+
return GraphName.of("ntp_time_provider");
4949
}
5050

5151
@Override
5252
public void onStart(ConnectedNode connectedNode) {
5353
try {
5454
ntpTimeProvider.updateTime();
5555
} catch (IOException e) {
56-
System.out.println("Dude");
5756
// Ignored. This is only a sanity check.
5857
}
5958
ntpTimeProvider.getCurrentTime();
@@ -62,6 +61,8 @@ public void onStart(ConnectedNode connectedNode) {
6261
latch.countDown();
6362
}
6463
}, nodeConfiguration);
65-
assertTrue(latch.await(1, TimeUnit.SECONDS));
64+
boolean result = latch.await(10, TimeUnit.SECONDS);
65+
//System.out.println("Latch waiting : " + latch.getCount() + " " + result + " [" + System.currentTimeMillis() + "]");
66+
assertTrue(result);
6667
}
6768
}

0 commit comments

Comments
 (0)