From b2c8cb53efd135eb37f603c040a5b9058caae2f7 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 3 Jul 2012 00:18:59 +0200 Subject: [PATCH] cross track error cache seems fixed --- .../domain/tracking/impl/CrossTrackErrorCache.java | 13 +++++++++---- .../com/sap/sailing/util/impl/SmartFutureCache.java | 10 +++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/CrossTrackErrorCache.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/CrossTrackErrorCache.java index 747c5c352e7..ad97319061c 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/CrossTrackErrorCache.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/CrossTrackErrorCache.java @@ -206,6 +206,10 @@ public class CrossTrackErrorCache extends AbstractRaceChangeListener { if (startAggregate == null) { startAggregate = cacheForCompetitor.getLastFixAtOrBefore(start); } + if (startAggregate == null) { + startAggregate = new CrossTrackErrorSumAndNumberOfFixes(/* time point */ null, + /* distanceInMetersSumFromStart */ 0, /* fixCountFromStart */ 0); + } CrossTrackErrorSumAndNumberOfFixes endAggregate; TimePoint end; if (legEndMarkPassing == null || legEndMarkPassing.getTimePoint().compareTo(to) >= 0) { @@ -216,10 +220,11 @@ public class CrossTrackErrorCache extends AbstractRaceChangeListener { } if (from.compareTo(end) < 0) { endAggregate = cacheForCompetitor.getLastFixAtOrBefore(end); - distanceInMeters += endAggregate.getDistanceInMetersSumFromStart() - - startAggregate.getDistanceInMetersSumFromStart(); - count += endAggregate.getFixCountFromStart() - startAggregate.getFixCountFromStart(); - startAggregate = endAggregate; + if (endAggregate != null) { + distanceInMeters += endAggregate.getDistanceInMetersSumFromStart() - startAggregate.getDistanceInMetersSumFromStart(); + count += endAggregate.getFixCountFromStart() - startAggregate.getFixCountFromStart(); + startAggregate = endAggregate; + } } } } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/util/impl/SmartFutureCache.java b/java/com.sap.sailing.domain/src/com/sap/sailing/util/impl/SmartFutureCache.java index 9644b552256..738f5bb4a16 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/util/impl/SmartFutureCache.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/util/impl/SmartFutureCache.java @@ -203,6 +203,7 @@ public class SmartFutureCache> { return result; } finally { getOrCreateLockForKey(key).writeLock().unlock(); + ongoingRecalculations.remove(key); } } catch (Throwable e) { // cache won't be updated @@ -217,7 +218,7 @@ public class SmartFutureCache> { } public V get(K key, boolean waitForLatest) { - V value; + V value = null; if (waitForLatest) { FutureTaskWithCancelBlocking future; synchronized (ongoingRecalculations) { @@ -225,6 +226,8 @@ public class SmartFutureCache> { future = ongoingRecalculations.get(key); if (future != null) { future.dontCancel(); + } else { + value = cache.get(key); } } if (future != null) { @@ -233,10 +236,7 @@ public class SmartFutureCache> { } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } - } else { - // no calculation currently going on; we probably don't know anything about this key - value = null; - } + } // else no calculation currently going on; value has been fetched from latest cache entry } else { getOrCreateLockForKey(key).readLock().lock(); try {