mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-07 19:42:17 +00:00
more robust exception handling within SailMasterConnectorImpl, catching exceptions caused by handlers
This commit is contained in:
1 parent
f8f1dfbb66
commit
b38242f251
8 files changed
+137
-19
No files matched your search
@@ -6,7 +6,8 @@ Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: SAP
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Require-Bundle: com.sap.sailing.domain,
|
||||
com.sap.sailing.udpconnector
|
||||
com.sap.sailing.udpconnector,
|
||||
com.googlecode.java-diff-utils;bundle-version="1.3.0"
|
||||
Import-Package: org.osgi.framework
|
||||
Export-Package: com.sap.sailing.domain.swisstimingadapter,
|
||||
com.sap.sailing.domain.swisstimingadapter.impl;x-friends:="com.sap.sailing.domain.swisstimingadapter.test"
|
||||
+6
-1
@@ -2,6 +2,7 @@ package com.sap.sailing.domain.swisstimingadapter;
|
||||
|
||||
import com.sap.sailing.domain.base.Buoy;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.Course;
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
import com.sap.sailing.domain.base.Nationality;
|
||||
import com.sap.sailing.domain.base.RaceDefinition;
|
||||
@@ -9,6 +10,8 @@ import com.sap.sailing.domain.base.TimePoint;
|
||||
import com.sap.sailing.domain.swisstimingadapter.impl.DomainFactoryImpl;
|
||||
import com.sap.sailing.domain.tracking.GPSFixMoving;
|
||||
|
||||
import difflib.PatchFailedException;
|
||||
|
||||
public interface DomainFactory {
|
||||
final static DomainFactory INSTANCE = new DomainFactoryImpl();
|
||||
|
||||
@@ -18,11 +21,13 @@ public interface DomainFactory {
|
||||
|
||||
Competitor getOrCreateCompetitor(com.sap.sailing.domain.swisstimingadapter.Competitor competitor);
|
||||
|
||||
RaceDefinition createRaceDefinition(Event event, Race race, StartList startList, Course course);
|
||||
RaceDefinition createRaceDefinition(Event event, Race race, StartList startList, com.sap.sailing.domain.swisstimingadapter.Course course);
|
||||
|
||||
Buoy getOrCreateBuoy(String trackerID);
|
||||
|
||||
GPSFixMoving createGPSFix(TimePoint timePointOfTransmission, Fix fix);
|
||||
|
||||
Competitor getCompetitorByBoatID(String sailNumber);
|
||||
|
||||
void updateCourseWaypoints(Course courseToUpdate, Iterable<Mark> marks) throws PatchFailedException;
|
||||
}
|
||||
+44
@@ -3,6 +3,7 @@ package com.sap.sailing.domain.swisstimingadapter.impl;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -37,8 +38,13 @@ import com.sap.sailing.domain.swisstimingadapter.Race;
|
||||
import com.sap.sailing.domain.swisstimingadapter.StartList;
|
||||
import com.sap.sailing.domain.tracking.GPSFixMoving;
|
||||
import com.sap.sailing.domain.tracking.impl.GPSFixMovingImpl;
|
||||
import com.sap.sailing.util.CourseAsWaypointList;
|
||||
import com.sap.sailing.util.Util;
|
||||
|
||||
import difflib.DiffUtils;
|
||||
import difflib.Patch;
|
||||
import difflib.PatchFailedException;
|
||||
|
||||
public class DomainFactoryImpl implements DomainFactory {
|
||||
private final Map<String, Event> raceIDToEventCache;
|
||||
private final Map<String, Competitor> boatIDToCompetitorCache;
|
||||
@@ -168,4 +174,42 @@ public class DomainFactoryImpl implements DomainFactory {
|
||||
timePointOfTransmission.asMillis() + fix.getAgeOfDataInMilliseconds()), fix.getSpeed());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCourseWaypoints(com.sap.sailing.domain.base.Course courseToUpdate, Iterable<Mark> marks) throws PatchFailedException {
|
||||
Iterable<Waypoint> courseWaypoints = courseToUpdate.getWaypoints();
|
||||
List<Waypoint> newWaypointList = new LinkedList<Waypoint>();
|
||||
// key existing waypoints by control points and re-use each one at most once during construction of the
|
||||
// new waypoint list; since several waypoints can have the same control point, the map goes from
|
||||
// control point to List<Waypoint>. The waypoints in the lists are held in the order of their
|
||||
// occurrence in courseToUpdate.getWaypoints().
|
||||
Map<com.sap.sailing.domain.base.ControlPoint, List<Waypoint>> existingWaypointsByControlPoint =
|
||||
new HashMap<com.sap.sailing.domain.base.ControlPoint, List<Waypoint>>();
|
||||
for (Waypoint waypoint : courseToUpdate.getWaypoints()) {
|
||||
List<Waypoint> wpl = existingWaypointsByControlPoint.get(waypoint.getControlPoint());
|
||||
if (wpl == null) {
|
||||
wpl = new ArrayList<Waypoint>();
|
||||
existingWaypointsByControlPoint.put(waypoint.getControlPoint(), wpl);
|
||||
}
|
||||
wpl.add(waypoint);
|
||||
}
|
||||
for (Mark mark : marks) {
|
||||
com.sap.sailing.domain.base.ControlPoint domainControlPoint = getOrCreateControlPoint(mark.getDevices());
|
||||
List<Waypoint> waypoints = existingWaypointsByControlPoint.get(domainControlPoint);
|
||||
Waypoint waypoint;
|
||||
if (waypoints == null || waypoints.isEmpty()) {
|
||||
// must be a new control point for which we don't have a waypoint yet
|
||||
waypoint = new WaypointImpl(domainControlPoint);
|
||||
} else {
|
||||
waypoint = waypoints.remove(0); // take the first from the list
|
||||
}
|
||||
newWaypointList.add(waypoint);
|
||||
}
|
||||
Patch<Waypoint> patch = DiffUtils.diff(courseWaypoints, newWaypointList);
|
||||
CourseAsWaypointList courseAsWaypointList = new CourseAsWaypointList(courseToUpdate);
|
||||
synchronized (courseToUpdate) {
|
||||
patch.applyToInPlace(courseAsWaypointList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+73
-12
@@ -327,19 +327,45 @@ public class SailMasterConnectorImpl extends SailMasterTransceiverImpl implement
|
||||
markIndicesRanksAndTimesSinceStartInMilliseconds.add(new Triple<Integer, Integer, Long>(markIndex, rank, timeSinceStartInMilliseconds));
|
||||
}
|
||||
for (SailMasterListener listener : listeners) {
|
||||
listener.receivedTimingData(raceID, boatID, markIndicesRanksAndTimesSinceStartInMilliseconds);
|
||||
try {
|
||||
listener.receivedTimingData(raceID, boatID, markIndicesRanksAndTimesSinceStartInMilliseconds);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersTMD", t);
|
||||
}
|
||||
}
|
||||
Set<SailMasterListener> raceSpecificListenerSet = raceSpecificListeners.get(message.getRaceID());
|
||||
if (raceSpecificListenerSet != null) {
|
||||
for (SailMasterListener listener : raceSpecificListenerSet) {
|
||||
try {
|
||||
listener.receivedTimingData(raceID, boatID, markIndicesRanksAndTimesSinceStartInMilliseconds);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersTMD", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyListenersCAM(SailMasterMessage message) throws ParseException {
|
||||
List<Triple<Integer, TimePoint, String>> clockAtMarkResults = parseClockAtMarkMessage(message);
|
||||
for (SailMasterListener listener : listeners) {
|
||||
listener.receivedClockAtMark(message.getSections()[1], clockAtMarkResults);
|
||||
try {
|
||||
listener.receivedClockAtMark(message.getSections()[1], clockAtMarkResults);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersCAM", t);
|
||||
}
|
||||
}
|
||||
Set<SailMasterListener> raceSpecificListenerSet = raceSpecificListeners.get(message.getRaceID());
|
||||
if (raceSpecificListenerSet != null) {
|
||||
for (SailMasterListener listener : raceSpecificListenerSet) {
|
||||
listener.receivedClockAtMark(message.getSections()[1], clockAtMarkResults);
|
||||
try {
|
||||
listener.receivedClockAtMark(message.getSections()[1], clockAtMarkResults);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersCAM", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -347,12 +373,22 @@ public class SailMasterConnectorImpl extends SailMasterTransceiverImpl implement
|
||||
private void notifyListenersSTL(SailMasterMessage message) {
|
||||
StartList startListMessage = parseStartListMessage(message);
|
||||
for (SailMasterListener listener : listeners) {
|
||||
listener.receivedStartList(message.getSections()[1], startListMessage);
|
||||
try {
|
||||
listener.receivedStartList(message.getSections()[1], startListMessage);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersSTL", t);
|
||||
}
|
||||
}
|
||||
Set<SailMasterListener> raceSpecificListenerSet = raceSpecificListeners.get(message.getRaceID());
|
||||
if (raceSpecificListenerSet != null) {
|
||||
for (SailMasterListener listener : raceSpecificListenerSet) {
|
||||
listener.receivedStartList(message.getSections()[1], startListMessage);
|
||||
try {
|
||||
listener.receivedStartList(message.getSections()[1], startListMessage);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersSTL", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -360,12 +396,22 @@ public class SailMasterConnectorImpl extends SailMasterTransceiverImpl implement
|
||||
private void notifyListenersCCG(SailMasterMessage message) {
|
||||
Course course = parseCourseConfigurationMessage(message);
|
||||
for (SailMasterListener listener : listeners) {
|
||||
listener.receivedCourseConfiguration(message.getSections()[1], course);
|
||||
try {
|
||||
listener.receivedCourseConfiguration(message.getSections()[1], course);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersCCG", t);
|
||||
}
|
||||
}
|
||||
Set<SailMasterListener> raceSpecificListenerSet = raceSpecificListeners.get(message.getRaceID());
|
||||
if (raceSpecificListenerSet != null) {
|
||||
for (SailMasterListener listener : raceSpecificListenerSet) {
|
||||
listener.receivedCourseConfiguration(message.getSections()[1], course);
|
||||
try {
|
||||
listener.receivedCourseConfiguration(message.getSections()[1], course);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersCCG", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,7 +419,12 @@ public class SailMasterConnectorImpl extends SailMasterTransceiverImpl implement
|
||||
private void notifyListenersRAC(SailMasterMessage message) {
|
||||
Iterable<Race> races = parseAvailableRacesMessage(message);
|
||||
for (SailMasterListener listener : listeners) {
|
||||
listener.receivedAvailableRaces(races);
|
||||
try {
|
||||
listener.receivedAvailableRaces(races);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersRAC", t);
|
||||
}
|
||||
}
|
||||
// not race specific; no need to notify any listener from raceSpecificListeners
|
||||
}
|
||||
@@ -430,14 +481,24 @@ public class SailMasterConnectorImpl extends SailMasterTransceiverImpl implement
|
||||
}
|
||||
}
|
||||
for (SailMasterListener listener : listeners) {
|
||||
listener.receivedRacePositionData(raceID, status, timePoint, startTimeEstimatedStartTime, millisecondsSinceRaceStart,
|
||||
nextMarkIndexForLeader, distanceToNextMarkForLeader, fixes);
|
||||
try {
|
||||
listener.receivedRacePositionData(raceID, status, timePoint, startTimeEstimatedStartTime, millisecondsSinceRaceStart,
|
||||
nextMarkIndexForLeader, distanceToNextMarkForLeader, fixes);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersRPD", t);
|
||||
}
|
||||
}
|
||||
Set<SailMasterListener> raceSpecificListenerSet = raceSpecificListeners.get(message.getRaceID());
|
||||
if (raceSpecificListenerSet != null) {
|
||||
for (SailMasterListener listener : raceSpecificListenerSet) {
|
||||
listener.receivedRacePositionData(raceID, status, timePoint, startTimeEstimatedStartTime, millisecondsSinceRaceStart,
|
||||
nextMarkIndexForLeader, distanceToNextMarkForLeader, fixes);
|
||||
try {
|
||||
listener.receivedRacePositionData(raceID, status, timePoint, startTimeEstimatedStartTime, millisecondsSinceRaceStart,
|
||||
nextMarkIndexForLeader, distanceToNextMarkForLeader, fixes);
|
||||
} catch (Throwable t) {
|
||||
logger.info("Exception occurred trying to notify listener "+listener+" about "+message+": "+t.getMessage());
|
||||
logger.throwing(SailMasterConnectorImpl.class.getName(), "notifyListenersRPD", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-3
@@ -41,6 +41,8 @@ import com.sap.sailing.domain.tracking.WindStore;
|
||||
import com.sap.sailing.domain.tracking.WindTrack;
|
||||
import com.sap.sailing.util.Util.Triple;
|
||||
|
||||
import difflib.PatchFailedException;
|
||||
|
||||
public class SwissTimingRaceTrackerImpl implements SwissTimingRaceTracker, SailMasterListener {
|
||||
private static final Logger logger = Logger.getLogger(SwissTimingRaceTrackerImpl.class.getName());
|
||||
|
||||
@@ -161,10 +163,9 @@ public class SwissTimingRaceTrackerImpl implements SwissTimingRaceTracker, SailM
|
||||
competitorTrack.addGPSFix(gpsFix);
|
||||
break;
|
||||
default:
|
||||
logger.info("Unknoen tracker type "+fix.getTrackerType());
|
||||
logger.info("Unknown tracker type "+fix.getTrackerType());
|
||||
}
|
||||
}
|
||||
// TODO implement receivedRacePositionData; extract race start time, add GPSFixMoving objects to tracked race
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +215,12 @@ public class SwissTimingRaceTrackerImpl implements SwissTimingRaceTracker, SailM
|
||||
createRaceDefinition(raceID);
|
||||
}
|
||||
} else {
|
||||
// TODO update trackedRace with updated course
|
||||
try {
|
||||
domainFactory.updateCourseWaypoints(trackedRace.getRace().getCourse(), course.getMarks());
|
||||
} catch (PatchFailedException e) {
|
||||
logger.info("Internal error trying to update course: "+e.getMessage());
|
||||
logger.throwing(SwissTimingRaceTrackerImpl.class.getName(), "receivedCourseConfiguration", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -62,6 +62,7 @@ import com.sap.sailing.domain.tractracadapter.Receiver;
|
||||
import com.sap.sailing.domain.tractracadapter.ReceiverType;
|
||||
import com.sap.sailing.domain.tractracadapter.TracTracConfiguration;
|
||||
import com.sap.sailing.domain.tractracadapter.TracTracRaceTracker;
|
||||
import com.sap.sailing.util.CourseAsWaypointList;
|
||||
import com.sap.sailing.util.Util;
|
||||
import com.sap.sailing.util.Util.Pair;
|
||||
import com.tractrac.clientmodule.CompetitorClass;
|
||||
|
||||
@@ -15,3 +15,4 @@ Export-Package: com.sap.sailing.domain.base,
|
||||
com.sap.sailing.domain.tracking.impl,
|
||||
com.sap.sailing.util
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Require-Bundle: com.googlecode.java-diff-utils;bundle-version="1.3.0"
|
||||
+1
-2
@@ -1,10 +1,9 @@
|
||||
package com.sap.sailing.domain.tractracadapter.impl;
|
||||
package com.sap.sailing.util;
|
||||
|
||||
import java.util.AbstractList;
|
||||
|
||||
import com.sap.sailing.domain.base.Course;
|
||||
import com.sap.sailing.domain.base.Waypoint;
|
||||
import com.sap.sailing.util.Util;
|
||||
|
||||
import difflib.Patch;
|
||||
|
||||
Reference in new issue
Block a user