From b1839449826859a16e5ca3aef9c81d8676b27cea Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Thu, 6 Dec 2012 17:38:27 -0600 Subject: [PATCH] Issue #1328 Fixed time matching error for 4-panel products where No Data Available on some of the panes Amend: Changed time cache object to have single setter for setting fields, changed map to identity map Change-Id: I598e9033187b794631d1dbfc78bb018084ec95cf Former-commit-id: 0cda5a49eef963c646486373565185a637a6b929 [formerly dbc9141454a2fb63e4a9c209f56907b706332961] [formerly 8fc766ab0540c20ef14e2fee38fa9af64d6d1b5e] [formerly 0cda5a49eef963c646486373565185a637a6b929 [formerly dbc9141454a2fb63e4a9c209f56907b706332961] [formerly 8fc766ab0540c20ef14e2fee38fa9af64d6d1b5e] [formerly 424c6e0b1be83bbea365444a3d3c3024d5abda32 [formerly 8fc766ab0540c20ef14e2fee38fa9af64d6d1b5e [formerly 9a5766f8a6bd61734b2f9e44aaabbef835d1d676]]]] Former-commit-id: 424c6e0b1be83bbea365444a3d3c3024d5abda32 Former-commit-id: d05d9c1904e70ff0258d25d3c3541c18377384cc [formerly 9a978a9156ac3bd88dfee3000d274e3be5607d93] [formerly 598a914c099b0e3e8613a8f807aaaa1c214ae6c0 [formerly 4cb9cc563215a626dae592e37fcef2cdced54ce5]] Former-commit-id: 68e92f951b16bc8ffce114577a92cd77f5d11e74 [formerly 87ad71d28d08a8793ca95cb4fb41319298193a1f] Former-commit-id: 057dc3019a540d66d18a4e90c27c3c3eecc8568e --- .../uf/viz/d2d/core/time/D2DTimeMatcher.java | 102 ++++++++++++------ .../core/time/TimeMatchingConfiguration.java | 35 ------ 2 files changed, 69 insertions(+), 68 deletions(-) diff --git a/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/time/D2DTimeMatcher.java b/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/time/D2DTimeMatcher.java index 1048c12fc6..d086a1c9dd 100644 --- a/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/time/D2DTimeMatcher.java +++ b/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/time/D2DTimeMatcher.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -84,6 +85,44 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(D2DTimeMatcher.class); + private static class TimeCache { + /** + * The last set of times that the resource with these properties was + * matched against. As long as we are matching against these same times + * then lastFrameTimes is valid. + */ + private DataTime[] lastBaseTimes; + + /** The result of the last time matching. */ + private DataTime[] lastFrameTimes; + + /** The number of frames time matched against */ + private int lastFrameCount; + + public DataTime[] getLastBaseTimes() { + return lastBaseTimes; + } + + public DataTime[] getLastFrameTimes() { + return lastFrameTimes; + } + + public int getLastFrameCount() { + return lastFrameCount; + } + + public void setTimes(DataTime[] baseTimes, DataTime[] frameTimes) { + setTimes(baseTimes, frameTimes, -1); + } + + public void setTimes(DataTime[] baseTimes, DataTime[] frameTimes, + int frameCount) { + this.lastBaseTimes = baseTimes; + this.lastFrameTimes = frameTimes; + this.lastFrameCount = frameCount; + } + } + protected transient AbstractVizResource timeMatchBasis; private IDisposeListener timeMatchBasisDisposeListener = new IDisposeListener() { @@ -121,6 +160,8 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { private AbstractTimeMatchingConfigurationFactory configFactory; + private Map, TimeCache> timeCacheMap = new IdentityHashMap, D2DTimeMatcher.TimeCache>(); + /** * Default Constructor. */ @@ -136,10 +177,10 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { } public void redoTimeMatching(AbstractVizResource resource) { - TimeMatchingConfiguration config = getConfiguration(resource - .getLoadProperties()); - config.setLastBaseTimes(null); - config.setLastFrameTimes(null); + TimeCache cache = timeCacheMap.get(resource); + if (cache != null) { + cache.setTimes(null, null); + } } /* @@ -149,7 +190,6 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { */ @Override public void redoTimeMatching(IDescriptor descriptor) throws VizException { - synchronized (this) { if (timeMatchBasis != null) { IDescriptor tmDescriptor = timeMatchBasis.getDescriptor(); @@ -311,9 +351,10 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { if (rsc != timeMatchBasis) { TimeMatchingConfiguration config = getConfiguration(rsc .getLoadProperties()); + TimeCache timeCache = getTimeCache(rsc); DataTime[] timeSteps = getFrameTimes(descriptor, framesInfo); - if (Arrays.equals(timeSteps, config.getLastBaseTimes())) { - framesInfo.getTimeMap().put(rsc, config.getLastFrameTimes()); + if (Arrays.equals(timeSteps, timeCache.getLastBaseTimes())) { + framesInfo.getTimeMap().put(rsc, timeCache.getLastFrameTimes()); } else { config = config.clone(); if (config.getDataTimes() == null @@ -325,10 +366,7 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { config.getDataTimes(), config.getClock(), timeSteps, config.getLoadMode(), config.getForecast(), config.getDelta(), config.getTolerance()); - getConfiguration(rsc.getLoadProperties()).setLastBaseTimes( - timeSteps); - getConfiguration(rsc.getLoadProperties()).setLastFrameTimes( - overlayDates); + timeCache.setTimes(timeSteps, overlayDates); framesInfo.getTimeMap().put(rsc, overlayDates); } } @@ -404,15 +442,12 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { private DataTime[] findBasisTimes(ResourceList resourceList, int numberOfFrames) throws VizException { if (timeMatchBasis != null) { - TimeMatchingConfiguration config = getConfiguration(timeMatchBasis - .getLoadProperties()); - DataTime[] times = config.getLastFrameTimes(); - if (times == null || config.getLastBaseTimes() != null - || config.getLastFrameCount() != numberOfFrames) { + TimeCache timeCache = getTimeCache(timeMatchBasis); + DataTime[] times = timeCache.getLastFrameTimes(); + if (times == null || timeCache.getLastBaseTimes() != null + || timeCache.getLastFrameCount() != numberOfFrames) { times = makeEmptyLoadList(numberOfFrames, timeMatchBasis); - config.setLastFrameTimes(times); - config.setLastBaseTimes(null); - config.setLastFrameCount(numberOfFrames); + timeCache.setTimes(null, times, numberOfFrames); } if (times != null) { return times; @@ -443,9 +478,8 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { } } else { DataTime[] times = makeEmptyLoadList(numberOfFrames, rsc); - getConfiguration(rsc.getLoadProperties()).setLastFrameTimes( - times); if (times != null) { + getTimeCache(rsc).setTimes(null, times, numberOfFrames); return times; } } @@ -541,7 +575,15 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { } } return new TimeMatchingConfiguration(); + } + private TimeCache getTimeCache(AbstractVizResource resource) { + TimeCache cache = timeCacheMap.get(resource); + if (cache == null) { + cache = new TimeCache(); + timeCacheMap.put(resource, cache); + } + return cache; } /** @@ -692,6 +734,7 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { timeMatchBasis = null; } } + timeCacheMap.remove(resource); } /** @@ -742,7 +785,6 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { config.getDataTimes(), config.getClock(), descriptor.getNumberOfFrames(), config.getLoadMode(), config.getForecast(), config.getDelta()); - getConfiguration(loadProps).setLastFrameTimes(dataTimesToLoad); } else { config = configFactory.getOverlayConfiguration(loadProps, this, availableTimes, descriptor); @@ -764,9 +806,6 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { config.getForecast(), config.getDelta(), config.getTolerance()); - getConfiguration(loadProps).setLastBaseTimes(existingDataTimes); - getConfiguration(loadProps).setLastFrameTimes(dataTimesToLoad); - if (timeMatchBasis.getDescriptor() != null && timeMatchBasis.getDescriptor() != descriptor) { // Still use my times, but the index from the time match basis @@ -789,23 +828,20 @@ public class D2DTimeMatcher extends AbstractTimeMatcher { */ public void changeTimeMatchBasis(AbstractVizResource resource) { if (timeMatchBasis != resource) { + TimeMatchingConfiguration config = getConfiguration(resource + .getLoadProperties()); + TimeCache timeCache = getTimeCache(resource); if (timeMatchBasis != null) { - TimeMatchingConfiguration config = getConfiguration(timeMatchBasis - .getLoadProperties()); config.setTimeMatchBasis(false); - config.setLastBaseTimes(null); - config.setLastFrameTimes(null); + timeCache.setTimes(null, null); timeMatchBasis .unregisterListener(timeMatchBasisDisposeListener); } timeMatchBasis = resource; if (timeMatchBasis != null) { - TimeMatchingConfiguration config = getConfiguration(timeMatchBasis - .getLoadProperties()); config.setTimeMatchBasis(true); - config.setLastBaseTimes(null); - config.setLastFrameTimes(null); + timeCache.setTimes(null, null); timeMatchBasis.registerListener(timeMatchBasisDisposeListener); } } diff --git a/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/time/TimeMatchingConfiguration.java b/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/time/TimeMatchingConfiguration.java index 6b5d184b11..a7a4f4efad 100644 --- a/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/time/TimeMatchingConfiguration.java +++ b/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/time/TimeMatchingConfiguration.java @@ -59,17 +59,6 @@ public class TimeMatchingConfiguration { private boolean timeMatchBasis = false; - // The last set of times that the resource with these properties was matched - // against. As long as we are matching against these same times then - // lastFrameTimes is valid. - private DataTime[] lastBaseTimes; - - // The result of the last time matching. - private DataTime[] lastFrameTimes; - - // The number of frames time matched against - private int lastFrameCount; - /** * Default Constructor */ @@ -217,28 +206,4 @@ public class TimeMatchingConfiguration { this.cancel = cancel; } - public DataTime[] getLastBaseTimes() { - return lastBaseTimes; - } - - public void setLastBaseTimes(DataTime[] lastBaseTimes) { - this.lastBaseTimes = lastBaseTimes; - } - - public DataTime[] getLastFrameTimes() { - return lastFrameTimes; - } - - public void setLastFrameTimes(DataTime[] lastFrameTimes) { - this.lastFrameTimes = lastFrameTimes; - } - - public void setLastFrameCount(int lastFrameCount) { - this.lastFrameCount = lastFrameCount; - } - - public int getLastFrameCount() { - return lastFrameCount; - } - }