com.isti.quakewatch.message
Class QWMessageHandler

java.lang.Object
  extended by com.isti.quakewatch.message.QWMessageHandler
All Implemented Interfaces:
EvtChMsgProcIntrf, MessageProcessor

public class QWMessageHandler
extends java.lang.Object
implements MessageProcessor

Class QWMessageHandler manages the request-resend-from-server aspects of message handling.


Field Summary
protected  java.util.Vector aliveMsgListenersVec
           
protected  byte[] certificateFileDataArr
           
protected  java.security.cert.X509Certificate certificateObj
           
protected  QWConnProperties cfgObj
           
protected  boolean checkMissedEnabledFlag
           
static int CHKNUM_MESSAGE_OK
           
static int CHKNUM_MISSED_MSGS
           
static int CHKNUM_OBSOLETE_MSG
           
protected  QWConnectionMgr connMgrObj
           
protected  QWDataMsgProcessor dataMsgProcObj
           
protected  int debugMessageCounter
           
protected  boolean debugMissedMsgTestFlag
           
protected  int debugMissedMsgTestValue
           
protected  boolean disableMissedMsgCheckingFlag
           
protected  boolean domainTypeFilteringFlag
           
protected  DomainTypeInfoTable domainTypeInfoTableObj
           
protected  TwoObjectMatcher domainTypeMatcherObj
           
protected  java.lang.Object domainTypeTableSyncObj
           
protected  TagValueTable fdrSrcHostMsgNumTableObj
           
protected  boolean fetchAndProcessMessagesFlag
           
protected  java.lang.Object fetchAndProcessMessagesSyncObject
           
protected  boolean fetchAndProcMsgRecvdFlag
           
protected  boolean fetchAndProcMsgsTerminateFlag
           
protected  long lastAliveMsgNum
           
protected  long lastFetchMsgsFromServerTime
           
protected  long lastReceivedMessageNumber
           
protected  boolean lastReceivedNumViaStatMsgFlag
           
protected  long lastReceivedTimeGenerated
           
protected  java.lang.Object lastRecvdValuesSyncObj
           
protected  LogFile logObj
           
 
Constructor Summary
QWMessageHandler(QWConnectionMgr connMgrObj, LogFile logObj)
          Creates a message-handler object.
 
Method Summary
 void addAliveMsgListener(QWAliveMsgListener listenerObj)
          Adds the given 'QWAliveMsgListener' object.
 boolean checkFetchAndProcMsgReceived()
          Checks if any fetched messages have been received since the last call to this method.
protected  int checkMessageNumber(long checkMsgNum, java.lang.Object messageObj)
          Checks to see if the given message number is greater than the message number of the last event message received, and if so, requests the missing messages from the server (via a worker thread).
protected  boolean checkStatusMessageObj(QWStatusMsgRecord statusRecObj, boolean logFlag)
          Checks the "FilteredMsgNum" child-elements of the given status message record for any gap in the message-number sequence for each domain/type name.
 void clearLastReceivedMsgNum()
          Clears the held message-number value for the last-received message.
 void clearLastReceivedMsgNum(boolean setMsgTimeCurrentFlag)
          Clears the held message-number value for the last-received message.
 void clearWaitingMsgsQueueTable()
          Clears the queue of data messages waiting to be processed.
 java.lang.String doFetchAndProcessMessagesFromServer(boolean requestedFlag, ProgressIndicatorInterface progressIndObj, boolean serverChangedFlag)
          Performs the work of requesting, fetching and processing new event message records from the server.
protected  java.lang.String doFetchAndProcessMessagesFromServer(long timeVal, long msgNum, boolean requestedFlag, ProgressIndicatorInterface progressIndObj, boolean serverChangedFlag)
          Performs the work of requesting, fetching and processing event message records from the server.
 boolean fetchAndProcessMessagesFromServer(long timeVal, long msgNum, boolean requestedFlag, IstiDialogInterface popupObj, ProgressIndicatorInterface progressIndObj, boolean serverChangedFlag)
          Requests, fetches and processes event message records from the server.
 boolean fetchAndProcInitMessagesFromServer(IstiDialogInterface popupObj, ProgressIndicatorInterface progressIndObj, boolean serverChangedFlag)
          Requests, fetches and processes the initial set of event message records from the server.
 void fireConnectionStatusChanged()
          Runs the 'connectionStatusChanged()' method on the status-checking thread to get the client check-in to be performed immediately.
 void generateCertificate()
          Generates the certificate.
 java.security.cert.X509Certificate getCertificate()
          Returns the certificate that was fetched from the server at connect time.
 boolean getDisableMissedMsgCheckingFlag()
          Returns a flag indicator of whether or not missed-message checking is always disabled.
 boolean getDomainTypeFilteringFlag()
          Returns true if any event domain and type names are being subscribed to.
static java.lang.String getFeederSourceHostStr(org.jdom.Element elemObj)
          Returns the value of the "FdrSourceHost" attribute of the given 'Element' object.
static long getFeederSrcMsgNumberValue(org.jdom.Element elemObj)
          Returns the value for the "FdrSourceMsgNum" attribute of the given 'Element' object.
 long getLastFetchMsgsFromServerTime()
          Returns time of last successful fetch of messages from the server.
 QWMsgNumTimeRec getLastReceivedMsgValues()
          Returns the message number and time-generated values for the last message received from the server (if available).
static java.lang.String getMessageEventDomainStr(org.jdom.Element elemObj)
          Returns the value of the "MsgEvtDomain" attribute of the given 'Element' object.
static java.lang.String getMessageEventMsgNumStr(org.jdom.Element elemObj)
          Returns the value of the "MsgEvtMsgNum" attribute of the given 'Element' object.
static java.lang.String getMessageEventTypeStr(org.jdom.Element elemObj)
          Returns the value of the "MsgEvtType" attribute of the given 'Element' object.
static long getMessageNumberValue(org.jdom.Element elemObj)
          Returns the value for the "MsgNumber" attribute of the given 'Element' object.
static java.util.Date getMessageTimeGeneratedDate(org.jdom.Element elemObj)
          Returns the Date object for the "TimeGenerated" attribute of the given 'Element' object.
 void invokeAliveMsgListeners(QWStatusMsgRecord recObj)
          Invokes all registered server-alive-message listeners using the given record object.
 boolean isConnectionValidated()
          Returns the status of whether or not the connection has been "validated" via the receipt of any server-alive messages.
 boolean isFetchAndProcessMessagesRunning()
          Returns the status of the 'fetchAndProcessMessagesFromServer()' method.
 boolean isLastReceivedMsgNumZero()
          Determines if the held message-number value for the last-received message is zero.
 boolean isProcessingEnabled()
          Returns an indicator of whether or not message processing is enabled.
 boolean isValidMessage(org.jdom.Element qwMsgElement, java.lang.String xmlMsgStr)
          Validates the message.
 void processMessage(org.jdom.Element qwMsgElement, java.lang.String xmlMsgStr, boolean requestedFlag, boolean allowQueuingFlag)
          Processes a "QWmessage" XML message.
 void processMessage(java.lang.String xmlMsgStr)
          Processes a "QWmessage" XML text message string.
 void processMessage(java.lang.String xmlMsgStr, boolean allowQueuingFlag)
          Processes a "QWmessage" XML text message string.
 void removeAliveMsgListener(QWAliveMsgListener listenerObj)
          Removes the given 'QWAliveMsgListener' object.
 void setDisableMissedMsgCheckingFlag(boolean flgVal)
          Configures whether or not missed-message check will always be disabled.
 void setDomainTypeListStr(java.lang.String listStr)
          Sets the list of event domain and type names being subscribed to for event-message filtering.
 void setProcessingEnabledFlag(boolean flgVal)
          Sets the message-processing-enabled and check-missed-msgs-enabled flags.
 void terminateFetchAndProcessMsgs()
          Terminates any 'fetchAndProcessMessages' thread that is running.
 void updateCheckMissedEnabledFlag()
          Updates the 'checkMissedEnabledFlag' to enable/disable missed-message checking.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHKNUM_MESSAGE_OK

public static final int CHKNUM_MESSAGE_OK
See Also:
Constant Field Values

CHKNUM_MISSED_MSGS

public static final int CHKNUM_MISSED_MSGS
See Also:
Constant Field Values

CHKNUM_OBSOLETE_MSG

public static final int CHKNUM_OBSOLETE_MSG
See Also:
Constant Field Values

connMgrObj

protected final QWConnectionMgr connMgrObj

dataMsgProcObj

protected final QWDataMsgProcessor dataMsgProcObj

logObj

protected final LogFile logObj

cfgObj

protected final QWConnProperties cfgObj

debugMissedMsgTestValue

protected final int debugMissedMsgTestValue

debugMissedMsgTestFlag

protected final boolean debugMissedMsgTestFlag

aliveMsgListenersVec

protected final java.util.Vector aliveMsgListenersVec

domainTypeMatcherObj

protected TwoObjectMatcher domainTypeMatcherObj

domainTypeFilteringFlag

protected boolean domainTypeFilteringFlag

lastAliveMsgNum

protected long lastAliveMsgNum

debugMessageCounter

protected int debugMessageCounter

fetchAndProcessMessagesFlag

protected boolean fetchAndProcessMessagesFlag

fetchAndProcessMessagesSyncObject

protected final java.lang.Object fetchAndProcessMessagesSyncObject

lastFetchMsgsFromServerTime

protected long lastFetchMsgsFromServerTime

fetchAndProcMsgsTerminateFlag

protected boolean fetchAndProcMsgsTerminateFlag

lastReceivedMessageNumber

protected long lastReceivedMessageNumber

lastReceivedTimeGenerated

protected long lastReceivedTimeGenerated

lastReceivedNumViaStatMsgFlag

protected boolean lastReceivedNumViaStatMsgFlag

lastRecvdValuesSyncObj

protected final java.lang.Object lastRecvdValuesSyncObj

fetchAndProcMsgRecvdFlag

protected boolean fetchAndProcMsgRecvdFlag

checkMissedEnabledFlag

protected boolean checkMissedEnabledFlag

disableMissedMsgCheckingFlag

protected boolean disableMissedMsgCheckingFlag

fdrSrcHostMsgNumTableObj

protected final TagValueTable fdrSrcHostMsgNumTableObj

domainTypeInfoTableObj

protected DomainTypeInfoTable domainTypeInfoTableObj

domainTypeTableSyncObj

protected java.lang.Object domainTypeTableSyncObj

certificateFileDataArr

protected byte[] certificateFileDataArr

certificateObj

protected java.security.cert.X509Certificate certificateObj
Constructor Detail

QWMessageHandler

public QWMessageHandler(QWConnectionMgr connMgrObj,
                        LogFile logObj)
Creates a message-handler object.

Parameters:
connMgrObj - the connection manager object to use.
logObj - log-file object to be used, or null for none.
Method Detail

addAliveMsgListener

public void addAliveMsgListener(QWAliveMsgListener listenerObj)
Adds the given 'QWAliveMsgListener' object. This object's method will be called when an alive message is received.

Parameters:
listenerObj - the listener object to add.

removeAliveMsgListener

public void removeAliveMsgListener(QWAliveMsgListener listenerObj)
Removes the given 'QWAliveMsgListener' object.

Parameters:
listenerObj - the listener object to remove.

setDomainTypeListStr

public void setDomainTypeListStr(java.lang.String listStr)
Sets the list of event domain and type names being subscribed to for event-message filtering.

Parameters:
listStr - the list string to use.

processMessage

public void processMessage(java.lang.String xmlMsgStr,
                           boolean allowQueuingFlag)
Processes a "QWmessage" XML text message string. This method implements the 'MessageProcessor' interface.

Parameters:
xmlMsgStr - the XML text message string.
allowQueuingFlag - true to allow queuing of the message (if message proccessing disabled).

processMessage

public void processMessage(java.lang.String xmlMsgStr)
Processes a "QWmessage" XML text message string. This method implements the 'MessageProcessor' interface.

Specified by:
processMessage in interface MessageProcessor
Parameters:
xmlMsgStr - the XML text message string.

processMessage

public void processMessage(org.jdom.Element qwMsgElement,
                           java.lang.String xmlMsgStr,
                           boolean requestedFlag,
                           boolean allowQueuingFlag)
Processes a "QWmessage" XML message.

Parameters:
qwMsgElement - "QWmessage" element containing the message.
xmlMsgStr - XML-text-string version of the message.
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).
allowQueuingFlag - true to allow queuing of the message (if message proccessing disabled).

invokeAliveMsgListeners

public void invokeAliveMsgListeners(QWStatusMsgRecord recObj)
Invokes all registered server-alive-message listeners using the given record object.

Parameters:
recObj - the 'QWStatusMsgRecord' object for the received message, or null if none available.

isProcessingEnabled

public boolean isProcessingEnabled()
Returns an indicator of whether or not message processing is enabled.

Returns:
true if message processing is enabled; false if not.

setProcessingEnabledFlag

public void setProcessingEnabledFlag(boolean flgVal)
Sets the message-processing-enabled and check-missed-msgs-enabled flags.

Parameters:
flgVal - true specifies that queued and incoming messages should now be processed and that missed-message checking should be enabled; false specifies that incoming messages should be put into the waiting-messages queue and that missed-message checking should be disabled.

updateCheckMissedEnabledFlag

public void updateCheckMissedEnabledFlag()
Updates the 'checkMissedEnabledFlag' to enable/disable missed-message checking.


setDisableMissedMsgCheckingFlag

public void setDisableMissedMsgCheckingFlag(boolean flgVal)
Configures whether or not missed-message check will always be disabled.

Parameters:
flgVal - true to have missed-message checking always disabled; false to allow missed-message checking.

getDisableMissedMsgCheckingFlag

public boolean getDisableMissedMsgCheckingFlag()
Returns a flag indicator of whether or not missed-message checking is always disabled.

Returns:
true if missed-message checking is always disabled; false if missed-message checking is allowed.

getLastReceivedMsgValues

public QWMsgNumTimeRec getLastReceivedMsgValues()
Returns the message number and time-generated values for the last message received from the server (if available).

Returns:
A new 'QWMsgNumTimeRec' object containing the message number and time-generated values for the last messaged received from the server (if not available then the values will be zeroes).

fetchAndProcessMessagesFromServer

public boolean fetchAndProcessMessagesFromServer(long timeVal,
                                                 long msgNum,
                                                 boolean requestedFlag,
                                                 IstiDialogInterface popupObj,
                                                 ProgressIndicatorInterface progressIndObj,
                                                 boolean serverChangedFlag)
Requests, fetches and processes event message records from the server. A worker thread is created and run to perform the work.

Parameters:
timeVal - the time-generated value for message associated with the given message number, or the requested time value to be used (milliseconds since 1/1/1970).
msgNum - the message number to use, or 0 or none.
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).
popupObj - dialog popup object to be closed when the loading of messages is complete, or null for none.
progressIndObj - progress bar widget to be updated during processing, or null for none.
serverChangedFlag - true if this is the initial fetch from a "new" server (one that was not connected to previously) and the "requestSourced...()" methods should be used.
Returns:
true if the worker thread was successfully launched, false if the worker thread is already running.

fetchAndProcInitMessagesFromServer

public boolean fetchAndProcInitMessagesFromServer(IstiDialogInterface popupObj,
                                                  ProgressIndicatorInterface progressIndObj,
                                                  boolean serverChangedFlag)
Requests, fetches and processes the initial set of event message records from the server. The request is for all message records newer than the latest message record held by this client (if available). A worker thread is created and run to perform the work.

Parameters:
popupObj - dialog popup object to be closed when the loading of messages is complete, or null for none.
progressIndObj - progress bar widget to be updated during processing, or null for none.
serverChangedFlag - true if this is the initial fetch from a "new" server (one that was not connected to previously) and the "requestSourced...()" methods should be used.
Returns:
true if the worker thread was successfully launched, false if the worker thread is already running.

isFetchAndProcessMessagesRunning

public boolean isFetchAndProcessMessagesRunning()
Returns the status of the 'fetchAndProcessMessagesFromServer()' method.

Returns:
true if the 'fetchAndProcessMessagesFromServer()' method's worker thread is running; false if not.

doFetchAndProcessMessagesFromServer

protected java.lang.String doFetchAndProcessMessagesFromServer(long timeVal,
                                                               long msgNum,
                                                               boolean requestedFlag,
                                                               ProgressIndicatorInterface progressIndObj,
                                                               boolean serverChangedFlag)
Performs the work of requesting, fetching and processing event message records from the server.

Parameters:
timeVal - the time-generated value for message associated with the given message number, or the requested time value to be used (milliseconds since 1/1/1970).
msgNum - the message number to use, or 0 or none.
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).
progressIndObj - progress indicator object to be updated during processing, or null for none.
serverChangedFlag - true if this is the initial fetch from a "new" server (one that was not connected to previously) and the "requestSourced...()" methods should be used.
Returns:
null if successful; an error message string if an error occurred.

doFetchAndProcessMessagesFromServer

public java.lang.String doFetchAndProcessMessagesFromServer(boolean requestedFlag,
                                                            ProgressIndicatorInterface progressIndObj,
                                                            boolean serverChangedFlag)
Performs the work of requesting, fetching and processing new event message records from the server. This method may be called on a regular periodic basis to poll the server for new messages.

Parameters:
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).
progressIndObj - progress indicator object to be updated during processing, or null for none.
serverChangedFlag - true if this is the initial fetch from a "new" server (one that was not connected to previously) and the "requestSourced...()" methods should be used.
Returns:
null if successful; an error message string if an error occurred (the error message string is logged).

checkFetchAndProcMsgReceived

public boolean checkFetchAndProcMsgReceived()
Checks if any fetched messages have been received since the last call to this method.

Returns:
true if any fetched messages have been received, false if not.

terminateFetchAndProcessMsgs

public void terminateFetchAndProcessMsgs()
Terminates any 'fetchAndProcessMessages' thread that is running.


clearLastReceivedMsgNum

public void clearLastReceivedMsgNum(boolean setMsgTimeCurrentFlag)
Clears the held message-number value for the last-received message. This reinitializes the missed-message tracking mechanism.

Parameters:
setMsgTimeCurrentFlag - true to set the time value for the last-received message to the current time (to prevent old messages from being fetched via 'doFetchAndProcessMessagesFromServer()' method).

clearLastReceivedMsgNum

public void clearLastReceivedMsgNum()
Clears the held message-number value for the last-received message. This reinitializes the missed-message tracking mechanism.


isLastReceivedMsgNumZero

public boolean isLastReceivedMsgNumZero()
Determines if the held message-number value for the last-received message is zero. This usually happens via the 'clearLastReceivedMsgNum()' method.

Returns:
true if the held message-number value for the last-received message is zero.

clearWaitingMsgsQueueTable

public void clearWaitingMsgsQueueTable()
Clears the queue of data messages waiting to be processed.


getLastFetchMsgsFromServerTime

public long getLastFetchMsgsFromServerTime()
Returns time of last successful fetch of messages from the server.

Returns:
time of last successful fetch of messages from the server, in milliseconds since 1/1/1970.

checkMessageNumber

protected int checkMessageNumber(long checkMsgNum,
                                 java.lang.Object messageObj)
Checks to see if the given message number is greater than the message number of the last event message received, and if so, requests the missing messages from the server (via a worker thread). Also checks to see if the given message number and time-generated date are older than those of the last-received message.

Parameters:
checkMsgNum - the message number to use.
messageObj - the 'Element' object to be checked if the message number is smaller then the current message number, or the 'QWStatusMsgRecord' object to be used, or null for no object.
Returns:
The value 'CHKNUM_MESSAGE_OK' if the message number is as expected; 'CHKNUM_MISSED_MSGS' if missed messages were detected; or 'CHKNUM_OBSOLETE_MSG' if the given message number and message date indicate that the message is obsolete and should be discarded.

checkStatusMessageObj

protected boolean checkStatusMessageObj(QWStatusMsgRecord statusRecObj,
                                        boolean logFlag)
Checks the "FilteredMsgNum" child-elements of the given status message record for any gap in the message-number sequence for each domain/type name. If a matching entry for any domain/type name is not found in the 'DomainTypeInfoTable' then a new one will be created with the message-number value from the "FilteredMsgNum" element.

Parameters:
statusRecObj - the 'QWStatusMsgRecord' object to use.
logFlag - true to generate a log message for each message-number gap found; false to generate no log messages.
Returns:
true if any gaps in message numbers wre found; false if not.

getCertificate

public java.security.cert.X509Certificate getCertificate()
Returns the certificate that was fetched from the server at connect time.

Returns:
The certificate that was fetched from the server at connect time, or null if none was fetched or error with certificate.

generateCertificate

public void generateCertificate()
Generates the certificate.


isValidMessage

public boolean isValidMessage(org.jdom.Element qwMsgElement,
                              java.lang.String xmlMsgStr)
Validates the message.

Parameters:
qwMsgElement - "QWmessage" element containing the message.
xmlMsgStr - the XML text message string.
Returns:
true if the message is valid (signature is valid or missing if allowed),false otherwise.

getDomainTypeFilteringFlag

public boolean getDomainTypeFilteringFlag()
Returns true if any event domain and type names are being subscribed to.

Returns:
true if any event domain and type names are being subscribed to.

isConnectionValidated

public boolean isConnectionValidated()
Returns the status of whether or not the connection has been "validated" via the receipt of any server-alive messages.

Returns:
true if any server-alive messages have been received since the last connect-to-server attempt, false if not.

fireConnectionStatusChanged

public void fireConnectionStatusChanged()
Runs the 'connectionStatusChanged()' method on the status-checking thread to get the client check-in to be performed immediately. This is used by the 'QWWebSvcsConnector' module to make a client check-in happen right after a successful connect to the server.


getMessageNumberValue

public static long getMessageNumberValue(org.jdom.Element elemObj)
Returns the value for the "MsgNumber" attribute of the given 'Element' object.

Parameters:
elemObj - the 'Element' object to use.
Returns:
The "MsgNumber" value, or 0 if none could be found and successfully parsed.

getMessageTimeGeneratedDate

public static java.util.Date getMessageTimeGeneratedDate(org.jdom.Element elemObj)
Returns the Date object for the "TimeGenerated" attribute of the given 'Element' object.

Parameters:
elemObj - the 'Element' object to use.
Returns:
A new Date object, or null if none could be found and successfully parsed.

getFeederSourceHostStr

public static java.lang.String getFeederSourceHostStr(org.jdom.Element elemObj)
Returns the value of the "FdrSourceHost" attribute of the given 'Element' object.

Parameters:
elemObj - the 'Element' object to use.
Returns:
The string value of the "FdrSourceHost" attribute, or null if the attribute was not found.

getFeederSrcMsgNumberValue

public static long getFeederSrcMsgNumberValue(org.jdom.Element elemObj)
Returns the value for the "FdrSourceMsgNum" attribute of the given 'Element' object.

Parameters:
elemObj - the 'Element' object to use.
Returns:
The "FdrSourceMsgNum" value, or 0 if none could be found and successfully parsed.

getMessageEventDomainStr

public static java.lang.String getMessageEventDomainStr(org.jdom.Element elemObj)
Returns the value of the "MsgEvtDomain" attribute of the given 'Element' object.

Parameters:
elemObj - the 'Element' object to use.
Returns:
The string value of the "MsgEvtDomain" attribute, or null if the attribute was not found.

getMessageEventTypeStr

public static java.lang.String getMessageEventTypeStr(org.jdom.Element elemObj)
Returns the value of the "MsgEvtType" attribute of the given 'Element' object.

Parameters:
elemObj - the 'Element' object to use.
Returns:
The string value of the "MsgEvtType" attribute, or null if the attribute was not found.

getMessageEventMsgNumStr

public static java.lang.String getMessageEventMsgNumStr(org.jdom.Element elemObj)
Returns the value of the "MsgEvtMsgNum" attribute of the given 'Element' object.

Parameters:
elemObj - the 'Element' object to use.
Returns:
The string value of the "MsgEvtMsgNum" attribute, or null if the attribute was not found.