com.isti.util
Class ExtendedArchiveManager

java.lang.Object
  extended by com.isti.util.ArchiveManager
      extended by com.isti.util.ExtendedArchiveManager
Direct Known Subclasses:
FlatDailyArchiveManager

public class ExtendedArchiveManager
extends ArchiveManager

Class ExtendedArchiveManager extends an archive manager to support: optional queuing of archive items. optional purging of archive items. 9/30/2003 -- [KF] Initial version. 10/03/2003 -- [KF] Extend 'IstiThread' instead of 'Thread'. 11/06/2003 -- [KF] Log stack trace for IOException. 01/02/2004 -- [KF] Added polling option that may be used instead of thread interrupt. 3/31/2004 -- [ET] Changed reference to 'saveItemArchiveDate()' to 'checkItemArchiveDate()'. 7/12/2005 -- [ET] Modified to make 'AbstractWorkerThread' class extend 'IstiNotifyThread' to avoid use of thread 'interrupt()' calls that can be problematic under Solaris OS; made worker-thread classes into static member classes of main class. 3/21/2007 -- [ET] Added 'terminateWorkerThreads()' method. 4/28/2010 -- [ET] Added optional 'strictArchiveDateFlag' parameter to constructor.


Nested Class Summary
protected static class ExtendedArchiveManager.AbstractWorkerThread
          Class AbstractWorkerThread is a general worker thread for archive managers.
protected static class ExtendedArchiveManager.ArchiveItemWorkerThread
          Class ArchiveItemWorkerThread fetches items from the queue and adds them to the archive.
protected static class ExtendedArchiveManager.PurgeWorkerThread
          Class PurgeWorkerThread purges items from the archive.
 
Nested classes/interfaces inherited from class com.isti.util.ArchiveManager
ArchiveManager.ProcessCallBack
 
Field Summary
protected  java.util.Vector archiveItemQueueVec
          The archive item queue vector.
protected static ExtendedArchiveManager.ArchiveItemWorkerThread archiveItemWTObj
           
protected static java.lang.Object archiveItemWTSyncObj
           
protected static ExtendedArchiveManager.PurgeWorkerThread purgeWTObj
           
protected static java.lang.Object purgeWTSyncObj
           
protected  boolean strictArchiveDateFlag
          Set 'true' if items must be in ascending date/time order.
 
Fields inherited from class com.isti.util.ArchiveManager
archiveAccessSyncObj, archiveClosedFlag, archivedClassConstructor, archivedFormPrefixStr, archivedItemDelimiter, archiveFileNameStr, archiveOutStm, archiveRootDirName, assumeNewlineFlag, dontPurgeLastFileFlag, filesForDateRangeVec, lastItemArchiveDate, leaveOutputStreamsOpenFlag, purgeIntoArchiveFlag, timeCheckOffsetMs
 
Constructor Summary
ExtendedArchiveManager(java.lang.Class classObj, java.lang.String archiveFileNameStr)
          Creates a new instance of ExtendedArchiveManager to archive instances of the given class.
ExtendedArchiveManager(java.lang.Class classObj, java.lang.String archiveRootDirName, java.lang.String archiveFileNameStr)
          Creates a new instance of ExtendedArchiveManager to archive instances of the given class.
ExtendedArchiveManager(java.lang.Class classObj, java.lang.String archiveRootDirName, java.lang.String archiveFileNameStr, boolean strictArchiveDateFlag)
          Creates a new instance of ExtendedArchiveManager to archive instances of the given class.
 
Method Summary
protected  void addToWorkerThread(ExtendedArchiveManager.AbstractWorkerThread wt)
          Adds this archive manager to the worker thread if it has not already been added.
 boolean archiveItem(Archivable item)
          Inserts an item into the archive.
protected  void archiveQueuedItem(Archivable item)
          Inserts an item into the archive.
 void closeArchive()
          Releases resources allocated for this archive manager.
 long getArchivePollTime()
          Gets the archive poll time.
 long getArchivePurgeAge()
          Gets the archive purge age in milliseconds.
 boolean isArchiveItemQueueEnabled()
          Determines if the archive item queue is enabled.
protected  boolean purgeArchive(long currentTime)
          Purges items and archive files with an archive date older than the purge age if enable.
protected  void removeFromWorkerThread(ExtendedArchiveManager.AbstractWorkerThread wt)
          Removes this archive manager from the worker thread if it was added.
 void setArchiveItemQueueEnabled(boolean b)
          Enables/disables the archive item queue.
 void setArchivePollTime(long archivePollTime)
          Sets the archive poll time.
 void setArchivePurgeAge(long age)
          Sets the archive purge age in milliseconds.
protected  void signalWorkerThread(ExtendedArchiveManager.AbstractWorkerThread wt)
          Signals the worker thread.
static void terminateWorkerThreads()
          Terminates the worker threads started by this archive manager.
 
Methods inherited from class com.isti.util.ArchiveManager
archiveItem, checkItemArchiveDate, close, close, closeArchiveOutStms, convertStringToArchivable, deleteFile, doesNextArchiveFileExist, flush, getArchiveAccessSyncObj, getArchivedFormPrefixStr, getArchivedItemDelimiter, getArchivedItems, getArchivedItems, getArchivedItemsVector, getArchivedItemsVector, getArchiveFileForName, getArchiveFileNameForDate, getArchiveFilesForDateRange, getDontPurgeLastFileFlag, getLeaveOutputStreamsOpenFlag, getLogFile, getLogPrefixString, getNewestArchiveFile, getNewestItemInArchiveFile, getNewestItemInEntireArchive, getNextItemDataFromFile, getNextLineFromFile, getOldestArchiveFile, getOldestItemInArchiveFile, getOldestItemInEntireArchive, getOutputStreamForItem, getPurgeIntoArchiveFlag, getTimeCheckOffsetMs, isArchiveClosed, processArchivedItems, processArchivedItems, purgeArchive, renameTo, setArchivedFormPrefixStr, setArchivedItemDelimiter, setDontPurgeLastFileFlag, setLeaveOutputStreamsOpenFlag, setLogFile, setLogPrefixString, setPurgeIntoArchiveFlag, setTimeCheckOffsetMs, writeItemToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

archiveItemQueueVec

protected final java.util.Vector archiveItemQueueVec
The archive item queue vector.


strictArchiveDateFlag

protected final boolean strictArchiveDateFlag
Set 'true' if items must be in ascending date/time order.


archiveItemWTSyncObj

protected static final java.lang.Object archiveItemWTSyncObj

archiveItemWTObj

protected static ExtendedArchiveManager.ArchiveItemWorkerThread archiveItemWTObj

purgeWTSyncObj

protected static final java.lang.Object purgeWTSyncObj

purgeWTObj

protected static ExtendedArchiveManager.PurgeWorkerThread purgeWTObj
Constructor Detail

ExtendedArchiveManager

public ExtendedArchiveManager(java.lang.Class classObj,
                              java.lang.String archiveRootDirName,
                              java.lang.String archiveFileNameStr,
                              boolean strictArchiveDateFlag)
                       throws java.lang.NoSuchMethodException
Creates a new instance of ExtendedArchiveManager to archive instances of the given class. The given class must have a constructor with 'String' and 'Archivable.Marker' parameters, like this:
public ArchivableImpl(String dataStr, Archivable.Marker mkrObj) ...
This constructor is used to create the class from a string of data. The 'Archivable.Marker' is used to mark the constructor as being available for de-archiving (and will usually be 'null').

Parameters:
classObj - class object representing the class to be archived.
archiveRootDirName - name of root directory in which to place archive files (and possibly directories), or null to use the current working directory.
archiveFileNameStr - name to use for the archive file(s).
strictArchiveDateFlag - true if items must be in ascending date/time order; false if not.
Throws:
java.lang.NoSuchMethodException - if a proper constructor does not exist for the class.
java.lang.NullPointerException - If archiveFileNameStr is null

ExtendedArchiveManager

public ExtendedArchiveManager(java.lang.Class classObj,
                              java.lang.String archiveRootDirName,
                              java.lang.String archiveFileNameStr)
                       throws java.lang.NoSuchMethodException
Creates a new instance of ExtendedArchiveManager to archive instances of the given class. The given class must have a constructor with 'String' and 'Archivable.Marker' parameters, like this:
public ArchivableImpl(String dataStr, Archivable.Marker mkrObj) ...
This constructor is used to create the class from a string of data. The 'Archivable.Marker' is used to mark the constructor as being available for de-archiving (and will usually be 'null'). Archived items must be added in ascending date/time order.

Parameters:
classObj - class object representing the class to be archived.
archiveRootDirName - name of root directory in which to place archive files (and possibly directories), or null to use the current working directory.
archiveFileNameStr - name to use for the archive file(s).
Throws:
java.lang.NoSuchMethodException - if a proper constructor does not exist for the class.
java.lang.NullPointerException - If archiveFileNameStr is null

ExtendedArchiveManager

public ExtendedArchiveManager(java.lang.Class classObj,
                              java.lang.String archiveFileNameStr)
                       throws java.lang.NoSuchMethodException
Creates a new instance of ExtendedArchiveManager to archive instances of the given class. The given class must have a constructor with 'String' and 'Archivable.Marker' parameters, like this:
public ArchivableImpl(String dataStr, Archivable.Marker mkrObj) ...
This constructor is used to create the class from a string of data. The 'Archivable.Marker' is used to mark the constructor as being available for de-archiving (and will usually be 'null'). The archive files will be placed in the current working directory. Archived items must be added in ascending date/time order.

Parameters:
classObj - class object representing the class to be archived.
archiveFileNameStr - name to use for the archive file(s).
Throws:
java.lang.NoSuchMethodException - if a proper constructor does not exist for the class.
java.lang.NullPointerException - If archiveFileNameStr is null
Method Detail

archiveItem

public boolean archiveItem(Archivable item)
                    throws java.io.IOException
Inserts an item into the archive.

Overrides:
archiveItem in class ArchiveManager
Parameters:
item - the item to be archived.
Returns:
true if the item was added, false otherwise.
Throws:
java.io.IOException - if the archive file can not be written to.

closeArchive

public void closeArchive()
Releases resources allocated for this archive manager.

Overrides:
closeArchive in class ArchiveManager

getArchivePurgeAge

public long getArchivePurgeAge()
Gets the archive purge age in milliseconds. The purge age is the number of milliseconds to keep objects in the archive, or 0 for "infinity".

Returns:
the archive purge age in milliseconds (0 if disabled.)
See Also:
setArchivePurgeAge

getArchivePollTime

public long getArchivePollTime()
Gets the archive poll time.

Returns:
the archive poll time in milliseconds or 0 for interrupts (default).

isArchiveItemQueueEnabled

public boolean isArchiveItemQueueEnabled()
Determines if the archive item queue is enabled.

Returns:
true if the the archive item queue is enabled, false otherwise.
See Also:
setArchiveItemQueueEnabled

setArchiveItemQueueEnabled

public void setArchiveItemQueueEnabled(boolean b)
Enables/disables the archive item queue.

Parameters:
b - true to enable, false to disable. NOTE: The archive poll time should be set prior to calling this method via the 'setArchivePollTime' method.
See Also:
isArchiveItemQueueEnabled, setArchivePollTime

setArchivePollTime

public void setArchivePollTime(long archivePollTime)
Sets the archive poll time.

Parameters:
archivePollTime - the archive poll time in milliseconds or 0 for interrupts (default).

setArchivePurgeAge

public void setArchivePurgeAge(long age)
Sets the archive purge age in milliseconds. The purge age is the number of milliseconds to keep objects in the archive, or 0 for "infinity".

Parameters:
age - the archive purge age in milliseconds (0 for disabled.)
See Also:
getArchivePurgeAge

terminateWorkerThreads

public static void terminateWorkerThreads()
Terminates the worker threads started by this archive manager. The worker threads handle item adding and purging for the archive. This method can be used to terminate the worker threads for all created archive-manager objects (instead of calling the 'closeArchive()' method for each archive manager).


addToWorkerThread

protected void addToWorkerThread(ExtendedArchiveManager.AbstractWorkerThread wt)
Adds this archive manager to the worker thread if it has not already been added.

Parameters:
wt - the worker thread.

archiveQueuedItem

protected void archiveQueuedItem(Archivable item)
                          throws java.io.IOException
Inserts an item into the archive.

Parameters:
item - the item to be archived.
Throws:
java.io.IOException - if the archive file can not be written to.

signalWorkerThread

protected void signalWorkerThread(ExtendedArchiveManager.AbstractWorkerThread wt)
Signals the worker thread.

Parameters:
wt - the worker thread.

purgeArchive

protected boolean purgeArchive(long currentTime)
Purges items and archive files with an archive date older than the purge age if enable.

Parameters:
currentTime - the current time in milliseconds.
Returns:
true if successful, false if an error occurred. The purge age must be set with a call to setArchivePurgeAge.
See Also:
setArchivePurgeAge, setArchivePurgeAge

removeFromWorkerThread

protected void removeFromWorkerThread(ExtendedArchiveManager.AbstractWorkerThread wt)
Removes this archive manager from the worker thread if it was added.

Parameters:
wt - the worker thread.