com.isti.quakewatch.util
Class QWStorageManager

java.lang.Object
  extended by java.lang.Thread
      extended by com.isti.quakewatch.util.QWStorageManager
All Implemented Interfaces:
QWStorageProcessor, QWAliveMsgListener, java.lang.Runnable

public class QWStorageManager
extends java.lang.Thread
implements QWStorageProcessor, QWAliveMsgListener

Class QWStorageManager manages the persistent storage of QuakeWatch XML text messages.


Nested Class Summary
protected  class QWStorageManager.QWMsgRecProcessCallBack
          Class QWMsgRecProcessCallBack implements the call-back to process 'QWMsgRecord' items from the archive.
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.String ARCHIVE_BASE_FNAME
          Default "base" filename for archive files ("QWEvents.txt").
static java.lang.String ARCHIVE_ROOT_DIRNAME
          Default name of root directory for archive ("storage").
static java.lang.Object eventFileLoadedValue
          Value returned via 'popupObj.show()' if events loaded OK.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
QWStorageManager(QWMessageHandler msgHandlerObj, EventListManager eventListManagerObj, IstiDialogInterface popupObj, ProgressIndicatorInterface progressBarObj, CfgPropItem maxLoadEventAgeDaysProp, CfgPropItem maxArchiveAgeDaysProp, LogFile logObj)
          Creates a manager for the persistent storage of QuakeWatch XML text messages.
QWStorageManager(QWMessageHandler msgHandlerObj, EventListManager eventListManagerObj, IstiDialogInterface popupObj, ProgressIndicatorInterface progressBarObj, CfgPropItem maxLoadEventAgeDaysProp, CfgPropItem maxArchiveAgeDaysProp, LogFile logObj, java.lang.String archiveRootDirName)
          Creates a manager for the persistent storage of QuakeWatch XML text messages.
QWStorageManager(QWMessageHandler msgHandlerObj, EventListManager eventListManagerObj, IstiDialogInterface popupObj, ProgressIndicatorInterface progressBarObj, CfgPropItem maxLoadEventAgeDaysProp, CfgPropItem maxArchiveAgeDaysProp, LogFile logObj, java.lang.String archiveRootDirName, java.lang.String archiveBaseFName)
          Creates a manager for the persistent storage of QuakeWatch XML text messages.
 
Method Summary
 void aliveMsgReceived(QWStatusMsgRecord recObj)
          Called each time an "Alive" message is received from the QWServer.
 void close()
          Closes the persistent storage archive.
 long getLastAliveMsgRecTimeOffs()
          Returns the received-time-offset value for the last-received server-alive message.
 boolean getLoadDoneFlag()
          Returns the status of loading XML messages from the storage file.
 void run()
          Separate thread method that loads event objects from the archive, sending them to the message manager.
 void storeRecord(QWMsgRecord recObj)
          Stores the given "QWmessage" element object into the persistent storage archive.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

eventFileLoadedValue

public static final java.lang.Object eventFileLoadedValue
Value returned via 'popupObj.show()' if events loaded OK.


ARCHIVE_ROOT_DIRNAME

public static final java.lang.String ARCHIVE_ROOT_DIRNAME
Default name of root directory for archive ("storage").

See Also:
Constant Field Values

ARCHIVE_BASE_FNAME

public static final java.lang.String ARCHIVE_BASE_FNAME
Default "base" filename for archive files ("QWEvents.txt").

See Also:
Constant Field Values
Constructor Detail

QWStorageManager

public QWStorageManager(QWMessageHandler msgHandlerObj,
                        EventListManager eventListManagerObj,
                        IstiDialogInterface popupObj,
                        ProgressIndicatorInterface progressBarObj,
                        CfgPropItem maxLoadEventAgeDaysProp,
                        CfgPropItem maxArchiveAgeDaysProp,
                        LogFile logObj,
                        java.lang.String archiveRootDirName,
                        java.lang.String archiveBaseFName)
                 throws java.lang.NoSuchMethodException
Creates a manager for the persistent storage of QuakeWatch XML text messages. This constructor spawns a separate thread that loads "QWmessage" XML text messages from the storage file, sending them to the message manager. Each line of data in the file is expected to contain a single, complete "QWmessage" XML text message, but other characters may precede the beginning of the message text.

Parameters:
msgHandlerObj - message handler object to use.
eventListManagerObj - event-list manager object to use.
popupObj - dialog popup object to be closed when the loading of messages is complete, or null for none.
progressBarObj - progress bar widget to be updated during initial load of data from storage file, or null for none.
maxLoadEventAgeDaysProp - a 'CfgPropItem' that specifies the floating-point number-of-days' worth of events to be loaded.
maxArchiveAgeDaysProp - a 'CfgPropItem' that specifies the maximum age in days before event-archive files are deleted.
logObj - LogFile object to use.
archiveRootDirName - name of root directory for archive.
archiveBaseFName - "base" filename for archive files.
Throws:
java.lang.NoSuchMethodException - if an error occurs while setting up the archive manager object (shouldn't happen).

QWStorageManager

public QWStorageManager(QWMessageHandler msgHandlerObj,
                        EventListManager eventListManagerObj,
                        IstiDialogInterface popupObj,
                        ProgressIndicatorInterface progressBarObj,
                        CfgPropItem maxLoadEventAgeDaysProp,
                        CfgPropItem maxArchiveAgeDaysProp,
                        LogFile logObj,
                        java.lang.String archiveRootDirName)
                 throws java.lang.NoSuchMethodException
Creates a manager for the persistent storage of QuakeWatch XML text messages. This constructor spawns a separate thread that loads "QWmessage" XML text messages from the storage file, sending them to the message manager. Each line of data in the file is expected to contain a single, complete "QWmessage" XML text message, but other characters may precede the beginning of the message text. The 'base' filename "QWEvents.txt" is used.

Parameters:
msgHandlerObj - message handler object to use.
eventListManagerObj - event-list manager object to use.
popupObj - dialog popup object to be closed when the loading of messages is complete, or null for none.
progressBarObj - progress bar widget to be updated during initial load of data from storage file, or null for none.
maxLoadEventAgeDaysProp - a 'CfgPropItem' that specifies the floating-point number-of-days' worth of events to be loaded.
maxArchiveAgeDaysProp - a 'CfgPropItem' that specifies the maximum age in days before event-archive files are deleted.
logObj - LogFile object to use.
archiveRootDirName - name of root directory for archive.
Throws:
java.lang.NoSuchMethodException - if an error occurs while setting up the archive manager object (shouldn't happen).

QWStorageManager

public QWStorageManager(QWMessageHandler msgHandlerObj,
                        EventListManager eventListManagerObj,
                        IstiDialogInterface popupObj,
                        ProgressIndicatorInterface progressBarObj,
                        CfgPropItem maxLoadEventAgeDaysProp,
                        CfgPropItem maxArchiveAgeDaysProp,
                        LogFile logObj)
                 throws java.lang.NoSuchMethodException
Creates a manager for the persistent storage of QuakeWatch XML text messages. This constructor spawns a separate thread that loads "QWmessage" XML text messages from the storage file, sending them to the message manager. Each line of data in the file is expected to contain a single, complete "QWmessage" XML text message, but other characters may precede the beginning of the message text. The root directory name "storage" and 'base' filename "QWEvents.txt" are used.

Parameters:
msgHandlerObj - message handler object to use.
eventListManagerObj - event-list manager object to use.
popupObj - dialog popup object to be closed when the loading of messages is complete, or null for none.
progressBarObj - progress bar widget to be updated during initial load of data from storage file, or null for none.
maxLoadEventAgeDaysProp - a 'CfgPropItem' that specifies the floating-point number-of-days' worth of events to be loaded.
maxArchiveAgeDaysProp - a 'CfgPropItem' that specifies the maximum age in days before event-archive files are deleted.
logObj - LogFile object to use.
Throws:
java.lang.NoSuchMethodException - if an error occurs while setting up the archive manager object (shouldn't happen).
Method Detail

close

public void close()
Closes the persistent storage archive.


storeRecord

public void storeRecord(QWMsgRecord recObj)
Stores the given "QWmessage" element object into the persistent storage archive.

Specified by:
storeRecord in interface QWStorageProcessor
Parameters:
recObj - the record object holding the "QWmessage" element.

aliveMsgReceived

public void aliveMsgReceived(QWStatusMsgRecord recObj)
Called each time an "Alive" message is received from the QWServer. If the time-generated time for the message is ahead of local time then the archive manager time-check offset value may be adjusted to make sure that new incoming event messages will not be rejected. This method implements the 'QWAliveMsgListener' interface.

Specified by:
aliveMsgReceived in interface QWAliveMsgListener
Parameters:
recObj - the 'QWStatusMsgRecord' object for the received message, or null if none available.

getLastAliveMsgRecTimeOffs

public long getLastAliveMsgRecTimeOffs()
Returns the received-time-offset value for the last-received server-alive message. This value indicates the difference between the local clock and the server clock, with a negative value indicating that the server clock is ahead of the local clock.

Returns:
The received-time-offset value, in milliseconds.

getLoadDoneFlag

public boolean getLoadDoneFlag()
Returns the status of loading XML messages from the storage file.

Returns:
true if the load is complete, false is not.

run

public void run()
Separate thread method that loads event objects from the archive, sending them to the message manager.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread