Skip to content

Commit

Permalink
A crude attempt. To iterate upon in the future.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffplourde committed Apr 21, 2015
1 parent 236c978 commit 44b052c
Showing 1 changed file with 23 additions and 0 deletions.
Expand Up @@ -2,8 +2,12 @@

import ice.*;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -44,6 +48,7 @@
import com.rti.dds.subscription.ViewStateKind;
import com.rti.dds.topic.ContentFilteredTopic;
import com.rti.dds.topic.Topic;

import org.springframework.jmx.export.annotation.ManagedResource;

@ManagedResource(description="TimeManager Controller")
Expand Down Expand Up @@ -287,6 +292,7 @@ private static final void subtract(Duration_t d1, Duration_t d2) {
private static final long HEARTBEAT_INTERVAL = 2000L;

protected void processAliveHeartbeat(final String unique_device_identifier, final String type, String host_name) {

log.trace("ALIVE:{}",unique_device_identifier);
for(TimeManagerListener listener : listeners) {
listener.aliveHeartbeat(unique_device_identifier, type, host_name);
Expand All @@ -305,6 +311,8 @@ protected void processSynchronization(String remote_udi, Duration_t latency, Dur
listener.synchronization(remote_udi, latency, clockDifference);
}
}

private DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

private final ConditionHandler hbReadHandler = new ConditionHandler() {
private final ice.HeartBeatSeq hb_seq = new ice.HeartBeatSeq();
Expand Down Expand Up @@ -363,6 +371,21 @@ public void conditionChanged(Condition condition) {
log.warn("Unable to get participant information for HeartBeat publication");
}
}

if(null != df && System.currentTimeMillis() < 31536000000L) {
// one time attempt to set the system clock
String dt = df.format(new Date(sampleInfo.source_timestamp.sec * 1000L + sampleInfo.source_timestamp.nanosec / 1000000L));
try {
log.warn("Attempting date --set " + dt);
// This may or may not work, in any event we only try once
Runtime.getRuntime().exec(new String[]{"sudo", "date","--set",dt});
} catch (IOException e) {
log.error("Error invoking 'date'", e);
}
df = null;
}


processAliveHeartbeat(heartbeat.unique_device_identifier, heartbeat.type, host_name);
if(null != tsWriter && sampleInfo.valid_data) {
if(holder == null) {
Expand Down

0 comments on commit 44b052c

Please sign in to comment.