Issue #2757. Added filter for removed stations and cleaned code.

Change-Id: I9998cf3bd20b2ec43956284257ee3dfcb8b52534

Former-commit-id: fa59172d87 [formerly b613a9d5b7e9b1c17fa354c9c6b617da040d1d71]
Former-commit-id: c7c40a3467
This commit is contained in:
Slav Korolev 2014-02-04 09:49:48 -05:00
parent bebd62c6b6
commit cbd17ea025
3 changed files with 150 additions and 132 deletions

View file

@ -47,6 +47,7 @@ import com.raytheon.uf.viz.monitor.util.MonitorConfigConstants.SafeSeasMonitor;
* @version 1.0
*/
public class SSThresholdMgr extends AbstractThresholdMgr {
private static SSThresholdMgr classInstance;
private SSThresholdMgr() {
@ -54,14 +55,19 @@ public class SSThresholdMgr extends AbstractThresholdMgr {
"DefaultSSMonitorThresholds.xml", "safeseas");
areaConfigMgr = getAreaConfigMgr();
init(); // call init() after areaConfigMgr is set
// call init() after areaConfigMgr is set
init();
}
public static SSThresholdMgr getInstance() {
/**
* Get instance.
*
* @return
*/
public static synchronized SSThresholdMgr getInstance() {
if (classInstance == null) {
classInstance = new SSThresholdMgr();
}
return classInstance;
}
@ -69,7 +75,7 @@ public class SSThresholdMgr extends AbstractThresholdMgr {
* DR#11279: When monitor area configuration is changed, threshold manager
* needs to be re-initialized using the new monitor area configuration
*/
public static void reInitialize() {
public static synchronized void reInitialize() {
if (classInstance != null) {
classInstance = null;
}
@ -79,6 +85,13 @@ public class SSThresholdMgr extends AbstractThresholdMgr {
classInstance.saveMonitorThresholds();
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.monitor.thresholds.AbstractThresholdMgr#getThresholdKeys
* (com.raytheon.uf.common.monitor.data.ObConst.DataUsageKey)
*/
@Override
protected ArrayList<String> getThresholdKeys(DataUsageKey dataUsage) {
ArrayList<String> threshKeys = new ArrayList<String>();
@ -96,6 +109,13 @@ public class SSThresholdMgr extends AbstractThresholdMgr {
return threshKeys;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.monitor.thresholds.AbstractThresholdMgr#getAreaConfigMgr
* ()
*/
@Override
public MonitorConfigurationManager getAreaConfigMgr() {
if (areaConfigMgr == null) {
@ -107,57 +127,4 @@ public class SSThresholdMgr extends AbstractThresholdMgr {
}
return areaConfigMgr;
}
// /**
// * Get the path where the display thresholds XML files are contained.
// * @return File path.
// */
// @Override
// public String getDisplayThresholdPath()
// {
// String fs = String.valueOf(File.separatorChar);
// StringBuilder sb = new StringBuilder();
//
// sb.append("safeseas").append(fs);
// sb.append("threshold").append(fs);
// sb.append("display").append(fs);
//
// return sb.toString();
// }
//
// /**
// * Get the path where the monitor thresholds XML files are contained.
// * @return File path.
// */
// @Override
// public String getMonitorThresholdPath()
// {
// String fs = String.valueOf(File.separatorChar);
// StringBuilder sb = new StringBuilder();
//
// sb.append("safeseas").append(fs);
// sb.append("threshold").append(fs);
// sb.append("monitor").append(fs);
//
// return sb.toString();
// }
//
// /**
// * Get the path where the XML file containing the user selected
// * default file is located.
// * @return The path of the user selected default file XML.
// */
// @Override
// public String getDefaultThresholdFilePath()
// {
// String fs = String.valueOf(File.separatorChar);
// StringBuilder sb = new StringBuilder();
//
// sb.append("safeseas").append(fs);
// sb.append("threshold").append(fs);
// sb.append("display").append(fs);
// sb.append("defaultThresh").append(fs);
//
// return sb.toString();
// }
}

View file

@ -54,10 +54,16 @@ public class SnowThresholdMgr extends AbstractThresholdMgr {
"DefaultSnowMonitorThresholds.xml", "snow");
areaConfigMgr = getAreaConfigMgr();
init(); // call init() after areaConfigMgr is set
// call init() after areaConfigMgr is set
init();
}
public static SnowThresholdMgr getInstance() {
/**
* Get instance.
*
* @return
*/
public static synchronized SnowThresholdMgr getInstance() {
if (classInstance == null) {
classInstance = new SnowThresholdMgr();
}
@ -69,7 +75,7 @@ public class SnowThresholdMgr extends AbstractThresholdMgr {
* DR#11279: When monitor area configuration is changed, threshold manager
* needs to be re-initialized using the new monitor area configuration
*/
public static void reInitialize() {
public static synchronized void reInitialize() {
if (classInstance != null) {
classInstance = null;
}
@ -79,6 +85,13 @@ public class SnowThresholdMgr extends AbstractThresholdMgr {
classInstance.saveMonitorThresholds();
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.monitor.thresholds.AbstractThresholdMgr#getThresholdKeys
* (com.raytheon.uf.common.monitor.data.ObConst.DataUsageKey)
*/
@Override
protected ArrayList<String> getThresholdKeys(DataUsageKey dataUsage) {
ArrayList<String> threshKeys = new ArrayList<String>();
@ -96,6 +109,13 @@ public class SnowThresholdMgr extends AbstractThresholdMgr {
return threshKeys;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.monitor.thresholds.AbstractThresholdMgr#getAreaConfigMgr
* ()
*/
@Override
public MonitorConfigurationManager getAreaConfigMgr() {
if (areaConfigMgr == null) {
@ -107,57 +127,4 @@ public class SnowThresholdMgr extends AbstractThresholdMgr {
}
return areaConfigMgr;
}
// /**
// * Get the path where the display thresholds XML files are contained.
// * @return File path.
// */
// @Override
// public String getDisplayThresholdPath()
// {
// String fs = String.valueOf(File.separatorChar);
// StringBuilder sb = new StringBuilder();
//
// sb.append("snow").append(fs);
// sb.append("threshold").append(fs);
// sb.append("display").append(fs);
//
// return sb.toString();
// }
//
// /**
// * Get the path where the monitor thresholds XML files are contained.
// * @return File path.
// */
// @Override
// public String getMonitorThresholdPath()
// {
// String fs = String.valueOf(File.separatorChar);
// StringBuilder sb = new StringBuilder();
//
// sb.append("snow").append(fs);
// sb.append("threshold").append(fs);
// sb.append("monitor").append(fs);
//
// return sb.toString();
// }
//
// /**
// * Get the path where the XML file containing the user selected
// * default file is located.
// * @return The path of the user selected default file XML.
// */
// @Override
// public String getDefaultThresholdFilePath()
// {
// String fs = String.valueOf(File.separatorChar);
// StringBuilder sb = new StringBuilder();
//
// sb.append("snow").append(fs);
// sb.append("threshold").append(fs);
// sb.append("display").append(fs);
// sb.append("defaultThresh").append(fs);
//
// return sb.toString();
// }
}

View file

@ -33,12 +33,16 @@ import com.raytheon.uf.common.dataplugin.fssobs.FSSObsRecord;
import com.raytheon.uf.common.dataplugin.fssobs.FSSObsRecordTransform;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.pointdata.PointDataContainer;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.alerts.AlertMessage;
import com.raytheon.uf.viz.core.datastructure.DataCubeContainer;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.localization.LocalizationManager;
import com.raytheon.uf.viz.core.notification.NotificationMessage;
import com.raytheon.uf.viz.monitor.data.MonitoringArea;
import com.raytheon.uf.viz.monitor.data.ObReport;
import com.raytheon.uf.viz.monitor.events.IMonitorConfigurationEvent;
import com.raytheon.uf.viz.monitor.events.IMonitorThresholdEvent;
@ -54,6 +58,7 @@ import com.raytheon.uf.viz.monitor.events.IMonitorThresholdEvent;
* Feb 25, 2010 4759 dhladky Initial creation.
* Mar 15, 2012 14510 zhao modified processProductAtStartup()
* Sep 11, 2013 2277 mschenke Got rid of ScriptCreator references
* Feb 04, 2014 2757 skorolev Added filter for removed stations
*
* </pre>
*
@ -63,9 +68,26 @@ import com.raytheon.uf.viz.monitor.events.IMonitorThresholdEvent;
*/
public abstract class ObsMonitor extends Monitor {
@Override
protected abstract boolean filterNotifyMessage(NotificationMessage alertMessage);
private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(ObsMonitor.class);
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.monitor.Monitor#filterNotifyMessage(com.raytheon.
* uf.viz.core.notification.NotificationMessage)
*/
@Override
protected abstract boolean filterNotifyMessage(
NotificationMessage alertMessage);
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.monitor.Monitor#nullifyMonitor()
*/
@Override
protected abstract void nullifyMonitor();
@ -86,25 +108,59 @@ public abstract class ObsMonitor extends Monitor {
*
* @param result
*/
protected abstract void process(ObReport result)
throws Exception;
protected abstract void process(ObReport result) throws Exception;
/**
* This method processes the incoming messages at startup
*
* @param report
*/
protected abstract void processAtStartup(ObReport report);
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.monitor.Monitor#processNotifyMessage(com.raytheon
* .uf.viz.core.notification.NotificationMessage)
*/
@Override
protected abstract void processNotifyMessage(NotificationMessage filtered);
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.monitor.Monitor#processProductMessage(com.raytheon
* .uf.viz.core.alerts.AlertMessage)
*/
@Override
protected abstract void processProductMessage(AlertMessage filtered);
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.monitor.listeners.IMonitorThresholdListener#
* thresholdUpdate
* (com.raytheon.uf.viz.monitor.events.IMonitorThresholdEvent)
*/
@Override
public abstract void thresholdUpdate(IMonitorThresholdEvent me);
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.monitor.listeners.IMonitorConfigurationListener#
* configUpdate
* (com.raytheon.uf.viz.monitor.events.IMonitorConfigurationEvent)
*/
@Override
public abstract void configUpdate(IMonitorConfigurationEvent me);
/**
* use this to do the initial filtering
*
* @see com.raytheon.uf.viz.monitor.Monitor#filterProductMessage(com.raytheon.uf.viz.core.alerts.AlertMessage)
*/
public boolean filterProductMessage(AlertMessage alertMessage) {
// Determine whether or not there is a station ID present in the decoded
@ -140,23 +196,38 @@ public abstract class ObsMonitor extends Monitor {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
ObReport result = GenerateFSSObReport
.generateObReport(objectToSend);
System.out.println("New FSSrecord ===> "
+ objectToSend.getDataURI());
process(result);
// Filter removed stations
ArrayList<String> zones = MonitoringArea
.getZoneIds(objectToSend
.getPlatformId());
if (!zones.isEmpty()) {
ObReport result = GenerateFSSObReport
.generateObReport(objectToSend);
statusHandler
.handle(Priority.INFO,
"New FSSrecord ===> "
+ objectToSend
.getDataURI());
process(result);
}
} catch (Exception e) {
e.printStackTrace();
statusHandler
.handle(Priority.PROBLEM,
"An error has occured processing the incoming messages.",
e);
}
}
});
} catch (Exception e) {
e.printStackTrace();
statusHandler
.handle(Priority.PROBLEM,
"An error has occured processing incoming dataURIs.",
e);
}
}
} catch (final Exception e) {
System.err.println("ObsMonitor: URI: " + dataURI
+ " failed to process. " + e.getMessage());
statusHandler.handle(Priority.PROBLEM, "ObsMonitor: URI: "
+ dataURI + " failed to process. " + e.getMessage());
}
}
@ -201,18 +272,31 @@ public abstract class ObsMonitor extends Monitor {
}
FSSObsRecord[] obsRecords = requestFSSObs(vals, selectedTimes);
for (PluginDataObject objectToSend : obsRecords) {
ObReport result = GenerateFSSObReport
.generateObReport(objectToSend);
processAtStartup(result);
for (FSSObsRecord objectToSend : obsRecords) {
// Filter removed stations
ArrayList<String> zones = MonitoringArea
.getZoneIds(objectToSend.getPlatformId());
if (!zones.isEmpty()) {
ObReport result = GenerateFSSObReport
.generateObReport(objectToSend);
processAtStartup(result);
}
}
}
} catch (final VizException e) {
System.err
.println("No data in database at startup. " + monitorUse);
statusHandler.handle(Priority.PROBLEM,
"No data in database at startup. " + monitorUse);
}
}
/**
* Gets array of FSSObs records.
*
* @param constraints
* @param times
* @return FSSObsRecord[]
* @throws VizException
*/
private FSSObsRecord[] requestFSSObs(
Map<String, RequestConstraint> constraints, DataTime[] times)
throws VizException {