com.isti.util
Class FlatDailyArchiveManager

java.lang.Object
  extended by com.isti.util.ArchiveManager
      extended by com.isti.util.ExtendedArchiveManager
          extended by com.isti.util.FlatDailyArchiveManager

public class FlatDailyArchiveManager
extends ExtendedArchiveManager

Class FlatDailyArchiveManager is an extension of ArchiveManager that uses a single file for each day, all stored in a single directory. Old archive files are purged (deleted) via the 'purgeArchive()' method, but old items within archive files are not purged (unless the behavior is changed via the 'setPurgeIntoArchiveFlag()' method). 7/21/2003 -- [ET] Changed default date-format time zone to GMT; added 'setDateFormatTimeZone()'. 9/16/2003 -- [ET] Removed 'archiveOutStmSyncObj', instead using 'archiveAccessSyncObj'. 9/17/2003 -- [KF] Extend ExtendedArchiveManager. 9/19/2003 -- [KF] Fix problem with NullPointerException with the 'getArchiveFilesForDateRange' method. 5/18/2004 -- [KF] Create a new date formatter for each instance. 9/24/2007 -- [ET] Added 'getDateForArchiveFileName()' and 'doesNextArchiveFileExist()' methods. 4/28/2010 -- [ET] Added optional 'strictArchiveDateFlag' parameter to constructor.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.isti.util.ExtendedArchiveManager
ExtendedArchiveManager.AbstractWorkerThread, ExtendedArchiveManager.ArchiveItemWorkerThread, ExtendedArchiveManager.PurgeWorkerThread
 
Nested classes/interfaces inherited from class com.isti.util.ArchiveManager
ArchiveManager.ProcessCallBack
 
Field Summary
static java.lang.String DEF_DATE_FORMAT_STR
          Default date-formatter pattern string ("yyyyMMdd").
static java.lang.String DEF_FNAME_DATE_SEPSTR
          Default datecode separator string ("_").
 
Fields inherited from class com.isti.util.ExtendedArchiveManager
archiveItemQueueVec, archiveItemWTObj, archiveItemWTSyncObj, purgeWTObj, purgeWTSyncObj, strictArchiveDateFlag
 
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
FlatDailyArchiveManager(java.lang.Class classObj, java.lang.String baseFileNameStr)
          Creates a new FlatDailyArchiveManager.
FlatDailyArchiveManager(java.lang.Class classObj, java.lang.String archiveRootDirName, java.lang.String baseFileNameStr)
          Creates a new FlatDailyArchiveManager.
FlatDailyArchiveManager(java.lang.Class classObj, java.lang.String archiveRootDirName, java.lang.String baseFileNameStr, boolean strictArchiveDateFlag)
          Creates a new FlatDailyArchiveManager.
 
Method Summary
protected  void createDefaultDateFormatter()
          Creates the default date formatter.
protected  boolean doesNextArchiveFileExist(java.lang.String fNameStr)
          Determines if the next file in the archive sequence exists.
protected  java.lang.String getArchiveFileNameForDate(java.util.Date dateObj)
          Returns the name of the archive file that would contain items with the given date.
protected  java.util.Vector getArchiveFilesForDateRange(java.util.Date startDate, java.util.Date endDate)
          Returns all of the archive file names that can potentially contain items with an archive date between startDate and endDate (inclusive).
protected  java.util.Date getDateForArchiveFileName(java.lang.String fNameStr)
          Parses the given filename for a date code.
 java.text.DateFormat getDateFormatObj()
          Returns the 'DateFormat' object used to generate date codes inserted into archive file names.
 java.text.DateFormat getFileNameDateParserObj()
          Returns a 'DateFormat' parser that may be used to parse a date value from an archive file name.
 java.lang.String getFNameDateSepStr()
          Returns the separator string put in front of date codes inserted into archive file names.
protected  java.io.OutputStream getOutputStreamForItem(Archivable item)
          Returns an output stream for the file that the item should be archived to, with a name based on the archive date of item.
 void setDateFormatObj(java.text.DateFormat dFormatObj)
          Sets the 'DateFormat' object used to generate date codes inserted into archive file names.
 void setDateFormatTimeZone(java.util.TimeZone timeZoneObj)
          Sets the time zone for the 'DateFormat' object used to generate date codes inserted into archive file names.
 void setFNameDateSepStr(java.lang.String sepStr)
          Sets the separator string put in front of date codes inserted into archive file names.
 
Methods inherited from class com.isti.util.ExtendedArchiveManager
addToWorkerThread, archiveItem, archiveQueuedItem, closeArchive, getArchivePollTime, getArchivePurgeAge, isArchiveItemQueueEnabled, purgeArchive, removeFromWorkerThread, setArchiveItemQueueEnabled, setArchivePollTime, setArchivePurgeAge, signalWorkerThread, terminateWorkerThreads
 
Methods inherited from class com.isti.util.ArchiveManager
archiveItem, checkItemArchiveDate, close, close, closeArchiveOutStms, convertStringToArchivable, deleteFile, flush, getArchiveAccessSyncObj, getArchivedFormPrefixStr, getArchivedItemDelimiter, getArchivedItems, getArchivedItems, getArchivedItemsVector, getArchivedItemsVector, getArchiveFileForName, getDontPurgeLastFileFlag, getLeaveOutputStreamsOpenFlag, getLogFile, getLogPrefixString, getNewestArchiveFile, getNewestItemInArchiveFile, getNewestItemInEntireArchive, getNextItemDataFromFile, getNextLineFromFile, getOldestArchiveFile, getOldestItemInArchiveFile, getOldestItemInEntireArchive, 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

DEF_DATE_FORMAT_STR

public static final java.lang.String DEF_DATE_FORMAT_STR
Default date-formatter pattern string ("yyyyMMdd").

See Also:
Constant Field Values

DEF_FNAME_DATE_SEPSTR

public static final java.lang.String DEF_FNAME_DATE_SEPSTR
Default datecode separator string ("_").

See Also:
Constant Field Values
Constructor Detail

FlatDailyArchiveManager

public FlatDailyArchiveManager(java.lang.Class classObj,
                               java.lang.String archiveRootDirName,
                               java.lang.String baseFileNameStr,
                               boolean strictArchiveDateFlag)
                        throws java.lang.NoSuchMethodException
Creates a new FlatDailyArchiveManager. The 'purgeIntoArchiveFlag' is set 'false' (see 'setPurgeIntoArchiveFlag()' for details). 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.
baseFileNameStr - the "base" file name to used to generate archive file names. A date code will be inserted before the extension part of the file name.
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 baseFileNameStr is null

FlatDailyArchiveManager

public FlatDailyArchiveManager(java.lang.Class classObj,
                               java.lang.String archiveRootDirName,
                               java.lang.String baseFileNameStr)
                        throws java.lang.NoSuchMethodException
Creates a new FlatDailyArchiveManager. The 'purgeIntoArchiveFlag' is set 'false' (see 'setPurgeIntoArchiveFlag()' for details). 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.
baseFileNameStr - the "base" file name to used to generate archive file names. A date code will be inserted before the extension part of the file name.
Throws:
java.lang.NoSuchMethodException - if a proper constructor does not exist for the class.
java.lang.NullPointerException - If baseFileNameStr is null

FlatDailyArchiveManager

public FlatDailyArchiveManager(java.lang.Class classObj,
                               java.lang.String baseFileNameStr)
                        throws java.lang.NoSuchMethodException
Creates a new FlatDailyArchiveManager. The 'purgeIntoArchiveFlag' is set 'false' (see 'setPurgeIntoArchiveFlag()' for details). 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.
baseFileNameStr - the "base" file name to used to generate archive file names. A date code will be inserted before the extension part of the file name.
Throws:
java.lang.NoSuchMethodException - if a proper constructor does not exist for the class.
java.lang.NullPointerException - If baseFileNameStr is null
Method Detail

setDateFormatObj

public void setDateFormatObj(java.text.DateFormat dFormatObj)
Sets the 'DateFormat' object used to generate date codes inserted into archive file names. The date codes must be in year-month-day order such that a lexicographic sort will result in proper ordering by time. If this method is not called then the default 'DateFormat' object is used ("yyyyMMdd").

Parameters:
dFormatObj - the 'DateFormat' object to use, or null to set the default 'DateFormat' object.

getDateFormatObj

public java.text.DateFormat getDateFormatObj()
Returns the 'DateFormat' object used to generate date codes inserted into archive file names.

Returns:
A 'DateFormat' object.

setDateFormatTimeZone

public void setDateFormatTimeZone(java.util.TimeZone timeZoneObj)
Sets the time zone for the 'DateFormat' object used to generate date codes inserted into archive file names. The default time zone is GMT.

Parameters:
timeZoneObj - the time zone object to use.

setFNameDateSepStr

public void setFNameDateSepStr(java.lang.String sepStr)
Sets the separator string put in front of date codes inserted into archive file names. If this method is not called then the default separator string is used ("_").

Parameters:
sepStr - the separator string to use, or null to set the default separator string.

getFNameDateSepStr

public java.lang.String getFNameDateSepStr()
Returns the separator string put in front of date codes inserted into archive file names.

Returns:
The separator string.

createDefaultDateFormatter

protected void createDefaultDateFormatter()
Creates the default date formatter.


getArchiveFileNameForDate

protected java.lang.String getArchiveFileNameForDate(java.util.Date dateObj)
Returns the name of the archive file that would contain items with the given date.

Overrides:
getArchiveFileNameForDate in class ArchiveManager
Parameters:
dateObj - the date object to use.
Returns:
The file name string.

getOutputStreamForItem

protected java.io.OutputStream getOutputStreamForItem(Archivable item)
                                               throws java.io.IOException
Returns an output stream for the file that the item should be archived to, with a name based on the archive date of item.

Overrides:
getOutputStreamForItem in class ArchiveManager
Parameters:
item - the item to be archived.
Returns:
An 'OutputStream' to be used to write to the archive file.
Throws:
java.io.IOException - if the archive file cannot be opened.

getArchiveFilesForDateRange

protected java.util.Vector getArchiveFilesForDateRange(java.util.Date startDate,
                                                       java.util.Date endDate)
Returns all of the archive file names that can potentially contain items with an archive date between startDate and endDate (inclusive). These files should be in order from oldest to newest.

Overrides:
getArchiveFilesForDateRange in class ArchiveManager
Parameters:
startDate - the start of the time range, or null to indicate the "beginning of time".
endDate - the end of the time range, or null to indicate the "end of time".
Returns:
A new 'Vector' of File objects.

getFileNameDateParserObj

public java.text.DateFormat getFileNameDateParserObj()
Returns a 'DateFormat' parser that may be used to parse a date value from an archive file name. Usages of this date formatter should be thread-synchronized to the formatter object.

Returns:
A 'DateFormat' parser object.

getDateForArchiveFileName

protected java.util.Date getDateForArchiveFileName(java.lang.String fNameStr)
Parses the given filename for a date code.

Parameters:
fNameStr - name of archive file.
Returns:
A new 'Date' object containing the date code, or null if the date code could not be parsed.

doesNextArchiveFileExist

protected boolean doesNextArchiveFileExist(java.lang.String fNameStr)
Determines if the next file in the archive sequence exists. For this "daily" archiver it is the archive file for the day following date specified in the given archive filename.

Overrides:
doesNextArchiveFileExist in class ArchiveManager
Parameters:
fNameStr - name of archive file.
Returns:
true if the next file in the archive sequence exists (or a date code could not be parsed from the given filename); false otherwise.