Issue #1890 moved date keys to references in FFMPRecord instead of hard object in FFMPBasin

Change-Id: I840e0805422686856744f0d39dda0aeac4755bb8

Former-commit-id: 978e68d893 [formerly 4c1e41a6a77ea89f2a0c0253671b8d6cca071c04]
Former-commit-id: 60fa768195
This commit is contained in:
Dave Hladky 2013-04-10 16:08:17 -05:00
parent e720bf74b5
commit c52445652a
11 changed files with 309 additions and 838 deletions

View file

@ -93,6 +93,7 @@ import com.raytheon.uf.viz.monitor.listeners.IMonitorListener;
* 02/19/13 1639 njensen Replaced ConcurrentHashMaps with data structures * 02/19/13 1639 njensen Replaced ConcurrentHashMaps with data structures
* 02/20/13 1635 D. Hladky Fixed multi guidance sources * 02/20/13 1635 D. Hladky Fixed multi guidance sources
* Mar 6, 2013 1769 dhladky Changed threading to use count down latch. * Mar 6, 2013 1769 dhladky Changed threading to use count down latch.
* Apr 9, 2013 1890 dhladky Fixed the broken cache file load
* *
* </pre> * </pre>
* *
@ -386,19 +387,40 @@ public class FFMPMonitor extends ResourceMonitor {
* @param dataKey * @param dataKey
* @param source * @param source
*/ */
public void insertFFMPData(FFMPAggregateRecord data, String siteKey, public void insertFFMPData(FFMPAggregateRecord data,
String source) { NavigableMap<Date, List<String>> uris, String siteKey, String source) {
// TODO do we need this method if we're no longer supporting cache
// records? // get record from cache
if (siteDataMap.containsSite(siteKey)) { FFMPSourceData sourceData = siteDataMap.get(siteKey).getSourceData(source);
if (siteDataMap.get(siteKey).containsSource(source)) { FFMPRecord curRecord = sourceData.getRecord();
for (Entry<String, FFMPBasinData> entry : data.getBasinsMap()
.entrySet()) { if (curRecord == null) {
FFMPBasinData basinData = entry.getValue(); // add each huc requested
basinData.populate(data.getTimes()); for (String huc : data.getBasinsMap().keySet()) {
// add all of the uris
for (Entry<Date, List<String>> duris : uris.entrySet()) {
for (String uri : duris.getValue()) {
if (curRecord == null) {
curRecord = new FFMPRecord(uri);
sourceData.setRecord(curRecord);
}
sourceData.addLoadedUri(huc, uri);
}
} }
} }
} }
if (curRecord != null) {
for (Entry<String, FFMPBasinData> entry : data.getBasinsMap()
.entrySet()) {
FFMPBasinData basinData = entry.getValue();
basinData.populate(data.getTimes());
curRecord.populate(basinData, entry.getKey());
}
}
} }
/** /**

View file

@ -56,6 +56,7 @@ import com.raytheon.uf.viz.monitor.ffmp.xml.FFMPTableColumnXML;
* Aug 01, 2012 14168 mpduff Add convenience methods for * Aug 01, 2012 14168 mpduff Add convenience methods for
* getting ColorCell and ReverseFilter * getting ColorCell and ReverseFilter
* Apr 12, 2013 1902 mpduff Speed up cell coloring. * Apr 12, 2013 1902 mpduff Speed up cell coloring.
* Apr 15. 2013 1890 dhladky Added Mikes fix for singleton.
* *
* </pre> * </pre>
* *
@ -128,27 +129,9 @@ public class FFMPConfig {
} }
public static synchronized FFMPConfig getInstance() { public static synchronized FFMPConfig getInstance() {
if (classInstance == null) {
classInstance = new FFMPConfig();
}
return classInstance; return classInstance;
} }
public void disposeResources() {
upperColor.dispose();
midColor.dispose();
lowerColor.dispose();
belowLowerColor.dispose();
defaultColor.dispose();
forcedFFGColor.dispose();
vgbColor.dispose();
}
public static void unloadConfig() {
classInstance = null;
}
private void init() { private void init() {
threshMgrMap = new HashMap<ThreshColNames, ThresholdManager>(); threshMgrMap = new HashMap<ThreshColNames, ThresholdManager>();

View file

@ -319,8 +319,8 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements
dataLoadFont.dispose(); dataLoadFont.dispose();
timeDurFont.dispose(); timeDurFont.dispose();
FFMPConfig.getInstance().disposeResources(); //FFMPConfig.getInstance().disposeResources();
FFMPConfig.unloadConfig(); //FFMPConfig.unloadConfig();
if (refreshColor != null) { if (refreshColor != null) {
refreshColor.dispose(); refreshColor.dispose();
@ -1311,15 +1311,20 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements
if (attributeDlg == null || attributeDlg.isDisposed()) { if (attributeDlg == null || attributeDlg.isDisposed()) {
attrData = ffmpTable.getVisibleColumns(); attrData = ffmpTable.getVisibleColumns();
attributeDlg = new AttributesDlg(shell, resource, attrData, this); attributeDlg = new AttributesDlg(shell, resource, attrData, this);
attributeDlg.open();
} else {
attributeDlg.bringToTop();
} }
attributeDlg.open();
} }
private void displayThresholdsDialog(ThreshColNames colName) { private void displayThresholdsDialog(ThreshColNames colName) {
if (attrThreshDlg == null) { if (attrThreshDlg == null) {
attrThreshDlg = new AttributeThresholdDlg(shell, colName, this); attrThreshDlg = new AttributeThresholdDlg(shell, colName, this);
attrThreshDlg.open();
} else {
attrThreshDlg.bringToTop();
} }
attrThreshDlg.open();
attrThreshDlg.newThreshold(colName); attrThreshDlg.newThreshold(colName);
} }
@ -2105,13 +2110,17 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements
shell.pack(); shell.pack();
} }
String prefix = null; String prefix = null;
if (status.getLoaderType() == LOADER_TYPE.SECONDARY) { if (status.getLoaderType() == LOADER_TYPE.SECONDARY) {
prefix = " Secondary Data Load: "; prefix = " Secondary Data Load: ";
} else { } else if (status.getLoaderType() == LOADER_TYPE.TERTIARY) {
prefix = " Tertiary Data Load: "; prefix = " Tertiary Data Load: ";
} } else if (status.getLoaderType() == LOADER_TYPE.GENERAL) {
prefix = " General Data Load: ";
} else {
prefix = " Tertiary Data Load: ";
}
if (status.isDone() == false) { if (status.isDone() == false) {
dataLoadingLbl.setText(prefix + status.getMessage()); dataLoadingLbl.setText(prefix + status.getMessage());

View file

@ -24,6 +24,7 @@ import java.util.List;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasin; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasin;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceInterpolation; import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceInterpolation;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord;
import com.raytheon.uf.common.dataplugin.ffmp.FFMPTemplates; import com.raytheon.uf.common.dataplugin.ffmp.FFMPTemplates;
import com.raytheon.uf.common.monitor.config.FFFGDataMgr; import com.raytheon.uf.common.monitor.config.FFFGDataMgr;
import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager; import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager;
@ -41,6 +42,7 @@ import com.raytheon.uf.common.monitor.xml.SourceXML;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jul 20, 2011 mpduff Initial creation * Jul 20, 2011 mpduff Initial creation
* 01/14/13 1569 dhladky changed arraylist to list * 01/14/13 1569 dhladky changed arraylist to list
* 04/15/13 1890 dhladky Changed COUNTY to use constant
* *
* </pre> * </pre>
* *
@ -132,7 +134,7 @@ public class FFFGForceUtil {
pfafList = ft.getAggregatePfafs(cBasin.getPfaf(), pfafList = ft.getAggregatePfafs(cBasin.getPfaf(),
resource.getSiteKey(), resource.getHuc()); resource.getSiteKey(), resource.getHuc());
} else if (!domain.equals("NA")) { } else if (!domain.equals("NA")) {
if (!resource.getHuc().equals("ALL")) { if (!resource.getHuc().equals(FFMPRecord.ALL)) {
pfafList = ft.getAggregatePfafsByDomain(cBasin.getPfaf(), pfafList = ft.getAggregatePfafsByDomain(cBasin.getPfaf(),
resource.getSiteKey(), domain, resource.getHuc()); resource.getSiteKey(), domain, resource.getHuc());
} }

View file

@ -72,6 +72,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.dialogs.FfmpTableConfigData;
* feb 20, 2013 1635 dhladky Fixed multi guidance displays * feb 20, 2013 1635 dhladky Fixed multi guidance displays
* Feb 28, 2013 1729 dhladky General enhancements for speed. * Feb 28, 2013 1729 dhladky General enhancements for speed.
* Apr 12, 2013 1902 mpduff Code Cleanup. * Apr 12, 2013 1902 mpduff Code Cleanup.
* Apr 15, 2013 1890 dhladky Added another constant fix
* </pre> * </pre>
* *
* @author dhladky * @author dhladky
@ -818,7 +819,7 @@ public class FFMPDataGenerator {
ArrayList<Long> pfafs = ft.getAggregatePfafs(basin.getPfaf(), ArrayList<Long> pfafs = ft.getAggregatePfafs(basin.getPfaf(),
siteKey, huc); siteKey, huc);
if (!pfafs.isEmpty()) { if (!pfafs.isEmpty()) {
if (huc.equals("COUNTY")) { if (huc.equals(FFMPRecord.COUNTY)) {
name = ft.getCountyStateName(siteKey, basin.getPfaf()); name = ft.getCountyStateName(siteKey, basin.getPfaf());
} else { } else {
for (int i = 0; i < pfafs.size(); i++) { for (int i = 0; i < pfafs.size(); i++) {

View file

@ -20,7 +20,6 @@
package com.raytheon.uf.viz.monitor.ffmp.ui.rsc; package com.raytheon.uf.viz.monitor.ffmp.ui.rsc;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -67,6 +66,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.listeners.FFMPLoaderEvent;
* 02/01/13 1569 D. Hladky Changed to reading aggregate records from pypies * 02/01/13 1569 D. Hladky Changed to reading aggregate records from pypies
* Feb 28, 2013 1729 dhladky Changed the way status messages are sent to the FFMP Dialog. * Feb 28, 2013 1729 dhladky Changed the way status messages are sent to the FFMP Dialog.
* Mar 6, 2013 1769 dhladky Changed threading to use count down latch. * Mar 6, 2013 1769 dhladky Changed threading to use count down latch.
* Apr 9, 2013 1890 dhladky removed loading of phantom Virtual template and cache file processing.
* </pre> * </pre>
* *
* @author dhladky * @author dhladky
@ -74,7 +74,8 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.listeners.FFMPLoaderEvent;
*/ */
public class FFMPDataLoader extends Thread { public class FFMPDataLoader extends Thread {
private static final IUFStatusHandler statusHandler = UFStatus.getHandler(FFMPDataLoader.class); private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(FFMPDataLoader.class);
private ProductXML product = null; private ProductXML product = null;
@ -156,13 +157,14 @@ public class FFMPDataLoader extends Thread {
@Override @Override
public void run() { public void run() {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
try { try {
resourceData.setLoader(loadType); resourceData.setLoader(loadType);
FFMPMonitor monitor = getMonitor(); FFMPMonitor monitor = getMonitor();
FFMPSourceConfigurationManager sourceConfig = monitor.getSourceConfig(); FFMPSourceConfigurationManager sourceConfig = monitor
.getSourceConfig();
ProductRunXML productRun = runner.getProduct(siteKey); ProductRunXML productRun = runner.getProduct(siteKey);
ArrayList<String> qpfSources = new ArrayList<String>(); ArrayList<String> qpfSources = new ArrayList<String>();
@ -235,6 +237,10 @@ public class FFMPDataLoader extends Thread {
if (loadType == LOADER_TYPE.TERTIARY) { if (loadType == LOADER_TYPE.TERTIARY) {
hucsToLoad.clear(); hucsToLoad.clear();
hucsToLoad.add(FFMPRecord.ALL); hucsToLoad.add(FFMPRecord.ALL);
} else {
// Only used as place holder name, No data is linked to it, uses
// ALL
hucsToLoad.remove(FFMPRecord.VIRTUAL);
} }
if (isDone()) { if (isDone()) {
@ -253,29 +259,28 @@ public class FFMPDataLoader extends Thread {
} }
// qpes // qpes
fireLoaderEvent(loadType, "Processing " + product.getQpe(), isDone()); fireLoaderEvent(loadType, "Processing " + product.getQpe(),
isDone());
FFMPAggregateRecord qpeCache = null; FFMPAggregateRecord qpeCache = null;
if (loadType == LOADER_TYPE.INITIAL) { if (loadType == LOADER_TYPE.INITIAL) {
SourceXML source = sourceConfig.getSource( SourceXML source = sourceConfig.getSource(product.getQpe());
product.getQpe());
qpeCache = readAggregateRecord(source, dataKey, wfo); qpeCache = readAggregateRecord(source, dataKey, wfo);
if (qpeCache != null) { if (qpeCache != null) {
monitor.insertFFMPData(qpeCache, siteKey, monitor.insertFFMPData(qpeCache, qpeURIs, siteKey, product.getQpe());
product.getQpe());
} }
} }
// Use this method of QPE data retrieval if you don't have cache files // Use this method of QPE data retrieval if you don't have cache
// files
if (!qpeURIs.isEmpty() && qpeCache == null) { if (!qpeURIs.isEmpty() && qpeCache == null) {
for (String phuc : hucsToLoad) { for (String phuc : hucsToLoad) {
if (phuc.equals(layer) if (phuc.equals(layer) || phuc.equals(FFMPRecord.ALL)) {
|| phuc.equals(FFMPRecord.ALL)) { monitor.processUris(qpeURIs, isProductLoad, siteKey,
monitor.processUris(qpeURIs, isProductLoad, product.getQpe(), timeBack, phuc);
siteKey, product.getQpe(), timeBack, phuc);
} }
} }
} }
@ -291,7 +296,6 @@ public class FFMPDataLoader extends Thread {
if (loadType == LOADER_TYPE.INITIAL) { if (loadType == LOADER_TYPE.INITIAL) {
SourceXML source = sourceConfig SourceXML source = sourceConfig
.getSource(qpfSources.get(i)); .getSource(qpfSources.get(i));
@ -300,36 +304,36 @@ public class FFMPDataLoader extends Thread {
if (qpfCache != null) { if (qpfCache != null) {
for (String phuc : hucsToLoad) { for (String phuc : hucsToLoad) {
if ((phuc.equals(layer) || phuc.equals(FFMPRecord.ALL)) if ((phuc.equals(layer) || phuc
.equals(FFMPRecord.ALL))
&& loadType == LOADER_TYPE.INITIAL && loadType == LOADER_TYPE.INITIAL
&& source.getSourceName().equals( && source.getSourceName().equals(
config.getFFMPConfigData() config.getFFMPConfigData()
.getIncludedQPF())) { .getIncludedQPF())) {
if (!qpfURIs.isEmpty()) { if (!qpfURIs.isEmpty()) {
monitor.processUris(qpfURIs, monitor.processUris(qpfURIs, isProductLoad,
isProductLoad, siteKey, siteKey, source.getSourceName(),
source.getSourceName(), timeBack, timeBack, phuc);
phuc);
} }
} }
} }
monitor.insertFFMPData(qpfCache, siteKey, monitor.insertFFMPData(qpfCache, qpfURIs, siteKey,
source.getSourceName()); source.getSourceName());
} }
} }
// if (isUrisProcessNeeded(qpfData,qpfURIs)) // if (isUrisProcessNeeded(qpfData,qpfURIs))
// {/*DR13839*/ // {/*DR13839*/
// Use this method of QPF data retrieval if you don't have cache files // Use this method of QPF data retrieval if you don't have cache
// files
if ((qpfCache == null) && !qpfURIs.isEmpty()) { if ((qpfCache == null) && !qpfURIs.isEmpty()) {
for (String phuc : hucsToLoad) { for (String phuc : hucsToLoad) {
if (phuc.equals(layer) if (phuc.equals(layer) || phuc.equals(FFMPRecord.ALL)) { // old
|| phuc.equals(FFMPRecord.ALL)) { // old // code:
// code: // keep
// keep // for
// for // reference*/
// reference*/
// if (isHucProcessNeeded(phuc)) {/*DR13839*/ // if (isHucProcessNeeded(phuc)) {/*DR13839*/
monitor.processUris(qpfURIs, isProductLoad, monitor.processUris(qpfURIs, isProductLoad,
siteKey, product.getQpf(i), timeBack, phuc); siteKey, product.getQpf(i), timeBack, phuc);
@ -344,24 +348,8 @@ public class FFMPDataLoader extends Thread {
fireLoaderEvent(loadType, "Processing " + product.getVirtual(), fireLoaderEvent(loadType, "Processing " + product.getVirtual(),
isDone()); isDone());
FFMPAggregateRecord vgbCache = null; // process virtual all for all only, never uses cache files
if (!virtualURIs.isEmpty()) {
if (loadType == LOADER_TYPE.INITIAL) {
SourceXML source = sourceConfig.getSource(
product.getVirtual());
vgbCache = readAggregateRecord(source, dataKey, wfo);
if (vgbCache != null) {
monitor.insertFFMPData(vgbCache, siteKey,
product.getVirtual());
}
}
// Use this method of Virtual data retrieval if you don't have cache files
if ((vgbCache == null) && !virtualURIs.isEmpty()) {
monitor.processUris(virtualURIs, isProductLoad, siteKey, monitor.processUris(virtualURIs, isProductLoad, siteKey,
product.getVirtual(), timeBack, FFMPRecord.ALL); product.getVirtual(), timeBack, FFMPRecord.ALL);
} }
@ -379,10 +367,12 @@ public class FFMPDataLoader extends Thread {
.get(guidSource.getSourceName()); .get(guidSource.getSourceName());
fireLoaderEvent(loadType, fireLoaderEvent(loadType,
"Processing " + guidSource.getSourceName(), isDone()); "Processing " + guidSource.getSourceName(),
isDone());
monitor.processUris(iguidURIs, isProductLoad, siteKey, monitor.processUris(iguidURIs, isProductLoad, siteKey,
guidSource.getSourceName(), timeBack, FFMPRecord.ALL); guidSource.getSourceName(), timeBack,
FFMPRecord.ALL);
fireLoaderEvent(loadType, guidSource.getSourceName(), fireLoaderEvent(loadType, guidSource.getSourceName(),
isDone()); isDone());
@ -390,10 +380,11 @@ public class FFMPDataLoader extends Thread {
} }
} }
} catch (Exception e) { } catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,"General Problem in Loading FFMP Data", e); statusHandler.handle(Priority.PROBLEM,
"General Problem in Loading FFMP Data", e);
} finally { } finally {
latch.countDown(); latch.countDown();
synchronized(this) { synchronized (this) {
this.notifyAll(); this.notifyAll();
} }
} }
@ -406,7 +397,8 @@ public class FFMPDataLoader extends Thread {
} }
long endTime = (System.currentTimeMillis()) - time; long endTime = (System.currentTimeMillis()) - time;
System.out.println(loadType.loaderType + " Loader took: " + endTime / 1000 + " seconds"); System.out.println(loadType.loaderType + " Loader took: " + endTime
/ 1000 + " seconds");
fireLoaderEvent(loadType, message, isDone()); fireLoaderEvent(loadType, message, isDone());
} }
@ -503,7 +495,8 @@ public class FFMPDataLoader extends Thread {
try { try {
// we are just checking if it exists or not // we are just checking if it exists or not
String pdataKey = product.getProductKey(); String pdataKey = product.getProductKey();
String sourceSiteDataKey = getSourceSiteDataKey(source, pdataKey); String sourceSiteDataKey = getSourceSiteDataKey(source,
pdataKey);
File hdf5File = FFMPUtils.getHdf5File(wfo, sourceSiteDataKey); File hdf5File = FFMPUtils.getHdf5File(wfo, sourceSiteDataKey);
DataStoreFactory.getDataStore(hdf5File); DataStoreFactory.getDataStore(hdf5File);
@ -516,16 +509,16 @@ public class FFMPDataLoader extends Thread {
return siteKey; return siteKey;
} }
/** /**
* Get the sourceSiteDataKey for this piece of data * Get the sourceSiteDataKey for this piece of data
*
* @param source * @param source
* @param pdataKey * @param pdataKey
* @return * @return
*/ */
private String getSourceSiteDataKey(SourceXML source, String pdataKey) { private String getSourceSiteDataKey(SourceXML source, String pdataKey) {
return source.getSourceName() + "-" + siteKey + "-" return source.getSourceName() + "-" + siteKey + "-" + pdataKey;
+ pdataKey;
} }
public boolean isDone() { public boolean isDone() {

View file

@ -163,6 +163,7 @@ import com.vividsolutions.jts.geom.Point;
* Feb 20, 2013 1635 dhladky Fixed multiple guidance display * Feb 20, 2013 1635 dhladky Fixed multiple guidance display
* Feb 28, 2013 1729 dhladky Changed the way the loaders are managed via the status updates. * Feb 28, 2013 1729 dhladky Changed the way the loaders are managed via the status updates.
* Mar 6, 2013 1769 dhladky Changed threading to use count down latch. * Mar 6, 2013 1769 dhladky Changed threading to use count down latch.
* Apr 9, 2013 1890 dhladky General cleanup.
* Apr 10, 2013 1896 bsteffen Make FFMPResource work better with D2D * Apr 10, 2013 1896 bsteffen Make FFMPResource work better with D2D
* time matcher. * time matcher.
* </pre> * </pre>
@ -1219,7 +1220,7 @@ public class FFMPResource extends
paintProps.setAlpha(getCapability(ImagingCapability.class) paintProps.setAlpha(getCapability(ImagingCapability.class)
.getAlpha()); .getAlpha());
boolean isShaded = isPolygonal(); boolean isShaded = true;
FFMPDrawable drawable = null; FFMPDrawable drawable = null;
if (paintTime != null) { if (paintTime != null) {
@ -1571,14 +1572,6 @@ public class FFMPResource extends
return geometryType; return geometryType;
} }
protected boolean isLineal() {
return getGeometryType().endsWith("LINESTRING");
}
protected boolean isPolygonal() {
return getGeometryType().endsWith("POLYGON");
}
/** /**
* Get color wrapper class * Get color wrapper class
* *

View file

@ -31,6 +31,7 @@ import javax.persistence.Transient;
import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.ISerializableObject;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.util.ImmutableDate;
/** /**
* FFMP basin/aggregated value holder * FFMP basin/aggregated value holder

View file

@ -1,572 +0,0 @@
package com.raytheon.uf.common.dataplugin.ffmp;
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
import java.awt.Point;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import com.raytheon.uf.common.cache.CacheException;
import com.raytheon.uf.common.cache.CacheFactory;
import com.raytheon.uf.common.cache.ICache;
import com.raytheon.uf.common.cache.disk.DiskCache;
import com.raytheon.uf.common.datastorage.IDataStore;
import com.raytheon.uf.common.datastorage.Request;
import com.raytheon.uf.common.datastorage.records.FloatDataRecord;
import com.raytheon.uf.common.datastorage.records.IDataRecord;
import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager;
import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager.SOURCE_TYPE;
import com.raytheon.uf.common.monitor.xml.DomainXML;
import com.raytheon.uf.common.monitor.xml.SourceXML;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
/**
* Cache coherent record
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 05/24/12 632 D. Hladky Initial release
*
* </pre>
*
* @author dhladky
* @version 1
*/
public class FFMPCacheRecord extends FFMPRecord {
private final String sourceCacheName;
private final String cacheName;
private final String cacheDir;
private ArrayList<String> hucs = new ArrayList<String>();
//private static final boolean useCache = !Boolean
// .getBoolean("com.raytheon.uf.common.ffmp.disableCache");
private static final boolean useCache = false;
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(FFMPCacheRecord.class);
/**
* Public constructor
* @param rec
* @param sourceCacheName
* @param cacheDir
*/
public FFMPCacheRecord(FFMPRecord rec, String sourceCacheName, String cacheDir) {
this.setSiteKey(rec.getSiteKey());
this.setWfo(rec.getWfo());
this.setDataKey(rec.getDataKey());
this.setSourceName(rec.getSourceName());
this.setPluginName(rec.getPluginName());
this.sourceCacheName = sourceCacheName;
this.cacheName = "FFMP-" + getWfo() + "-" + getSiteKey() + "-" +getDataKey()+ "-"
+ getSourceCacheName();
// set a default value
if (cacheDir == null) {
cacheDir = "/tmp";
}
this.cacheDir = cacheDir;
}
public String getSourceCacheName() {
return sourceCacheName;
}
/**
*
*/
private static final long serialVersionUID = 1L;
@SuppressWarnings({ "unchecked" })
private DiskCache<FFMPBasinData> getCache() {
DiskCache<FFMPBasinData> diskCache = null;
CacheFactory cf = CacheFactory.getInstance();
try {
diskCache = (DiskCache<FFMPBasinData>) cf.getCache(this.cacheName);
} catch (CacheException e) {
synchronized (this) {
// make sure not done on another thread
try {
diskCache = (DiskCache<FFMPBasinData>) cf
.getCache(this.cacheName);
} catch (CacheException e1) {
diskCache = createCache(this.cacheName);
CacheFactory.getInstance().addCache(this.cacheName,
diskCache);
}
}
}
return diskCache;
}
/**
* Get BasinData Map from cache
*
* @param siteKey
* @param sourceName
* @return
*/
@Override
public FFMPBasinData getBasinData(String hucName) {
return getBasinData(hucName, false);
}
/**
* Get BasinData Map from cache
*
* @param siteKey
* @param sourceName
* @return
*/
public FFMPBasinData getBasinData(String hucName, boolean lock) {
FFMPBasinData basins = null;
if (hucName != null) {
if (useCache) {
try {
DiskCache<FFMPBasinData> diskCache = getCache();
basins = (FFMPBasinData) diskCache.getFromCache(hucName, lock);
if (basins == null) {
basins = new FFMPBasinData(hucName);
if (!hucs.contains(hucName)) {
hucs.add(hucName);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
basins = super.getBasinData(hucName);
}
}
return basins;
}
/**
* Create cache objects if needed
*
* @param siteKey
* @return
*/
private DiskCache<FFMPBasinData> createCache(String name) {
ICache<FFMPBasinData> cache = new DiskCache<FFMPBasinData>();
DiskCache<FFMPBasinData> dc = (DiskCache<FFMPBasinData>) cache;
dc.setName(name);
dc.setBaseCacheDir(getCacheDir());
dc.setSizeMemCacheMap(2); // For FFMP hold two generally COUNTY and ALL
dc.activateCache();
return dc;
}
/**
* Set source record to cache
*
* @param siteKey
* @param sourceName
* @param record
*/
@Override
public void setBasinData(FFMPBasinData basins, String hucName) {
if (hucName != null) {
if (useCache) {
try {
synchronized (basins) {
DiskCache<FFMPBasinData> diskCache = getCache();
try {
diskCache.addToCache(hucName, basins);
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
super.setBasinData(basins, hucName);
}
}
}
/**
* Cache File reader
*
* @param basins
* @param hucName
*/
public void setCacheData(FFMPBasinData basins, String hucName) {
if (getBasinData(hucName) != null) {
basins = getBasinData(hucName, true);
//System.out.println("Adding Cache Data: "+hucName+" "+getSourceName());
synchronized (basins) {
for (Entry<Long, FFMPBasin> entry : basins.getBasins()
.entrySet()) {
FFMPBasin basin = basins.get(entry.getKey());
if (basin != null) {
if (basin instanceof FFMPGuidanceBasin) {
FFMPGuidanceBasin gbasin = (FFMPGuidanceBasin) basin;
gbasin.getGuidValues().putAll(
((FFMPGuidanceBasin) entry.getValue())
.getGuidValues());
} else {
basin.getValues().putAll(
entry.getValue().getValues());
}
} else {
basins.put(entry.getKey(), entry.getValue());
}
}
}
setBasinData(basins, hucName);
} else {
setBasinData(basins, hucName);
//System.out.println("Adding Whole Object Buddy Data: "+hucName+" "+getSourceName());
}
}
/**
* Gets the Hash out of the datastore by HUC
*
* @param dataStore
* @param huc
*/
public void retrieveMapFromDataStore(IDataStore dataStore, String uri,
FFMPTemplates template, String huc, Date date, String sourceName)
throws Exception {
FFMPBasinData fbd = null;
boolean aggregate = true;
if (huc.equals("ALL")) {
aggregate = false;
}
fbd = getBasinData(huc, true);
String key = getSiteKey();
synchronized (template) {
SourceXML source = FFMPSourceConfigurationManager.getInstance()
.getSource(sourceName);
for (DomainXML domain : template.getDomains()) {
LinkedHashMap<Long, ?> map = template.getMap(key,
domain.getCwa(), huc);
if (map != null && map.keySet().size() > 0) {
IDataRecord rec = null;
try {
rec = dataStore.retrieve(uri + "/" + domain.getCwa(),
huc, Request.ALL);
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"FFMPRecord: no data record for: " + uri + "/"
+ domain.getCwa());
}
if (rec != null) {
float[] values = ((FloatDataRecord) rec).getFloatData();
int j = 0;
if (values != null) {
// System.err.println(sourceName);
if (source.getSourceType().equals(
SOURCE_TYPE.GUIDANCE.getSourceType())) {
for (Long pfaf : map.keySet()) {
try {
FFMPGuidanceBasin basin = (FFMPGuidanceBasin) fbd
.get(pfaf);
if (basin == null) {
basin = new FFMPGuidanceBasin(pfaf,
aggregate);
fbd.put(pfaf, basin);
}
if (basin.containsKey(date, sourceName)) {
if (basin
.getValue(date, sourceName) == FFMPUtils.MISSING
|| basin.getValue(date,
sourceName).isNaN()) {
float curval = basin.getValue(
date, sourceName);
if (curval >= 0.0f
&& values[j] >= 0.0f) {
basin.setValue(sourceName,
date, (curval + values[j])/ 2);
} else {
basin.setValue(sourceName,
date, values[j]);
}
}
} else {
basin.setValue(sourceName, date,
values[j]);
}
j++;
} catch (Exception e) {
break;
}
}
} else {
for (Long pfaf : map.keySet()) {
try {
FFMPBasin basin = fbd.get(pfaf);
if (basin == null) {
basin = new FFMPBasin(pfaf,
aggregate);
fbd.put(pfaf, basin);
}
if (basin.contains(date)) {
float curval = basin.getValue(date);
if (curval >= 0.0f
&& values[j] >= 0.0f) {
basin.setValue(date, (curval + values[j]) / 2);
} else {
basin.setValue(date, values[j]);
}
} else {
basin.setValue(date, values[j]);
}
j++;
} catch (Exception e) {
break;
}
}
}
}
}
}
}
}
setBasinData(fbd, huc);
}
/**
* Gets a single basin out of the dataStore
*
* @param dataStore
* @param huc
*/
public void retrieveBasinFromDataStore(IDataStore dataStore, String uri,
FFMPTemplates template, String huc, Date date, String sourceName,
FFMPBasin basin) {
FFMPBasinData fbd = null;
try {
SourceXML source = FFMPSourceConfigurationManager.getInstance()
.getSource(sourceName);
Long pfaf = basin.getPfaf();
fbd = getBasinData("ALL", true);
synchronized (template) {
for (DomainXML domain : template.getDomains()) {
LinkedHashMap<Long, ?> map = template.getMap(getSiteKey(),
domain.getCwa(), huc);
if (map != null && map.get(pfaf) != null) {
int index = 0;
for (Long pfafToCheck : map.keySet()) {
if (pfafToCheck.equals(pfaf)) {
break;
}
index++;
}
try {
IDataRecord rec = dataStore.retrieve(uri + "/"
+ domain.getCwa(), huc, Request
.buildPointRequest(new Point(index, 0)));
if (rec != null) {
float[] values = ((FloatDataRecord) rec)
.getFloatData();
boolean isFFG = false;
if (source.getSourceType().equals(
SOURCE_TYPE.GUIDANCE.getSourceType())) {
isFFG = true;
}
if (values != null) {
// System.err.println(sourceName);
if (isFFG) {
((FFMPGuidanceBasin) basin).setValue(
sourceName, date, values[0]);
} else {
basin.setValue(date, values[0]);
}
}
}
} catch (Throwable e) {
statusHandler.handle(Priority.PROBLEM,
"ERROR Retrieving Map for URI: " + uri
+ "..." + huc, e);
}
}
}
}
setBasinData(fbd, "ALL");
} catch (Exception e) {
statusHandler.handle(Priority.ERROR, "ERROR Retrieving HUC..."
+ huc);
}
}
/**
* Gets the Virtual Hash out of the datastore by HUC
*
* @param dataStore
* @param huc
*/
public void retrieveVirtualBasinFromDataStore(IDataStore dataStore,
String uri, FFMPTemplates template, Date date, FFMPBasin basin) {
FFMPBasinData fbd = null;
try {
boolean aggregate = false;
fbd = getBasinData("ALL", true);
String key = getDataKey();
for (DomainXML domain : template.getDomains()) {
LinkedHashMap<String, FFMPVirtualGageBasinMetaData> lids = template
.getVirtualGageBasins(key, domain.getCwa());
int size = lids.size();
if (size > 0) {
try {
IDataRecord rec = dataStore
.retrieve(uri + "/" + domain.getCwa(), "ALL",
Request.ALL);
if (rec != null) {
float[] values = ((FloatDataRecord) rec)
.getFloatData();
if (values != null) {
int j = 0;
for (Entry<String, FFMPVirtualGageBasinMetaData> entry : lids
.entrySet()) {
FFMPVirtualGageBasinMetaData fvgbmd = entry
.getValue();
FFMPVirtualGageBasin vgbasin = (FFMPVirtualGageBasin) fbd
.get(fvgbmd.getLookupId());
if (vgbasin == null) {
vgbasin = new FFMPVirtualGageBasin(
fvgbmd.getLid(),
fvgbmd.getLookupId(), aggregate);
fbd.put(fvgbmd.getLookupId(), vgbasin);
}
vgbasin.setValue(date, values[j]);
j++;
}
}
}
}
catch (Throwable e) {
statusHandler.handle(
Priority.PROBLEM,
"ERROR Retrieving Virtual ..."
+ domain.getCwa() + " : " + "ALL");
}
}
}
setBasinData(fbd, "ALL");
} catch (Throwable e) {
statusHandler.handle(Priority.ERROR, "ERROR Retrieving Virtual..."
+ "ALL");
}
}
/**
* Purges out old data
*
* @param date
*/
public void purgeData(Date date) {
for (String ihuc : hucs) {
FFMPBasinData basinData = getBasinData(ihuc, true);
basinData.purgeData(date);
setBasinData(basinData, ihuc);
}
}
/**
* Dump cache
*/
public void closeCache() {
getCache().closeCache();
}
public String getCacheDir() {
return cacheDir;
}
}

View file

@ -22,11 +22,14 @@ package com.raytheon.uf.common.dataplugin.ffmp;
import java.awt.Point; import java.awt.Point;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.lang.ref.WeakReference;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -37,6 +40,7 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.hibernate.annotations.Index; import org.hibernate.annotations.Index;
import com.raytheon.uf.common.dataplugin.IDecoderGettable; import com.raytheon.uf.common.dataplugin.IDecoderGettable;
@ -57,6 +61,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.util.ImmutableDate;
/** /**
* Record implementation for FFMP plugin * Record implementation for FFMP plugin
@ -72,6 +77,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
* Feb 28, 2013 1729 dhladky Supressed un-necessary debug loggers * Feb 28, 2013 1729 dhladky Supressed un-necessary debug loggers
* Apr 4, 2013 1846 bkowal Added an index on refTime and forecastTime * Apr 4, 2013 1846 bkowal Added an index on refTime and forecastTime
* Apr 8, 2013 1293 bkowal Removed references to hdffileid. * Apr 8, 2013 1293 bkowal Removed references to hdffileid.
* April, 9 2013 1890 dhladky Moved dates to referenced map in record rather than multiple dates in FFMPBasin objs.
* *
* </pre> * </pre>
* *
@ -131,6 +137,8 @@ public class FFMPRecord extends PersistablePluginDataObject
@Transient @Transient
private boolean isRate = false; private boolean isRate = false;
protected static ConcurrentMap<Long, WeakReference<ImmutableDate>> cacheTimes = new ConcurrentHashMap<Long, WeakReference<ImmutableDate>>();
private static final transient IUFStatusHandler statusHandler = UFStatus private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(FFMPRecord.class); .getHandler(FFMPRecord.class);
@ -384,103 +392,96 @@ public class FFMPRecord extends PersistablePluginDataObject
} }
fbd = getBasinData(huc); fbd = getBasinData(huc);
ImmutableDate idate = getCacheDate(date);
synchronized (template) { SourceXML source = FFMPSourceConfigurationManager.getInstance()
.getSource(sourceName);
SourceXML source = FFMPSourceConfigurationManager.getInstance() for (DomainXML domain : template.getDomains()) {
.getSource(sourceName);
for (DomainXML domain : template.getDomains()) { LinkedHashMap<Long, ?> map = template.getMap(getSiteKey(), domain.getCwa(), huc);
LinkedHashMap<Long, ?> map = template.getMap(getSiteKey(),
domain.getCwa(), huc);
if (map != null && map.keySet().size() > 0) { if (map != null && !map.isEmpty()) {
IDataRecord rec = null; IDataRecord rec = null;
try { try {
rec = dataStore.retrieve(uri + "/" + domain.getCwa(), rec = dataStore.retrieve(uri + "/" + domain.getCwa(), huc,
huc, Request.ALL); Request.ALL);
} catch (Exception e) { } catch (Exception e) {
statusHandler.handle(Priority.DEBUG, statusHandler.handle(Priority.DEBUG,
"FFMPRecord: no data record for: " + uri + "/" "FFMPRecord: no data record for: " + uri + "/"
+ domain.getCwa()); + domain.getCwa());
} }
if (rec != null) { if (rec != null) {
float[] values = ((FloatDataRecord) rec).getFloatData(); float[] values = ((FloatDataRecord) rec).getFloatData();
int j = 0; int j = 0;
if (values != null) { if (values != null) {
// System.err.println(sourceName); // System.err.println(sourceName);
if (source.getSourceType().equals( if (source.getSourceType().equals(
SOURCE_TYPE.GUIDANCE.getSourceType())) { SOURCE_TYPE.GUIDANCE.getSourceType())) {
for (Long pfaf : map.keySet()) { for (Long pfaf : map.keySet()) {
try { try {
FFMPGuidanceBasin basin = (FFMPGuidanceBasin) fbd FFMPGuidanceBasin basin = (FFMPGuidanceBasin) fbd
.get(pfaf); .get(pfaf);
if (basin == null) { if (basin == null) {
basin = new FFMPGuidanceBasin(pfaf, basin = new FFMPGuidanceBasin(pfaf,
aggregate); aggregate);
fbd.put(pfaf, basin); fbd.put(pfaf, basin);
} }
if (basin.containsKey(date, sourceName)) { Float curval = basin.getValue(idate,
if (basin sourceName);
.getValue(date, sourceName) == FFMPUtils.MISSING
|| basin.getValue(date,
sourceName).isNaN()) {
float curval = basin.getValue( if (curval != FFMPUtils.MISSING
date, sourceName); || !curval.isNaN()) {
if (curval >= 0.0f if (curval >= 0.0f && values[j] >= 0.0f) {
&& values[j] >= 0.0f) { basin.setValue(sourceName, idate,
basin.setValue(sourceName, (curval + values[j]) / 2);
date, (curval + values[j])/ 2); } else if (values[j] >= 0.0f){
} else { basin.setValue(sourceName, idate,
basin.setValue(sourceName,
date, values[j]);
}
}
} else {
basin.setValue(sourceName, date,
values[j]); values[j]);
} }
// do not overwrite original value
j++; } else {
} catch (Exception e) { basin.setValue(sourceName, idate,
break; values[j]);
} }
j++;
} catch (Exception e) {
break;
} }
} else {
for (Long pfaf : map.keySet()) {
try {
FFMPBasin basin = fbd.get(pfaf);
if (basin == null) {
basin = new FFMPBasin(pfaf,
aggregate);
fbd.put(pfaf, basin);
}
if (basin.contains(date)) { }
float curval = basin.getValue(date); } else {
if (curval >= 0.0f for (Long pfaf : map.keySet()) {
&& values[j] >= 0.0f) { try {
basin.setValue(date, (curval + values[j])/ 2);; FFMPBasin basin = fbd.get(pfaf);
} else { if (basin == null) {
basin.setValue(date, values[j]); basin = new FFMPBasin(pfaf, aggregate);
} fbd.put(pfaf, basin);
} else {
basin.setValue(date, values[j]);
}
j++;
} catch (Exception e) {
break;
} }
if (basin.contains(idate)) {
float curval = basin.getValue(idate);
if (curval >= 0.0f && values[j] >= 0.0f) {
basin.setValue(idate,
(curval + values[j]) / 2);
} else if (values[j] >= 0.0f) {
basin.setValue(idate, values[j]);
} // do not overwrite original value
} else {
// no value at time exists, write regardless
basin.setValue(idate, values[j]);
}
j++;
} catch (Exception e) {
break;
} }
} }
} }
@ -488,6 +489,7 @@ public class FFMPRecord extends PersistablePluginDataObject
} }
} }
} }
} }
/** /**
@ -504,58 +506,57 @@ public class FFMPRecord extends PersistablePluginDataObject
SourceXML source = FFMPSourceConfigurationManager.getInstance() SourceXML source = FFMPSourceConfigurationManager.getInstance()
.getSource(sourceName); .getSource(sourceName);
Long pfaf = basin.getPfaf(); Long pfaf = basin.getPfaf();
ImmutableDate idate = getCacheDate(date);
synchronized (template) { for (DomainXML domain : template.getDomains()) {
for (DomainXML domain : template.getDomains()) { LinkedHashMap<Long, ?> map = template.getMap(getSiteKey(),
domain.getCwa(), huc);
LinkedHashMap<Long, ?> map = template.getMap(getSiteKey(), if (map != null && map.get(pfaf) != null) {
domain.getCwa(), huc);
if (map != null && map.get(pfaf) != null) { int index = 0;
for (Long pfafToCheck : map.keySet()) {
int index = 0; if (pfafToCheck.equals(pfaf)) {
for (Long pfafToCheck : map.keySet()) { break;
if (pfafToCheck.equals(pfaf)) {
break;
}
index++;
} }
index++;
}
try { try {
IDataRecord rec = dataStore.retrieve(uri + "/" IDataRecord rec = dataStore.retrieve(
+ domain.getCwa(), huc, Request uri + "/" + domain.getCwa(), huc,
.buildPointRequest(new Point(index, 0))); Request.buildPointRequest(new Point(index, 0)));
if (rec != null) { if (rec != null) {
float[] values = ((FloatDataRecord) rec) float[] values = ((FloatDataRecord) rec)
.getFloatData(); .getFloatData();
boolean isFFG = false; boolean isFFG = false;
if (source.getSourceType().equals( if (source.getSourceType().equals(
SOURCE_TYPE.GUIDANCE.getSourceType())) { SOURCE_TYPE.GUIDANCE.getSourceType())) {
isFFG = true; isFFG = true;
} }
if (values != null) { if (values != null) {
// System.err.println(sourceName); // System.err.println(sourceName);
if (isFFG) { if (isFFG) {
((FFMPGuidanceBasin) basin).setValue( ((FFMPGuidanceBasin) basin).setValue(
sourceName, date, values[0]); sourceName, idate, values[0]);
} else { } else {
basin.setValue(date, values[0]); basin.setValue(idate, values[0]);
}
} }
} }
} catch (Throwable e) {
statusHandler.handle(Priority.PROBLEM,
"ERROR Retrieving Map for URI: " + uri
+ "..." + huc);
} }
} catch (Throwable e) {
statusHandler.handle(Priority.PROBLEM,
"ERROR Retrieving Map for URI: " + uri + "..."
+ huc);
} }
} }
} }
} catch (Exception e) { } catch (Exception e) {
statusHandler.handle(Priority.ERROR, "ERROR Retrieving HUC..." statusHandler.handle(Priority.ERROR, "ERROR Retrieving HUC..."
+ huc); + huc);
@ -575,56 +576,54 @@ public class FFMPRecord extends PersistablePluginDataObject
boolean aggregate = false; boolean aggregate = false;
fbd = getBasinData(ALL); fbd = getBasinData(ALL);
String key = getDataKey(); String key = getDataKey();
ImmutableDate idate = getCacheDate(date);
synchronized (template) { for (DomainXML domain : template.getDomains()) {
for (DomainXML domain : template.getDomains()) { LinkedHashMap<String, FFMPVirtualGageBasinMetaData> lids = template
.getVirtualGageBasins(key, domain.getCwa());
LinkedHashMap<String, FFMPVirtualGageBasinMetaData> lids = template if (lids != null) {
.getVirtualGageBasins(key, domain.getCwa()); int size = lids.size();
if (lids != null) { if (size > 0) {
int size = lids.size();
if (size > 0) { IDataRecord rec = null;
IDataRecord rec = null; try {
rec = dataStore.retrieve(uri + "/" + domain.getCwa(),
try { ALL, Request.ALL);
rec = dataStore.retrieve( } catch (Exception e) {
uri + "/" + domain.getCwa(), ALL, // This is a routine error. Sometimes you can not have
Request.ALL); // data for a configured source
} catch (Exception e) { // This suppresses spurrious messages that would inflate
// This is a routine error. Sometimes you can not have data for a configured source // the loags needlessly.
// This suppresses spurrious messages that would inflate the loags needlessly. if (statusHandler.isPriorityEnabled(Priority.DEBUG)) {
if (statusHandler.isPriorityEnabled(Priority.DEBUG)) { statusHandler.handle(Priority.DEBUG,
statusHandler.handle(Priority.DEBUG, "FFMPRecord: no data for: " + uri + "/"
"FFMPRecord: no data for: " + uri + "/" + domain.getCwa());
+ domain.getCwa());
}
} }
}
if (rec != null) { if (rec != null) {
float[] values = ((FloatDataRecord) rec) float[] values = ((FloatDataRecord) rec).getFloatData();
.getFloatData(); if (values != null) {
if (values != null) { int j = 0;
int j = 0;
for (Entry<String, FFMPVirtualGageBasinMetaData> entry : lids for (Entry<String, FFMPVirtualGageBasinMetaData> entry : lids
.entrySet()) { .entrySet()) {
FFMPVirtualGageBasinMetaData fvgbmd = entry FFMPVirtualGageBasinMetaData fvgbmd = entry
.getValue(); .getValue();
FFMPVirtualGageBasin vgbasin = (FFMPVirtualGageBasin) fbd FFMPVirtualGageBasin vgbasin = (FFMPVirtualGageBasin) fbd
.get(fvgbmd.getLookupId()); .get(fvgbmd.getLookupId());
if (vgbasin == null) { if (vgbasin == null) {
vgbasin = new FFMPVirtualGageBasin( vgbasin = new FFMPVirtualGageBasin(
fvgbmd.getLid(), fvgbmd.getLid(),
fvgbmd.getLookupId(), aggregate); fvgbmd.getLookupId(), aggregate);
fbd.put(fvgbmd.getLookupId(), vgbasin); fbd.put(fvgbmd.getLookupId(), vgbasin);
}
vgbasin.setValue(date, values[j]);
j++;
} }
vgbasin.setValue(idate, values[j]);
j++;
} }
} }
} }
@ -646,11 +645,11 @@ public class FFMPRecord extends PersistablePluginDataObject
boolean aggregate = false; boolean aggregate = false;
fbd = getBasinData(ALL); fbd = getBasinData(ALL);
String key = getDataKey(); String key = getDataKey();
ImmutableDate idate = getCacheDate(date);
for (DomainXML domain : template.getDomains()) { for (DomainXML domain : template.getDomains()) {
LinkedHashMap<String, FFMPVirtualGageBasinMetaData> lids = template LinkedHashMap<String, FFMPVirtualGageBasinMetaData> lids = template.getVirtualGageBasins(key, domain.getCwa());
.getVirtualGageBasins(key, domain.getCwa());
int size = lids.size(); int size = lids.size();
if (size > 0) { if (size > 0) {
@ -677,7 +676,7 @@ public class FFMPRecord extends PersistablePluginDataObject
fvgbmd.getLookupId(), aggregate); fvgbmd.getLookupId(), aggregate);
fbd.put(fvgbmd.getLookupId(), vgbasin); fbd.put(fvgbmd.getLookupId(), vgbasin);
} }
vgbasin.setValue(date, values[j]); vgbasin.setValue(idate, values[j]);
j++; j++;
} }
} }
@ -814,5 +813,45 @@ public class FFMPRecord extends PersistablePluginDataObject
setBasinData(basinData, basinData.getHucLevel()); setBasinData(basinData, basinData.getHucLevel());
} }
} }
/**
* Gets and maintains the list of times. This will lesson memory consumption
* because it means all FFMPBasin TreeMap date keys reference back to this
* Hash. Seeing as there are 10000+ of those this will certainly help.
*
* @param date
* @return
*/
protected ImmutableDate getCacheDate(Date date) {
WeakReference<ImmutableDate> idate = cacheTimes.get(date.getTime());
ImmutableDate myDate = null;
if (idate != null) {
myDate = idate.get();
}
if (myDate == null) {
long time = date.getTime();
myDate = new ImmutableDate(time);
idate = new WeakReference<ImmutableDate>(myDate);
cacheTimes.putIfAbsent(time, idate);
}
return myDate;
}
/**
* Populate data from the cache files
* @param basins
* @param hucName
*/
public void populate(FFMPBasinData basins, String hucName) {
setBasinData(basins, hucName);
//System.out.println("Adding Whole Object Cache Data: "+hucName+" "+getSourceName());
}
} }

View file

@ -1282,7 +1282,7 @@ public class FFMPTemplates {
* @param huc * @param huc
* @return * @return
*/ */
public LinkedHashMap<Long, ?> getMap(String dataKey, String cwa, String huc) { public synchronized LinkedHashMap<Long, ?> getMap(String dataKey, String cwa, String huc) {
LinkedHashMap<Long, ?> map = null; LinkedHashMap<Long, ?> map = null;
HashMap<String, LinkedHashMap<Long, ?>> hucMap = null; HashMap<String, LinkedHashMap<Long, ?>> hucMap = null;
@ -1398,7 +1398,7 @@ public class FFMPTemplates {
* *
* @return * @return
*/ */
public LinkedHashMap<String, FFMPVirtualGageBasinMetaData> getVirtualGageBasins( public synchronized LinkedHashMap<String, FFMPVirtualGageBasinMetaData> getVirtualGageBasins(
String dataKey, String cwa) { String dataKey, String cwa) {
LinkedHashMap<String, FFMPVirtualGageBasinMetaData> map = null; LinkedHashMap<String, FFMPVirtualGageBasinMetaData> map = null;