From 334b156d2e0a6e9a210b516e413dabefc239ec83 Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Tue, 30 Sep 2014 12:37:13 -0500 Subject: [PATCH] Omaha #3353 Fix deadlock that freezes cave. Change-Id: I4afa5c505178f30ada5dd58612b0703ab9529e6b Former-commit-id: acbde703a2b973b5428f8476514fdad1639c6554 [formerly 871fa68ddf242f1e63286939b1324fc3197c7336] Former-commit-id: 398a8d6043ad5f4afbb16ecafcb268bb79fe57cc --- .../viz/warngen/gui/WarngenLayer.java | 73 +++++++++++++----- .../warning/gis/GeospatialDataGenerator.java | 9 ++- .../gis/GenerateGeospatialDataResult.java | 76 +++++++++++++++++++ 3 files changed, 139 insertions(+), 19 deletions(-) create mode 100644 edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/gis/GenerateGeospatialDataResult.java diff --git a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/gui/WarngenLayer.java b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/gui/WarngenLayer.java index be27b8da41..508a4cc112 100644 --- a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/gui/WarngenLayer.java +++ b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/gui/WarngenLayer.java @@ -67,6 +67,7 @@ import com.raytheon.uf.common.dataplugin.warning.config.BulletActionGroup; import com.raytheon.uf.common.dataplugin.warning.config.DialogConfiguration; import com.raytheon.uf.common.dataplugin.warning.config.GridSpacing; import com.raytheon.uf.common.dataplugin.warning.config.WarngenConfiguration; +import com.raytheon.uf.common.dataplugin.warning.gis.GenerateGeospatialDataResult; import com.raytheon.uf.common.dataplugin.warning.gis.GeospatialData; import com.raytheon.uf.common.dataplugin.warning.gis.GeospatialDataSet; import com.raytheon.uf.common.dataplugin.warning.gis.GeospatialFactory; @@ -231,6 +232,7 @@ import com.vividsolutions.jts.io.WKTReader; * 09/15/2014 3353 rferrel No longer have null parent shell for the GenerateGeoDataSetDialog. * 09/17/2014 ASM #15465 Qinglu Lin get backupOfficeShort and backupOfficeLoc from backup WFO config.xml, and pop up AlertViz if * any of them is missing. + * 11/03/2014 3353 rferrel Ignore GeoSpatialData notification when this is the instance layer will do an update. * * * @author mschenke @@ -242,13 +244,21 @@ public class WarngenLayer extends AbstractStormTrackResource { .getHandler(WarngenLayer.class); String uniqueFip = null; + String backupOfficeShort = null; + String backupOfficeLoc = null; Map geomArea = new HashMap(); Map geomCentroid = new HashMap(); + /** + * Geospatial data generator notifications caused by instance's actions. + * When notification arrives no futher work needs to be done. + */ + private final Set ignoreNotifications = new HashSet(); + private static class GeospatialDataList { private static final String LOCAL_GEOM = "localGeometry"; @@ -654,21 +664,33 @@ public class WarngenLayer extends AbstractStormTrackResource { @Override public void notificationArrived(NotificationMessage[] messages) { + boolean initWarngen = false; for (NotificationMessage message : messages) { try { Object payload = message.getMessagePayload(); - if (payload instanceof String) { - System.out - .println("Geometry Metadata has been updated based on " - + payload + " shapefile data"); - warngenLayer.siteMap.clear(); - warngenLayer.init(warngenLayer.configuration); + if (payload instanceof GenerateGeospatialDataResult) { + GenerateGeospatialDataResult result = (GenerateGeospatialDataResult) payload; + synchronized (warngenLayer.ignoreNotifications) { + String curKey = result.getArea() + "." + + result.getSite(); + + if (warngenLayer.ignoreNotifications + .contains(curKey)) { + warngenLayer.ignoreNotifications.remove(curKey); + } else { + siteMap.remove(curKey); + initWarngen = true; + } + } } } catch (NotificationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + statusHandler.handle(Priority.PROBLEM, + "Getting notification message's payload", e); } } + if (initWarngen) { + warngenLayer.init(warngenLayer.configuration); + } } } @@ -1220,12 +1242,13 @@ public class WarngenLayer extends AbstractStormTrackResource { statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); } + customMaps.loadCustomMaps(Arrays.asList(config.getMaps())); + + createAreaAndCentroidMaps(); + + this.configuration = config; }// end synchronize - customMaps.loadCustomMaps(Arrays.asList(config.getMaps())); - createAreaAndCentroidMaps(); - - this.configuration = config; System.out.println("Total time to init warngen config = " + (System.currentTimeMillis() - t0) + "ms"); } @@ -1267,6 +1290,16 @@ public class WarngenLayer extends AbstractStormTrackResource { } else { // This makes sure dialog exists and is open createDialog(); + + /* + * Add to list prior to opening the genDialog. That + * way if the notfication arrives prior to or after + * closing the genDialog the notfication will be + * ignored. + */ + synchronized (ignoreNotifications) { + ignoreNotifications.add(currKey); + } GenerateGeoDataSetDialog genDialog = new GenerateGeoDataSetDialog( dialog.getShell(), site, gmd); @@ -1490,10 +1523,12 @@ public class WarngenLayer extends AbstractStormTrackResource { boolean shortTag = false; boolean locTag = false; String infoType = null; - if (backupOfficeShort == null || backupOfficeShort.trim().length() == 0) { + if (backupOfficeShort == null + || backupOfficeShort.trim().length() == 0) { shortTag = true; } - if (backupOfficeLoc == null || backupOfficeLoc.trim().length() == 0) { + if (backupOfficeLoc == null + || backupOfficeLoc.trim().length() == 0) { locTag = true; } if (shortTag && locTag) { @@ -1506,8 +1541,9 @@ public class WarngenLayer extends AbstractStormTrackResource { } } if (infoType != null) { - statusHandler.handle(Priority.CRITICAL, "Info for " + infoType + " in " + backupSite + - "'s config.xml is missing."); + statusHandler.handle(Priority.CRITICAL, "Info for " + + infoType + " in " + backupSite + + "'s config.xml is missing."); } } } @@ -1601,7 +1637,9 @@ public class WarngenLayer extends AbstractStormTrackResource { public enum GeoFeatureType { COUNTY("county", "FIPS"), MARINE("marinezones", "ID"); final private String tableName; + final private String fipsField; + private GeoFeatureType(String tableName, String fipsField) { this.tableName = tableName; this.fipsField = fipsField; @@ -1649,7 +1687,8 @@ public class WarngenLayer extends AbstractStormTrackResource { else if (type == GeoFeatureType.MARINE) templateName = "specialMarineWarning"; else - throw new IllegalArgumentException("Unsupported geo feature type " + type); + throw new IllegalArgumentException( + "Unsupported geo feature type " + type); WarngenConfiguration config = WarngenConfiguration.loadConfig( templateName, getLocalizedSite(), null); loadGeodataForConfiguration(config); diff --git a/edexOsgi/com.raytheon.edex.plugin.warning/src/com/raytheon/edex/plugin/warning/gis/GeospatialDataGenerator.java b/edexOsgi/com.raytheon.edex.plugin.warning/src/com/raytheon/edex/plugin/warning/gis/GeospatialDataGenerator.java index ab40c5a799..b8d5a1b3fd 100644 --- a/edexOsgi/com.raytheon.edex.plugin.warning/src/com/raytheon/edex/plugin/warning/gis/GeospatialDataGenerator.java +++ b/edexOsgi/com.raytheon.edex.plugin.warning/src/com/raytheon/edex/plugin/warning/gis/GeospatialDataGenerator.java @@ -47,6 +47,7 @@ import com.raytheon.uf.common.dataplugin.warning.config.AreaSourceConfiguration; import com.raytheon.uf.common.dataplugin.warning.config.DialogConfiguration; import com.raytheon.uf.common.dataplugin.warning.config.GeospatialConfiguration; import com.raytheon.uf.common.dataplugin.warning.config.WarngenConfiguration; +import com.raytheon.uf.common.dataplugin.warning.gis.GenerateGeospatialDataResult; import com.raytheon.uf.common.dataplugin.warning.gis.GeospatialData; import com.raytheon.uf.common.dataplugin.warning.gis.GeospatialDataSet; import com.raytheon.uf.common.dataplugin.warning.gis.GeospatialFactory; @@ -109,6 +110,7 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier; * Apr 29, 2014 3033 jsanchez Properly handled site and back up site files. * Jul 15, 2014 3352 rferrel Better logging and threading added. * Aug 21, 2014 3353 rferrel Added getGeospatialTimeset and cluster locking of METADATA_FILE. + * generateGeoSpatialList now sends GenerateGeospatialDataResult. * * * @author rjpeter @@ -457,12 +459,15 @@ public class GeospatialDataGenerator { persistGeoData(site, lastRunTimeMap, curTime, dataSet); if (updaterEndpoint != null) { + GenerateGeospatialDataResult result = new GenerateGeospatialDataResult(); String updatedTimeStamp = getTimeStamp(curTime, lastRunTime); - + result.setTimestamp(updatedTimeStamp); + result.setSite(site); + result.setArea(metaData.getAreaSource()); try { EDEXUtil.getMessageProducer().sendAsync( - updaterEndpoint, updatedTimeStamp); + updaterEndpoint, result); } catch (EdexException e) { statusHandler.error("Could not send message to " + updaterEndpoint, e); diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/gis/GenerateGeospatialDataResult.java b/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/gis/GenerateGeospatialDataResult.java new file mode 100644 index 0000000000..0736da0498 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/gis/GenerateGeospatialDataResult.java @@ -0,0 +1,76 @@ +/** + * 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. + **/ +package com.raytheon.uf.common.dataplugin.warning.gis; + +import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; +import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; + +/** + * The results from a GenerateGeospatialDataRequest. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 3, 2014  3353      rferrel     Initial creation
+ * 
+ * 
+ * + * @author rferrel + * @version 1.0 + */ + +@DynamicSerialize +public class GenerateGeospatialDataResult { + @DynamicSerializeElement + private String timestamp; + + @DynamicSerializeElement + private String site; + + @DynamicSerializeElement + private String area; + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getSite() { + return site; + } + + public void setSite(String site) { + this.site = site; + } + + public String getArea() { + return area; + } + + public void setArea(String area) { + this.area = area; + } +}