From 6f8dc96c3da2f4ffd3536915083c8cf658822bc8 Mon Sep 17 00:00:00 2001 From: Brian Clements Date: Mon, 21 Jul 2014 17:05:29 -0500 Subject: [PATCH] Omaha #3373 fixed jaxb pooling performance issues Change-Id: Icf7949e956f2b21ba156f4f0a19a2c41d0037681 Former-commit-id: 37d97b9e4897a401c79d5accf275531af5ab945b [formerly 2ec52d8956b77aad30d46d7b4b2202c868b38a4d] Former-commit-id: a20345bf5068ff741fd13a65fe8076107a6a517d --- .../EnsembleGridAssembler.java | 5 ++- .../plugin/grib/spatial/GribSpatialCache.java | 45 ++++++++++++------- .../grib/util/Grib1ParameterLookup.java | 3 +- .../grid/dataset/DatasetInfoLookup.java | 12 ++--- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/decoderpostprocessors/EnsembleGridAssembler.java b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/decoderpostprocessors/EnsembleGridAssembler.java index 8fdeed2d46..07ea4426cf 100644 --- a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/decoderpostprocessors/EnsembleGridAssembler.java +++ b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/decoderpostprocessors/EnsembleGridAssembler.java @@ -81,7 +81,8 @@ import com.raytheon.uf.edex.plugin.grid.dao.GridDao; * Oct 15, 2013 2473 bsteffen Remove deprecated method calls. * Nov 19, 2013 2478 rjpeter Make update process update database also. * Dec 06, 2013 2170 rjpeter Update to pass PluginDataObject[] to notification. - * Apr 21, 2014 2060 njensen Remove dependency on grid dataURI column + * Apr 21, 2014 2060 njensen Remove dependency on grid dataURI column + * Jul 21, 2014 3373 bclement JAXB manager api changes * * * @author bphillip @@ -124,7 +125,7 @@ public class EnsembleGridAssembler implements IDecoderPostProcessor { SingleTypeJAXBManager jaxbManager; try { - jaxbManager = new SingleTypeJAXBManager( + jaxbManager = new SingleTypeJAXBManager(true, CompositeModel.class); } catch (JAXBException e) { statusHandler.handle(Priority.PROBLEM, diff --git a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/spatial/GribSpatialCache.java b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/spatial/GribSpatialCache.java index bdfde24c06..d33263c392 100644 --- a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/spatial/GribSpatialCache.java +++ b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/spatial/GribSpatialCache.java @@ -27,6 +27,8 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import javax.xml.bind.JAXBException; + import org.opengis.metadata.spatial.PixelOrientation; import com.raytheon.edex.plugin.grib.exception.GribException; @@ -74,6 +76,7 @@ import com.vividsolutions.jts.geom.Coordinate; * Jan 04, 2013 15653 M.Porricelli Shift subgrid domain westward like * AWIPSI * Oct 15, 2013 2473 bsteffen Rewrite deprecated code. + * Jul 21, 2014 3373 bclement JAXB managers only live during initializeGrids() * * * @@ -86,15 +89,6 @@ public class GribSpatialCache { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(GribSpatialCache.class); - private static final SingleTypeJAXBManager GRID_COVERAGE_JAXB = SingleTypeJAXBManager - .createWithoutException(GridCoverage.class); - - private static final SingleTypeJAXBManager SUB_GRID_DEF_JAXB = SingleTypeJAXBManager - .createWithoutException(SubGridDef.class); - - private static final SingleTypeJAXBManager SUB_GRID_CENTER_JAXB = SingleTypeJAXBManager - .createWithoutException(DefaultSubGridCenterPoint.class); - /** The singleton instance */ private static GribSpatialCache instance; @@ -429,17 +423,20 @@ public class GribSpatialCache { * Loads and validates subGridDef pointed to by filePath. If definition * empty/invalid returns null. * + * @param subGridDefJaxb * @param filePath + * @param defaultCenter * @return */ - private SubGridDef loadSubGridDef(final String filePath, - final Coordinate defaultCenter) { + private SubGridDef loadSubGridDef( + final SingleTypeJAXBManager subGridDefJaxb, + final String filePath, final Coordinate defaultCenter) { SubGridDef rval = null; File f = new File(filePath); if (f.length() > 0) { try { - rval = SUB_GRID_DEF_JAXB.unmarshalFromXmlFile(f); + rval = subGridDefJaxb.unmarshalFromXmlFile(f); if ((rval.getReferenceModel() == null && rval .getReferenceGrid() == null) || (rval.getModelNames() == null) @@ -498,14 +495,28 @@ public class GribSpatialCache { Map> gridNameMap = new HashMap>(); Map spatialNameMap = new HashMap(); Map subGridDefMap = new HashMap(); + + SingleTypeJAXBManager gridCovJaxb; + SingleTypeJAXBManager subGridDefJaxb; + try { + subGridDefJaxb = new SingleTypeJAXBManager(true, + SubGridDef.class); + gridCovJaxb = new SingleTypeJAXBManager(true, + GridCoverage.class); + } catch (JAXBException e) { + statusHandler.error("Unable to create grid JAXB managers", e); + return; + } + do { ct = ClusterLockUtils.lock("grib", "spatialCache", 120000, true); } while (!LockState.SUCCESSFUL.equals(ct.getLockState())); + try { for (FileData fd : fdl.getCoverageFileList()) { try { - GridCoverage grid = GRID_COVERAGE_JAXB + GridCoverage grid = gridCovJaxb .unmarshalFromXmlFile(fd.getFilePath()); String name = grid.getName(); grid = insert(grid); @@ -535,8 +546,8 @@ public class GribSpatialCache { } for (FileData fd : fdl.getSubGridFileList()) { try { - SubGridDef subGridDef = loadSubGridDef(fd.getFilePath(), - defaultCenterPoint); + SubGridDef subGridDef = loadSubGridDef(subGridDefJaxb, + fd.getFilePath(), defaultCenterPoint); if (subGridDef == null) { continue; } @@ -599,12 +610,14 @@ public class GribSpatialCache { IPathManager pm = PathManagerFactory.getPathManager(); LocalizationFile defaultSubGridLocationFile = pm .getStaticLocalizationFile("/grib/defaultSubGridCenterPoint.xml"); + SingleTypeJAXBManager subGridCenterJaxb = new SingleTypeJAXBManager( + DefaultSubGridCenterPoint.class); if ((defaultSubGridLocationFile != null) && defaultSubGridLocationFile.exists()) { try { DefaultSubGridCenterPoint defaultSubGridLocation = defaultSubGridLocationFile .jaxbUnmarshal(DefaultSubGridCenterPoint.class, - SUB_GRID_CENTER_JAXB); + subGridCenterJaxb); if ((defaultSubGridLocation != null) && (defaultSubGridLocation.getCenterLatitude() != null) && (defaultSubGridLocation.getCenterLongitude() != null)) { diff --git a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/util/Grib1ParameterLookup.java b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/util/Grib1ParameterLookup.java index 7ba53022f6..690741690a 100644 --- a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/util/Grib1ParameterLookup.java +++ b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/util/Grib1ParameterLookup.java @@ -46,6 +46,7 @@ import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; * ------------- -------- ----------- -------------------------- * Mar 09, 2010 4758 bphillip Initial Creation * Oct 15, 2013 2473 bsteffen Remove deprecated method calls. + * Jul 21, 2014 3373 bclement JAXB manager API changes * * * @@ -127,7 +128,7 @@ public class Grib1ParameterLookup { try { JAXBManager jaxbManager = new SingleTypeJAXBManager( - Grib1ParameterSet.class); + true, Grib1ParameterSet.class); if (baseParameterFile.exists()) { Grib1ParameterSet parameterSet = baseParameterFile .jaxbUnmarshal(Grib1ParameterSet.class, jaxbManager); diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java index 54fadee3f5..8835b01e67 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java @@ -28,8 +28,8 @@ import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; -import com.raytheon.uf.common.serialization.JAXBManager; import com.raytheon.uf.common.serialization.SerializationException; +import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; @@ -46,6 +46,7 @@ import com.raytheon.uf.common.status.UFStatus; * ------------- -------- ----------- -------------------------- * Feb 27, 2012 bsteffen Initial creation * Dec 16, 2013 2574 bsteffen Update deprecated method call. + * Jul 21, 2014 3373 bclement changed to use single type JAXB manager * * * @@ -72,9 +73,10 @@ public class DatasetInfoLookup { } private void init() { - JAXBManager manager = null; + SingleTypeJAXBManager manager = null; try { - manager = new JAXBManager(DatasetInfoSet.class); + manager = new SingleTypeJAXBManager(true, + DatasetInfoSet.class); } catch (JAXBException e) { statusHandler .error("Error loading context for DatasetInfo, no datasetInfo will be loaded.", @@ -98,8 +100,8 @@ public class DatasetInfoLookup { return; } try { - DatasetInfoSet set = manager.unmarshalFromXmlFile( - DatasetInfoSet.class, file.getFile()); + DatasetInfoSet set = manager.unmarshalFromXmlFile(file + .getFile()); for (DatasetInfo info : set.getInfos()) { infoMap.put(info.getDatasetId(), info); }