diff --git a/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/AbstractReceiverWithQueue.java b/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/AbstractReceiverWithQueue.java index b812ae685fb..c19abc3ef40 100755 --- a/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/AbstractReceiverWithQueue.java +++ b/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/AbstractReceiverWithQueue.java @@ -121,6 +121,9 @@ public abstract class AbstractReceiverWithQueue implements Runnable, Re e.printStackTrace(); } } + if (simulator != null) { + simulator.stop(); + } } @Override diff --git a/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/Simulator.java b/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/Simulator.java index 4eb4bd0cc7b..d451fa4273b 100755 --- a/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/Simulator.java +++ b/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/Simulator.java @@ -32,6 +32,7 @@ public class Simulator { private WindStore windStore; private long advanceInMillis = -1; private Timer timer = new Timer("Timer for TracTrac Simulator"); + private boolean stopped; /** * Creates a wind store which replays the wind store events against a tracked race, correcting the wind fixes with @@ -70,6 +71,9 @@ public class Simulator { @Override public void run() { for (Wind wind : windSourceAndTrack.getValue().getRawFixes()) { + if (stopped) { + break; + } trackedRace.recordWind(delayWind(wind), windSourceAndTrack.getKey()); } } @@ -77,6 +81,10 @@ public class Simulator { } } + public void stop() { + stopped = true; + } + private Wind delayWind(Wind wind) { TimePoint delayedTimePoint = delay(wind.getTimePoint()); return new WindImpl(wind.getPosition(), delayedTimePoint, new KnotSpeedWithBearingImpl(wind.getKnots(), wind.getBearing())); diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java index 9450cc7245b..01e64bcf222 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java @@ -329,7 +329,9 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener { } protected void invalidateMarkPassingTimes() { - markPassingsTimes.clear(); + synchronized (markPassingsTimes) { + markPassingsTimes.clear(); + } } /** @@ -481,45 +483,49 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener { @Override public Iterable>> getMarkPassingsTimes() { - if (markPassingsTimes.isEmpty()) { - int wayPointNumber = 1; - // Remark: sometimes it can happen that a mark passing with a wrong time stamp breaks the right time order - // of the waypoint times - Date previousLegPassingTime = null; - for (Waypoint waypoint : getRace().getCourse().getWaypoints()) { - TimePoint firstPassingTime = null; - TimePoint lastPassingTime = null; - if (wayPointNumber == 1) { - // For the first leg the use of "firstPassingDate" is not correct, - // because boats can pass the start line before the actual start; - // therefore we are using the calculated start time here - firstPassingTime = getStartOfRace(); - } else { - NavigableSet markPassings = getMarkPassingsInOrderAsNavigableSet(waypoint); - if (markPassings != null && !markPassings.isEmpty()) { - // ensure the leg times are in the right time order; there may perhaps be left-overs for marks to be - // reached later that - // claim it has been passed in the past which may have been an accidental tracker read-out; - // the results of getMarkPassingsInOrder(to) has by definition an ascending time-point ordering - synchronized (markPassings) { - for (MarkPassing currentMarkPassing : markPassings) { - Date currentPassingDate = currentMarkPassing.getTimePoint().asDate(); - if (previousLegPassingTime == null || currentPassingDate.after(previousLegPassingTime)) { - firstPassingTime = currentMarkPassing.getTimePoint(); - previousLegPassingTime = currentPassingDate; - break; + synchronized (markPassingsTimes) { + if (markPassingsTimes.isEmpty()) { + int wayPointNumber = 1; + // Remark: sometimes it can happen that a mark passing with a wrong time stamp breaks the right time + // order of the waypoint times + Date previousLegPassingTime = null; + for (Waypoint waypoint : getRace().getCourse().getWaypoints()) { + TimePoint firstPassingTime = null; + TimePoint lastPassingTime = null; + if (wayPointNumber == 1) { + // For the first leg the use of "firstPassingDate" is not correct, + // because boats can pass the start line before the actual start; + // therefore we are using the calculated start time here + firstPassingTime = getStartOfRace(); + } else { + NavigableSet markPassings = getMarkPassingsInOrderAsNavigableSet(waypoint); + if (markPassings != null && !markPassings.isEmpty()) { + // ensure the leg times are in the right time order; there may perhaps be left-overs for + // marks to be reached later that + // claim it has been passed in the past which may have been an accidental tracker read-out; + // the results of getMarkPassingsInOrder(to) has by definition an ascending time-point + // ordering + synchronized (markPassings) { + for (MarkPassing currentMarkPassing : markPassings) { + Date currentPassingDate = currentMarkPassing.getTimePoint().asDate(); + if (previousLegPassingTime == null + || currentPassingDate.after(previousLegPassingTime)) { + firstPassingTime = currentMarkPassing.getTimePoint(); + previousLegPassingTime = currentPassingDate; + break; + } } } } } + Pair timesPair = new Pair(firstPassingTime, + lastPassingTime); + markPassingsTimes.add(new Pair>(waypoint, timesPair)); + wayPointNumber++; } - Pair timesPair = new Pair(firstPassingTime, lastPassingTime); - markPassingsTimes.add(new Pair>(waypoint, timesPair)); - wayPointNumber++; } + return markPassingsTimes; } - - return markPassingsTimes; } @Override