delay rank and maneuver cache invalidation by a constant time (currently 7.5s)

This commit is contained in:
Axel Uhl
2012-03-17 15:32:27 +01:00
parent d0362c05e6
commit 5e1e724c7e
2 changed files with 27 additions and 5 deletions
@@ -12,6 +12,8 @@ import java.util.List;
import java.util.Map;
import java.util.NavigableSet;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -85,6 +87,9 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
*/
private static final double GEONAMES_RADIUS_CACLCULATION_FACTOR = 10.0;
// TODO make this variable
private static final long DELAY_FOR_CACHE_CLEARING_IN_MILLISECONDS = 7500;
// TODO observe the race course; if it changes, update leg structures; consider fine-grained update events that tell
// what changed
private final RaceDefinition race;
@@ -153,6 +158,8 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
private final WindStore windStore;
private Timer cacheInvalidationTimer;
public TrackedRaceImpl(TrackedEvent trackedEvent, RaceDefinition race, WindStore windStore,
long millisecondsOverWhichToAverageWind, long millisecondsOverWhichToAverageSpeed) {
this(trackedEvent, race, windStore, millisecondsOverWhichToAverageWind, millisecondsOverWhichToAverageSpeed,
@@ -672,12 +679,26 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
notifyAll();
}
/**
* Schedules the clearing of the caches. If a cache clearing is already scheduled, this is a no-op.
*/
private synchronized void clearAllCaches() {
synchronized (competitorRankings) {
competitorRankings.clear();
}
synchronized (maneuverCache) {
maneuverCache.clear();
if (cacheInvalidationTimer == null) {
cacheInvalidationTimer = new Timer("Cache invalidation timer for TrackedRaceImpl " + getRace().getName());
cacheInvalidationTimer.schedule(new TimerTask() {
@Override
public void run() {
synchronized (TrackedRaceImpl.this) {
cacheInvalidationTimer = null;
synchronized (competitorRankings) {
competitorRankings.clear();
}
synchronized (maneuverCache) {
maneuverCache.clear();
}
}
}
}, DELAY_FOR_CACHE_CLEARING_IN_MILLISECONDS);
}
}
@@ -15,6 +15,7 @@
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/sapvm"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -console -clean"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Xmx2048m -Djetty.home=${project_loc:com.sap.sailing.server}/../target/configuration/jetty -Djava.util.logging.config.file=${project_loc:com.sap.sailing.server}/../target/configuration/logging_debug.properties"/>