mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-26 23:46:36 +00:00
refactored adding a race tracker in RacingEventService
This commit is contained in:
+7
-9
@@ -9,7 +9,6 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -100,7 +99,7 @@ public class EndToEndListeningStoreAndFowardTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndToEndScenarioWithInitMessages() throws IOException, InterruptedException, ParseException {
|
||||
public void testEndToEndScenarioWithInitMessages() throws Exception {
|
||||
String[] racesToTrack = new String[] { "4711", "4712" };
|
||||
String scriptName = "/InitMessagesScript.txt";
|
||||
setUpUsingScript(racesToTrack, scriptName);
|
||||
@@ -128,7 +127,7 @@ public class EndToEndListeningStoreAndFowardTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongRaceLog() throws IOException, InterruptedException, ParseException {
|
||||
public void testLongRaceLog() throws Exception {
|
||||
String[] racesToTrack = new String[] { "W4702" };
|
||||
String scriptName1 = "/SailMasterDataInterfaceRACandSTL.txt";
|
||||
String scriptName2 = "/SailMasterDataInterface-ExampleAsText.txt";
|
||||
@@ -180,7 +179,7 @@ public class EndToEndListeningStoreAndFowardTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongLogRaceNewConfig() throws UnknownHostException, InterruptedException, IOException, ParseException {
|
||||
public void testLongLogRaceNewConfig() throws Exception {
|
||||
String[] racesToTrack = new String[] { "W4702" };
|
||||
String scriptName1 = "/SailMasterDataInterfaceRACandSTL.txt";
|
||||
String scriptName2 = "/SailMasterDataInterface-ExampleAsText.txt";
|
||||
@@ -232,7 +231,7 @@ public class EndToEndListeningStoreAndFowardTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateCCGMessageAndWaypointUniqueness() throws IOException, InterruptedException, ParseException {
|
||||
public void testDuplicateCCGMessageAndWaypointUniqueness() throws Exception {
|
||||
String[] racesToTrack = new String[] { "W4702" };
|
||||
setUpUsingScript(racesToTrack, "/DuplicateCCG.txt");
|
||||
|
||||
@@ -255,7 +254,7 @@ public class EndToEndListeningStoreAndFowardTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRongRaceLogRACZero() throws UnknownHostException, InterruptedException, IOException, ParseException{
|
||||
public void testRongRaceLogRACZero() throws Exception{
|
||||
String[] racesToTrack = new String[] { "W4702" };
|
||||
String scriptName2 = "/SailMasterDataInterfaceRACZero.txt";
|
||||
setUpUsingScript(racesToTrack, scriptName2);
|
||||
@@ -272,7 +271,7 @@ public class EndToEndListeningStoreAndFowardTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndToEndWithSwissTimingData() throws IOException, InterruptedException, ParseException {
|
||||
public void testEndToEndWithSwissTimingData() throws Exception {
|
||||
String[] racesToTrack = new String[] { "W4702" };
|
||||
String scriptName1 = "/SailMasterDataInterfaceRACandSTL.txt";
|
||||
String scriptName2 = "/SailMasterDataInterface-ExampleAsText.txt";
|
||||
@@ -289,8 +288,7 @@ public class EndToEndListeningStoreAndFowardTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpUsingScript(String[] racesToTrack, String... scriptNames) throws InterruptedException,
|
||||
UnknownHostException, IOException, ParseException {
|
||||
private void setUpUsingScript(String[] racesToTrack, String... scriptNames) throws Exception {
|
||||
for (String raceToTrack : racesToTrack) {
|
||||
RacesHandle raceHandle = racingEventService.addSwissTimingRace(raceToTrack, "localhost", CLIENT_PORT, /* canSendRequests */
|
||||
false, emptyWindStore, -1);
|
||||
|
||||
+6
@@ -12,6 +12,8 @@ import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.swisstimingadapter.impl.DomainFactoryImpl;
|
||||
import com.sap.sailing.domain.tracking.GPSFixMoving;
|
||||
import com.sap.sailing.domain.tracking.MarkPassing;
|
||||
import com.sap.sailing.domain.tracking.RaceTrackingConnectivityParameters;
|
||||
import com.sap.sailing.domain.tracking.WindStore;
|
||||
|
||||
import difflib.PatchFailedException;
|
||||
|
||||
@@ -37,4 +39,8 @@ public interface DomainFactory {
|
||||
MarkPassing createMarkPassing(TimePoint timePoint, Waypoint waypoint, Competitor competitor);
|
||||
|
||||
void removeRace(String raceID);
|
||||
|
||||
RaceTrackingConnectivityParameters createTrackingConnectivityParameters(String hostname, int port, String raceID, boolean canSendRequests,
|
||||
SwissTimingFactory swissTimingFactory, DomainFactory domainFactory, WindStore windStore,
|
||||
RaceSpecificMessageLoader messageLoader);
|
||||
}
|
||||
|
||||
+12
@@ -35,9 +35,13 @@ import com.sap.sailing.domain.swisstimingadapter.Fix;
|
||||
import com.sap.sailing.domain.swisstimingadapter.Mark;
|
||||
import com.sap.sailing.domain.swisstimingadapter.MessageType;
|
||||
import com.sap.sailing.domain.swisstimingadapter.Race;
|
||||
import com.sap.sailing.domain.swisstimingadapter.RaceSpecificMessageLoader;
|
||||
import com.sap.sailing.domain.swisstimingadapter.StartList;
|
||||
import com.sap.sailing.domain.swisstimingadapter.SwissTimingFactory;
|
||||
import com.sap.sailing.domain.tracking.GPSFixMoving;
|
||||
import com.sap.sailing.domain.tracking.MarkPassing;
|
||||
import com.sap.sailing.domain.tracking.RaceTrackingConnectivityParameters;
|
||||
import com.sap.sailing.domain.tracking.WindStore;
|
||||
import com.sap.sailing.domain.tracking.impl.GPSFixMovingImpl;
|
||||
|
||||
import difflib.PatchFailedException;
|
||||
@@ -250,4 +254,12 @@ public class DomainFactoryImpl implements DomainFactory {
|
||||
return baseDomainFactory.getOrCreateNationality(nationalityName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceTrackingConnectivityParameters createTrackingConnectivityParameters(String hostname, int port, String raceID, boolean canSendRequests,
|
||||
SwissTimingFactory swissTimingFactory, DomainFactory domainFactory, WindStore windStore,
|
||||
RaceSpecificMessageLoader messageLoader) {
|
||||
return new SwissTimingTrackingConnectivityParameters(hostname, port, raceID, canSendRequests,
|
||||
swissTimingFactory, domainFactory, windStore, messageLoader);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-1
@@ -78,13 +78,17 @@ public class SwissTimingRaceTrackerImpl extends AbstractRaceTrackerImpl implemen
|
||||
this.raceID = raceID;
|
||||
this.messageLoader = messageLoader;
|
||||
this.windStore = windStore;
|
||||
this.id = new Triple<String, String, Integer>(raceID, hostname, port);
|
||||
this.id = createID(raceID, hostname, port);
|
||||
connector.addSailMasterListener(raceID, this);
|
||||
event = domainFactory.getOrCreateEvent(raceID);
|
||||
setTrackedEvent(trackedEventRegistry.getOrCreateTrackedEvent(event));
|
||||
connector.trackRace(raceID);
|
||||
}
|
||||
|
||||
static Triple<String, String, Integer> createID(String raceID, String hostname, int port) {
|
||||
return new Triple<String, String, Integer>(raceID, hostname, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws MalformedURLException, IOException, InterruptedException {
|
||||
connector.removeSailMasterListener(raceID, this);
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.sap.sailing.domain.swisstimingadapter.impl;
|
||||
|
||||
import com.sap.sailing.domain.swisstimingadapter.DomainFactory;
|
||||
import com.sap.sailing.domain.swisstimingadapter.RaceSpecificMessageLoader;
|
||||
import com.sap.sailing.domain.swisstimingadapter.SwissTimingFactory;
|
||||
import com.sap.sailing.domain.tracking.RaceTracker;
|
||||
import com.sap.sailing.domain.tracking.RaceTrackingConnectivityParameters;
|
||||
import com.sap.sailing.domain.tracking.TrackedEventRegistry;
|
||||
import com.sap.sailing.domain.tracking.WindStore;
|
||||
|
||||
public class SwissTimingTrackingConnectivityParameters implements RaceTrackingConnectivityParameters {
|
||||
private final String hostname;
|
||||
private final int port;
|
||||
private final String raceID;
|
||||
private final boolean canSendRequests;
|
||||
private final SwissTimingFactory swissTimingFactory;
|
||||
private final DomainFactory domainFactory;
|
||||
private final WindStore windStore;
|
||||
private final RaceSpecificMessageLoader messageLoader;
|
||||
|
||||
public SwissTimingTrackingConnectivityParameters(String hostname, int port, String raceID, boolean canSendRequests,
|
||||
SwissTimingFactory swissTimingFactory, DomainFactory domainFactory, WindStore windStore,
|
||||
RaceSpecificMessageLoader messageLoader) {
|
||||
super();
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.raceID = raceID;
|
||||
this.canSendRequests = canSendRequests;
|
||||
this.swissTimingFactory = swissTimingFactory;
|
||||
this.domainFactory = domainFactory;
|
||||
this.windStore = windStore;
|
||||
this.messageLoader = messageLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceTracker createRaceTracker(TrackedEventRegistry trackedEventRegistry) throws Exception {
|
||||
return swissTimingFactory.createRaceTracker(raceID, hostname, port, canSendRequests, windStore, messageLoader,
|
||||
domainFactory, trackedEventRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTrackerID() {
|
||||
return SwissTimingRaceTrackerImpl.createID(raceID, hostname, port);
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -7,6 +7,7 @@ import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util;
|
||||
import com.sap.sailing.domain.tracking.RaceTracker;
|
||||
import com.sap.sailing.domain.tracking.RaceTrackingConnectivityParameters;
|
||||
import com.sap.sailing.domain.tracking.TrackedEventRegistry;
|
||||
@@ -43,9 +44,8 @@ public class RaceTrackingConnectivityParametersImpl implements RaceTrackingConne
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTrackerID() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public Util.Triple<URL, URI, URI> getTrackerID() {
|
||||
return TracTracRaceTrackerImpl.createID(paramURL, liveURI, storedURI);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-1
@@ -108,7 +108,7 @@ public class TracTracRaceTrackerImpl extends AbstractRaceTrackerImpl implements
|
||||
TrackedEventRegistry trackedEventRegistry) throws URISyntaxException, MalformedURLException,
|
||||
FileNotFoundException {
|
||||
super();
|
||||
urls = new Triple<URL, URI, URI>(paramURL, liveURI, storedURI);
|
||||
urls = createID(paramURL, liveURI, storedURI);
|
||||
this.races = new HashSet<RaceDefinition>();
|
||||
this.windStore = windStore;
|
||||
this.domainFactory = domainFactory;
|
||||
@@ -145,6 +145,10 @@ public class TracTracRaceTrackerImpl extends AbstractRaceTrackerImpl implements
|
||||
addListenersForStoredDataAndStartController(typeControllers);
|
||||
}
|
||||
|
||||
static Triple<URL, URI, URI> createID(URL paramURL, URI liveURI, URI storedURI) {
|
||||
return new Triple<URL, URI, URI>(paramURL, liveURI, storedURI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Control points may get added late in the race. If they don't have a tracker installed, their position
|
||||
* will be static. This position can be retrieved from {@link ControlPoint#getLat1()} etc. This method registers
|
||||
|
||||
@@ -242,7 +242,8 @@ public interface RacingEventService extends TrackedEventRegistry {
|
||||
void updateStoredLeaderboard(Leaderboard leaderboard);
|
||||
|
||||
RacesHandle addSwissTimingRace(String raceID, String hostname, int port, boolean canSendRequests,
|
||||
WindStore windStore, long timeoutInMilliseconds) throws InterruptedException, UnknownHostException, IOException, ParseException;
|
||||
WindStore windStore, long timeoutInMilliseconds) throws InterruptedException, UnknownHostException,
|
||||
IOException, ParseException, Exception;
|
||||
|
||||
SwissTimingFactory getSwissTimingFactory();
|
||||
|
||||
|
||||
+6
-38
@@ -391,44 +391,12 @@ public class RacingEventServiceImpl implements RacingEventService, EventFetcher,
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized RacesHandle addSwissTimingRace(String raceID, String hostname, int port, boolean canSendRequests,
|
||||
WindStore windStore, long timeoutInMilliseconds) throws InterruptedException, UnknownHostException, IOException, ParseException {
|
||||
Triple<String, String, Integer> key = new Triple<String, String, Integer>(raceID, hostname, port);
|
||||
RaceTracker tracker = raceTrackersByID.get(key);
|
||||
if (tracker == null) {
|
||||
tracker = getSwissTimingFactory().createRaceTracker(raceID, hostname, port, canSendRequests,
|
||||
windStore, swissTimingAdapterPersistence, swissTimingDomainFactory, this);
|
||||
raceTrackersByID.put(tracker.getID(), tracker);
|
||||
Set<RaceTracker> trackers = raceTrackersByEvent.get(tracker.getEvent());
|
||||
if (trackers == null) {
|
||||
trackers = new HashSet<RaceTracker>();
|
||||
raceTrackersByEvent.put(tracker.getEvent(), trackers);
|
||||
}
|
||||
trackers.add(tracker);
|
||||
// TODO we assume here that the event name is unique which necessesitates adding the boat class name to it in EventImpl constructor
|
||||
String eventName = tracker.getEvent().getName();
|
||||
Event eventWithName = eventsByName.get(eventName);
|
||||
// TODO we assume here that the event name is unique which necessesitates adding the boat class name to it in EventImpl constructor
|
||||
if (eventWithName != null) {
|
||||
if (eventWithName != tracker.getEvent()) {
|
||||
throw new RuntimeException("Internal error. Two Event objects with equal name "+eventName);
|
||||
}
|
||||
} else {
|
||||
eventsByName.put(eventName, tracker.getEvent());
|
||||
}
|
||||
} else {
|
||||
WindStore existingTrackersWindStore = tracker.getWindStore();
|
||||
if (!existingTrackersWindStore.equals(windStore)) {
|
||||
logger.warning("Wind store mismatch. Requested wind store: "+windStore+
|
||||
". Wind store in use by existing tracker: "+existingTrackersWindStore);
|
||||
}
|
||||
}
|
||||
DynamicTrackedEvent trackedEvent = tracker.getTrackedEvent();
|
||||
ensureEventIsObservedForDefaultLeaderboardAndAutoLeaderboardLinking(trackedEvent);
|
||||
if (timeoutInMilliseconds != -1) {
|
||||
scheduleAbortTrackerAfterInitialTimeout(tracker, timeoutInMilliseconds);
|
||||
}
|
||||
return tracker.getRacesHandle();
|
||||
public synchronized RacesHandle addSwissTimingRace(String raceID, String hostname, int port,
|
||||
boolean canSendRequests, WindStore windStore, long timeoutInMilliseconds) throws Exception {
|
||||
return addRace(
|
||||
swissTimingDomainFactory.createTrackingConnectivityParameters(hostname, port, raceID, canSendRequests,
|
||||
swissTimingFactory, swissTimingDomainFactory, windStore, swissTimingAdapterPersistence),
|
||||
windStore, timeoutInMilliseconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user