fixing bug 773: waiting only for some time for the RaceDefinition; if wrong regatta, tracker stops

This commit is contained in:
Axel Uhl committed 2012-06-16 21:58:05 +02:00
1 parent 045be2e12a
commit ba6a2c7da0
7 files changed
+44 -25

No files matched your search

@@ -222,7 +222,7 @@ public interface DomainFactory {
* <code>timeoutInMilliseconds</code> in case no modifications happen on the set of races cached by this factory. * <code>timeoutInMilliseconds</code> in case no modifications happen on the set of races cached by this factory.
* *
* @param timeoutInMilliseconds * @param timeoutInMilliseconds
* passing -1 means an infinite timeout; 0 means return immediately with <code>null</code> result if no * passing -1 means an infinite timeout; 0 means return immediately with <code>null</code> as result if no
* race definition is found for <code>race</code>. * race definition is found for <code>race</code>.
*/ */
RaceDefinition getAndWaitForRaceDefinition(Race race, long timeoutInMilliseconds); RaceDefinition getAndWaitForRaceDefinition(Race race, long timeoutInMilliseconds);
@@ -7,7 +7,6 @@ import com.sap.sailing.domain.common.impl.Util.Triple;
import com.sap.sailing.domain.tracking.RaceTracker; import com.sap.sailing.domain.tracking.RaceTracker;
public interface TracTracRaceTracker extends RaceTracker { public interface TracTracRaceTracker extends RaceTracker {
/** /**
* returns the paramURL, liveURI and storedURI for the TracTrac connection maintained by this tracker * returns the paramURL, liveURI and storedURI for the TracTrac connection maintained by this tracker
*/ */
@@ -8,6 +8,7 @@ import com.sap.sailing.domain.base.RaceDefinition;
import com.sap.sailing.domain.common.impl.Util.Triple; import com.sap.sailing.domain.common.impl.Util.Triple;
import com.sap.sailing.domain.tracking.DynamicTrackedRace; import com.sap.sailing.domain.tracking.DynamicTrackedRace;
import com.sap.sailing.domain.tracking.DynamicTrackedRegatta; import com.sap.sailing.domain.tracking.DynamicTrackedRegatta;
import com.sap.sailing.domain.tracking.RaceTracker;
import com.sap.sailing.domain.tracking.TrackedRace; import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.domain.tracking.TrackedRegatta; import com.sap.sailing.domain.tracking.TrackedRegatta;
import com.sap.sailing.domain.tractracadapter.DomainFactory; import com.sap.sailing.domain.tractracadapter.DomainFactory;
@@ -133,17 +134,23 @@ public abstract class AbstractReceiverWithQueue<A, B, C> implements Runnable, Re
protected abstract void handleEvent(Triple<A, B, C> event); protected abstract void handleEvent(Triple<A, B, C> event);
/** /**
* Tries to find a {@link TrackedRace} for <code>race</code> in the {@link com.sap.sailing.domain.base.Regatta} corresponding * Tries to find a {@link TrackedRace} for <code>race</code> in the {@link com.sap.sailing.domain.base.Regatta}
* to {@link #tractracEvent}, as keyed by the {@link #domainFactory}. If the {@link RaceDefinition} for <code>race</code> * corresponding to {@link #tractracEvent}, as keyed by the {@link #domainFactory}. Waits for
* is not found in the {@link com.sap.sailing.domain.base.Regatta}, <code>null</code> is returned. If the {@link TrackedRace} * {@link RaceTracker#TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS} milliseconds for the
* for <code>race</code> isn't found in the {@link TrackedRegatta}, <code>null</code> is returned, too. * {@link RaceDefinition} to show up. If it doesn't, <code>null</code> is returned. If the {@link RaceDefinition}
* for <code>race</code> is not found in the {@link com.sap.sailing.domain.base.Regatta}, <code>null</code> is
* returned. If the {@link TrackedRace} for <code>race</code> isn't found in the {@link TrackedRegatta},
* <code>null</code> is returned, too.
*/ */
protected DynamicTrackedRace getTrackedRace(Race race) { protected DynamicTrackedRace getTrackedRace(Race race) {
DynamicTrackedRace result = null; DynamicTrackedRace result = null;
RaceDefinition raceDefinition = getDomainFactory().getAndWaitForRaceDefinition(race); RaceDefinition raceDefinition = getDomainFactory().getAndWaitForRaceDefinition(race,
com.sap.sailing.domain.base.Regatta domainRegatta = trackedRegatta.getRegatta(); RaceTracker.TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS);
if (domainRegatta.getRaceByName(raceDefinition.getName()) != null) { if (raceDefinition != null) {
result = trackedRegatta.getTrackedRace(raceDefinition); com.sap.sailing.domain.base.Regatta domainRegatta = trackedRegatta.getRegatta();
if (domainRegatta.getRaceByName(raceDefinition.getName()) != null) {
result = trackedRegatta.getTrackedRace(raceDefinition);
}
} }
return result; return result;
} }
@@ -226,7 +226,14 @@ public class DomainFactoryImpl implements DomainFactory {
boolean interrupted = false; boolean interrupted = false;
while ((timeoutInMilliseconds == -1 || System.currentTimeMillis()-start < timeoutInMilliseconds) && !interrupted && result == null) { while ((timeoutInMilliseconds == -1 || System.currentTimeMillis()-start < timeoutInMilliseconds) && !interrupted && result == null) {
try { try {
raceCache.wait(); if (timeoutInMilliseconds == -1) {
raceCache.wait();
} else {
long timeToWait = timeoutInMilliseconds-(System.currentTimeMillis()-start);
if (timeToWait > 0) {
raceCache.wait(timeToWait);
}
}
result = raceCache.get(race); result = raceCache.get(race);
} catch (InterruptedException e) { } catch (InterruptedException e) {
interrupted = true; interrupted = true;
@@ -312,7 +319,9 @@ public class DomainFactoryImpl implements DomainFactory {
@Override @Override
public Iterable<Receiver> getUpdateReceivers(DynamicTrackedRegatta trackedRegatta, public Iterable<Receiver> getUpdateReceivers(DynamicTrackedRegatta trackedRegatta,
com.tractrac.clientmodule.Event tractracEvent, TimePoint startOfTracking, TimePoint endOfTracking, long delayToLiveInMillis, WindStore windStore, DynamicRaceDefinitionSet raceDefinitionSetToUpdate, TrackedRegattaRegistry trackedRegattaRegistry) { com.tractrac.clientmodule.Event tractracEvent, TimePoint startOfTracking, TimePoint endOfTracking,
long delayToLiveInMillis, WindStore windStore, DynamicRaceDefinitionSet raceDefinitionSetToUpdate,
TrackedRegattaRegistry trackedRegattaRegistry) {
return getUpdateReceivers(trackedRegatta, tractracEvent, windStore, startOfTracking, endOfTracking, delayToLiveInMillis, return getUpdateReceivers(trackedRegatta, tractracEvent, windStore, startOfTracking, endOfTracking, delayToLiveInMillis,
raceDefinitionSetToUpdate, trackedRegattaRegistry, ReceiverType.RACECOURSE, raceDefinitionSetToUpdate, trackedRegattaRegistry, ReceiverType.RACECOURSE,
ReceiverType.MARKPASSINGS, ReceiverType.MARKPOSITIONS, ReceiverType.RACESTARTFINISH, ReceiverType.RAWPOSITIONS); ReceiverType.MARKPASSINGS, ReceiverType.MARKPOSITIONS, ReceiverType.RACESTARTFINISH, ReceiverType.RAWPOSITIONS);
@@ -32,6 +32,13 @@ import com.sap.sailing.domain.common.RegattaAndRaceIdentifier;
* *
*/ */
public interface RaceTracker { public interface RaceTracker {
/**
* By default, wait five minutes for race data; sometimes, a tracking provider's server may be under heavy load and
* may serve races one after another. If many races are requested concurrently, this can lead to a queue
* of several minutes length.
*/
static long TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS = 300000;
/** /**
* Stops tracking the races. * Stops tracking the races.
*/ */
@@ -105,6 +105,7 @@ import com.sap.sailing.domain.tracking.GPSFixMoving;
import com.sap.sailing.domain.tracking.GPSFixTrack; import com.sap.sailing.domain.tracking.GPSFixTrack;
import com.sap.sailing.domain.tracking.Maneuver; import com.sap.sailing.domain.tracking.Maneuver;
import com.sap.sailing.domain.tracking.MarkPassing; import com.sap.sailing.domain.tracking.MarkPassing;
import com.sap.sailing.domain.tracking.RaceTracker;
import com.sap.sailing.domain.tracking.RacesHandle; import com.sap.sailing.domain.tracking.RacesHandle;
import com.sap.sailing.domain.tracking.TrackedLeg; import com.sap.sailing.domain.tracking.TrackedLeg;
import com.sap.sailing.domain.tracking.TrackedLegOfCompetitor; import com.sap.sailing.domain.tracking.TrackedLegOfCompetitor;
@@ -214,13 +215,6 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
private static final long serialVersionUID = 9031688830194537489L; private static final long serialVersionUID = 9031688830194537489L;
/**
* Wait five minutes for race data; sometimes, a tracking provider's server may be under heavy load and
* may serve races one after another. If many races are requested concurrently, this can lead to a queue
* of several minutes length.
*/
private static final long TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS = 300000;
private final ServiceTracker<RacingEventService, RacingEventService> racingEventServiceTracker; private final ServiceTracker<RacingEventService, RacingEventService> racingEventServiceTracker;
private final ServiceTracker<ReplicationService, ReplicationService> replicationServiceTracker; private final ServiceTracker<ReplicationService, ReplicationService> replicationServiceTracker;
@@ -622,14 +616,16 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
if (storedURI == null || storedURI.trim().length() == 0) { if (storedURI == null || storedURI.trim().length() == 0) {
storedURI = rr.storedURI; storedURI = rr.storedURI;
} }
final RacesHandle raceHandle = getService().addTracTracRace(regattaToAddTo, new URL(rr.paramURL), new URI(liveURI), final RacesHandle raceHandle = getService().addTracTracRace(regattaToAddTo, new URL(rr.paramURL),
new URI(storedURI), new MillisecondsTimePoint(rr.trackingStartTime), new URI(liveURI), new URI(storedURI), new MillisecondsTimePoint(rr.trackingStartTime),
new MillisecondsTimePoint(rr.trackingEndTime), MongoWindStoreFactory.INSTANCE.getMongoWindStore(mongoObjectFactory, domainObjectFactory), TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS); new MillisecondsTimePoint(rr.trackingEndTime),
MongoWindStoreFactory.INSTANCE.getMongoWindStore(mongoObjectFactory, domainObjectFactory),
RaceTracker.TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS);
if (trackWind) { if (trackWind) {
new Thread("Wind tracking starter for race "+rr.regattaName+"/"+rr.name) { new Thread("Wind tracking starter for race "+rr.regattaName+"/"+rr.name) {
public void run() { public void run() {
try { try {
startTrackingWind(raceHandle, correctWindByDeclination, TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS); startTrackingWind(raceHandle, correctWindByDeclination, RaceTracker.TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -1624,12 +1620,13 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
boolean canSendRequests, boolean trackWind, final boolean correctWindByDeclination) throws Exception { boolean canSendRequests, boolean trackWind, final boolean correctWindByDeclination) throws Exception {
final RacesHandle raceHandle = getService().addSwissTimingRace(regattaToAddTo, rr.ID, hostname, port, final RacesHandle raceHandle = getService().addSwissTimingRace(regattaToAddTo, rr.ID, hostname, port,
canSendRequests, canSendRequests,
MongoWindStoreFactory.INSTANCE.getMongoWindStore(mongoObjectFactory, domainObjectFactory), TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS); MongoWindStoreFactory.INSTANCE.getMongoWindStore(mongoObjectFactory, domainObjectFactory),
RaceTracker.TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS);
if (trackWind) { if (trackWind) {
new Thread("Wind tracking starter for race "+rr.ID+"/"+rr.description) { new Thread("Wind tracking starter for race "+rr.ID+"/"+rr.description) {
public void run() { public void run() {
try { try {
startTrackingWind(raceHandle, correctWindByDeclination, TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS); startTrackingWind(raceHandle, correctWindByDeclination, RaceTracker.TIMEOUT_FOR_RECEIVING_RACE_DEFINITION_IN_MILLISECONDS);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }