Omaha #4125 - Fix jaxb performance issue
Change-Id: I7b306098a96b86fb5a9c1262b2fb92f5f24ba0b1 Former-commit-id: 9f81dd0ec5e00827f5a9a98376f15c5139908ce1
This commit is contained in:
parent
ecb7199c3b
commit
1184d7629c
3 changed files with 55 additions and 32 deletions
|
@ -70,6 +70,7 @@ import com.raytheon.uf.common.localization.PathManagerFactory;
|
|||
import com.raytheon.uf.common.message.WsId;
|
||||
import com.raytheon.uf.common.python.PyUtil;
|
||||
import com.raytheon.uf.common.python.PythonEval;
|
||||
import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
@ -107,7 +108,7 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
|
|||
* Jan 21, 2014 #2720 randerso Improve efficiency of merging polygons in edit area generation
|
||||
* Aug 27, 2014 #3563 randerso Fix issue where edit areas are regenerated unnecessarily
|
||||
* Oct 20, 2014 #3685 randerso Changed structure of editAreaAttrs to keep zones from different maps separated
|
||||
*
|
||||
* Feb 19, 2015 #4125 rjpeter Fix jaxb performance issue
|
||||
* </pre>
|
||||
*
|
||||
* @author randerso
|
||||
|
@ -577,6 +578,9 @@ public class MapManager {
|
|||
}
|
||||
|
||||
if (areaDir.isDirectory() && areaDir.canWrite()) {
|
||||
SingleTypeJAXBManager<ReferenceData> jaxbManager = ReferenceData
|
||||
.getJAXBManager();
|
||||
|
||||
for (ReferenceData ref : data) {
|
||||
ref.getPolygons(CoordinateType.LATLON);
|
||||
File path = new File(FileUtil.join(areaDir.getAbsolutePath(),
|
||||
|
@ -586,8 +590,7 @@ public class MapManager {
|
|||
// old one, write a warning to the log.
|
||||
ReferenceData other = null;
|
||||
try {
|
||||
other = ReferenceData.getJAXBManager()
|
||||
.unmarshalFromXmlFile(path);
|
||||
other = jaxbManager.unmarshalFromXmlFile(path);
|
||||
} catch (Exception e) {
|
||||
statusHandler.error("Error reading edit area file "
|
||||
+ path.getAbsolutePath(), e);
|
||||
|
@ -604,7 +607,7 @@ public class MapManager {
|
|||
} else {
|
||||
// Write the new edit area file.
|
||||
try {
|
||||
ReferenceData.getJAXBManager().marshalToXmlFile(ref,
|
||||
jaxbManager.marshalToXmlFile(ref,
|
||||
path.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
statusHandler.error("Error writing edit area to file "
|
||||
|
|
|
@ -33,6 +33,7 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
|||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.LocalizationUtil;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.util.FileUtil;
|
||||
|
@ -50,7 +51,7 @@ import com.raytheon.uf.common.util.FileUtil;
|
|||
* Aug 07, 2013 1561 njensen Use pm.listFiles() instead of pm.listStaticFiles()
|
||||
* Sep 30, 2013 2361 njensen Use JAXBManager for XML
|
||||
* Sep 08, 2104 3592 randerso Changed to use new pm listStaticFiles()
|
||||
*
|
||||
* Feb 19, 2015 4125 rjpeter Fix jaxb performance issue
|
||||
* </pre>
|
||||
*
|
||||
* @author dgilling
|
||||
|
@ -65,9 +66,9 @@ public class ReferenceMgr {
|
|||
private static final String EDIT_AREAS_DIR = FileUtil.join("gfe",
|
||||
"editAreas");
|
||||
|
||||
private IPathManager pathMgr;
|
||||
private final IPathManager pathMgr;
|
||||
|
||||
private GridLocation dbGridLocation;
|
||||
private final GridLocation dbGridLocation;
|
||||
|
||||
public ReferenceMgr(final IFPServerConfig config) {
|
||||
this.pathMgr = PathManagerFactory.getPathManager();
|
||||
|
@ -113,6 +114,8 @@ public class ReferenceMgr {
|
|||
final List<ReferenceID> ids) {
|
||||
ServerResponse<List<ReferenceData>> sr = new ServerResponse<List<ReferenceData>>();
|
||||
List<ReferenceData> data = new ArrayList<ReferenceData>();
|
||||
SingleTypeJAXBManager<ReferenceData> jaxbManager = ReferenceData
|
||||
.getJAXBManager();
|
||||
|
||||
// process each ReferenceID requested
|
||||
for (ReferenceID id : ids) {
|
||||
|
@ -131,8 +134,8 @@ public class ReferenceMgr {
|
|||
// open and read the file
|
||||
ReferenceData refData = null;
|
||||
try {
|
||||
refData = ReferenceData.getJAXBManager().unmarshalFromXmlFile(
|
||||
lf.getFile().getPath());
|
||||
refData = jaxbManager.unmarshalFromXmlFile(lf.getFile()
|
||||
.getPath());
|
||||
} catch (Exception e) {
|
||||
sr.addMessage("Unable to read reference data [" + id + "]");
|
||||
data = Collections.emptyList();
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
**/
|
||||
package com.raytheon.uf.common.dataplugin.gfe.reference;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -36,7 +38,7 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation;
|
|||
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DBit;
|
||||
import com.raytheon.uf.common.dataplugin.gfe.util.GfeUtil;
|
||||
import com.raytheon.uf.common.geospatial.MapUtil;
|
||||
import com.raytheon.uf.common.geospatial.adapter.JTSGeometryAdapter;
|
||||
import com.raytheon.uf.common.geospatial.adapter.GeometryAdapter;
|
||||
import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
|
@ -69,7 +71,7 @@ import com.vividsolutions.jts.geom.Polygonal;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* 01/31/2008 randerso Initial creation
|
||||
* 10/01/2013 2361 njensen Added static JAXBManager
|
||||
*
|
||||
* 02/19/2015 4125 rjpeter Updated to return a new pooled JAXBManager on request.
|
||||
* </pre>
|
||||
*
|
||||
* @author randerso
|
||||
|
@ -85,8 +87,7 @@ public class ReferenceData {
|
|||
|
||||
private static final GeometryFactory geometryFactory = new GeometryFactory();
|
||||
|
||||
private static final SingleTypeJAXBManager<ReferenceData> jaxb = SingleTypeJAXBManager
|
||||
.createWithoutException(ReferenceData.class);
|
||||
private static Reference<SingleTypeJAXBManager<ReferenceData>> jaxbRef = null;
|
||||
|
||||
public enum RefType {
|
||||
NONE, QUERY, POLYGON, QUERY_POLYGON
|
||||
|
@ -102,7 +103,7 @@ public class ReferenceData {
|
|||
@DynamicSerializeElement
|
||||
private String query;
|
||||
|
||||
@XmlJavaTypeAdapter(value = JTSGeometryAdapter.class)
|
||||
@XmlJavaTypeAdapter(value = GeometryAdapter.class)
|
||||
@DynamicSerializeElement
|
||||
private MultiPolygon polygons;
|
||||
|
||||
|
@ -113,12 +114,27 @@ public class ReferenceData {
|
|||
private CoordinateType coordType;
|
||||
|
||||
/**
|
||||
* Returns the JAXBManager that handles ReferenceData
|
||||
* Returns the JAXBManager that handles ReferenceData.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static SingleTypeJAXBManager<ReferenceData> getJAXBManager() {
|
||||
return jaxb;
|
||||
// not worried about concurrency, two can be created without issue
|
||||
SingleTypeJAXBManager<ReferenceData> rval = null;
|
||||
|
||||
if (jaxbRef != null) {
|
||||
rval = jaxbRef.get();
|
||||
}
|
||||
|
||||
if (rval == null) {
|
||||
rval = SingleTypeJAXBManager.createWithoutException(true,
|
||||
ReferenceData.class);
|
||||
if (rval != null) {
|
||||
jaxbRef = new SoftReference<>(rval);
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,7 +240,7 @@ public class ReferenceData {
|
|||
* @return
|
||||
*/
|
||||
public MultiPolygon getPolygons(CoordinateType coordType) {
|
||||
if (grid != null && polygons == null) {
|
||||
if ((grid != null) && (polygons == null)) {
|
||||
calcPolygons();
|
||||
}
|
||||
convertTo(coordType);
|
||||
|
@ -308,7 +324,7 @@ public class ReferenceData {
|
|||
* from these newly converted polygons and the current Reference ID.
|
||||
*/
|
||||
private void convertToGrid() {
|
||||
if (grid != null && polygons == null) {
|
||||
if ((grid != null) && (polygons == null)) {
|
||||
coordType = CoordinateType.GRID;
|
||||
calcPolygons();
|
||||
}
|
||||
|
@ -339,7 +355,7 @@ public class ReferenceData {
|
|||
* ID.
|
||||
*/
|
||||
private void convertToLatLon() {
|
||||
if (grid != null && polygons == null) {
|
||||
if ((grid != null) && (polygons == null)) {
|
||||
coordType = CoordinateType.GRID;
|
||||
calcPolygons();
|
||||
}
|
||||
|
@ -361,11 +377,11 @@ public class ReferenceData {
|
|||
* @return
|
||||
*/
|
||||
public RefType refType() {
|
||||
if (query != null && query.length() > 0 && polygons != null) {
|
||||
if ((query != null) && (query.length() > 0) && (polygons != null)) {
|
||||
return RefType.QUERY_POLYGON;
|
||||
} else if (query != null && query.length() > 0) {
|
||||
} else if ((query != null) && (query.length() > 0)) {
|
||||
return RefType.QUERY;
|
||||
} else if (polygons != null || grid != null) {
|
||||
} else if ((polygons != null) || (grid != null)) {
|
||||
return RefType.POLYGON;
|
||||
}
|
||||
|
||||
|
@ -378,7 +394,7 @@ public class ReferenceData {
|
|||
* @return
|
||||
*/
|
||||
public boolean isQuery() {
|
||||
return query != null && query.length() > 0;
|
||||
return (query != null) && (query.length() > 0);
|
||||
}
|
||||
|
||||
// no implementation found in C++ source
|
||||
|
@ -509,13 +525,13 @@ public class ReferenceData {
|
|||
int endcol = -1;
|
||||
while (endcol < cols) {
|
||||
startcol = endcol + 1;
|
||||
while (startcol < cols && !grid.getAsBoolean(startcol, row)) {
|
||||
while ((startcol < cols) && !grid.getAsBoolean(startcol, row)) {
|
||||
startcol++;
|
||||
}
|
||||
|
||||
endcol = startcol + 1;
|
||||
if (startcol < cols) {
|
||||
while (endcol < cols && grid.getAsBoolean(endcol, row)) {
|
||||
while ((endcol < cols) && grid.getAsBoolean(endcol, row)) {
|
||||
endcol++;
|
||||
}
|
||||
|
||||
|
@ -674,11 +690,11 @@ public class ReferenceData {
|
|||
RefType type = refType();
|
||||
s.append(" Type: " + type);
|
||||
|
||||
if (type == RefType.POLYGON || type == RefType.QUERY_POLYGON) {
|
||||
if ((type == RefType.POLYGON) || (type == RefType.QUERY_POLYGON)) {
|
||||
// s.append(" Polygons: " + polygons);
|
||||
s.append(" CoordType: " + coordType);
|
||||
}
|
||||
if (type == RefType.QUERY || type == RefType.QUERY_POLYGON) {
|
||||
if ((type == RefType.QUERY) || (type == RefType.QUERY_POLYGON)) {
|
||||
s.append(" Query: " + query);
|
||||
}
|
||||
|
||||
|
@ -727,12 +743,13 @@ public class ReferenceData {
|
|||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
result = (prime * result)
|
||||
+ (coordType == null ? 0 : coordType.hashCode());
|
||||
result = prime * result + (gloc == null ? 0 : gloc.hashCode());
|
||||
result = prime * result + (grid == null ? 0 : grid.hashCode());
|
||||
result = prime * result + (polygons == null ? 0 : polygons.hashCode());
|
||||
result = prime * result + (query == null ? 0 : query.hashCode());
|
||||
result = (prime * result) + (gloc == null ? 0 : gloc.hashCode());
|
||||
result = (prime * result) + (grid == null ? 0 : grid.hashCode());
|
||||
result = (prime * result)
|
||||
+ (polygons == null ? 0 : polygons.hashCode());
|
||||
result = (prime * result) + (query == null ? 0 : query.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue