Issue #1890 moved date keys to references in FFMPRecord instead of hard object in FFMPBasin
Change-Id: I840e0805422686856744f0d39dda0aeac4755bb8 Former-commit-id: 4c1e41a6a77ea89f2a0c0253671b8d6cca071c04
This commit is contained in:
parent
35b956fc4c
commit
978e68d893
11 changed files with 309 additions and 838 deletions
|
@ -93,6 +93,7 @@ import com.raytheon.uf.viz.monitor.listeners.IMonitorListener;
|
|||
* 02/19/13 1639 njensen Replaced ConcurrentHashMaps with data structures
|
||||
* 02/20/13 1635 D. Hladky Fixed multi guidance sources
|
||||
* Mar 6, 2013 1769 dhladky Changed threading to use count down latch.
|
||||
* Apr 9, 2013 1890 dhladky Fixed the broken cache file load
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -386,19 +387,40 @@ public class FFMPMonitor extends ResourceMonitor {
|
|||
* @param dataKey
|
||||
* @param source
|
||||
*/
|
||||
public void insertFFMPData(FFMPAggregateRecord data, String siteKey,
|
||||
String source) {
|
||||
// TODO do we need this method if we're no longer supporting cache
|
||||
// records?
|
||||
if (siteDataMap.containsSite(siteKey)) {
|
||||
if (siteDataMap.get(siteKey).containsSource(source)) {
|
||||
for (Entry<String, FFMPBasinData> entry : data.getBasinsMap()
|
||||
.entrySet()) {
|
||||
FFMPBasinData basinData = entry.getValue();
|
||||
basinData.populate(data.getTimes());
|
||||
public void insertFFMPData(FFMPAggregateRecord data,
|
||||
NavigableMap<Date, List<String>> uris, String siteKey, String source) {
|
||||
|
||||
// get record from cache
|
||||
FFMPSourceData sourceData = siteDataMap.get(siteKey).getSourceData(source);
|
||||
FFMPRecord curRecord = sourceData.getRecord();
|
||||
|
||||
if (curRecord == null) {
|
||||
// add each huc requested
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,6 +56,7 @@ import com.raytheon.uf.viz.monitor.ffmp.xml.FFMPTableColumnXML;
|
|||
* Aug 01, 2012 14168 mpduff Add convenience methods for
|
||||
* getting ColorCell and ReverseFilter
|
||||
* Apr 12, 2013 1902 mpduff Speed up cell coloring.
|
||||
* Apr 15. 2013 1890 dhladky Added Mikes fix for singleton.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -128,27 +129,9 @@ public class FFMPConfig {
|
|||
}
|
||||
|
||||
public static synchronized FFMPConfig getInstance() {
|
||||
if (classInstance == null) {
|
||||
classInstance = new FFMPConfig();
|
||||
}
|
||||
|
||||
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() {
|
||||
threshMgrMap = new HashMap<ThreshColNames, ThresholdManager>();
|
||||
|
||||
|
|
|
@ -319,8 +319,8 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements
|
|||
|
||||
dataLoadFont.dispose();
|
||||
timeDurFont.dispose();
|
||||
FFMPConfig.getInstance().disposeResources();
|
||||
FFMPConfig.unloadConfig();
|
||||
//FFMPConfig.getInstance().disposeResources();
|
||||
//FFMPConfig.unloadConfig();
|
||||
|
||||
if (refreshColor != null) {
|
||||
refreshColor.dispose();
|
||||
|
@ -1311,15 +1311,20 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements
|
|||
if (attributeDlg == null || attributeDlg.isDisposed()) {
|
||||
attrData = ffmpTable.getVisibleColumns();
|
||||
attributeDlg = new AttributesDlg(shell, resource, attrData, this);
|
||||
attributeDlg.open();
|
||||
} else {
|
||||
attributeDlg.bringToTop();
|
||||
}
|
||||
attributeDlg.open();
|
||||
}
|
||||
|
||||
private void displayThresholdsDialog(ThreshColNames colName) {
|
||||
if (attrThreshDlg == null) {
|
||||
attrThreshDlg = new AttributeThresholdDlg(shell, colName, this);
|
||||
attrThreshDlg.open();
|
||||
} else {
|
||||
attrThreshDlg.bringToTop();
|
||||
}
|
||||
attrThreshDlg.open();
|
||||
|
||||
attrThreshDlg.newThreshold(colName);
|
||||
}
|
||||
|
||||
|
@ -2105,13 +2110,17 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements
|
|||
shell.pack();
|
||||
}
|
||||
|
||||
String prefix = null;
|
||||
String prefix = null;
|
||||
|
||||
if (status.getLoaderType() == LOADER_TYPE.SECONDARY) {
|
||||
prefix = " Secondary Data Load: ";
|
||||
} else {
|
||||
prefix = " Tertiary Data Load: ";
|
||||
}
|
||||
if (status.getLoaderType() == LOADER_TYPE.SECONDARY) {
|
||||
prefix = " Secondary Data Load: ";
|
||||
} else if (status.getLoaderType() == LOADER_TYPE.TERTIARY) {
|
||||
prefix = " Tertiary Data Load: ";
|
||||
} else if (status.getLoaderType() == LOADER_TYPE.GENERAL) {
|
||||
prefix = " General Data Load: ";
|
||||
} else {
|
||||
prefix = " Tertiary Data Load: ";
|
||||
}
|
||||
|
||||
if (status.isDone() == false) {
|
||||
dataLoadingLbl.setText(prefix + status.getMessage());
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||
|
||||
import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasin;
|
||||
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.monitor.config.FFFGDataMgr;
|
||||
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
|
||||
* 01/14/13 1569 dhladky changed arraylist to list
|
||||
* 04/15/13 1890 dhladky Changed COUNTY to use constant
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -132,7 +134,7 @@ public class FFFGForceUtil {
|
|||
pfafList = ft.getAggregatePfafs(cBasin.getPfaf(),
|
||||
resource.getSiteKey(), resource.getHuc());
|
||||
} else if (!domain.equals("NA")) {
|
||||
if (!resource.getHuc().equals("ALL")) {
|
||||
if (!resource.getHuc().equals(FFMPRecord.ALL)) {
|
||||
pfafList = ft.getAggregatePfafsByDomain(cBasin.getPfaf(),
|
||||
resource.getSiteKey(), domain, resource.getHuc());
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.dialogs.FfmpTableConfigData;
|
|||
* feb 20, 2013 1635 dhladky Fixed multi guidance displays
|
||||
* Feb 28, 2013 1729 dhladky General enhancements for speed.
|
||||
* Apr 12, 2013 1902 mpduff Code Cleanup.
|
||||
* Apr 15, 2013 1890 dhladky Added another constant fix
|
||||
* </pre>
|
||||
*
|
||||
* @author dhladky
|
||||
|
@ -818,7 +819,7 @@ public class FFMPDataGenerator {
|
|||
ArrayList<Long> pfafs = ft.getAggregatePfafs(basin.getPfaf(),
|
||||
siteKey, huc);
|
||||
if (!pfafs.isEmpty()) {
|
||||
if (huc.equals("COUNTY")) {
|
||||
if (huc.equals(FFMPRecord.COUNTY)) {
|
||||
name = ft.getCountyStateName(siteKey, basin.getPfaf());
|
||||
} else {
|
||||
for (int i = 0; i < pfafs.size(); i++) {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package com.raytheon.uf.viz.monitor.ffmp.ui.rsc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
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
|
||||
* 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.
|
||||
* Apr 9, 2013 1890 dhladky removed loading of phantom Virtual template and cache file processing.
|
||||
* </pre>
|
||||
*
|
||||
* @author dhladky
|
||||
|
@ -74,7 +74,8 @@ import com.raytheon.uf.viz.monitor.ffmp.ui.listeners.FFMPLoaderEvent;
|
|||
*/
|
||||
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;
|
||||
|
||||
|
@ -156,13 +157,14 @@ public class FFMPDataLoader extends Thread {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
resourceData.setLoader(loadType);
|
||||
FFMPMonitor monitor = getMonitor();
|
||||
FFMPSourceConfigurationManager sourceConfig = monitor.getSourceConfig();
|
||||
FFMPMonitor monitor = getMonitor();
|
||||
FFMPSourceConfigurationManager sourceConfig = monitor
|
||||
.getSourceConfig();
|
||||
|
||||
ProductRunXML productRun = runner.getProduct(siteKey);
|
||||
ArrayList<String> qpfSources = new ArrayList<String>();
|
||||
|
@ -235,6 +237,10 @@ public class FFMPDataLoader extends Thread {
|
|||
if (loadType == LOADER_TYPE.TERTIARY) {
|
||||
hucsToLoad.clear();
|
||||
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()) {
|
||||
|
@ -253,29 +259,28 @@ public class FFMPDataLoader extends Thread {
|
|||
}
|
||||
|
||||
// qpes
|
||||
fireLoaderEvent(loadType, "Processing " + product.getQpe(), isDone());
|
||||
fireLoaderEvent(loadType, "Processing " + product.getQpe(),
|
||||
isDone());
|
||||
FFMPAggregateRecord qpeCache = null;
|
||||
|
||||
if (loadType == LOADER_TYPE.INITIAL) {
|
||||
|
||||
SourceXML source = sourceConfig.getSource(
|
||||
product.getQpe());
|
||||
SourceXML source = sourceConfig.getSource(product.getQpe());
|
||||
|
||||
qpeCache = readAggregateRecord(source, dataKey, wfo);
|
||||
|
||||
if (qpeCache != null) {
|
||||
monitor.insertFFMPData(qpeCache, siteKey,
|
||||
product.getQpe());
|
||||
monitor.insertFFMPData(qpeCache, qpeURIs, siteKey, 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) {
|
||||
for (String phuc : hucsToLoad) {
|
||||
if (phuc.equals(layer)
|
||||
|| phuc.equals(FFMPRecord.ALL)) {
|
||||
monitor.processUris(qpeURIs, isProductLoad,
|
||||
siteKey, product.getQpe(), timeBack, phuc);
|
||||
if (phuc.equals(layer) || phuc.equals(FFMPRecord.ALL)) {
|
||||
monitor.processUris(qpeURIs, isProductLoad, siteKey,
|
||||
product.getQpe(), timeBack, phuc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +296,6 @@ public class FFMPDataLoader extends Thread {
|
|||
|
||||
if (loadType == LOADER_TYPE.INITIAL) {
|
||||
|
||||
|
||||
SourceXML source = sourceConfig
|
||||
.getSource(qpfSources.get(i));
|
||||
|
||||
|
@ -300,36 +304,36 @@ public class FFMPDataLoader extends Thread {
|
|||
|
||||
if (qpfCache != null) {
|
||||
for (String phuc : hucsToLoad) {
|
||||
if ((phuc.equals(layer) || phuc.equals(FFMPRecord.ALL))
|
||||
if ((phuc.equals(layer) || phuc
|
||||
.equals(FFMPRecord.ALL))
|
||||
&& loadType == LOADER_TYPE.INITIAL
|
||||
&& source.getSourceName().equals(
|
||||
config.getFFMPConfigData()
|
||||
.getIncludedQPF())) {
|
||||
.getIncludedQPF())) {
|
||||
if (!qpfURIs.isEmpty()) {
|
||||
|
||||
monitor.processUris(qpfURIs,
|
||||
isProductLoad, siteKey,
|
||||
source.getSourceName(), timeBack,
|
||||
phuc);
|
||||
monitor.processUris(qpfURIs, isProductLoad,
|
||||
siteKey, source.getSourceName(),
|
||||
timeBack, phuc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
monitor.insertFFMPData(qpfCache, siteKey,
|
||||
monitor.insertFFMPData(qpfCache, qpfURIs, siteKey,
|
||||
source.getSourceName());
|
||||
}
|
||||
}
|
||||
// if (isUrisProcessNeeded(qpfData,qpfURIs))
|
||||
// {/*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()) {
|
||||
for (String phuc : hucsToLoad) {
|
||||
if (phuc.equals(layer)
|
||||
|| phuc.equals(FFMPRecord.ALL)) { // old
|
||||
// code:
|
||||
// keep
|
||||
// for
|
||||
// reference*/
|
||||
if (phuc.equals(layer) || phuc.equals(FFMPRecord.ALL)) { // old
|
||||
// code:
|
||||
// keep
|
||||
// for
|
||||
// reference*/
|
||||
// if (isHucProcessNeeded(phuc)) {/*DR13839*/
|
||||
monitor.processUris(qpfURIs, isProductLoad,
|
||||
siteKey, product.getQpf(i), timeBack, phuc);
|
||||
|
@ -344,24 +348,8 @@ public class FFMPDataLoader extends Thread {
|
|||
|
||||
fireLoaderEvent(loadType, "Processing " + product.getVirtual(),
|
||||
isDone());
|
||||
FFMPAggregateRecord vgbCache = null;
|
||||
|
||||
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()) {
|
||||
// process virtual all for all only, never uses cache files
|
||||
if (!virtualURIs.isEmpty()) {
|
||||
monitor.processUris(virtualURIs, isProductLoad, siteKey,
|
||||
product.getVirtual(), timeBack, FFMPRecord.ALL);
|
||||
}
|
||||
|
@ -379,10 +367,12 @@ public class FFMPDataLoader extends Thread {
|
|||
.get(guidSource.getSourceName());
|
||||
|
||||
fireLoaderEvent(loadType,
|
||||
"Processing " + guidSource.getSourceName(), isDone());
|
||||
"Processing " + guidSource.getSourceName(),
|
||||
isDone());
|
||||
|
||||
monitor.processUris(iguidURIs, isProductLoad, siteKey,
|
||||
guidSource.getSourceName(), timeBack, FFMPRecord.ALL);
|
||||
guidSource.getSourceName(), timeBack,
|
||||
FFMPRecord.ALL);
|
||||
|
||||
fireLoaderEvent(loadType, guidSource.getSourceName(),
|
||||
isDone());
|
||||
|
@ -390,10 +380,11 @@ public class FFMPDataLoader extends Thread {
|
|||
}
|
||||
}
|
||||
} 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 {
|
||||
latch.countDown();
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
this.notifyAll();
|
||||
}
|
||||
}
|
||||
|
@ -406,7 +397,8 @@ public class FFMPDataLoader extends Thread {
|
|||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -503,7 +495,8 @@ public class FFMPDataLoader extends Thread {
|
|||
try {
|
||||
// we are just checking if it exists or not
|
||||
String pdataKey = product.getProductKey();
|
||||
String sourceSiteDataKey = getSourceSiteDataKey(source, pdataKey);
|
||||
String sourceSiteDataKey = getSourceSiteDataKey(source,
|
||||
pdataKey);
|
||||
File hdf5File = FFMPUtils.getHdf5File(wfo, sourceSiteDataKey);
|
||||
DataStoreFactory.getDataStore(hdf5File);
|
||||
|
||||
|
@ -516,16 +509,16 @@ public class FFMPDataLoader extends Thread {
|
|||
|
||||
return siteKey;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the sourceSiteDataKey for this piece of data
|
||||
*
|
||||
* @param source
|
||||
* @param pdataKey
|
||||
* @return
|
||||
*/
|
||||
private String getSourceSiteDataKey(SourceXML source, String pdataKey) {
|
||||
return source.getSourceName() + "-" + siteKey + "-"
|
||||
+ pdataKey;
|
||||
return source.getSourceName() + "-" + siteKey + "-" + pdataKey;
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
|
|
|
@ -163,6 +163,7 @@ import com.vividsolutions.jts.geom.Point;
|
|||
* 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.
|
||||
* 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
|
||||
* time matcher.
|
||||
* </pre>
|
||||
|
@ -1219,7 +1220,7 @@ public class FFMPResource extends
|
|||
paintProps.setAlpha(getCapability(ImagingCapability.class)
|
||||
.getAlpha());
|
||||
|
||||
boolean isShaded = isPolygonal();
|
||||
boolean isShaded = true;
|
||||
FFMPDrawable drawable = null;
|
||||
|
||||
if (paintTime != null) {
|
||||
|
@ -1571,14 +1572,6 @@ public class FFMPResource extends
|
|||
return geometryType;
|
||||
}
|
||||
|
||||
protected boolean isLineal() {
|
||||
return getGeometryType().endsWith("LINESTRING");
|
||||
}
|
||||
|
||||
protected boolean isPolygonal() {
|
||||
return getGeometryType().endsWith("POLYGON");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color wrapper class
|
||||
*
|
||||
|
|
|
@ -31,6 +31,7 @@ import javax.persistence.Transient;
|
|||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
import com.raytheon.uf.common.time.util.ImmutableDate;
|
||||
|
||||
/**
|
||||
* FFMP basin/aggregated value holder
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,11 +22,14 @@ package com.raytheon.uf.common.dataplugin.ffmp;
|
|||
import java.awt.Point;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.persistence.Column;
|
||||
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.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.hibernate.annotations.Index;
|
||||
|
||||
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.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.common.time.util.ImmutableDate;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Apr 4, 2013 1846 bkowal Added an index on refTime and forecastTime
|
||||
* 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>
|
||||
*
|
||||
|
@ -131,6 +137,8 @@ public class FFMPRecord extends PersistablePluginDataObject
|
|||
|
||||
@Transient
|
||||
private boolean isRate = false;
|
||||
|
||||
protected static ConcurrentMap<Long, WeakReference<ImmutableDate>> cacheTimes = new ConcurrentHashMap<Long, WeakReference<ImmutableDate>>();
|
||||
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(FFMPRecord.class);
|
||||
|
@ -384,103 +392,96 @@ public class FFMPRecord extends PersistablePluginDataObject
|
|||
}
|
||||
|
||||
fbd = getBasinData(huc);
|
||||
ImmutableDate idate = getCacheDate(date);
|
||||
|
||||
synchronized (template) {
|
||||
SourceXML source = FFMPSourceConfigurationManager.getInstance()
|
||||
.getSource(sourceName);
|
||||
|
||||
SourceXML source = FFMPSourceConfigurationManager.getInstance()
|
||||
.getSource(sourceName);
|
||||
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(), domain.getCwa(), huc);
|
||||
|
||||
if (map != null && map.keySet().size() > 0) {
|
||||
if (map != null && !map.isEmpty()) {
|
||||
|
||||
IDataRecord rec = null;
|
||||
IDataRecord rec = null;
|
||||
|
||||
try {
|
||||
rec = dataStore.retrieve(uri + "/" + domain.getCwa(),
|
||||
huc, Request.ALL);
|
||||
} catch (Exception e) {
|
||||
statusHandler.handle(Priority.DEBUG,
|
||||
"FFMPRecord: no data record for: " + uri + "/"
|
||||
+ domain.getCwa());
|
||||
}
|
||||
try {
|
||||
rec = dataStore.retrieve(uri + "/" + domain.getCwa(), huc,
|
||||
Request.ALL);
|
||||
} catch (Exception e) {
|
||||
statusHandler.handle(Priority.DEBUG,
|
||||
"FFMPRecord: no data record for: " + uri + "/"
|
||||
+ domain.getCwa());
|
||||
}
|
||||
|
||||
if (rec != null) {
|
||||
float[] values = ((FloatDataRecord) rec).getFloatData();
|
||||
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);
|
||||
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 == 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(idate,
|
||||
sourceName);
|
||||
|
||||
float curval = basin.getValue(
|
||||
date, sourceName);
|
||||
if (curval != FFMPUtils.MISSING
|
||||
|| !curval.isNaN()) {
|
||||
|
||||
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,
|
||||
if (curval >= 0.0f && values[j] >= 0.0f) {
|
||||
basin.setValue(sourceName, idate,
|
||||
(curval + values[j]) / 2);
|
||||
} else if (values[j] >= 0.0f){
|
||||
basin.setValue(sourceName, idate,
|
||||
values[j]);
|
||||
}
|
||||
|
||||
j++;
|
||||
} catch (Exception e) {
|
||||
break;
|
||||
}
|
||||
// do not overwrite original value
|
||||
} else {
|
||||
basin.setValue(sourceName, idate,
|
||||
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;
|
||||
}
|
||||
} 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(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()
|
||||
.getSource(sourceName);
|
||||
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(),
|
||||
domain.getCwa(), huc);
|
||||
if (map != null && map.get(pfaf) != null) {
|
||||
|
||||
if (map != null && map.get(pfaf) != null) {
|
||||
|
||||
int index = 0;
|
||||
for (Long pfafToCheck : map.keySet()) {
|
||||
if (pfafToCheck.equals(pfaf)) {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
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)));
|
||||
try {
|
||||
IDataRecord rec = dataStore.retrieve(
|
||||
uri + "/" + domain.getCwa(), huc,
|
||||
Request.buildPointRequest(new Point(index, 0)));
|
||||
|
||||
if (rec != null) {
|
||||
float[] values = ((FloatDataRecord) rec)
|
||||
.getFloatData();
|
||||
if (rec != null) {
|
||||
float[] values = ((FloatDataRecord) rec)
|
||||
.getFloatData();
|
||||
|
||||
boolean isFFG = false;
|
||||
boolean isFFG = false;
|
||||
|
||||
if (source.getSourceType().equals(
|
||||
SOURCE_TYPE.GUIDANCE.getSourceType())) {
|
||||
isFFG = true;
|
||||
}
|
||||
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]);
|
||||
}
|
||||
if (values != null) {
|
||||
// System.err.println(sourceName);
|
||||
if (isFFG) {
|
||||
((FFMPGuidanceBasin) basin).setValue(
|
||||
sourceName, idate, values[0]);
|
||||
} else {
|
||||
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) {
|
||||
statusHandler.handle(Priority.ERROR, "ERROR Retrieving HUC..."
|
||||
+ huc);
|
||||
|
@ -575,56 +576,54 @@ public class FFMPRecord extends PersistablePluginDataObject
|
|||
boolean aggregate = false;
|
||||
fbd = getBasinData(ALL);
|
||||
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
|
||||
.getVirtualGageBasins(key, domain.getCwa());
|
||||
if (lids != null) {
|
||||
int size = lids.size();
|
||||
|
||||
if (lids != null) {
|
||||
int size = lids.size();
|
||||
if (size > 0) {
|
||||
|
||||
if (size > 0) {
|
||||
IDataRecord rec = null;
|
||||
|
||||
IDataRecord rec = null;
|
||||
|
||||
try {
|
||||
rec = dataStore.retrieve(
|
||||
uri + "/" + domain.getCwa(), ALL,
|
||||
Request.ALL);
|
||||
} catch (Exception e) {
|
||||
// This is a routine error. Sometimes you can not have data for a configured source
|
||||
// This suppresses spurrious messages that would inflate the loags needlessly.
|
||||
if (statusHandler.isPriorityEnabled(Priority.DEBUG)) {
|
||||
statusHandler.handle(Priority.DEBUG,
|
||||
"FFMPRecord: no data for: " + uri + "/"
|
||||
+ domain.getCwa());
|
||||
}
|
||||
try {
|
||||
rec = dataStore.retrieve(uri + "/" + domain.getCwa(),
|
||||
ALL, Request.ALL);
|
||||
} catch (Exception e) {
|
||||
// This is a routine error. Sometimes you can not have
|
||||
// data for a configured source
|
||||
// This suppresses spurrious messages that would inflate
|
||||
// the loags needlessly.
|
||||
if (statusHandler.isPriorityEnabled(Priority.DEBUG)) {
|
||||
statusHandler.handle(Priority.DEBUG,
|
||||
"FFMPRecord: no data for: " + uri + "/"
|
||||
+ domain.getCwa());
|
||||
}
|
||||
}
|
||||
|
||||
if (rec != null) {
|
||||
float[] values = ((FloatDataRecord) rec)
|
||||
.getFloatData();
|
||||
if (values != null) {
|
||||
int j = 0;
|
||||
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++;
|
||||
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(idate, values[j]);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -646,11 +645,11 @@ public class FFMPRecord extends PersistablePluginDataObject
|
|||
boolean aggregate = false;
|
||||
fbd = getBasinData(ALL);
|
||||
String key = getDataKey();
|
||||
ImmutableDate idate = getCacheDate(date);
|
||||
|
||||
for (DomainXML domain : template.getDomains()) {
|
||||
|
||||
LinkedHashMap<String, FFMPVirtualGageBasinMetaData> lids = template
|
||||
.getVirtualGageBasins(key, domain.getCwa());
|
||||
LinkedHashMap<String, FFMPVirtualGageBasinMetaData> lids = template.getVirtualGageBasins(key, domain.getCwa());
|
||||
int size = lids.size();
|
||||
|
||||
if (size > 0) {
|
||||
|
@ -677,7 +676,7 @@ public class FFMPRecord extends PersistablePluginDataObject
|
|||
fvgbmd.getLookupId(), aggregate);
|
||||
fbd.put(fvgbmd.getLookupId(), vgbasin);
|
||||
}
|
||||
vgbasin.setValue(date, values[j]);
|
||||
vgbasin.setValue(idate, values[j]);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
@ -814,5 +813,45 @@ public class FFMPRecord extends PersistablePluginDataObject
|
|||
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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1282,7 +1282,7 @@ public class FFMPTemplates {
|
|||
* @param huc
|
||||
* @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;
|
||||
HashMap<String, LinkedHashMap<Long, ?>> hucMap = null;
|
||||
|
@ -1398,7 +1398,7 @@ public class FFMPTemplates {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
public LinkedHashMap<String, FFMPVirtualGageBasinMetaData> getVirtualGageBasins(
|
||||
public synchronized LinkedHashMap<String, FFMPVirtualGageBasinMetaData> getVirtualGageBasins(
|
||||
String dataKey, String cwa) {
|
||||
|
||||
LinkedHashMap<String, FFMPVirtualGageBasinMetaData> map = null;
|
||||
|
|
Loading…
Add table
Reference in a new issue