diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/CourseUpdateTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/CourseUpdateTest.java index 282bb77bc66..c3a86c00e5a 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/CourseUpdateTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/CourseUpdateTest.java @@ -76,7 +76,7 @@ public class CourseUpdateTest extends AbstractTracTracLiveTest { public void setUp() throws MalformedURLException, IOException, InterruptedException, URISyntaxException, SubscriberInitializationException, ParseException, CreateModelException { super.setUp(); domainFactory = new DomainFactoryImpl(new com.sap.sailing.domain.base.impl.DomainFactoryImpl()); - domainRegatta = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracEvent(), /* trackedRegattaRegistry */ null); + domainRegatta = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracRace(), /* trackedRegattaRegistry */ null); trackedRegatta = new DynamicTrackedRegattaImpl(domainRegatta); IRace tractracRace = SynchronizationUtil.getRaces(getTracTracEvent()).iterator().next(); ArrayList receivers = new ArrayList(); diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/MultipleClassesInRegattaTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/MultipleClassesInRegattaTest.java index 42f3f223414..387dc43ce7a 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/MultipleClassesInRegattaTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/MultipleClassesInRegattaTest.java @@ -1,8 +1,8 @@ package com.sap.sailing.domain.test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; import java.io.FileNotFoundException; import java.io.IOException; @@ -15,8 +15,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; - - import com.sap.sailing.domain.racelog.impl.EmptyRaceLogStore; import com.sap.sailing.domain.tracking.impl.EmptyWindStore; import com.sap.sailing.domain.tractracadapter.DomainFactory; @@ -82,7 +80,7 @@ public class MultipleClassesInRegattaTest { assertEquals("505", kiwotest2.getRegatta().getBoatClass().getName()); assertEquals("49er", kiwotest3.getRegatta().getBoatClass().getName()); assertEquals("STG", weym470may112014_2.getRegatta().getBoatClass().getName()); - assertSame(weym470may112014_2.getRegatta(), kiwotest1.getRegatta()); + assertNotSame(weym470may112014_2.getRegatta(), kiwotest1.getRegatta()); // expecting that each race gets a distinct default regatta assertNotSame(kiwotest1.getRegatta(), kiwotest2.getRegatta()); assertNotSame(kiwotest1.getRegatta(), kiwotest3.getRegatta()); assertNotSame(kiwotest2.getRegatta(), kiwotest3.getRegatta()); diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/OnlineTracTracBasedTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/OnlineTracTracBasedTest.java index bb3b0474c94..cd329da9efe 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/OnlineTracTracBasedTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/OnlineTracTracBasedTest.java @@ -183,7 +183,7 @@ public abstract class OnlineTracTracBasedTest extends AbstractTracTracLiveTest { if (domainFactory == null) { domainFactory = new DomainFactoryImpl(new com.sap.sailing.domain.base.impl.DomainFactoryImpl()); } - domainEvent = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracEvent(), /* trackedRegattaRegistry */ null); + domainEvent = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracRace(), /* trackedRegattaRegistry */ null); trackedRegatta = new DynamicTrackedRegattaImpl(domainEvent); } diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/ReceiveMarkPassingDataTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/ReceiveMarkPassingDataTest.java index 064478b5c7f..b8d9260f0e0 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/ReceiveMarkPassingDataTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/ReceiveMarkPassingDataTest.java @@ -93,7 +93,7 @@ public class ReceiveMarkPassingDataTest extends AbstractTracTracLiveTest { receivers.add(receiver); for (Receiver r : DomainFactory.INSTANCE.getUpdateReceivers( new DynamicTrackedRegattaImpl(DomainFactory.INSTANCE.getOrCreateDefaultRegatta( - EmptyRaceLogStore.INSTANCE, getTracTracEvent(), /* trackedRegattaRegistry */null)), + EmptyRaceLogStore.INSTANCE, getTracTracRace(), /* trackedRegattaRegistry */null)), SynchronizationUtil.getRaces(getTracTracEvent()).iterator().next(), EmptyWindStore.INSTANCE, /* delayToLiveInMillis */ 0l, /* simulator */null, new DynamicRaceDefinitionSet() { diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/ReceiveTrackingDataTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/ReceiveTrackingDataTest.java index 75eb1d77871..8a600204f6b 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/ReceiveTrackingDataTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/ReceiveTrackingDataTest.java @@ -62,7 +62,7 @@ public class ReceiveTrackingDataTest extends AbstractTracTracLiveTest { } } }; - Regatta regatta = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracEvent(), /* trackedRegattaRegistry */ null); + Regatta regatta = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracRace(), /* trackedRegattaRegistry */ null); DynamicTrackedRegatta trackedRegatta = new DynamicTrackedRegattaImpl(regatta); trackedRegatta.addRaceListener(new RaceListener() { @Override diff --git a/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/DomainFactory.java b/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/DomainFactory.java index 73823d03274..6e9e263416b 100755 --- a/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/DomainFactory.java +++ b/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/DomainFactory.java @@ -100,7 +100,7 @@ public interface DomainFactory { * boat class exists yet. * @param trackedRegattaRegistry TODO */ - com.sap.sailing.domain.base.Regatta getOrCreateDefaultRegatta(RaceLogStore raceLogStore, IEvent event, TrackedRegattaRegistry trackedRegattaRegistry); + com.sap.sailing.domain.base.Regatta getOrCreateDefaultRegatta(RaceLogStore raceLogStore, IRace race, TrackedRegattaRegistry trackedRegattaRegistry); /** * Creates a race tracked for the specified URL/URIs and starts receiving all available existing and future push diff --git a/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/DomainFactoryImpl.java b/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/DomainFactoryImpl.java index 8751507d942..4b25129fff9 100644 --- a/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/DomainFactoryImpl.java +++ b/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/DomainFactoryImpl.java @@ -108,12 +108,11 @@ public class DomainFactoryImpl implements DomainFactory { new HashMap, com.sap.sailing.domain.base.Regatta>(); /** - * A cache based on weak references to the TracTrac event, allowing for quick Event lookup as long as the - * TracTrac event remains referenced. This is intended to reduce the number of times the dominant boat - * class needs to be determined for an regatta. Synchronization for additions / removals is tied to the + * A cache based on weak references to the TracTrac race, allowing for quick race lookup as long as the + * TracTrac race remains referenced. Synchronization for additions / removals is tied to the * synchronization for {@link #regattaCache}. */ - private final WeakIdentityHashMap weakRegattaCache = new WeakIdentityHashMap<>(); + private final WeakIdentityHashMap weakDefaultRegattaCache = new WeakIdentityHashMap<>(); /** * Maps from the TracTrac race UUIDs to the domain model's {@link RaceDefinition} objects that represent the race @@ -345,7 +344,7 @@ public class DomainFactoryImpl implements DomainFactory { } @Override - public Regatta getOrCreateDefaultRegatta(RaceLogStore raceLogStore, IEvent event, TrackedRegattaRegistry trackedRegattaRegistry) { + public Regatta getOrCreateDefaultRegatta(RaceLogStore raceLogStore, IRace race, TrackedRegattaRegistry trackedRegattaRegistry) { synchronized (regattaCache) { // FIXME Dialog with Lasse by Skype on 2011-06-17: // [6:20:04 PM] Axel Uhl: Lasse, can Event.getCompetitorClassList() ever produce more than one result? @@ -360,22 +359,25 @@ public class DomainFactoryImpl implements DomainFactory { // try a quick look-up in the weak cache using the TracTrac event as key; only if that delivers no result, // compute the dominant boat class which requires a lot more effort - Regatta result = weakRegattaCache.get(event); + Regatta result = weakDefaultRegattaCache.get(race); if (result == null) { - Collection competitorClassList = event.getCompetitorClasses(); + Collection competitorClassList = new ArrayList<>(); + for (IRaceCompetitor competitor : race.getRaceCompetitors()) { + competitorClassList.add(competitor.getCompetitor().getCompetitorClass()); + } BoatClass boatClass = getDominantBoatClass(competitorClassList); - Pair key = new Pair(event.getName(), boatClass == null ? null + Pair key = new Pair(race.getName(), boatClass == null ? null : boatClass.getName()); result = regattaCache.get(key); // FIXME When a Regatta is removed from RacingEventService, it isn't removed here. We use a "stale" regatta here. // This is particularly bad if a persistent regatta was loaded but a default regatta was accidentally created. // Then, there is no way but restart the server to get rid of this stale cache entry here. if (result == null) { - result = new RegattaImpl(raceLogStore, event.getName(), boatClass, trackedRegattaRegistry, + result = new RegattaImpl(raceLogStore, race.getName(), boatClass, trackedRegattaRegistry, // use the low-point system as the default scoring scheme - getBaseDomainFactory().createScoringScheme(ScoringSchemeType.LOW_POINT), event.getId(), null); + getBaseDomainFactory().createScoringScheme(ScoringSchemeType.LOW_POINT), race.getId(), null); regattaCache.put(key, result); - weakRegattaCache.put(event, result); + weakDefaultRegattaCache.put(race, result); logger.info("Created regatta "+result.getName()+" ("+result.hashCode()+") because none found for key "+key); } } @@ -468,7 +470,7 @@ public class DomainFactoryImpl implements DomainFactory { if (oldSize > 0 && Util.size(regatta.getAllRaces()) == 0) { logger.info("Removing regatta "+regatta.getName()+" ("+regatta.hashCode()+") from TracTrac DomainFactoryImpl"); regattaCache.remove(key); - weakRegattaCache.remove(tractracEvent); + weakDefaultRegattaCache.remove(tractracRace); } TrackedRegatta trackedRegatta = trackedRegattaRegistry.getTrackedRegatta(regatta); if (trackedRegatta != null) { diff --git a/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/TracTracRaceTrackerImpl.java b/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/TracTracRaceTrackerImpl.java index c3b412d0832..f4a1dcca251 100755 --- a/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/TracTracRaceTrackerImpl.java +++ b/java/com.sap.sailing.domain.tractracadapter/src/com/sap/sailing/domain/tractracadapter/impl/TracTracRaceTrackerImpl.java @@ -325,7 +325,7 @@ public class TracTracRaceTrackerImpl extends AbstractRaceTrackerImpl implements // if regatta is still null, no previous assignment of any of the races in this TracTrac event to a Regatta was // found; // in this case, create a default regatta based on the TracTrac event data - this.regatta = effectiveRegatta == null ? domainFactory.getOrCreateDefaultRegatta(raceLogStore, tractracRace.getEvent(), trackedRegattaRegistry) : effectiveRegatta; + this.regatta = effectiveRegatta == null ? domainFactory.getOrCreateDefaultRegatta(raceLogStore, tractracRace, trackedRegattaRegistry) : effectiveRegatta; trackedRegatta = trackedRegattaRegistry.getOrCreateTrackedRegatta(this.regatta); receivers = new HashSet(); for (Receiver receiver : domainFactory.getUpdateReceivers(getTrackedRegatta(), delayToLiveInMillis, diff --git a/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingWindTracksTest.java b/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingWindTracksTest.java index c0c5dd3f80d..9738054dbd9 100755 --- a/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingWindTracksTest.java +++ b/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingWindTracksTest.java @@ -75,7 +75,7 @@ public class TestStoringAndRetrievingWindTracksTest extends AbstractTracTracLive @Test public void testStoreAFewWindEntries() throws UnknownHostException, MongoException, InterruptedException { DomainFactory domainFactory = DomainFactory.INSTANCE; - Regatta domainEvent = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracEvent(), /* trackedRegattaRegistry */ null); + Regatta domainEvent = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracRace(), /* trackedRegattaRegistry */ null); DynamicTrackedRegatta trackedRegatta = new RacingEventServiceImpl().getOrCreateTrackedRegatta(domainEvent); Iterable typeControllers = domainFactory.getUpdateReceivers(trackedRegatta, Util.get(SynchronizationUtil.getRaces(getTracTracEvent()), 0), EmptyWindStore.INSTANCE,