Merge "Issue #1804 Cache db queries in radar decoder. Change-Id: I534d70e7dc6cc704e066cba9e2307a675996e3be" into omaha_13.3.1

Former-commit-id: a421cfe73e [formerly 6046872ab5 [formerly d17f8b4df74b52f703636d253c25aa4db73dfc6d]]
Former-commit-id: 6046872ab5
Former-commit-id: 26aa93a6f4
This commit is contained in:
Richard Peter 2013-03-19 15:34:36 -05:00 committed by Gerrit Code Review
commit 7d0568efed
3 changed files with 57 additions and 55 deletions

View file

@ -35,6 +35,7 @@ import com.raytheon.edex.plugin.radar.dao.RadarStationDao;
import com.raytheon.edex.plugin.radar.level2.Level2BaseRadar;
import com.raytheon.edex.plugin.radar.level3.Level3BaseRadar;
import com.raytheon.edex.plugin.radar.util.RadarEdexTextProductUtil;
import com.raytheon.edex.plugin.radar.util.RadarSpatialUtil;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.PluginException;
import com.raytheon.uf.common.dataplugin.radar.RadarRecord;
@ -87,6 +88,8 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
* Dec 03, 2010 2235 cjeanbap EDEXUtility.sendMessageAlertViz() signature changed.
* Mar 18, 2013 1804 bsteffen Remove AlphanumericValues from radar
* HDF5.
* Mar 19, 2013 1804 bsteffen Cache db queries in radar decoder.
*
* </pre>
*
* @author bphillip
@ -202,7 +205,8 @@ public class RadarDecoder extends AbstractDecoder {
RadarRecord record = new RadarRecord();
record.setProductCode(l3Radar.getMessageCode());
record.setDataTime(new DataTime(l3Radar.getMessageTimestamp()));
RadarStation station = getStationById(l3Radar.getSourceId());
RadarStation station = RadarSpatialUtil
.getRadarStationByRpgIdDec(l3Radar.getSourceId());
if (station == null) {
record.setIcao("unkn");
logger.error(headers.get("ingestfilename")
@ -656,23 +660,6 @@ public class RadarDecoder extends AbstractDecoder {
record.setRawData(precipPacket.getPrecipData());
}
/**
* Retrieve the radar station from the dao for the rpg id given
*
* @param rpg_id
* @return
*/
private RadarStation getStationById(int rpg_id) {
try {
RadarStation station = radarStationDao.queryByRpgIdDec(String
.format("%03d", rpg_id));
return station;
} catch (Exception e) {
logger.error("Error retrieving RadarStation for id: " + rpg_id, e);
}
return null;
}
/**
* Retrieve the radar station from the dao for the name given
*

View file

@ -38,8 +38,8 @@ import java.util.regex.Pattern;
import org.apache.tools.bzip2.CBZip2InputStream;
import com.raytheon.edex.esb.Headers;
import com.raytheon.edex.plugin.radar.dao.RadarStationDao;
import com.raytheon.edex.plugin.radar.util.RadarEdexTextProductUtil;
import com.raytheon.edex.plugin.radar.util.RadarSpatialUtil;
import com.raytheon.uf.common.dataplugin.radar.RadarStation;
import com.raytheon.uf.common.dataplugin.radar.level3.AlertAdaptationParameters;
import com.raytheon.uf.common.dataplugin.radar.level3.AlertMessage;
@ -716,24 +716,7 @@ public class Level3BaseRadar {
productVersion = theRadarData.readByte();
productSpotBlank = theRadarData.readByte();
if (afosId == "") {
if ("".equals(radarLoc)) {
RadarStationDao stat = new RadarStationDao();
try {
RadarStation loc = stat.queryByRpgIdDec(String
.valueOf(theSourceId));
if (loc != null) {
radarLoc = loc.getRdaId();
radarLoc = radarLoc.substring(1);
}
} catch (DataAccessLayerException e) {
theHandler.handle(Priority.ERROR,
"Unable to query database for radar location", e);
}
}
afosId = RadarTextProductUtil
.createAfosId(theProductCode, radarLoc);
}
lookupAfosId();
int symbologyBlockOffset = theRadarData.readInt() * 2;
int graphicBlockOffset = theRadarData.readInt() * 2;
int tabularBlockOffset = theRadarData.readInt() * 2;
@ -865,24 +848,9 @@ public class Level3BaseRadar {
}
tabularBlock.setString(builder.toString());
if (afosId == "") {
if ("".equals(radarLoc)) {
RadarStationDao stat = new RadarStationDao();
try {
RadarStation loc = stat.queryByRpgIdDec(String
.valueOf(theSourceId));
if (loc != null) {
radarLoc = loc.getRdaId();
radarLoc = radarLoc.substring(1);
}
} catch (DataAccessLayerException e) {
theHandler.handle(Priority.ERROR,
"Unable to query database for radar location", e);
}
}
afosId = RadarTextProductUtil
.createAfosId(theMessageCode, radarLoc);
}
lookupAfosId();
if (RadarTextProductUtil.radarTable.keySet().contains(theMessageCode)) {
byte[] wmoid = wmoHeader.getBytes();
WMOHeader header = new WMOHeader(wmoid, headers);
@ -901,6 +869,29 @@ public class Level3BaseRadar {
}
}
/**
* Set the afosId and radarLoc based off the sourceId.
*/
private void lookupAfosId() {
if (afosId.isEmpty()) {
if (radarLoc.isEmpty()) {
try {
RadarStation loc = RadarSpatialUtil
.getRadarStationByRpgIdDec(theSourceId);
if (loc != null) {
radarLoc = loc.getRdaId();
radarLoc = radarLoc.substring(1);
}
} catch (DataAccessLayerException e) {
theHandler.handle(Priority.ERROR,
"Unable to query database for radar location", e);
}
}
afosId = RadarTextProductUtil
.createAfosId(theMessageCode, radarLoc);
}
}
private void parseRequestResponse() throws IOException {
String temp = new String();
theRadarData.skip(4);

View file

@ -21,11 +21,14 @@ package com.raytheon.edex.plugin.radar.util;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.geotools.referencing.GeodeticCalculator;
import com.raytheon.edex.plugin.radar.dao.RadarStationDao;
import com.raytheon.uf.common.dataplugin.radar.RadarStation;
import com.raytheon.uf.edex.database.DataAccessLayerException;
import com.vividsolutions.jts.geom.Coordinate;
/**
@ -37,6 +40,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 19, 2010 #4473 rjpeter Initial creation.
* Mar 19, 2013 1804 bsteffen Cache db queries in radar decoder.
*
* </pre>
*
@ -45,6 +49,8 @@ import com.vividsolutions.jts.geom.Coordinate;
*/
public class RadarSpatialUtil {
private static Map<Integer, RadarStation> rpgIdDec2radarStation = new ConcurrentHashMap<Integer, RadarStation>();
/**
* Gets the closest RadarStation entry for a given wfo, lat, lon
*
@ -92,4 +98,22 @@ public class RadarSpatialUtil {
return rval;
}
/**
* Provides a level of caching around RadarStationDao.queryByRpgIdDec.
*
* @param rpgIdDec
* @return
* @throws DataAccessLayerException
*/
public static RadarStation getRadarStationByRpgIdDec(int rpgIdDec)
throws DataAccessLayerException {
RadarStation station = rpgIdDec2radarStation.get(rpgIdDec);
if (station == null) {
RadarStationDao stat = new RadarStationDao();
station = stat.queryByRpgIdDec(String.format("%03d", rpgIdDec));
rpgIdDec2radarStation.put(rpgIdDec, station);
}
return station;
}
}