diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/RuleXML.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/RuleXML.java index 698c4ac80f..7a9904d210 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/RuleXML.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/RuleXML.java @@ -27,8 +27,6 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import com.raytheon.uf.common.datadelivery.registry.Subscription; -import com.raytheon.uf.common.status.IUFStatusHandler; -import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.viz.datadelivery.system.CreateEditRuleDlg.FreqUnitOptions; import com.raytheon.uf.viz.datadelivery.system.Operator; import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames; @@ -54,11 +52,6 @@ import com.raytheon.uf.viz.datadelivery.utils.DataSizeUnit; @SuppressWarnings({ "unchecked", "rawtypes" }) @XmlAccessorType(XmlAccessType.NONE) public abstract class RuleXML { - - /** Status Handler */ - private final IUFStatusHandler statusHandler = UFStatus - .getHandler(RuleXML.class); - /** Rule name */ @XmlElement protected String ruleName; diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/CreateEditRuleDlg.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/CreateEditRuleDlg.java index 3b3c721501..b5cb686005 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/CreateEditRuleDlg.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/CreateEditRuleDlg.java @@ -19,6 +19,7 @@ **/ package com.raytheon.uf.viz.datadelivery.system; +import java.util.List; import java.util.regex.Pattern; import org.eclipse.swt.SWT; @@ -227,6 +228,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog { this(parent, create, null, ruleType); } + /** + * Create the rule header. + */ private void createRuleHeader() { if (create) { if (PRIORITY_TYPE.equals(ruleType)) { @@ -269,9 +273,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog { protected void initializeComponents(Shell shell) { if (!create) { if (PRIORITY_TYPE.equals(ruleType)) { - ruleXml = srm.loadPriorityRule(ruleName); + ruleXml = srm.getPriorityRule(ruleName); } else { - ruleXml = srm.loadLatencyRule(ruleName); + ruleXml = srm.getLatencyRule(ruleName); } if (DATASET_SIZE.equals(ruleXml.getRuleField())) { @@ -411,7 +415,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog { String item = fieldCombo.getItem(index); updateSelectionFields(item); } - }); OpsNetFieldNames[] fieldItems = OpsNetFieldNames.values(); @@ -450,7 +453,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog { createFreqUnitItems(); } unitsCombo.select(0); - } if (PRIORITY_TYPE.equals(ruleType)) { @@ -481,7 +483,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog { } priorityCombo.select(0); - } else { gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); gl = new GridLayout(3, false); @@ -507,19 +508,16 @@ public class CreateEditRuleDlg extends CaveSWTDialog { Label minutesLbl = new Label(latencySelectionComp, SWT.NONE); minutesLbl.setLayoutData(gd); minutesLbl.setText("Minutes"); - } populateFields(); ruleDefinitionGroup.pack(); - } /** * Upon edit, populate the fields. */ private void populateFields() { - if (!create) { String field = ruleXml.getRuleField(); if (!field.isEmpty()) { @@ -602,7 +600,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog { close(); } }); - } /** @@ -651,6 +648,13 @@ public class CreateEditRuleDlg extends CaveSWTDialog { Operator operator = OperatorAdapter.fromString(operationCombo .getItem(operationCombo.getSelectionIndex())); + List ruleNames = null; + if (PRIORITY_TYPE.equals(ruleType)) { + ruleNames = srm.getPriorityRuleNames(); + } else { + ruleNames = srm.getLatencyRuleNames(); + } + if (create) { valid = DataDeliveryGUIUtils.hasText(ruleNameText); @@ -663,13 +667,29 @@ public class CreateEditRuleDlg extends CaveSWTDialog { } ruleName = ruleNameText.getText(); + + if (INVALID_PATTERN.matcher(ruleName.trim()).find()) { + DataDeliveryUtils.showMessage(getShell(), SWT.ERROR, + INVALID_CHARS_TITLE, INVALID_CHARS_MESSAGE); + return false; + } + + // Check for duplicate rule name + if (ruleNames.contains(ruleName)) { + DataDeliveryUtils + .showMessage( + shell, + SWT.ERROR, + "Duplicate Rule", + "A rule titled " + + ruleName + + " already exists.\n\nPlease select a different name."); + ruleNameText.selectAll(); + + return false; + } } - if (INVALID_PATTERN.matcher(ruleName.trim()).find()) { - DataDeliveryUtils.showMessage(getShell(), SWT.ERROR, - INVALID_CHARS_TITLE, INVALID_CHARS_MESSAGE); - return false; - } String value = null; if (DataDeliveryGUIUtils.hasText(ruleValue)) { value = ruleValue.getText(); @@ -770,21 +790,12 @@ public class CreateEditRuleDlg extends CaveSWTDialog { } setReturnValue(saved); - - if (!saved) { - DataDeliveryUtils - .showMessage( - getShell(), - SWT.OK, - "Duplicate Name", - "A rule named " - + ruleName - + " already exists\n\nPlease select a different name."); - ruleNameText.selectAll(); - } return saved; } + /** + * Populate the units combo. + */ private void createSizeUnitItems() { unitsCombo.removeAll(); DataSizeUnit[] sizeUnits = DataSizeUnit.values(); @@ -793,6 +804,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog { } } + /** + * Populate the operation combo. + */ private void createSizeOpItems() { operationCombo.removeAll(); OperatorTypes[] sizeOps = OperatorTypes.values(); @@ -801,6 +815,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog { } } + /** + * Populate the frequency units combo. + */ private void createFreqUnitItems() { FreqUnitOptions[] freqUnits = FreqUnitOptions.values(); for (FreqUnitOptions fuo : freqUnits) { @@ -808,6 +825,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog { } } + /** + * populate the operation combo. + */ private void createNameOpItems() { operationCombo.removeAll(); NameOperationItems[] nameOperation = NameOperationItems.values(); diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/IRulesUpdateListener.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/IRulesUpdateListener.java new file mode 100644 index 0000000000..f393c815b7 --- /dev/null +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/IRulesUpdateListener.java @@ -0,0 +1,44 @@ +/** + * 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.uf.viz.datadelivery.system; + +/** + * Rules file update notifier interface. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 16, 2013   1420     mpduff      Initial creation
+ * 
+ * 
+ * + * @author mpduff + * @version 1.0 + */ + +public interface IRulesUpdateListener { + /** + * Update rules. + */ + void update(); +} diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemLatencyTab.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemLatencyTab.java index ad70cc3fe4..1e2a94f8b6 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemLatencyTab.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemLatencyTab.java @@ -263,10 +263,7 @@ public class SystemLatencyTab { ruleDlg = new CreateEditRuleDlg(parentComp.getShell(), create, ruleName, LATENCY_TYPE); } - boolean reloadFlag = (Boolean) ruleDlg.open(); - if (reloadFlag) { - loadList(); - } + ruleDlg.open(); } else { ruleDlg.bringToTop(); } diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemManagementDlg.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemManagementDlg.java index 441f9eb9fa..61e2bab7e6 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemManagementDlg.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemManagementDlg.java @@ -45,6 +45,7 @@ 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.util.StringUtil; +import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.ForceApplyPromptResponse; import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.IForceApplyPromptDisplayText; import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils; @@ -71,7 +72,7 @@ import com.raytheon.viz.ui.presenter.IDisplay; * @version 1.0 */ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay, - IForceApplyPromptDisplayText { + IForceApplyPromptDisplayText, IRulesUpdateListener { /** Status Handler */ private final IUFStatusHandler statusHandler = UFStatus @@ -128,10 +129,18 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay, /** OK button */ private Button okBtn; + /** Available bandwidth modified flag */ private boolean availableBandwidthModified; + /** Available bandwidth spinner widget */ private Spinner availBandwidthSpinner; + /** The system latency tab */ + private SystemLatencyTab lTab; + + /** The system priority tab */ + private SystemPriorityTab pTab; + /** * Constructor. * @@ -141,6 +150,7 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay, public SystemManagementDlg(Shell parent) { super(parent, SWT.DIALOG_TRIM, CAVE.NONE); setText("Data Delivery System Management"); + SystemRuleManager.getInstance().registerAsListener(this); } @@ -181,6 +191,17 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay, } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#disposed() + */ + @Override + protected void disposed() { + super.disposed(); + SystemRuleManager.getInstance().deregisterAsListener(this); + } + /** * Create top bar route information. */ @@ -283,7 +304,7 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay, priorityComp.setLayout(gl); priorityComp.setLayoutData(gd); priorityTab.setControl(priorityComp); - SystemPriorityTab pTab = new SystemPriorityTab(priorityComp); + pTab = new SystemPriorityTab(priorityComp); gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); gl = new GridLayout(1, false); @@ -296,7 +317,7 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay, latencyComp.setLayout(gl); latencyComp.setLayoutData(gd); latencyTab.setControl(latencyComp); - SystemLatencyTab lTab = new SystemLatencyTab(latencyComp); + lTab = new SystemLatencyTab(latencyComp); gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false); gl = new GridLayout(1, false); @@ -309,6 +330,9 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay, routingComp.setLayoutData(gd); routingTab.setControl(routingComp); SystemRoutingTab rTab = new SystemRoutingTab(routingComp); + + lTab.loadList(); + pTab.loadList(); } /** @@ -466,4 +490,17 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay, "Don't know how to handle option [" + option + "]"); } } + + @Override + public void update() { + VizApp.runAsync(new Runnable() { + @Override + public void run() { + if (!shell.isDisposed()) { + lTab.loadList(); + pTab.loadList(); + } + } + }); + } } diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemPriorityTab.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemPriorityTab.java index f39ce7daae..1d4635fd11 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemPriorityTab.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemPriorityTab.java @@ -268,10 +268,7 @@ public class SystemPriorityTab { create, ruleName, PRIORITY_TYPE); } - boolean reloadFlag = (Boolean) ruleDlg.open(); - if (reloadFlag) { - loadList(); - } + ruleDlg.open(); } else { ruleDlg.bringToTop(); } diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleManager.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleManager.java index 5f1dc81a0b..434a3f1c94 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleManager.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleManager.java @@ -32,6 +32,8 @@ import javax.xml.bind.Unmarshaller; import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthService; import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Subscription; +import com.raytheon.uf.common.localization.FileUpdatedMessage; +import com.raytheon.uf.common.localization.ILocalizationFileObserver; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; @@ -89,6 +91,12 @@ public class SystemRuleManager { private final IUFStatusHandler statusHandler = UFStatus .getHandler(SystemRuleManager.class); + /** Latency Rules Localization File */ + private LocalizationFile latencyRulesLocFile; + + /** Priority Rules Localization File */ + private LocalizationFile priorityRulesLocFile; + /** JAXB context */ private JAXBContext jax; @@ -101,11 +109,21 @@ public class SystemRuleManager { /** Bandwidth service */ private IBandwidthService bandwidthService; + /** Latency Rules XML object */ + private LatencyRulesXML latencyRules; + + /** Priority Rules XML object */ + private PriorityRulesXML priorityRules; + + private final List listeners = new ArrayList(); + /** * Constructor. */ private SystemRuleManager() { createContext(); + loadLatencyRules(); + loadPriorityRules(); } /** @@ -144,7 +162,7 @@ public class SystemRuleManager { * @throws JAXBException */ public List getPriorityRuleNames() { - return getPriorityRules().getRuleNames(); + return getPriorityRules(false).getRuleNames(); } /** @@ -154,8 +172,8 @@ public class SystemRuleManager { * the name of the rule * @return the PriorityRuleXML object */ - public PriorityRuleXML loadPriorityRule(String name) { - PriorityRulesXML priorityRules = getPriorityRules(); + public PriorityRuleXML getPriorityRule(String name) { + PriorityRulesXML priorityRules = getPriorityRules(false); for (PriorityRuleXML rule : priorityRules.getRules()) { if (rule.getRuleName().equals(name)) { return rule; @@ -172,8 +190,8 @@ public class SystemRuleManager { * the name of the rule * @return the LatencyRuleXML object */ - public LatencyRuleXML loadLatencyRule(String name) { - LatencyRulesXML latencyRules = getLatencyRules(); + public LatencyRuleXML getLatencyRule(String name) { + LatencyRulesXML latencyRules = getLatencyRules(false); for (LatencyRuleXML rule : latencyRules.getRules()) { if (rule.getRuleName().equals(name)) { return rule; @@ -190,7 +208,7 @@ public class SystemRuleManager { * @throws JAXBException */ public List getLatencyRuleNames() { - return getLatencyRules().getRuleNames(); + return getLatencyRules(false).getRuleNames(); } /** @@ -203,15 +221,22 @@ public class SystemRuleManager { public boolean savePriorityRules(PriorityRulesXML xmlObj) { IPathManager pm = PathManagerFactory.getPathManager(); - LocalizationContext context = pm.getContext( - LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile priorityRulesLocFile = pm.getLocalizationFile(context, - this.PRIORITY_RULE_FILE); - try { - marshaller.marshal(xmlObj, priorityRulesLocFile.getFile()); - priorityRulesLocFile.save(); - return true; + // If site, then write out, otherwise save it as site. + if (priorityRulesLocFile.getContext().getLocalizationLevel() + .equals(LocalizationLevel.SITE)) { + marshaller.marshal(xmlObj, priorityRulesLocFile.getFile()); + return priorityRulesLocFile.save(); + } else { + LocalizationContext context = pm.getContext( + LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); + + priorityRulesLocFile = pm.getLocalizationFile(context, + this.PRIORITY_RULE_FILE); + addPriorityRulesFileObserver(); + marshaller.marshal(xmlObj, priorityRulesLocFile.getFile()); + return priorityRulesLocFile.save(); + } } catch (JAXBException e) { statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e); } catch (LocalizationOpFailedException e) { @@ -231,15 +256,22 @@ public class SystemRuleManager { public boolean saveLatencyRules(LatencyRulesXML xmlObj) { IPathManager pm = PathManagerFactory.getPathManager(); - LocalizationContext context = pm.getContext( - LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile latencyRulesLocFile = pm.getLocalizationFile(context, - this.LATENCY_RULE_FILE); - try { - marshaller.marshal(xmlObj, latencyRulesLocFile.getFile()); - latencyRulesLocFile.save(); - return true; + // If site, then write out, otherwise save it as site. + if (latencyRulesLocFile.getContext().getLocalizationLevel() + .equals(LocalizationLevel.SITE)) { + marshaller.marshal(xmlObj, latencyRulesLocFile.getFile()); + return latencyRulesLocFile.save(); + } else { + LocalizationContext context = pm.getContext( + LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); + + latencyRulesLocFile = pm.getLocalizationFile(context, + this.LATENCY_RULE_FILE); + addLatencyRulesFileObserver(); + marshaller.marshal(xmlObj, latencyRulesLocFile.getFile()); + return latencyRulesLocFile.save(); + } } catch (JAXBException e) { statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e); } catch (LocalizationOpFailedException e) { @@ -256,7 +288,7 @@ public class SystemRuleManager { * the rule name to delete */ public void deleteLatencyRule(String ruleName) { - LatencyRulesXML latencyRules = getLatencyRules(); + LatencyRulesXML latencyRules = getLatencyRules(false); for (LatencyRuleXML rule : latencyRules.getRules()) { if (rule.getRuleName().equals(ruleName)) { @@ -274,7 +306,7 @@ public class SystemRuleManager { * the rule name to delete */ public void deletePriorityRule(String ruleName) { - PriorityRulesXML priorityRules = getPriorityRules(); + PriorityRulesXML priorityRules = getPriorityRules(false); for (PriorityRuleXML rule : priorityRules.getRules()) { if (rule.getRuleName().equals(ruleName)) { @@ -293,7 +325,7 @@ public class SystemRuleManager { * @return true if updated */ public boolean updateRule(LatencyRuleXML rule) { - LatencyRulesXML rulesXml = getLatencyRules(); + LatencyRulesXML rulesXml = getLatencyRules(false); boolean saved = rulesXml.updateRule(rule); if (saved) { return saveLatencyRules(rulesXml); @@ -310,7 +342,7 @@ public class SystemRuleManager { * @return true if updated */ public boolean updateRule(PriorityRuleXML rule) { - PriorityRulesXML rulesXml = getPriorityRules(); + PriorityRulesXML rulesXml = getPriorityRules(false); boolean saved = rulesXml.updateRule(rule); if (saved) { saved = savePriorityRules(rulesXml); @@ -331,7 +363,7 @@ public class SystemRuleManager { * @return true if updated */ public boolean saveRule(PriorityRuleXML rule) { - PriorityRulesXML rulesXml = getPriorityRules(); + PriorityRulesXML rulesXml = getPriorityRules(false); boolean saved = rulesXml.addRule(rule); if (saved) { saved = savePriorityRules(rulesXml); @@ -352,7 +384,7 @@ public class SystemRuleManager { * @return true if updated */ public boolean saveRule(LatencyRuleXML rule) { - LatencyRulesXML rulesXml = getLatencyRules(); + LatencyRulesXML rulesXml = getLatencyRules(false); boolean saved = rulesXml.addRule(rule); if (saved) { saved = saveLatencyRules(rulesXml); @@ -368,19 +400,23 @@ public class SystemRuleManager { /** * Get the latency rules. * + * @param reread + * true to reread the file from disk + * * @return The latency rules xml object */ - private LatencyRulesXML getLatencyRules() { - LocalizationFile lfile = getRules(this.LATENCY_RULE_FILE); - - LatencyRulesXML latencyRules = new LatencyRulesXML(); - if (lfile != null && lfile.exists()) { - try { - latencyRules = (LatencyRulesXML) unmarshaller.unmarshal(lfile - .getFile()); - } catch (JAXBException e) { - statusHandler - .handle(Priority.ERROR, e.getLocalizedMessage(), e); + private LatencyRulesXML getLatencyRules(boolean reread) { + if (latencyRules == null || reread) { + if (this.latencyRulesLocFile != null + && latencyRulesLocFile.exists()) { + try { + latencyRules = (LatencyRulesXML) unmarshaller + .unmarshal(latencyRulesLocFile.getFile()); + } catch (JAXBException e) { + statusHandler.handle(Priority.ERROR, + e.getLocalizedMessage(), e); + latencyRules = new LatencyRulesXML(); + } } } @@ -390,34 +426,26 @@ public class SystemRuleManager { /** * Get the priority rules * + * @param reread + * true to reread the file from disk + * * @return The priority rules xml object */ - private PriorityRulesXML getPriorityRules() { - LocalizationFile lfile = getRules(this.PRIORITY_RULE_FILE); - - PriorityRulesXML priorityRules = new PriorityRulesXML(); - if (lfile != null && lfile.exists()) { - try { - priorityRules = (PriorityRulesXML) unmarshaller.unmarshal(lfile - .getFile()); - } catch (JAXBException e) { - statusHandler - .handle(Priority.ERROR, e.getLocalizedMessage(), e); + private PriorityRulesXML getPriorityRules(boolean reread) { + if (priorityRules == null || reread) + if (this.priorityRulesLocFile != null + && priorityRulesLocFile.exists()) { + try { + priorityRules = (PriorityRulesXML) unmarshaller + .unmarshal(priorityRulesLocFile.getFile()); + } catch (JAXBException e) { + statusHandler.handle(Priority.ERROR, + e.getLocalizedMessage(), e); + priorityRules = new PriorityRulesXML(); + } } - } - return priorityRules; - } - /** - * Get the rules files - * - * @param name - * Rules file name to get - * @return The localization file - */ - private LocalizationFile getRules(String name) { - IPathManager pm = PathManagerFactory.getPathManager(); - return pm.getStaticLocalizationFile(name); + return priorityRules; } /** @@ -442,7 +470,7 @@ public class SystemRuleManager { * @return */ public int getLatency(Subscription sub, Set cycleTimes) { - LatencyRulesXML rulesXml = this.getLatencyRules(); + LatencyRulesXML rulesXml = this.getLatencyRules(false); int latency = 999; boolean found = false; for (LatencyRuleXML rule : rulesXml.getRules()) { @@ -471,7 +499,7 @@ public class SystemRuleManager { * @return */ public int getPriority(Subscription sub, Set cycleTimes) { - PriorityRulesXML rulesXml = this.getPriorityRules(); + PriorityRulesXML rulesXml = this.getPriorityRules(false); int priority = 3; boolean found = false; for (PriorityRuleXML rule : rulesXml.getRules()) { @@ -546,4 +574,87 @@ public class SystemRuleManager { return getInstance().bandwidthService .setBandwidthForNetworkInKilobytes(network, bandwidth); } + + /** + * Read the latency rules file. + */ + private void loadLatencyRules() { + IPathManager pm = PathManagerFactory.getPathManager(); + this.latencyRulesLocFile = pm + .getStaticLocalizationFile(this.LATENCY_RULE_FILE); + addLatencyRulesFileObserver(); + getLatencyRules(true); + } + + /** + * Load the priority rules file. + */ + private void loadPriorityRules() { + IPathManager pm = PathManagerFactory.getPathManager(); + this.priorityRulesLocFile = pm + .getStaticLocalizationFile(this.PRIORITY_RULE_FILE); + addPriorityRulesFileObserver(); + getPriorityRules(true); + } + + /** + * Add a file observer to the latency rules file to get notified when the + * file changes. + */ + private void addLatencyRulesFileObserver() { + latencyRulesLocFile + .addFileUpdatedObserver(new ILocalizationFileObserver() { + @Override + public void fileUpdated(FileUpdatedMessage message) { + loadLatencyRules(); + fireUpdates(); + } + }); + } + + /** + * Add a file observer to the priority rules file to get notified when the + * file changes. + */ + private void addPriorityRulesFileObserver() { + priorityRulesLocFile + .addFileUpdatedObserver(new ILocalizationFileObserver() { + @Override + public void fileUpdated(FileUpdatedMessage message) { + loadPriorityRules(); + fireUpdates(); + } + }); + } + + /** + * Notify the listeners the files changed. + */ + private void fireUpdates() { + for (IRulesUpdateListener listener : listeners) { + listener.update(); + } + } + + /** + * Register as a listener for rules file changes. + * + * @param listener + */ + public void registerAsListener(IRulesUpdateListener listener) { + if (!listeners.contains(listener)) { + listeners.add(listener); + } + } + + /** + * Unregister as a listener for rules files changed. + * + * @param listener + */ + public void deregisterAsListener(IRulesUpdateListener listener) { + if (listeners.contains(listener)) { + listeners.remove(listener); + } + } } diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/utility/common_static/base/datadelivery/systemManagement/rules/latencyRules.xml b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/utility/common_static/base/datadelivery/systemManagement/rules/latencyRules.xml index ab09f88dfb..f686a0eda8 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/utility/common_static/base/datadelivery/systemManagement/rules/latencyRules.xml +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/utility/common_static/base/datadelivery/systemManagement/rules/latencyRules.xml @@ -1,19 +1,19 @@ - + Dataset Frequency Hourly-Products <= Hrs 1 40 - - + + Dataset Frequency MultiHour-Products > Hrs 1 115 - + diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/utility/common_static/base/datadelivery/systemManagement/rules/priorityRules.xml b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/utility/common_static/base/datadelivery/systemManagement/rules/priorityRules.xml new file mode 100644 index 0000000000..36fe07252c --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/utility/common_static/base/datadelivery/systemManagement/rules/priorityRules.xml @@ -0,0 +1,4 @@ + + + + diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/utility/common_static/base/roles/userRoles.xml b/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/utility/common_static/base/roles/userRoles.xml index 67ab28709d..61c231cbea 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/utility/common_static/base/roles/userRoles.xml +++ b/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/utility/common_static/base/roles/userRoles.xml @@ -89,6 +89,8 @@ + + com.raytheon.localization.site/common_static/purge com.raytheon.localization.site/cave_static/colormaps @@ -119,6 +121,7 @@ com.raytheon.localization.site/common_static/radar/rmr/rmrAvailableRequests.xml com.raytheon.localization.site/common_static/shef com.raytheon.localization.site/common_static/roles + com.raytheon.localization.site/common_static/datadelivery