From 75f9f8df3f51a3fbe66b0a5ebc5017864ee5009d Mon Sep 17 00:00:00 2001 From: Greg Armendariz Date: Wed, 7 Aug 2013 14:34:27 -0400 Subject: [PATCH] 13.5.1-11 baseline Former-commit-id: c402dbf6e9d8afb951c3cb0c4102799026b9074d [formerly ea7b22500ee62eab5397d9c9b8014802ac476954] [formerly 4ec04083bd2a4b0edc07f23070037386f5e33a1e [formerly 7142e607157f6d6ac1ba5cb24f3b3dbf9ab75f7f]] Former-commit-id: 4ec04083bd2a4b0edc07f23070037386f5e33a1e Former-commit-id: 26e58d8cdb6500c5a913cab5ae3766c69cd76257 --- .../uf/viz/core/rsc/IInputHandler.java | 5 +- .../d2d/core/legend/D2DLegendResource.java | 4 +- .../alarms/AlertalarmStdTextProductUtil.java | 4 +- .../transform/shef/MetarToShefFilter.java | 60 +++++++------------ .../shef/MetarToShefTransformer.java | 59 ++++++++++++++---- .../transform/shef/obs/ObsToSHEFOptions.java | 43 ++++++++----- 6 files changed, 105 insertions(+), 70 deletions(-) diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/IInputHandler.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/IInputHandler.java index ede8d437f7..8119be86a8 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/IInputHandler.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/IInputHandler.java @@ -30,6 +30,7 @@ import org.eclipse.swt.widgets.Event; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 7/1/06 chammack Initial Creation. + * 08/02/2013 DR 16427 Qinglu Lin (David's approach) Added SYSTEM_RESOURCE_LOW(1) to InputPriority. * * * @@ -39,8 +40,8 @@ import org.eclipse.swt.widgets.Event; public interface IInputHandler { public static enum InputPriority { - LOWEST(0), RESOURCE(3), SYSTEM_RESOURCE(4), PART(5), PERSPECTIVE(6), WINDOW( - 7); + LOWEST(0), SYSTEM_RESOURCE_LOW(1), RESOURCE(3), SYSTEM_RESOURCE(4), PART(5), PERSPECTIVE(6), + WINDOW(7); public Integer value; diff --git a/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/legend/D2DLegendResource.java b/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/legend/D2DLegendResource.java index 6b95b144bd..0f8e253ddc 100644 --- a/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/legend/D2DLegendResource.java +++ b/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/legend/D2DLegendResource.java @@ -71,6 +71,8 @@ import com.raytheon.viz.ui.actions.DummyAction; * drawn into the smaller pane. * Sep 4, 2012 15335 kshresth Will now display lightning/wind fields * when magnification set to 0 + * Aug 2, 2013 DR 16427 Qinglu Lin (David's approach) Changing InputPriority.SYSTEM_RESOURCE to + * InputPriority.SYSTEM_RESOURCE_LOW in initInternal(). * * * @@ -500,7 +502,7 @@ public class D2DLegendResource extends IDisplayPaneContainer rc = getResourceContainer(); if (rc != null) { rc.registerMouseHandler(legendHandler, - InputPriority.SYSTEM_RESOURCE); + InputPriority.SYSTEM_RESOURCE_LOW); rc.registerMouseHandler(changeModeHandler, InputPriority.RESOURCE); } } diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmStdTextProductUtil.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmStdTextProductUtil.java index 76f3c23386..f30156189e 100644 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmStdTextProductUtil.java +++ b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmStdTextProductUtil.java @@ -88,6 +88,8 @@ public class AlertalarmStdTextProductUtil { setCurrentReportfile(); reportAlarm(); + + System.exit(reportWriter.getAlarmCount()); } /* @@ -230,7 +232,7 @@ public class AlertalarmStdTextProductUtil { if (alarmCount > 0) { log.info(alarmCount + " alarms reported, report written to " + reportWriter.getFilename()); - saveReportTotextDb(); + //saveReportTotextDb(); } else { log.info("No alarms reported, info sent to " + reportWriter.getFilename()); diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/MetarToShefFilter.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/MetarToShefFilter.java index 8a91774037..1f5e647741 100644 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/MetarToShefFilter.java +++ b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/MetarToShefFilter.java @@ -27,6 +27,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import javax.xml.bind.JAXBException; @@ -63,6 +64,7 @@ import com.raytheon.uf.edex.decodertools.core.filterimpl.PluginDataObjectFilter; * ---------- ------- -------- -------------------------- * 1/10/2013 15497 wkwock Initial creation * 2/13/2013 1584 mpduff Fix creation of "dummy" config. + * 08/08/2013 16408 wkwock Use different metar.cfg file and options * * * @@ -167,16 +169,13 @@ public class MetarToShefFilter { } } - private PluginDataObject[] filterARun(PluginDataObject[] reports, + private PluginDataObject filterARun(PluginDataObject report, List filterElements) { - int reportCount = 0; - if (reports != null) { - - for (int i = 0; i < reports.length; i++) { - PluginDataObject r = null; - boolean keep = true; - for (AbstractFilterElement element : filterElements) { - r = element.filter(reports[i]); + if (report != null) { + PluginDataObject r = null; + boolean keep = true; + for (AbstractFilterElement element : filterElements) { + r = element.filter(report); // Only allow keep to be set to true. Once true it stays // that way. @@ -200,26 +199,12 @@ public class MetarToShefFilter { } } if (keep) { - reportCount++; + report = r; } else { - reports[i] = null; + report = null; } - } } - if (reportCount == 0) { - reports = new PluginDataObject[0]; - } else { - PluginDataObject[] newReports = new PluginDataObject[reportCount]; - int i = 0; - // Copy in the reports that passed filtering. - for (PluginDataObject report : reports) { - if (report != null) { - newReports[i++] = report; - } - } - reports = newReports; - } - return reports; + return report; } /** @@ -228,19 +213,20 @@ public class MetarToShefFilter { */ // @Override public PluginDataObject[] filter(PluginDataObject[] reports) { - PluginDataObject[] resultRpt = null; - for (MetarToShefRun mtsr : metarToShefRun) { - PluginDataObject[] tmpRprts = reports.clone(); - resultRpt = filterARun(tmpRprts, mtsr.getFilterElements()); - if (resultRpt != null && resultRpt.length >= 1) { - logger.info("Report matchs in filter " + mtsr.getFilterName()); - MetarToShefTransformer.setCfgNOption(mtsr.getConfigFileName(), - mtsr.getMetarToShefOptions()); - break; + HashMap matchList = new HashMap(); + ArrayList reportList = new ArrayList (); + for (PluginDataObject report : reports) { + for (MetarToShefRun mtsr : metarToShefRun) { + PluginDataObject resultRpt = filterARun(report, mtsr.getFilterElements()); + if (resultRpt != null ) { + reportList.add(resultRpt); + matchList.put(resultRpt.getDataURI(), mtsr); + MetarToShefTransformer.setMatchList (matchList); + break; + } } } - - return resultRpt; + return (PluginDataObject[])reportList.toArray(new PluginDataObject[reportList.size()]); } private void createDummyFilter() { diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/MetarToShefTransformer.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/MetarToShefTransformer.java index fa82c881b1..38a1bf2e37 100644 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/MetarToShefTransformer.java +++ b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/MetarToShefTransformer.java @@ -22,6 +22,7 @@ package com.raytheon.edex.transform.shef; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.HashMap; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -51,6 +52,7 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader; * AWIPS2 DR Work * 20120918 1185 jkorman Added save to archive capability. * Jan 30, 2010 15779 lbousaidi added 4 letter to station id for ACR + * Aug 08, 2013 16408 wkwock Use different metar.cfg file and options * * * @author jkorman @@ -81,10 +83,23 @@ public class MetarToShefTransformer extends private static final int P1_MIN = 50; private static final int P2_MAX = 5; - private static String cfgFileName="metar.cfg"; - private static String cmdLnOptions=""; - private static boolean refreshOptions=true; + /* + * Max list for optionsList and matchList to prevent memory leak. + * (500 or any big number should be fine) + */ + private static final int MAX_LIST = 500; + /* + * MetarToShefRun list which has metar.cfg file and options to used by conversion + */ + private static HashMap mtsrList = new HashMap(); + + /* + * List of metar.cfg files + options. + */ + private HashMap optionsList = new HashMap(); + private ObsToSHEFOptions defaultOptions =null; + /** * Construct an instance of this transformer. * @param cmdLine Command line options that may be used if these @@ -92,6 +107,7 @@ public class MetarToShefTransformer extends */ public MetarToShefTransformer(String cmdLine) { super(cmdLine, WMO_HEADER_FMT); + defaultOptions = options; } /** @@ -421,21 +437,38 @@ public class MetarToShefTransformer extends public final byte[] transformMetar(MetarRecord report, Headers headers) throws TransformerException { - if (refreshOptions) { - logger.info("Metar to SHEF now use config file: "+cfgFileName+" with options:"+cmdLnOptions); - options.setCfgFileName(cfgFileName); - options.updateCommandLine(cmdLnOptions); - options.updateOptions(); - refreshOptions=false; + ObsToSHEFOptions tmpOptions=null; + MetarToShefRun mtsr = mtsrList.get(report.getDataURI()); + if (mtsr==null) { + tmpOptions = defaultOptions; + } else { + tmpOptions = optionsList.get(mtsr.getConfigFileName()+mtsr.getMetarToShefOptions()); + if (tmpOptions==null) { + //just to prevent t memory leak + if (optionsList.size()>MAX_LIST) { + optionsList.clear(); + } + tmpOptions = new ObsToSHEFOptions(mtsr.getConfigFileName(),mtsr.getMetarToShefOptions(),true); + optionsList.put(mtsr.getConfigFileName()+mtsr.getMetarToShefOptions(), tmpOptions); + } + mtsrList.remove(report.getDataURI()); } + options=tmpOptions; + logger.info("Metar to SHEF for "+report.getStationId()+" use config file: "+options.getCfgFileName()+" with options:"+mtsr.getMetarToShefOptions()); configureArchiveDir(); return transformReport(report, headers); } - public static void setCfgNOption (String cfg, String options){ - cfgFileName=cfg; - cmdLnOptions=options; - refreshOptions=true; + /* + * set matchList + */ + public static void setMatchList (HashMap matchLst) { + //should add to the list and remove after use. clear if reach certain big number + if (mtsrList.size()>MAX_LIST) { + mtsrList.clear(); + } + + mtsrList.putAll(matchLst); } } \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/obs/ObsToSHEFOptions.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/obs/ObsToSHEFOptions.java index 8adc2b0213..48ffa942d6 100644 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/obs/ObsToSHEFOptions.java +++ b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/obs/ObsToSHEFOptions.java @@ -57,7 +57,8 @@ import com.raytheon.uf.common.localization.PathManagerFactory; * May 24, 2010 jkorman Initial creation * ====================================== * AWIPS2 DR Work - * 20120918 1185 jkorman Added save to archive capability. + * 20120918 1185 jkorman Added save to archive capability. + * Aug 08, 2013 16408 wkwock Added get configuration file name function * * * @@ -66,9 +67,6 @@ import com.raytheon.uf.common.localization.PathManagerFactory; */ public class ObsToSHEFOptions { - // 1 minute update delta. - private static final long UPDATE_DELTA = 60L * 1000L; - private static final String METAR_CFG = "metar.cfg"; private static final String ERROR_1_FMT = "Could not create {%s} context for file \"%s\""; @@ -399,8 +397,6 @@ public class ObsToSHEFOptions { private final boolean localized; - private long updateTime = 0; - /** * * @param cmdLine @@ -414,7 +410,20 @@ public class ObsToSHEFOptions { } else { readConfig(cfgFileName, optConfigContext); } - updateTime = System.currentTimeMillis(); + } + localized = useLocalized; + } + + /** + * + * @param cmdLine + */ + public ObsToSHEFOptions(String configFileName, String cmdLine, boolean useLocalized) { + cfgFileName = configFileName; + initOptions(); + parseCommandLine(cmdLine); + if (useLocalized) { + readConfig(cfgFileName, optConfigContext); } localized = useLocalized; } @@ -845,15 +854,11 @@ public class ObsToSHEFOptions { * Check if the metar.cfg needs to be reread. */ public void updateOptions() { - long cTime = System.currentTimeMillis() - updateTime; - if (cTime > UPDATE_DELTA) { - if (loaded && localized) { - if (cfgFileName==null) { - readConfig(METAR_CFG, optConfigContext); - } else { - readConfig(cfgFileName, optConfigContext); - } - updateTime = System.currentTimeMillis(); + if (loaded && localized) { + if (cfgFileName==null) { + readConfig(METAR_CFG, optConfigContext); + } else { + readConfig(cfgFileName, optConfigContext); } } } @@ -888,6 +893,8 @@ public class ObsToSHEFOptions { }else{ readConfig(cfgFileName, optConfigContext); } + } else { + logger.warn("Uanble to read file "+cfgFileName); } } } else { @@ -990,6 +997,10 @@ public class ObsToSHEFOptions { cfgFileName=fileName; } + public String getCfgFileName () { + return cfgFileName; + } + public String toString() { StringBuilder sb = new StringBuilder();