working towards reducing the number of GetRaceMapData calls; however, this version is INCORRECT; see TODO comments

This commit is contained in:
Axel Uhl committed 2015-12-01 21:39:21 +01:00
1 parent cff08e107d
commit f62c09f821
3 files changed
+43 -19

No files matched your search

@@ -42,12 +42,10 @@ public class GetRaceMapDataAction implements AsyncAction<RaceMapDataDTO> {
for (Map.Entry<CompetitorDTO, Date> fromEntry : from.entrySet()) {
fromByCompetitorIdAsString.put(fromEntry.getKey().getIdAsString(), fromEntry.getValue());
}
Map<String, Date> toByCompetitorIdAsString = new HashMap<String, Date>();
for (Map.Entry<CompetitorDTO, Date> toEntry : to.entrySet()) {
toByCompetitorIdAsString.put(toEntry.getKey().getIdAsString(), toEntry.getValue());
}
sailingService.getRaceMapData(raceIdentifier, date, fromByCompetitorIdAsString, toByCompetitorIdAsString,
extrapolate, simulationLegIdentifier, new AsyncCallback<CompactRaceMapDataDTO>() {
@Override
@@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -178,18 +179,23 @@ public class FixesAndTails {
* overlap with those already known, the fixes are merged into the list of already known fixes for the competitor.
* Otherwise, the fixes received in <code>result</code> replace those known so far for the respective competitor.
* The {@link #tails} affected by these fixes are updated accordingly when modifications fall inside the interval
* shown by the tail, as defined by {@link #firstShownFix} and {@link #lastShownFix}. The tails are, however,
* not trimmed according to the specification for the tail length. This has to happen elsewhere (see also
* shown by the tail, as defined by {@link #firstShownFix} and {@link #lastShownFix}. The tails are, however, not
* trimmed according to the specification for the tail length. This has to happen elsewhere (see also
* {@link #updateTail}).
*
* @param fixesForCompetitors
* For each list the invariant must hold that an {@link GPSFixDTO#extrapolated extrapolated} fix must be
* the last one in the list
*
* @return the competitors for which new fixes have been added; this will not include competitors appearing as keys
* in <code>foxesForCompetitor</code> but with a <code>null</code> or empty fixes list
*/
protected void updateFixes(Map<CompetitorDTO, List<GPSFixDTO>> fixesForCompetitors,
protected Iterable<CompetitorDTO> updateFixes(Map<CompetitorDTO, List<GPSFixDTO>> fixesForCompetitors,
Map<CompetitorDTO, Boolean> overlapsWithKnownFixes, TailFactory tailFactory, long timeForPositionTransitionMillis) {
final Set<CompetitorDTO> competitorsWithNewFixes = new HashSet<>();
for (Map.Entry<CompetitorDTO, List<GPSFixDTO>> e : fixesForCompetitors.entrySet()) {
if (e.getValue() != null && !e.getValue().isEmpty()) {
competitorsWithNewFixes.add(e.getKey());
List<GPSFixDTO> fixesForCompetitor = fixes.get(e.getKey());
if (fixesForCompetitor == null) {
fixesForCompetitor = new ArrayList<GPSFixDTO>();
@@ -212,6 +218,7 @@ public class FixesAndTails {
}
}
}
return competitorsWithNewFixes;
}
/**
@@ -772,18 +772,25 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
// For those competitors for which the tails don't overlap (and therefore will be replaced by the new tail coming from the server)
// we expect some potential delay in computing the full tail. Therefore, in those cases we fire two requests: one fetching only the
// boat positions at newTime with zero tail length; and another one fetching everything else.
// TODO bug3378: two calls that both request simulation and mark data wastes bandwidth and CPU; one of them should only use getBoatPositions to request missing pieces of tails; showBoatsOnMap must not remove canvases / tails if one of the two calls delivers only partial results
GetRaceMapDataAction getRaceMapDataForAllOverlappingAndTipsOfNonOverlapping = getRaceMapDataForAllOverlappingAndTipsOfNonOverlapping(fromAndToAndOverlap, race, newTime);
final boolean updateMarksAndLinesExceptAdvantageLineInCallback;
if (getRaceMapDataForAllOverlappingAndTipsOfNonOverlapping != null) {
asyncActionsExecutor.execute(getRaceMapDataForAllOverlappingAndTipsOfNonOverlapping, GET_RACE_MAP_DATA_CATEGORY,
getRaceMapDataCallback(oldTime, newTime, fromAndToAndOverlap.getC(), competitorsToShow, requestID));
getRaceMapDataCallback(oldTime, newTime, fromAndToAndOverlap.getC(), competitorsToShow, requestID,
/* updateMarksAndLinesExceptAdvantageLineInCallback */ true));
updateMarksAndLinesExceptAdvantageLineInCallback = false; // don't do this again in the second call that mainly fetches
requestID = ++boatPositionRequestIDCounter;
} else {
updateMarksAndLinesExceptAdvantageLineInCallback = true;
}
// next, do the full thing; being the later call, if request throttling kicks in, the later call
// supersedes the earlier call which may get dropped then
GetRaceMapDataAction getRaceMapDataAction = new GetRaceMapDataAction(sailingService, competitorSelection.getAllCompetitors(), race,
useNullAsTimePoint() ? null : newTime, fromAndToAndOverlap.getA(), fromAndToAndOverlap.getB(), /* extrapolate */ true, (settings.isShowSimulationOverlay() ? simulationOverlay.getLegIdentifier() : null));
asyncActionsExecutor.execute(getRaceMapDataAction, GET_RACE_MAP_DATA_CATEGORY,
getRaceMapDataCallback(oldTime, newTime, fromAndToAndOverlap.getC(), competitorsToShow, requestID));
getRaceMapDataCallback(oldTime, newTime, fromAndToAndOverlap.getC(), competitorsToShow, requestID,
updateMarksAndLinesExceptAdvantageLineInCallback));
// draw the wind into the map, get the combined wind
List<String> windSourceTypeNames = new ArrayList<String>();
@@ -868,11 +875,18 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
return result;
}
/**
* @param updateMarksAndLinesExceptAdvantageLineInCallback
* when <code>true</code>, mark positions, mark-related lines such as start line and course middle lines,
* three hull length circles and side lines are drawn; otherwise, only the boats, their info flags and
* the advantage line will be updated.
*/
private AsyncCallback<RaceMapDataDTO> getRaceMapDataCallback(
final Date oldTime,
final Date newTime,
final Map<CompetitorDTO, Boolean> hasTailOverlapForCompetitor,
final Iterable<CompetitorDTO> competitorsToShow, final int requestID) {
final Iterable<CompetitorDTO> competitorsToShow, final int requestID,
final boolean updateMarksAndLinesExceptAdvantageLineInCallback) {
return new AsyncCallback<RaceMapDataDTO>() {
@Override
public void onFailure(Throwable caught) {
@@ -895,9 +909,15 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
// Do boat specific actions
Map<CompetitorDTO, List<GPSFixDTO>> boatData = raceMapDataDTO.boatPositions;
long timeForPositionTransitionMillis = calculateTimeForPositionTransition(newTime, oldTime);
fixesAndTails.updateFixes(boatData, hasTailOverlapForCompetitor, RaceMap.this, timeForPositionTransitionMillis);
showBoatsOnMap(newTime, timeForPositionTransitionMillis, getCompetitorsToShow());
showCompetitorInfoOnMap(newTime, timeForPositionTransitionMillis, competitorSelection.getSelectedFilteredCompetitors());
Iterable<CompetitorDTO> competitorsForWhichNewFixesWereReveiced =
fixesAndTails.updateFixes(boatData, hasTailOverlapForCompetitor, RaceMap.this, timeForPositionTransitionMillis);
if (!Util.isEmpty(competitorsForWhichNewFixesWereReveiced)) {
showBoatsOnMap(newTime, timeForPositionTransitionMillis, competitorsForWhichNewFixesWereReveiced);
showCompetitorInfoOnMap(newTime, timeForPositionTransitionMillis, competitorSelection.getSelectedFilteredCompetitors());
// even though the wind data is retrieved by a separate call, re-draw the advantage line because it needs to
// adjust to new boat positions
showAdvantageLine(competitorsToShow, newTime);
}
if (douglasMarkers != null) {
removeAllMarkDouglasPeuckerpoints();
}
@@ -905,17 +925,16 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
removeAllManeuverMarkers();
}
// Do mark specific actions
showCourseMarksOnMap(raceMapDataDTO.coursePositions);
if (requiresCoordinateSystemUpdateWhenCoursePositionAndWindDirectionIsKnown) {
updateCoordinateSystemFromSettings();
}
showCourseSidelinesOnMap(raceMapDataDTO.courseSidelines);
showStartAndFinishAndCourseMiddleLines(raceMapDataDTO.coursePositions);
showStartLineToFirstMarkTriangle(raceMapDataDTO.coursePositions);
// even though the wind data is retrieved by a separate call, re-draw the advantage line because it needs to
// adjust to new boat positions
showAdvantageLine(competitorsToShow, newTime);
if (updateMarksAndLinesExceptAdvantageLineInCallback) {
// Do mark specific actions
showCourseMarksOnMap(raceMapDataDTO.coursePositions);
showCourseSidelinesOnMap(raceMapDataDTO.courseSidelines);
showStartAndFinishAndCourseMiddleLines(raceMapDataDTO.coursePositions);
showStartLineToFirstMarkTriangle(raceMapDataDTO.coursePositions);
}
// Rezoom the map
LatLngBounds zoomToBounds = null;