fix towards bug 1044: synchronize creation of control points in SwissTiming DomainFactoryImpl

This commit is contained in:
Axel Uhl
2012-11-15 13:39:42 +01:00
parent 196b16f29b
commit 34e40fa4bd
2 changed files with 22 additions and 16 deletions
@@ -193,22 +193,27 @@ public class DomainFactoryImpl implements DomainFactory {
}
private ControlPoint getOrCreateControlPoint(Iterable<String> devices) {
ControlPoint result = controlPointCache.get(devices);
if (result == null) {
switch (Util.size(devices)) {
case 1:
result = getOrCreateBuoy(devices.iterator().next());
break;
case 2:
Iterator<String> buoyNameIter = devices.iterator();
String left = buoyNameIter.next();
String right = buoyNameIter.next();
result = baseDomainFactory.createGate(getOrCreateBuoy(left), getOrCreateBuoy(right), left+"/"+right);
break;
default:
throw new RuntimeException("Don't know how to handle control points with number of devices neither 1 nor 2. Was "+Util.size(devices));
ControlPoint result;
synchronized (controlPointCache) {
result = controlPointCache.get(devices);
if (result == null) {
switch (Util.size(devices)) {
case 1:
result = getOrCreateBuoy(devices.iterator().next());
break;
case 2:
Iterator<String> buoyNameIter = devices.iterator();
String left = buoyNameIter.next();
String right = buoyNameIter.next();
result = baseDomainFactory.createGate(getOrCreateBuoy(left), getOrCreateBuoy(right), left + "/" + right);
break;
default:
throw new RuntimeException(
"Don't know how to handle control points with number of devices neither 1 nor 2. Was "
+ Util.size(devices));
}
controlPointCache.put(devices, result);
}
controlPointCache.put(devices, result);
}
return result;
}
@@ -376,7 +376,8 @@ public class CourseImpl extends NamedImpl implements Course {
// 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>>();
Map<com.sap.sailing.domain.base.ControlPoint, List<Waypoint>> existingWaypointsByControlPoint =
new HashMap<com.sap.sailing.domain.base.ControlPoint, List<Waypoint>>();
for (Waypoint waypoint : courseWaypoints) {
List<Waypoint> wpl = existingWaypointsByControlPoint.get(waypoint.getControlPoint());
if (wpl == null) {