mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-10 22:30:56 +00:00
added more synchronization to keep race stable as sorting for ranks is going on
This commit is contained in:
1 parent
a00ed444ad
commit
81bc0159e3
4 files changed
+21
-14
No files matched your search
+3
-4
@@ -47,7 +47,7 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordFix(Competitor competitor, GPSFixMoving fix) {
|
||||
public synchronized void recordFix(Competitor competitor, GPSFixMoving fix) {
|
||||
DynamicTrack<Competitor, GPSFixMoving> track = getTrack(competitor);
|
||||
track.addGPSFix(fix); // the track notifies this tracked race which in turn notifies its listeners
|
||||
if (getStart() == null || getStart().compareTo(fix.getTimePoint())>0) {
|
||||
@@ -205,13 +205,13 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordWind(Wind wind, WindSource windSource) {
|
||||
public synchronized void recordWind(Wind wind, WindSource windSource) {
|
||||
getWindTrack(windSource).add(wind);
|
||||
updated(wind.getTimePoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeWind(Wind wind, WindSource windSource) {
|
||||
public synchronized void removeWind(Wind wind, WindSource windSource) {
|
||||
getWindTrack(windSource).remove(wind);
|
||||
updated(wind.getTimePoint());
|
||||
}
|
||||
@@ -234,7 +234,6 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
|
||||
@Override
|
||||
public void markPassingReceived(MarkPassing markPassing) {
|
||||
notifyListeners(markPassing);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-7
@@ -89,13 +89,16 @@ public class TrackedLegImpl implements TrackedLeg, RaceChangeListener<Competitor
|
||||
for (TrackedLegOfCompetitor competitorLeg : getTrackedLegsOfCompetitors()) {
|
||||
rankedCompetitorList.add(competitorLeg);
|
||||
}
|
||||
Collections.sort(rankedCompetitorList, new WindwardToGoComparator(this, timePoint));
|
||||
rankedCompetitorList = Collections.unmodifiableList(rankedCompetitorList);
|
||||
competitorTracksOrderedByRank.put(timePoint, rankedCompetitorList);
|
||||
if (Util.size(getTrackedLegsOfCompetitors()) != rankedCompetitorList.size()) {
|
||||
logger.warning("Number of competitors in leg (" + Util.size(getTrackedLegsOfCompetitors())
|
||||
+ ") differs from number of competitors in race ("
|
||||
+ Util.size(getTrackedRace().getRace().getCompetitors()) + ")");
|
||||
// ensure that race isn't updated by events as we're tying to sort the competitors
|
||||
synchronized (getTrackedRace()) {
|
||||
Collections.sort(rankedCompetitorList, new WindwardToGoComparator(this, timePoint));
|
||||
rankedCompetitorList = Collections.unmodifiableList(rankedCompetitorList);
|
||||
competitorTracksOrderedByRank.put(timePoint, rankedCompetitorList);
|
||||
if (Util.size(getTrackedLegsOfCompetitors()) != rankedCompetitorList.size()) {
|
||||
logger.warning("Number of competitors in leg (" + Util.size(getTrackedLegsOfCompetitors())
|
||||
+ ") differs from number of competitors in race ("
|
||||
+ Util.size(getTrackedRace().getRace().getCompetitors()) + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
return rankedCompetitorList;
|
||||
|
||||
+2
-2
@@ -254,12 +254,12 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRank(Competitor competitor) throws NoWindException {
|
||||
public synchronized int getRank(Competitor competitor) throws NoWindException {
|
||||
return getRank(competitor, MillisecondsTimePoint.now());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRank(Competitor competitor, TimePoint timePoint) throws NoWindException {
|
||||
public synchronized int getRank(Competitor competitor, TimePoint timePoint) throws NoWindException {
|
||||
try {
|
||||
synchronized (competitorRankings) {
|
||||
List<Competitor> rankedCompetitors = competitorRankings.get(timePoint);
|
||||
|
||||
Reference in new issue
Block a user