com.isti.quakewatch.util
Class QWWebSvcsConnector

java.lang.Object
  extended by com.isti.quakewatch.util.QWAbstractConnector
      extended by com.isti.quakewatch.util.QWWebSvcsConnector

public class QWWebSvcsConnector
extends QWAbstractConnector

Class QWWebSvcsConnector manages a connection to a QuakeWatch Web Services Server.


Nested Class Summary
protected  class QWWebSvcsConnector.MessageFetchingThread
          Class MessageFetchingThread defines a thread used to continuously fetch messages from a QuakeWatch Web Services Server.
protected  class QWWebSvcsConnector.WebServicesConnectThread
          Class WebServicesConnectThread defines a thread used to connect to a QuakeWatch Web Services Server.
protected  class QWWebSvcsConnector.WebServicesDisconnectThread
          Class WebServicesDisconnectThread defines a thread used to disconnect from a QuakeWatch Web Services Server.
 
Nested classes/interfaces inherited from class com.isti.quakewatch.util.QWAbstractConnector
QWAbstractConnector.ServerHostInfo, QWAbstractConnector.StatusCheckFailedException
 
Field Summary
protected  boolean aliveMessageRequestedFlag
           
protected  AddrPortListMgr altServersListMgr
           
protected  boolean connectedToServerFlag
           
protected  ConnLoginRejectCallBack connLoginRejectCallBackObj
           
protected static int DEF_POLLINGITVL_MS
          Default polling interval (used if unable to fetch from server).
protected  CfgPropItem maxServerAliveSecProp
           
protected  QWWebSvcsConnector.MessageFetchingThread messageFetchingThreadObj
           
protected  int messagePollingIntervalMS
           
protected  java.lang.Object msgFetchingThreadSyncObj
           
protected  QWMessageHandler msgHandlerObj
           
protected  QWWebSvcsConnector.WebServicesConnectThread webSvcsConnectThreadObj
           
protected  java.lang.Object webSvcsConnThreadSyncObj
           
protected  QWWebSvcsConnector.WebServicesDisconnectThread webSvcsDisconnectThreadObj
           
protected  java.lang.Object webSvcsDisconnThreadSyncObj
           
protected  java.lang.String webSvcsInitErrorMsgStr
           
protected static java.lang.Class webSvcsManagerClassObj
           
protected  QWWebSvcsInterface webSvcsManagerObj
           
protected static java.lang.String webSvcsMgrClassErrMsgStr
           
 
Fields inherited from class com.isti.quakewatch.util.QWAbstractConnector
acceptorRejectIDString, acceptorRejectReasonStr, certificateFileDataArr, connAttemptFailedFlag, connAttemptRejectedFlag, connAttemptStartedFlag, connectDoneFlag, connectionInfoPropsString, connectionPasswordString, connectionUserNameString, connInvalidatedFlag, connStatusObj, disconnectClientServicesFlag, disconnectDoneFlag, encryptDecryptUtilObj, filterDomainTypeListStr, filterEventTypeArr, logObj, prevStatusMsgTypeNameStr, REQMSGS_NUM_RETRIES, serverHostInfoObj, serverIdNameString, serverRepHostAddrString, serverRevisionString, statusMsgTypeNameStr, statusReportDataAvailFlag
 
Constructor Summary
QWWebSvcsConnector(ConnLoginRejectCallBack connLoginRejectCallBackObj, QWMessageHandler msgHandlerObj, CfgPropItem maxServerAliveSecProp, AddrPortListMgr altServersListMgr, ConnStatusInterface connStatusObj, LogFile logObj)
          Creates a QW Web Services Server connector object.
QWWebSvcsConnector(QWWebSvcsInterface webSvcsManagerObj, ConnLoginRejectCallBack connLoginRejectCallBackObj, QWMessageHandler msgHandlerObj, CfgPropItem maxServerAliveSecProp, AddrPortListMgr altServersListMgr, ConnStatusInterface connStatusObj, LogFile logObj)
          Creates a QW Web Services Server connector object.
 
Method Summary
protected  boolean doDisconnectClientServices()
          Performs the work of disconnecting this client from the server services.
 void enterConnectionInfo(java.lang.String userNameStr, java.lang.String passwordStr, java.lang.String connPropsStr)
          Enters the connection-information values to be sent when the client connects to the server.
 java.lang.String fetchClientUpgradeInfoFromServer()
          Returns information about available client-program upgrades via the server 'getClientUpgradeInfo()' method.
 java.lang.String fetchRedirectedServerLoc()
          Returns the location of the server that the client is being redirected to.
 boolean getConnectedFlag()
          Returns the connection status.
 boolean getInitializedFlag()
          Returns the "initialized" status of the connection.
 java.lang.String getServerIDNameStr()
          Returns the server ID name string (defined in the QWServer's configuration file).
 java.lang.String getServerRepHostAddrStr()
          Returns the host address reported by the server.
 java.lang.String getServerRevisionStr()
          Returns the server revision string.
 java.lang.String getStatusReportData()
          Fetches the latest status-report data from the server.
 long getStatusReportTime()
          Fetches the timestamp value for the latest status report from the server.
 void invalidateConnection()
          Marks the connection as "invalidated", causing the 'getConnectedFlag()' method to return 'false'.
 boolean isReqServerMsgsAvailable()
          Returns an indicator of whether or not the 'requestMessages()' method is available on the current server.
 boolean isStatusReportDataAvail()
          Determines if get-status-report methods are available on the server.
static boolean loadQWWebSvcsManagerClassObj()
          Loads the class object for the 'QWWebSvcsManager' class.
protected  void notifyConnLoginAttemptRejected(java.lang.String connStatusStr)
          Method called when a connect-to-server login attempt was rejected.
 boolean performClientStatusCheck()
          Calls the server 'clientStatusCheck()' method.
 void requestServerAliveMsg()
          Requests that the server send an 'Alive' message immediately.
 java.lang.String requestServerMessages(long timeVal, long msgNum, java.lang.String hostMsgNumListStr)
          Requests that messages newer or equal to the specified time value or later than the specified message number be returned from the server.
 void shutdownConnection(boolean showPopupFlag)
          Shuts down the connection and waits for the disconnect to complete or timeout.
 void startConnectViaHostInfo(java.lang.String serverHostAddrStr, int serverHostPortNum, boolean showPopupFlag)
          Starts a new thread that establishes a connection to a QWServer.
 void startDisconnectThread()
          Starts a new thread that disconnects the QW web services connection.
 void terminateConnectThread(int numWaitSecs)
          Terminates and disposes any event channel connect thread that is running.
 void terminateDisconnectThread(int numWaitSecs)
          Terminates and disposes any event channel disconnect thread that is running.
 void updateConnectParams(java.lang.String clientHostAddress, int clientPortNum)
          Updates the connection parameters to be used on the next initialization.
 
Methods inherited from class com.isti.quakewatch.util.QWAbstractConnector
autoClearConnStatusPopupDialog, clearConnAttemptFailedFlag, clearConnAttemptRejectedFlag, clearConnAttemptStartedFlag, disconnectClientServices, disconnectClientServices, getCertificateFileDataArr, getConnAttemptFailedFlag, getConnAttemptRejectedFlag, getConnAttemptStartedFlag, getConnPanelObj, getDecodedStatusReport, getDetailedServerIDString, getServerIDString, setAcceptorRejectIDStr, setConnPanelData, setConnPanelData, setConnPanelInitError, setConnPanelInitError, setConnStatusRefocusComponent, setFilterDomainTypeList, showConnPanelPopup, startConnectViaHostInfo, updateFilterDomainTypeList, userRequestShowConnStatusPopupDialog
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEF_POLLINGITVL_MS

protected static final int DEF_POLLINGITVL_MS
Default polling interval (used if unable to fetch from server).

See Also:
Constant Field Values

webSvcsManagerObj

protected final QWWebSvcsInterface webSvcsManagerObj

msgHandlerObj

protected final QWMessageHandler msgHandlerObj

maxServerAliveSecProp

protected final CfgPropItem maxServerAliveSecProp

altServersListMgr

protected final AddrPortListMgr altServersListMgr

webSvcsManagerClassObj

protected static java.lang.Class webSvcsManagerClassObj

webSvcsMgrClassErrMsgStr

protected static java.lang.String webSvcsMgrClassErrMsgStr

webSvcsInitErrorMsgStr

protected java.lang.String webSvcsInitErrorMsgStr

connectedToServerFlag

protected boolean connectedToServerFlag

connLoginRejectCallBackObj

protected ConnLoginRejectCallBack connLoginRejectCallBackObj

webSvcsConnectThreadObj

protected QWWebSvcsConnector.WebServicesConnectThread webSvcsConnectThreadObj

webSvcsConnThreadSyncObj

protected final java.lang.Object webSvcsConnThreadSyncObj

webSvcsDisconnectThreadObj

protected QWWebSvcsConnector.WebServicesDisconnectThread webSvcsDisconnectThreadObj

webSvcsDisconnThreadSyncObj

protected final java.lang.Object webSvcsDisconnThreadSyncObj

messageFetchingThreadObj

protected QWWebSvcsConnector.MessageFetchingThread messageFetchingThreadObj

msgFetchingThreadSyncObj

protected final java.lang.Object msgFetchingThreadSyncObj

messagePollingIntervalMS

protected int messagePollingIntervalMS

aliveMessageRequestedFlag

protected boolean aliveMessageRequestedFlag
Constructor Detail

QWWebSvcsConnector

public QWWebSvcsConnector(QWWebSvcsInterface webSvcsManagerObj,
                          ConnLoginRejectCallBack connLoginRejectCallBackObj,
                          QWMessageHandler msgHandlerObj,
                          CfgPropItem maxServerAliveSecProp,
                          AddrPortListMgr altServersListMgr,
                          ConnStatusInterface connStatusObj,
                          LogFile logObj)
Creates a QW Web Services Server connector object.

Parameters:
webSvcsManagerObj - QW Web Services Server manager to use, or null to dynamically instantiate 'QWWebSvcsManager'.
connLoginRejectCallBackObj - call-back object whose method is invoked when a connect-login-attempt cannot be completed, or null for none.
msgHandlerObj - 'QWMessageHandler' object to use, or null for none.
maxServerAliveSecProp - configuration property object specifying maximum # of seconds between server-alive messages, or null to have default value used.
altServersListMgr - alternate servers list manager object, or null for none.
connStatusObj - connection-status panel object, or null for none.
logObj - log-file object to be used, or null for none.

QWWebSvcsConnector

public QWWebSvcsConnector(ConnLoginRejectCallBack connLoginRejectCallBackObj,
                          QWMessageHandler msgHandlerObj,
                          CfgPropItem maxServerAliveSecProp,
                          AddrPortListMgr altServersListMgr,
                          ConnStatusInterface connStatusObj,
                          LogFile logObj)
Creates a QW Web Services Server connector object. The QW web services manager class "com.isti.quakewatch.qwwebsvcs.QWWebSvcsManager" is dynamically instantiated.

Parameters:
connLoginRejectCallBackObj - call-back object whose method is invoked when a connect-login-attempt cannot be completed, or null for none.
msgHandlerObj - 'QWMessageHandler' object to use, or null for none.
maxServerAliveSecProp - configuration property object specifying maximum # of seconds between server-alive messages, or null to have default value used.
altServersListMgr - alternate servers list manager object, or null for none.
connStatusObj - connection-status panel object, or null for none.
logObj - log-file object to be used, or null for none.
Method Detail

loadQWWebSvcsManagerClassObj

public static boolean loadQWWebSvcsManagerClassObj()
Loads the class object for the 'QWWebSvcsManager' class.

Returns:
true if successful; false if not.

updateConnectParams

public void updateConnectParams(java.lang.String clientHostAddress,
                                int clientPortNum)
Updates the connection parameters to be used on the next initialization.

Specified by:
updateConnectParams in class QWAbstractConnector
Parameters:
clientHostAddress - an IP address to be associated with this client, or null to have the address auto-determined.
clientPortNum - a port address value to be associated with this client, or 0 to have the port address auto-determined.

enterConnectionInfo

public void enterConnectionInfo(java.lang.String userNameStr,
                                java.lang.String passwordStr,
                                java.lang.String connPropsStr)
Enters the connection-information values to be sent when the client connects to the server. This overridden version calls the parent method and then adds a username entry to the connection-information properties string.

Overrides:
enterConnectionInfo in class QWAbstractConnector
Parameters:
userNameStr - the user name string to use.
passwordStr - the password string to use.
connPropsStr - the connection-information properties string to use.

startConnectViaHostInfo

public void startConnectViaHostInfo(java.lang.String serverHostAddrStr,
                                    int serverHostPortNum,
                                    boolean showPopupFlag)
Starts a new thread that establishes a connection to a QWServer.

Specified by:
startConnectViaHostInfo in class QWAbstractConnector
Parameters:
serverHostAddrStr - the host address used to locate the server.
serverHostPortNum - the port number used to locate the server.
showPopupFlag - true to force the connection status popup dialog to be shown.

terminateConnectThread

public void terminateConnectThread(int numWaitSecs)
Terminates and disposes any event channel connect thread that is running.

Parameters:
numWaitSecs - number of seconds to wait for thread to finish terminating.

shutdownConnection

public void shutdownConnection(boolean showPopupFlag)
Shuts down the connection and waits for the disconnect to complete or timeout.

Specified by:
shutdownConnection in class QWAbstractConnector
Parameters:
showPopupFlag - true to force the connection status popup dialog to be shown.

startDisconnectThread

public void startDisconnectThread()
Starts a new thread that disconnects the QW web services connection.


terminateDisconnectThread

public void terminateDisconnectThread(int numWaitSecs)
Terminates and disposes any event channel disconnect thread that is running.

Parameters:
numWaitSecs - number of seconds to wait for thread to finish terminating.

doDisconnectClientServices

protected boolean doDisconnectClientServices()
Performs the work of disconnecting this client from the server services.

Specified by:
doDisconnectClientServices in class QWAbstractConnector
Returns:
true if successful; false if an error occurred.

getServerIDNameStr

public java.lang.String getServerIDNameStr()
Returns the server ID name string (defined in the QWServer's configuration file).

Specified by:
getServerIDNameStr in class QWAbstractConnector
Returns:
The server ID name string, or null if not available.

getServerRepHostAddrStr

public java.lang.String getServerRepHostAddrStr()
Returns the host address reported by the server.

Specified by:
getServerRepHostAddrStr in class QWAbstractConnector
Returns:
The host address reported by the server, or null if not available.

getServerRevisionStr

public java.lang.String getServerRevisionStr()
Returns the server revision string.

Specified by:
getServerRevisionStr in class QWAbstractConnector
Returns:
The server revision string, or null if not available.

requestServerAliveMsg

public void requestServerAliveMsg()
Requests that the server send an 'Alive' message immediately.

Specified by:
requestServerAliveMsg in class QWAbstractConnector

isReqServerMsgsAvailable

public boolean isReqServerMsgsAvailable()
Returns an indicator of whether or not the 'requestMessages()' method is available on the current server.

Specified by:
isReqServerMsgsAvailable in class QWAbstractConnector
Returns:
true.

requestServerMessages

public java.lang.String requestServerMessages(long timeVal,
                                              long msgNum,
                                              java.lang.String hostMsgNumListStr)
Requests that messages newer or equal to the specified time value or later than the specified message number be returned from the server. If a 'hostMsgNumListStr' value is not given and a non-zero message number is given and the given time value matches then messages with message numbers greater than the given message number are returned; otherwise messages newer or equal to the specified time value are returned (within a tolerance value). If a 'hostMsgNumListStr' value is given then it is used with the server "requestSourced...()" methods (and any given message number is ignored). An XML message containing the messages is returned, using the following format:
 [QWresend NumRequested="10"]
   [QWmessage ...] [/QWmessage]
   [QWmessage ...] [/QWmessage]
   ...
 [/QWresend]
 
(Substitute angle brackets for square brackets.) The number of messages that would be required to fill the request is returned in the "NumRequested" attribute. However, no more than the oldest 'maxResendNumMsgs' number of messages will be returned in any single call to this method (additional calls may be needed to fetch all of the desired messages).

Specified by:
requestServerMessages in class QWAbstractConnector
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.
hostMsgNumListStr - a list of feeder-data-source host-name/message-number entries, or null or empty string if the "requestSourced...()" methods should not be used.
Returns:
An XML-formatted string containing the messages, or an empty string if an error occurs.

performClientStatusCheck

public boolean performClientStatusCheck()
                                 throws java.lang.NoSuchMethodException,
                                        QWAbstractConnector.StatusCheckFailedException
Calls the server 'clientStatusCheck()' method.

Specified by:
performClientStatusCheck in class QWAbstractConnector
Returns:
true if the an updated version of the client is available; false if not.
Throws:
java.lang.NoSuchMethodException - if the 'clientStatusCheck()' method is not implemented on the server.
StatusCheckFailedException - if the call to 'clientStatusCheck()' failed with an exception other than 'NoSuchMethodException'.
QWAbstractConnector.StatusCheckFailedException

fetchClientUpgradeInfoFromServer

public java.lang.String fetchClientUpgradeInfoFromServer()
Returns information about available client-program upgrades via the server 'getClientUpgradeInfo()' method.

Specified by:
fetchClientUpgradeInfoFromServer in class QWAbstractConnector
Returns:
An XML-formatted string containing information about available client-program upgrades, or null if an error occurred.

fetchRedirectedServerLoc

public java.lang.String fetchRedirectedServerLoc()
Returns the location of the server that the client is being redirected to. The returned string may also be a comma-separated list of "hostAddr:portNum" entries.

Specified by:
fetchRedirectedServerLoc in class QWAbstractConnector
Returns:
The redirect-server location string in the form "hostAddr:portNum", an empty string if the client is not being redirected, or null if an error occurred.

isStatusReportDataAvail

public boolean isStatusReportDataAvail()
Determines if get-status-report methods are available on the server.

Specified by:
isStatusReportDataAvail in class QWAbstractConnector
Returns:
true if get-status-report methods are available on the server; false if not.

getStatusReportTime

public long getStatusReportTime()
Fetches the timestamp value for the latest status report from the server.

Specified by:
getStatusReportTime in class QWAbstractConnector
Returns:
The timestamp value for the latest status report from the server, or 0 if no report is available or if an error occurred.

getStatusReportData

public java.lang.String getStatusReportData()
Fetches the latest status-report data from the server.

Specified by:
getStatusReportData in class QWAbstractConnector
Returns:
A string containing the latest status-report data from the server, an empty string if no report is available, or null if an error occurred.

notifyConnLoginAttemptRejected

protected void notifyConnLoginAttemptRejected(java.lang.String connStatusStr)
Method called when a connect-to-server login attempt was rejected. A worker thread and a slight delay are used to give the 'connect' thread a chance to terminate cleanly.

Parameters:
connStatusStr - a message-string describing the status of the current connection to the server.

getInitializedFlag

public boolean getInitializedFlag()
Returns the "initialized" status of the connection.

Specified by:
getInitializedFlag in class QWAbstractConnector
Returns:
true if the connection is initialized.

getConnectedFlag

public boolean getConnectedFlag()
Returns the connection status. If 'invalidateConnection()' has been called then this method will return false until the connection is reinitialized.

Specified by:
getConnectedFlag in class QWAbstractConnector
Returns:
true if the connection is active, false if not.

invalidateConnection

public void invalidateConnection()
Marks the connection as "invalidated", causing the 'getConnectedFlag()' method to return 'false'.

Specified by:
invalidateConnection in class QWAbstractConnector