cross track error cache seems fixed

This commit is contained in:
Axel Uhl committed 2012-07-03 00:18:59 +02:00
1 parent e791ce6f92
commit b2c8cb53ef
2 files changed
+14 -9

No files matched your search

@@ -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;
}
}
}
}
@@ -203,6 +203,7 @@ public class SmartFutureCache<K, V, U extends UpdateInterval<U>> {
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<K, V, U extends UpdateInterval<U>> {
}
public V get(K key, boolean waitForLatest) {
V value;
V value = null;
if (waitForLatest) {
FutureTaskWithCancelBlocking<V, U> future;
synchronized (ongoingRecalculations) {
@@ -225,6 +226,8 @@ public class SmartFutureCache<K, V, U extends UpdateInterval<U>> {
future = ongoingRecalculations.get(key);
if (future != null) {
future.dontCancel();
} else {
value = cache.get(key);
}
}
if (future != null) {
@@ -233,10 +236,7 @@ public class SmartFutureCache<K, V, U extends UpdateInterval<U>> {
} 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 {