com.isti.quakewatch.message
Class QWMsgManager

java.lang.Object
  extended by com.isti.quakewatch.message.QWMsgManager
All Implemented Interfaces:
QWDataMsgProcessor

public class QWMsgManager
extends java.lang.Object
implements QWDataMsgProcessor

Class QWMsgManager is a message manager for QuakeWatch XML messages.


Constructor Summary
QWMsgManager(EventListManager eventListManagerObj, CfgPropItem maxServerEventAgeDaysProp, CfgPropItem maxLoadEventAgeDaysProp, QWFilterProperties filterPropertiesObj, java.lang.String regionsFileDirStr, LogFile logFileObj)
          Creates a message manager for QuakeWatch XML messages.
 
Method Summary
 void addFilteredEvtsListChgListener(DataChangedListener listenerObj)
          Registers the given 'DataChangedListener' object to be notified when the filtered-events table is changed.
 void addMsgObjsListener(QWMsgObjsListener listenerObj)
          Adds the 'QWMsgObjsListener' object to the list being used.
 void applyStorageAndFilterParams()
          Reapplies the storage and filter parameters to all events.
 boolean checkFilterEventMsgRecord(QWEventMsgRecord recObj)
          Checks the given event message record object, testing if the event date/time is before the minimum storage date/time and if the record passes the filter, removing or moving if so.
static int compVersionStrs(java.lang.String ver1Str, java.lang.String ver2Str)
          Compares version strings.
static int compVersionStrs(java.lang.String ver1Str, java.lang.String ver2Str, int def1Val, int bothNullVal)
          Compares version strings.
 void delOldProductCacheMsgs()
          This method should be called on a periodic basis to remove old messages from the product-message cache.
 int getFilteredEventRecordTableSize()
          Returns the size of the table of event message record objects that have been filtered out.
 java.util.List getFilteredEventsList()
          Returns a list of event message record objects that have been filtered out.
 QWEventMsgRecord getFilteredEvtMsgRecObj(java.lang.String keyStr)
          Returns the event message record object for the given key string.
 QWFilterProperties getFilterProperties()
          Returns the 'QWFilterProperties' object in use.
 QWMsgNumTimeRec getLastEventInStorage()
          Returns the last event held in storage.
 LogFile getLogObj()
          Returns the log-file object used by the message manager.
 QWEventMsgRecord getNextEventMsgRecord()
          Returns event records from the event table one at time in a round-robin fashion.
static java.lang.String getQDMVersionStr()
          Returns the version string for the QDM library.
 java.lang.String getRegionsLoadErrorString()
          Returns the "regions.xml"-load-error string, indicating the result of the attempt to load the QDM "regions.xml" file in the constructor.
 java.lang.String getRegionsXmlFileStr()
          Returns the pathname for the QDM "regions.xml" file used by this message manager.
 boolean isProcessUpdates()
          Determines if the message manager will process updates caused by filtered lower-priority events.
 void performNextEventsCheck()
          This method may be called on a periodic basis to filter-out and remove events as they age.
 void processDataMessage(org.jdom.Element qwMsgElement, org.jdom.Element dataMsgElement, java.lang.String xmlMsgStr, boolean requestedFlag)
          Processes any number of "Event", "Product" and "StationAmp" elements in the given "DataMessage" element.
 boolean processNextFilteredEventMsgRecord()
          Processes event records in the filtered table one at time in a round-robin fashion, testing each to see if the event date/time is before the minimum storage date/time and removing if so.
 boolean reapplyEventsFilter(boolean reloadFilteredFlag)
          Reapplies the storage and filter parameters to the table of events held by this message manager, removing any event record objects that no longer pass the parameters.
 void removeFilteredEvtsListChgListener(DataChangedListener listenerObj)
          Unregisters the given 'DataChangedListener' object from the list of listeners for the filtered-events table.
 void removeMsgObjsListener(QWMsgObjsListener listenerObj)
          Removes the 'QWMsgObjsListener' object from the list being used.
 void setConnectionMgr(QWConnectionMgr connMgrObj)
          Enters the connection manager to be used by this message manager.
 void setMsgObjsListener(QWMsgObjsListener listenerObj)
          Sets the 'QWMsgObjsListener' object to be used.
 void setProcessUpdatesFlag(boolean b)
          Sets if the message manager will process updates caused by filtered lower-priority events.
 void setStorageProcessor(QWStorageProcessor storageProcObj)
          Sets the storage processor object to be used for storing messages processed by this object.
 void setStorageProcessor(QWStorageProcessor storageProcObj, boolean storeInvalidMsgsFlag)
          Sets the storage processor object to be used for storing messages processed by this object.
 void setupApplyParamsObjs(IstiDialogInterface popupObj, DataChangedListener listenerObj)
          Sets up the dialog-popup and completion call-back objects to be used by the 'applyStorageAndFilterParams()' method.
 void setUseProductCacheFlag(boolean flgVal)
          Configures whether or not the product cache is used.
 void startEventsCheckThread()
          Creates and starts a thread that calls 'performNextEventsCheck()' once every 100 milliseconds.
 void stopEventsCheckThread()
          Terminates the events-check thread created by the 'startEventsCheckThread()' method.
 void updateStorageMinimumDate()
          Updates the minimum-storage date from the 'maxLoadEventAgeDays' property.
static void updateTimeZones(java.util.TimeZone zone)
          Updates time zone used for date/time values for all event-message and "StationAmp" record objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QWMsgManager

public QWMsgManager(EventListManager eventListManagerObj,
                    CfgPropItem maxServerEventAgeDaysProp,
                    CfgPropItem maxLoadEventAgeDaysProp,
                    QWFilterProperties filterPropertiesObj,
                    java.lang.String regionsFileDirStr,
                    LogFile logFileObj)
Creates a message manager for QuakeWatch XML messages.

Parameters:
eventListManagerObj - the event-list manager object to use.
maxServerEventAgeDaysProp - property item for maximum age of events requested from server.
maxLoadEventAgeDaysProp - property item for maximum age in days for events to be loaded and held.
filterPropertiesObj - the filter-properties object to use, or null for none.
regionsFileDirStr - the name of the directory containing the "regions.xml" file for QDM.
logFileObj - log file object to use, or null for none.
Method Detail

setConnectionMgr

public void setConnectionMgr(QWConnectionMgr connMgrObj)
Enters the connection manager to be used by this message manager.

Specified by:
setConnectionMgr in interface QWDataMsgProcessor
Parameters:
connMgrObj - The connection-manager object to use.

setupApplyParamsObjs

public void setupApplyParamsObjs(IstiDialogInterface popupObj,
                                 DataChangedListener listenerObj)
Sets up the dialog-popup and completion call-back objects to be used by the 'applyStorageAndFilterParams()' method. The 'applyStorageAndFilterParams()' method will be called automatically when any filter parameters are changed or when the maximum-loaded-event-age parameter is decreased.

Parameters:
popupObj - popup dialog to be shown during reapply, or null for none.
listenerObj - call-back listener to be invoked after reapply is complete, or null for none.

setUseProductCacheFlag

public void setUseProductCacheFlag(boolean flgVal)
Configures whether or not the product cache is used.

Parameters:
flgVal - true for product cache used; false for not.

getRegionsLoadErrorString

public java.lang.String getRegionsLoadErrorString()
Returns the "regions.xml"-load-error string, indicating the result of the attempt to load the QDM "regions.xml" file in the constructor.

Returns:
null if the QDM "regions.xml" file was loaded successfully; an error-message string if the load failed.

getRegionsXmlFileStr

public java.lang.String getRegionsXmlFileStr()
Returns the pathname for the QDM "regions.xml" file used by this message manager.

Returns:
The pathname for the QDM "regions.xml" file.

startEventsCheckThread

public void startEventsCheckThread()
Creates and starts a thread that calls 'performNextEventsCheck()' once every 100 milliseconds. This will filter-out and remove events as they age.


stopEventsCheckThread

public void stopEventsCheckThread()
Terminates the events-check thread created by the 'startEventsCheckThread()' method.


processDataMessage

public void processDataMessage(org.jdom.Element qwMsgElement,
                               org.jdom.Element dataMsgElement,
                               java.lang.String xmlMsgStr,
                               boolean requestedFlag)
Processes any number of "Event", "Product" and "StationAmp" elements in the given "DataMessage" element. This method is needed to implement the 'QWDataMsgProcessor' interface.

Specified by:
processDataMessage in interface QWDataMsgProcessor
Parameters:
qwMsgElement - The "QWmessage" element.
dataMsgElement - The "DataMessage" element.
xmlMsgStr - the XML text message string.
requestedFlag - true to set the "requested" flag on the generated data-message objects (to indicate that they should not be processed as a "real-time" message).

compVersionStrs

public static int compVersionStrs(java.lang.String ver1Str,
                                  java.lang.String ver2Str,
                                  int def1Val,
                                  int bothNullVal)
Compares version strings. If numeric version strings given then a numeric comparison is performed (so, for example, "10" is greater than "9").

Parameters:
ver1Str - first version string.
ver2Str - second version string.
def1Val - default value to be returned if first version string contains no data (null or empty) and second version string contains data.
bothNullVal - value to be returned if both version strings contain no data (null or empty).
Returns:
An integer that is less than, equal to or greater than zero as the first string is less than, equal to or greater than the second string (or one of the given values).

compVersionStrs

public static int compVersionStrs(java.lang.String ver1Str,
                                  java.lang.String ver2Str)
Compares version strings. If numeric version strings given then a numeric comparison is performed (so, for example, "10" is greater than "9").

Parameters:
ver1Str - first version string.
ver2Str - second version string.
Returns:
An integer that is less than, equal to or greater than zero as the first string is less than, equal to or greater than the second string.

addMsgObjsListener

public void addMsgObjsListener(QWMsgObjsListener listenerObj)
Adds the 'QWMsgObjsListener' object to the list being used. This object's methods will be called when new event-message record objects are created in response to XML messages received from the QWServer.

Parameters:
listenerObj - the listener object to add.

removeMsgObjsListener

public void removeMsgObjsListener(QWMsgObjsListener listenerObj)
Removes the 'QWMsgObjsListener' object from the list being used.

Parameters:
listenerObj - the listener object to remove.

setMsgObjsListener

public void setMsgObjsListener(QWMsgObjsListener listenerObj)
Sets the 'QWMsgObjsListener' object to be used. This object's methods will be called when new event-message record objects are created in response to XML messages received from the QWServer.

Parameters:
listenerObj - the listener object to use.

updateStorageMinimumDate

public void updateStorageMinimumDate()
Updates the minimum-storage date from the 'maxLoadEventAgeDays' property. New events before this date will be discarded, and when 'reapplyEventsFilter()' is performed, events before this date/time will be deleted.


reapplyEventsFilter

public boolean reapplyEventsFilter(boolean reloadFilteredFlag)
Reapplies the storage and filter parameters to the table of events held by this message manager, removing any event record objects that no longer pass the parameters.

Parameters:
reloadFilteredFlag - true to have the table of filtered events reprocessed into the main table, false to not.
Returns:
true if the main table of events has been changed, false if not.

applyStorageAndFilterParams

public void applyStorageAndFilterParams()
Reapplies the storage and filter parameters to all events. The 'setupApplyParamsObjs()' method may be used to setup the dialog-popup and completion call-back objects for this method.


getNextEventMsgRecord

public QWEventMsgRecord getNextEventMsgRecord()
Returns event records from the event table one at time in a round-robin fashion.

Returns:
The next 'QWEventMsgRecord' object in the event table, or null if the table is empty.

checkFilterEventMsgRecord

public boolean checkFilterEventMsgRecord(QWEventMsgRecord recObj)
Checks the given event message record object, testing if the event date/time is before the minimum storage date/time and if the record passes the filter, removing or moving if so.

Parameters:
recObj - the event message record to use.
Returns:
true if the event message record was removed from the main table, false if not.

processNextFilteredEventMsgRecord

public boolean processNextFilteredEventMsgRecord()
Processes event records in the filtered table one at time in a round-robin fashion, testing each to see if the event date/time is before the minimum storage date/time and removing if so.

Returns:
true if the event message record was removed from the filtered table, false if not.

performNextEventsCheck

public void performNextEventsCheck()
This method may be called on a periodic basis to filter-out and remove events as they age.


delOldProductCacheMsgs

public void delOldProductCacheMsgs()
This method should be called on a periodic basis to remove old messages from the product-message cache.


getFilterProperties

public QWFilterProperties getFilterProperties()
Returns the 'QWFilterProperties' object in use.

Returns:
The 'QWFilterProperties' object in use, or null if none.

getFilteredEventsList

public java.util.List getFilteredEventsList()
Returns a list of event message record objects that have been filtered out. Events not displayed because of QDM-low-priority are also included in the list.

Returns:
A new list of event message record objects that have been filtered out.

getFilteredEvtMsgRecObj

public QWEventMsgRecord getFilteredEvtMsgRecObj(java.lang.String keyStr)
Returns the event message record object for the given key string.

Parameters:
keyStr - event-ID key string.
Returns:
The event message record object for the given key string, or null if no match.

addFilteredEvtsListChgListener

public void addFilteredEvtsListChgListener(DataChangedListener listenerObj)
Registers the given 'DataChangedListener' object to be notified when the filtered-events table is changed.

Parameters:
listenerObj - the 'DataChangedListener' object.

removeFilteredEvtsListChgListener

public void removeFilteredEvtsListChgListener(DataChangedListener listenerObj)
Unregisters the given 'DataChangedListener' object from the list of listeners for the filtered-events table.

Parameters:
listenerObj - the 'DataChangedListener' object.

getFilteredEventRecordTableSize

public int getFilteredEventRecordTableSize()
Returns the size of the table of event message record objects that have been filtered out.

Returns:
The number of event message records in the filtered table.

getLastEventInStorage

public QWMsgNumTimeRec getLastEventInStorage()
Returns the last event held in storage. This method is needed to implement the 'QWDataMsgProcessor' interface.

Specified by:
getLastEventInStorage in interface QWDataMsgProcessor
Returns:
The 'QWMsgNumTimeRec' object for the last event held in storage, or null if none available.

isProcessUpdates

public boolean isProcessUpdates()
Determines if the message manager will process updates caused by filtered lower-priority events.

Returns:
true if processing updates, false otherwise.

setProcessUpdatesFlag

public void setProcessUpdatesFlag(boolean b)
Sets if the message manager will process updates caused by filtered lower-priority events.

Parameters:
b - true to process updates, false otherwise.

setStorageProcessor

public void setStorageProcessor(QWStorageProcessor storageProcObj)
Sets the storage processor object to be used for storing messages processed by this object. Invalid messages will not be sent to the storage processor.

Parameters:
storageProcObj - the storage processor object to use.

setStorageProcessor

public void setStorageProcessor(QWStorageProcessor storageProcObj,
                                boolean storeInvalidMsgsFlag)
Sets the storage processor object to be used for storing messages processed by this object.

Parameters:
storeInvalidMsgsFlag - true to have invalid messages sent to the storage processor (if the message is well-formed XML); false to have all invalid messages discarded (default).
storageProcObj - the storage processor object to use.

getLogObj

public LogFile getLogObj()
Returns the log-file object used by the message manager.

Returns:
The 'LogFile' object in use.

getQDMVersionStr

public static java.lang.String getQDMVersionStr()
Returns the version string for the QDM library.

Returns:
The version string for the QDM library.

updateTimeZones

public static void updateTimeZones(java.util.TimeZone zone)
Updates time zone used for date/time values for all event-message and "StationAmp" record objects.

Parameters:
zone - time zone.