warngen JMS workaround, fixes #217

This commit is contained in:
Michael James 2018-06-07 18:02:47 -06:00 committed by mjames-upc
parent 5795a00b3c
commit e6c6643204
3 changed files with 38 additions and 305 deletions

View file

@ -121,6 +121,7 @@ import com.vividsolutions.jts.geom.LineString;
* if there is no storm motion.
* 03-18-2016 ASM #18751 D. Friedman Followup for #18421: Do not set StormTrackState.oneStormAngle
* when motion is zero.
* 06-07-2018 mjames@ucar Do not post data.
*
* </pre>
*
@ -1001,7 +1002,6 @@ public class StormTrackDisplay implements IRenderable {
}
state.speed = speed;
postData(state);
}
private void generateNewTrackInfo(StormTrackState state, int anchorIndex,
@ -1154,7 +1154,6 @@ public class StormTrackDisplay implements IRenderable {
state.timePoints = timePoints;
state.futurePoints = futurePoints;
postData(state);
}
private Coordinate updateAnchorPoint(StormTrackState currentState,
@ -1468,19 +1467,4 @@ public class StormTrackDisplay implements IRenderable {
return (360 + angle) % 360;
}
private void postData(StormTrackState state) {
if (!(state.speed > 0)) {
return;
}
StormTrackData data = new StormTrackData();
Coordinate[] coords = new Coordinate[state.timePoints.length];
for (int i = 0; i < coords.length; ++i) {
coords[i] = new Coordinate(state.timePoints[i].coord);
}
data.setCoordinates(coords);
data.setMotionDirection(state.angle);
data.setMotionSpeed((int) mpsToKts.convert(state.speed));
dataManager.setStormTrackData(data);
}
}

View file

@ -1,282 +0,0 @@
/**
* 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.viz.warngen.comm;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import com.raytheon.uf.common.dataplugin.text.request.InsertStdTextProductRequest;
import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.status.IPerformanceStatusHandler;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.PerformanceStatus;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.comm.JMSConnection;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.localization.LocalizationManager;
import com.raytheon.uf.viz.core.requests.ThriftClient;
import com.raytheon.viz.core.mode.CAVEMode;
import com.raytheon.viz.texteditor.TextWorkstationConstants;
import com.raytheon.viz.texteditor.msgs.IWarngenObserver;
import com.raytheon.viz.texteditor.util.SiteAbbreviationUtil;
/**
* Sends warning products to text workstation and text database.
*
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 11, 2009 mschenke Initial creation
* 01Jun2010 2187 cjeanbap Added operational mode functionality
* 02Aug2010 2187 cjeanbap Update variable/method signature to be consistent.
* 04Oct2010 7193 cjeanbap Add time-to-live value to MessageProducer.
* Sep 13, 2013 2368 rjpeter Set delivery mode to PERSISTENT.
* May 7, 2015 ASM #17438 D. Friedman Clean up debug and performance logging.
* Sep 03, 2015 4784 rjpeter Set notifySubscriptions on sendToTextDatabase.
* Jun 15, 2017 ---- mjames@ucar Force practice mode.
* </pre>
*
* @author mschenke
* @version 1.0
*/
public class WarningSender implements IWarngenObserver {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(WarningSender.class);
private static final IPerformanceStatusHandler perfLog = PerformanceStatus
.getHandler("WG:");
private final String hostName = null;
private boolean notifyError;
private static final long MILLISECONDS_PER_SECOND = 1000;
private static final long SECONDS_PER_MINUTE = 60;
private static final long TTL_MINUTES = 5;
private static Pattern PATTERN = Pattern.compile("(\\d{1,1})");
private static final SimpleDateFormat sdf;
static {
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
}
/*
* (non-Javadoc) Incoming message was not a binary
*
* @see
* com.raytheon.viz.texteditor.msgs.IWarngenObserver#setTextWarngenDisplay
* (java.lang.String)
*/
@Override
public void setTextWarngenDisplay(String warning, boolean ne) {
this.notifyError = ne;
String number = "0";
String host = TextWorkstationConstants.getId();
long t0 = System.currentTimeMillis();
String siteNode = SiteAbbreviationUtil.getSiteNode(LocalizationManager
.getInstance().getCurrentSite());
perfLog.logDuration("Get site node time",
System.currentTimeMillis() - t0);
if (host == null) {
statusHandler.handle(Priority.ERROR,
"Text Workstation host not set in preferences.");
} else {
Matcher m = PATTERN.matcher(host);
if (m.find()) {
number = m.group();
}
}
String id = siteNode + "WRKWG" + number;
boolean sentToTextDatabase = false;
try {
boolean messageNotSent = true;
int connectCount = 0;
t0 = System.currentTimeMillis();
byte[] data = SerializationUtil.transformToThrift(id + ":"
+ warning);
while (messageNotSent && (connectCount < 4)) {
Session s = null;
MessageProducer mp = null;
Connection conn = null;
try {
conn = JMSConnection.getInstance().getFactory()
.createConnection();
s = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
mp = s.createProducer(s
.createQueue(TextWorkstationConstants
.getDestinationTextWorkstationQueueName()));
mp.setTimeToLive(TTL_MINUTES * SECONDS_PER_MINUTE
* MILLISECONDS_PER_SECOND);
BytesMessage m = s.createBytesMessage();
m.writeBytes(data);
m.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
mp.send(m);
long t1 = System.currentTimeMillis();
perfLog.log(id + " sent to text workstation in "
+ (t1 - t0) + "ms in " + (connectCount + 1)
+ (connectCount > 0 ? " tries" : " try"));
messageNotSent = false;
} catch (JMSException e) {
if (notifyError) {
statusHandler
.handle(Priority.PROBLEM,
"Error trying to send product ["
+ id
+ "] to Text Workstation. Attempting to reconnect. ",
e);
notifyError = false;
}
} finally {
if (mp != null) {
try {
mp.close();
mp = null;
} catch (Exception e) {
mp = null;
}
}
if (s != null) {
try {
s.close();
s = null;
} catch (Exception e) {
s = null;
}
}
if (conn != null) {
try {
conn.close();
conn = null;
} catch (Exception e) {
conn = null;
}
}
}
if (messageNotSent) {
if (!sentToTextDatabase) {
try {
sendToTextDatabase(id, warning);
sentToTextDatabase = true;
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Error trying to save product [" + id
+ "] to Text Database: ", e);
}
}
connectCount++;
switch (connectCount) {
case 1:
Thread.sleep(1000);
break;
case 2:
Thread.sleep(5 * 1000);
break;
case 3:
Thread.sleep(30 * 1000);
break;
case 4:
statusHandler.handle(Priority.PROBLEM,
"Could not reconnect (" + id
+ ") after 3 tries: ");
break;
}
}
}
if (!sentToTextDatabase) {
try {
sendToTextDatabase(id, warning);
sentToTextDatabase = true;
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Error trying to save product [" + id
+ "] to Text Database: ", e);
}
}
} catch (UnknownHostException uhe) {
if (notifyError) {
statusHandler.handle(Priority.PROBLEM,
"unable to map hostname, " + hostName
+ ", to an ip address", uhe);
notifyError = false;
}
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Error trying to send product [" + id
+ "] to Text Workstation: ", e);
}
}
/**
* Saves a product to the text database.
*
* @param id
* @param warning
* @throws VizException
*/
public static void sendToTextDatabase(String id, String warning)
throws VizException {
boolean operationalMode = false;
// Generate StdTextProduct and insert into db
long t0 = System.currentTimeMillis();
InsertStdTextProductRequest request = new InsertStdTextProductRequest(id, warning,
operationalMode);
request.setNotifySubscriptions(true);
ThriftClient.sendRequest(request);
perfLog.logDuration(id + " save to textdb",
System.currentTimeMillis() - t0);
}
public static String getCurTimeString() {
String rval = null;
synchronized (sdf) {
rval = sdf.format(new Date());
}
return rval;
}
}

View file

@ -87,11 +87,12 @@ import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.localization.LocalizationManager;
import com.raytheon.uf.viz.core.maps.MapManager;
import com.raytheon.uf.viz.core.requests.ThriftClient;
import com.raytheon.uf.viz.d2d.ui.map.SideView;
import com.raytheon.viz.awipstools.common.stormtrack.StormTrackState.DisplayType;
import com.raytheon.viz.awipstools.common.stormtrack.StormTrackState.Mode;
import com.raytheon.viz.core.mode.CAVEMode;
import com.raytheon.viz.texteditor.msgs.IWarngenObserver;
import com.raytheon.viz.texteditor.TextWorkstationConstants;
import com.raytheon.viz.texteditor.dialogs.TextEditorDialog;
import com.raytheon.viz.texteditor.util.SiteAbbreviationUtil;
import com.raytheon.viz.texteditor.util.VtecUtil;
import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
@ -100,7 +101,6 @@ import com.raytheon.viz.ui.input.EditableManager;
import com.raytheon.viz.ui.simulatedtime.SimulatedTimeOperations;
import com.raytheon.viz.warngen.Activator;
import com.raytheon.viz.warngen.WarngenConstants;
import com.raytheon.viz.warngen.comm.WarningSender;
import com.raytheon.viz.warngen.gis.PolygonUtil;
import com.raytheon.viz.warngen.template.TemplateRunner;
import com.raytheon.viz.warngen.util.CurrentWarnings;
@ -189,6 +189,7 @@ import com.vividsolutions.jts.geom.Polygon;
* Feb 16, 2016 DR 17531 Qinglu Lin Added overloaded setTrackLocked(boolean, boolean), updated expSelected().
* Jul 07, 2016 DR 5665 Jon Schmid Corrected WarngenLayer duration save and restore when selecting new TrackType.
* Jun 25, 2017 mjames@ucar Simple dialog.
* Jun 07, 2018 mjames@ucar Bypass JMS messaging and send directly to a textWS window.
* </pre>
*
* @author chammack
@ -214,6 +215,8 @@ public class WarngenDialog extends CaveSWTDialog implements
private static final int FONT_HEIGHT = 9;
private static Pattern PATTERN = Pattern.compile("(\\d{1,1})");
private class TemplateRunnerInitJob extends Job {
private final String site;
@ -339,7 +342,7 @@ public class WarngenDialog extends CaveSWTDialog implements
private boolean invalidFollowUpAction = false;
private final IWarngenObserver wed = new WarningSender();
private TextEditorDialog wgDlg;
/** Bullet list font. */
private Font bulletListFont = null;
@ -1264,7 +1267,7 @@ public class WarngenDialog extends CaveSWTDialog implements
try {
String result = resultContainer[0];
if (result != null) {
wed.setTextWarngenDisplay(result, true);
setTextWarngenDisplay(result);
updateWarngenUIState(result);
} else {
statusHandler.handle(Priority.PROBLEM,
@ -1290,7 +1293,35 @@ public class WarngenDialog extends CaveSWTDialog implements
}
}
private boolean checkDamSelection() {
protected void setTextWarngenDisplay(String warning) {
String number = "0";
String host = TextWorkstationConstants.getId();
String siteNode = SiteAbbreviationUtil.getSiteNode(LocalizationManager
.getInstance().getCurrentSite());
if (host == null) {
statusHandler.handle(Priority.ERROR,
"Text Workstation host not set in preferences.");
} else {
Matcher m = PATTERN.matcher(host);
if (m.find()) {
number = m.group();
}
}
String id = siteNode + "WRKWG" + number;
try {
String product = id + ":" + warning;
if (wgDlg == null) {
wgDlg = new TextEditorDialog(getShell(), "Text Warngen", false,
"9", true);
}
wgDlg.showWarngenProduct(product, null);
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Error trying to send product [" + id + "] to Text Workstation: ", e);
}
}
private boolean checkDamSelection() {
if (bulletListManager.isDamNameSeletcted()
&& (bulletListManager.isDamCauseSelected() == false)) {
/*