mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-02 18:33:54 +00:00
clean up SwissTiming Event/Race/TrackedEvent/TrackedRace after stopping tracking it;
this may need to be adjusted once we add BoatClass support and hence group several races in one Event object
This commit is contained in:
1 parent
4c96d2e23c
commit
9699896de3
7 files changed
+51
-13
No files matched your search
+2
@@ -34,4 +34,6 @@ public interface DomainFactory {
|
||||
void updateCourseWaypoints(Course courseToUpdate, Iterable<Mark> marks) throws PatchFailedException;
|
||||
|
||||
MarkPassing createMarkPassing(String raceID, String boatID, Waypoint waypoint, TimePoint timePoint);
|
||||
|
||||
void removeRace(String raceID);
|
||||
}
|
||||
+30
-1
@@ -2,10 +2,12 @@ package com.sap.sailing.domain.swisstimingadapter.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sap.sailing.domain.base.Boat;
|
||||
import com.sap.sailing.domain.base.BoatClass;
|
||||
@@ -48,6 +50,14 @@ import difflib.DiffUtils;
|
||||
import difflib.Patch;
|
||||
import difflib.PatchFailedException;
|
||||
|
||||
/**
|
||||
* {@link RaceDefinition} objects created by this factory are created using the SwissTiming "Race ID"
|
||||
* as the {@link RaceDefinition#getName() race name}. This at the same time defines the name of the
|
||||
* single {@link Event} created per {@link RaceDefinition}.
|
||||
*
|
||||
* @author Axel Uhl (d043530)
|
||||
*
|
||||
*/
|
||||
public class DomainFactoryImpl implements DomainFactory {
|
||||
private final Map<String, Event> raceIDToEventCache;
|
||||
private final Map<String, Competitor> boatIDToCompetitorCache;
|
||||
@@ -111,7 +121,7 @@ public class DomainFactoryImpl implements DomainFactory {
|
||||
public RaceDefinition createRaceDefinition(Event event, Race race, StartList startList, Course course) {
|
||||
com.sap.sailing.domain.base.Course domainCourse = createCourse(race.getDescription(), course);
|
||||
Iterable<Competitor> competitors = createCompetitorList(startList);
|
||||
RaceDefinition result = new RaceDefinitionImpl(race.getDescription(), domainCourse,
|
||||
RaceDefinition result = new RaceDefinitionImpl(race.getRaceID(), domainCourse,
|
||||
getOrCreateBoatClassFromRaceID(race.getRaceID()), competitors);
|
||||
event.addRace(result);
|
||||
return result;
|
||||
@@ -227,4 +237,23 @@ public class DomainFactoryImpl implements DomainFactory {
|
||||
return new MarkPassingImpl(timePoint, waypoint, getCompetitorByBoatID(boatID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRace(String raceID) {
|
||||
Event event = getOrCreateEvent(raceID);
|
||||
Set<RaceDefinition> toRemove = new HashSet<RaceDefinition>();
|
||||
if (event != null) {
|
||||
for (RaceDefinition race : event.getAllRaces()) {
|
||||
if (race.getName().equals(raceID)) {
|
||||
toRemove.add(race);
|
||||
}
|
||||
}
|
||||
for (RaceDefinition raceToRemove : toRemove) {
|
||||
event.removeRace(raceToRemove);
|
||||
}
|
||||
if (Util.isEmpty(event.getAllRaces())) {
|
||||
raceIDToEventCache.remove(raceID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+3
-10
@@ -42,7 +42,6 @@ import com.sap.sailing.domain.tracking.MarkPassing;
|
||||
import com.sap.sailing.domain.tracking.RaceHandle;
|
||||
import com.sap.sailing.domain.tracking.RaceTracker;
|
||||
import com.sap.sailing.domain.tracking.TrackedEventRegistry;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
import com.sap.sailing.domain.tracking.WindStore;
|
||||
import com.sap.sailing.domain.tracking.WindTrack;
|
||||
import com.sap.sailing.util.Util;
|
||||
@@ -69,6 +68,7 @@ public class SwissTimingRaceTrackerImpl extends AbstractRaceTrackerImpl implemen
|
||||
protected SwissTimingRaceTrackerImpl(String raceID, String hostname, int port, WindStore windStore,
|
||||
DomainFactory domainFactory, SwissTimingFactory factory, RaceSpecificMessageLoader messageLoader,
|
||||
TrackedEventRegistry trackedEventRegistry, boolean canSendRequests) throws InterruptedException, UnknownHostException, IOException, ParseException {
|
||||
super(trackedEventRegistry);
|
||||
this.connector = factory.getOrCreateSailMasterConnector(hostname, port, messageLoader, canSendRequests);
|
||||
this.domainFactory = domainFactory;
|
||||
this.raceID = raceID;
|
||||
@@ -85,15 +85,8 @@ public class SwissTimingRaceTrackerImpl extends AbstractRaceTrackerImpl implemen
|
||||
@Override
|
||||
public void stop() throws MalformedURLException, IOException, InterruptedException {
|
||||
connector.removeSailMasterListener(raceID, this);
|
||||
Set<RaceDefinition> races = getRaces();
|
||||
if (races != null && !races.isEmpty()) {
|
||||
for (RaceDefinition race : races) {
|
||||
TrackedRace trackedRace = getTrackedEvent().getExistingTrackedRace(race);
|
||||
if (trackedRace != null) {
|
||||
getTrackedEvent().removedTrackedRace(trackedRace);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.stop();
|
||||
domainFactory.removeRace(raceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
@@ -95,6 +95,7 @@ public class TracTracRaceTrackerImpl extends AbstractRaceTrackerImpl implements
|
||||
protected TracTracRaceTrackerImpl(DomainFactory domainFactory, URL paramURL, URI liveURI, URI storedURI,
|
||||
WindStore windStore, TrackedEventRegistry trackedEventRegistry) throws URISyntaxException,
|
||||
MalformedURLException, FileNotFoundException {
|
||||
super(trackedEventRegistry);
|
||||
urls = new Triple<URL, URI, URI>(paramURL, liveURI, storedURI);
|
||||
this.races = new HashSet<RaceDefinition>();
|
||||
this.windStore = windStore;
|
||||
|
||||
+13
@@ -5,10 +5,20 @@ import java.net.MalformedURLException;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sap.sailing.domain.base.RaceDefinition;
|
||||
import com.sap.sailing.util.Util;
|
||||
|
||||
public abstract class AbstractRaceTrackerImpl implements RaceTracker {
|
||||
private DynamicTrackedEvent trackedEvent;
|
||||
|
||||
/**
|
||||
* Used during {@link #stop} to remove the {@link #trackedEvent} if it has no more tracked races
|
||||
*/
|
||||
private final TrackedEventRegistry trackedEventRegistry;
|
||||
|
||||
public AbstractRaceTrackerImpl(TrackedEventRegistry trackedEventRegistry) {
|
||||
this.trackedEventRegistry = trackedEventRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicTrackedEvent getTrackedEvent() {
|
||||
return trackedEvent;
|
||||
@@ -28,6 +38,9 @@ public abstract class AbstractRaceTrackerImpl implements RaceTracker {
|
||||
trackedEvent.removedTrackedRace(trackedRace);
|
||||
}
|
||||
}
|
||||
if (Util.isEmpty(trackedEvent.getTrackedRaces())) {
|
||||
trackedEventRegistry.remove(trackedEvent.getEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ public interface TrackedEventRegistry {
|
||||
* immediately. See also {@link #getOrCreateTrackedEvent(com.sap.sailing.domain.base.Event)}.
|
||||
*/
|
||||
DynamicTrackedEvent getTrackedEvent(com.sap.sailing.domain.base.Event event);
|
||||
|
||||
|
||||
void remove(Event event);
|
||||
|
||||
}
|
||||
@@ -473,7 +473,7 @@ public class RacingEventServiceImpl implements RacingEventService {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DynamicTrackedEvent getTrackedEvent(com.sap.sailing.domain.base.Event event) {
|
||||
return eventTrackingCache.get(event);
|
||||
|
||||
Reference in new issue
Block a user