|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.isti.util.ArchiveManager
Class ArchiveManager defines an archive manager that organizes items by date. As a stand-alone class it implements a very simple archival system (a single file); but it can be extended for more complex archival needs. 7/10/2003 -- [HS,ET] Initial version. 8/20/2003 -- [ET] Fixed 'processArchivedItems()' method to respond to terminate-processing flag from call-back method. 8/22/2003 -- [ET] Fixed bug where 'get/processArchivedItems()' would always start with second item of first file; added 'getOldestArchiveFile()', 'getOldestItemInArchiveFile()' and 'getOldestItemInEntireArchive()' and 'getArchiveAccessSyncObj()' methods. 9/4/2003 -- [ET] Modified to support 'maxCount' limits. 9/8/2003 -- [ET] Bug fix to 'maxCount' limit in 'processArchivedItems()'. 9/9/2003 -- [KF] Added 'getArchivedItemsVector' methods. 9/15/2003 -- [KF] Modified to close the archive output stream(s) before deleting files. 9/16/2003 -- [ET] Removed 'archiveOutStmSyncObj', instead using 'archiveAccessSyncObj'; setup to have only public methods contain 'synchronized' blocks. 9/22/2003 -- [KF] Add constructors throwing NullPointerException if 'archiveFileNameStr' is null, Add 'getLogPrefixString', 'setLogPrefixString', 'getLogFile', and 'setLogFile' methods, Add a return value to the 'archiveItem' method to state if the item was added or not. 9/24/2003 -- [ET] Added 'checkArchiveItemOrder()' method (commented out). 9/25/2003 -- [KF] Added logging messages of errors and warnings. 9/30/2003 -- [KF] Added 'setLeaveOutputStreamsOpenFlag' and 'getLeaveOutputStreamsOpenFlag' methods, and added debug logging of stack trace for exceptions. 11/6/2003 -- [KF] Added logging to various 'set' methods. 11/17/2003 -- [ET] Changed logging level on various 'set' methods to 'debug2'. 3/31/2004 -- [ET] Fixed issue of rejecting added-items with archive dates in the future by implementing a tolerance value that can be modified by the new methods 'get/setTimeCheckOffsetMs()'; renamed method 'saveItemArchiveDate()' to 'checkItemArchiveDate()'; added explicit initializations to 'null' to several member variables. 8/6/2004 -- [KF] Made global logging use console output if not set. 12/21/2005 -- [ET] Fixed methods 'getNewestItemInArchiveFile()' and 'getOldestItemInArchiveFile()' by making them close input file when complete. 9/24/2007 -- [ET] Added 'get/setDontPurgeLastFileFlag()' methods and implementation.
Nested Class Summary | |
static interface |
ArchiveManager.ProcessCallBack
Interface ProcessCallBack defines the call-back object passed into the 'processArchivedItems()' method. |
Field Summary | |
protected java.lang.Object |
archiveAccessSyncObj
Thread synchronization object for archive access. |
protected boolean |
archiveClosedFlag
Flag set true after 'closeArchive()' called. |
protected java.lang.reflect.Constructor |
archivedClassConstructor
Constructor for 'Archivable' class used with this manager. |
protected java.lang.String |
archivedFormPrefixStr
Prefix that all archived-form items should begin with (or null). |
protected java.lang.String |
archivedItemDelimiter
A string that we delimit archived items by. |
protected java.lang.String |
archiveFileNameStr
Name to use for archive file(s). |
protected java.io.OutputStream |
archiveOutStm
The OutputStream object we're archiving to. |
protected java.lang.String |
archiveRootDirName
Root directory of our archive. |
protected boolean |
assumeNewlineFlag
Flag set true if the 'archivedItemDelimiter' string is a newline. |
protected boolean |
dontPurgeLastFileFlag
true to not purge last file if none after it. |
protected java.util.Vector |
filesForDateRangeVec
Vector used if 'getArchiveFilesForDateRange()' not overridden. |
protected java.util.Date |
lastItemArchiveDate
The date of the last item archived. |
protected boolean |
leaveOutputStreamsOpenFlag
true to leave the output streams open until the archive is closed. |
protected boolean |
purgeIntoArchiveFlag
true to purge items inside archives, false to only deal with files. |
protected int |
timeCheckOffsetMs
Time offset used when checking item-date vs. |
Constructor Summary | |
ArchiveManager(java.lang.Class classObj,
java.lang.String archiveFileNameStr)
Creates a new instance of ArchiveManager to archive instances of the given class. |
|
ArchiveManager(java.lang.Class classObj,
java.lang.String archiveRootDirName,
java.lang.String archiveFileNameStr)
Creates a new instance of ArchiveManager to archive instances of the given class. |
Method Summary | |
boolean |
archiveItem(Archivable item)
Inserts an item into the archive. |
protected boolean |
archiveItem(Archivable item,
boolean checkDateFlag)
Inserts an item into the archive. |
protected boolean |
checkItemArchiveDate(Archivable item)
Validates an item to be added the archive. |
protected void |
close(java.io.InputStream inStmObj)
Closes the specified input stream. |
protected void |
close(java.io.OutputStream outStmObj)
Closes the specified output stream. |
void |
closeArchive()
Releases resources allocated for this archive manager. |
protected void |
closeArchiveOutStms()
Close the archive output streams. |
protected Archivable |
convertStringToArchivable(java.lang.String str)
Converts the given string to an 'Archivable' object. |
protected boolean |
deleteFile(java.io.File fileObj)
Deletes the file. |
protected boolean |
doesNextArchiveFileExist(java.lang.String fNameStr)
Determines if the next file in the archive sequence exists. |
protected void |
flush(java.io.OutputStream outStmObj)
Flushes the specified output stream. |
java.lang.Object |
getArchiveAccessSyncObj()
Returns the Object used to thread-synchronize the archive. |
java.lang.String |
getArchivedFormPrefixStr()
Returns the prefix string that all items in their archived form should begin with. |
java.lang.String |
getArchivedItemDelimiter()
Returns the delimiter string to be used in the archive file, to seperate items. |
java.util.Enumeration |
getArchivedItems(java.util.Date startDate,
java.util.Date endDate)
Returns all of the archived items between two date/time values (inclusive). |
java.util.Enumeration |
getArchivedItems(java.util.Date startDate,
java.util.Date endDate,
int maxCount)
Returns all of the archived items between two date/time values (inclusive). |
java.util.Vector |
getArchivedItemsVector(java.util.Date startDate,
java.util.Date endDate)
Returns all of the archived items between two date/time values (inclusive). |
java.util.Vector |
getArchivedItemsVector(java.util.Date startDate,
java.util.Date endDate,
int maxCount)
Returns all of the archived items between two date/time values (inclusive). |
protected java.io.File |
getArchiveFileForName(java.lang.String fNameStr)
Returns the file object for the given file name. |
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)
Given 2 dates (inclusive), returns an enumeration of File objects that can be used to later create a stream. |
boolean |
getDontPurgeLastFileFlag()
Returns the "purge last archive file" flag. |
boolean |
getLeaveOutputStreamsOpenFlag()
Gets whether or not the output streams are left open until the archive is closed. |
LogFile |
getLogFile()
Gets the log file. |
java.lang.String |
getLogPrefixString()
Returns the prefix to use for log output. |
java.io.File |
getNewestArchiveFile()
Returns the newest archive file available. |
Archivable |
getNewestItemInArchiveFile(java.io.File fileObj)
Returns the last 'Archivable' item in the given archive file. |
Archivable |
getNewestItemInEntireArchive()
Returns the last 'Archivable' item available in the entire archive. |
protected java.lang.String |
getNextItemDataFromFile(java.io.InputStream stmObj)
Returns the data for next item from the archive file. |
protected java.lang.String |
getNextLineFromFile(java.io.BufferedReader rdrObj)
Returns the next line of data from the given stream. |
java.io.File |
getOldestArchiveFile()
Returns the oldest archive file available. |
Archivable |
getOldestItemInArchiveFile(java.io.File fileObj)
Returns the first 'Archivable' item in the given archive file. |
Archivable |
getOldestItemInEntireArchive()
Returns the first 'Archivable' item available in the entire archive. |
protected java.io.OutputStream |
getOutputStreamForItem(Archivable item)
Returns an output stream for the file that the item should be archived to. |
boolean |
getPurgeIntoArchiveFlag()
Returns the "purge items inside archives" flag. |
int |
getTimeCheckOffsetMs()
Returns the time offset used when checking the archive-date of added items against the current system time. |
boolean |
isArchiveClosed()
Returns the "closed" status of this archive manager. |
void |
processArchivedItems(java.util.Date startDate,
java.util.Date endDate,
ArchiveManager.ProcessCallBack callBackObj)
Processes all of the archived items between two date/time values (inclusive). |
void |
processArchivedItems(java.util.Date startDate,
java.util.Date endDate,
ArchiveManager.ProcessCallBack callBackObj,
int maxCount)
Processes all of the archived items between two date/time values (inclusive). |
boolean |
purgeArchive(java.util.Date cutoffDate)
Purges items and archive files with an archive date older than the given cutoff date. |
protected boolean |
renameTo(java.io.File fileObj,
java.io.File dest)
Renames the source file to the destination file. |
void |
setArchivedFormPrefixStr(java.lang.String str)
Sets a prefix string that all items in their archived form should begin with. |
void |
setArchivedItemDelimiter(java.lang.String str)
Sets the delimiter string to be used in the archive file, to seperate items. |
void |
setDontPurgeLastFileFlag(boolean flgVal)
Configures whether or not the 'purgeArchive()' method will remove the newest archive file whose date is before the purge-cutoff date when the next file in the archive sequence does not exist. |
void |
setLeaveOutputStreamsOpenFlag(boolean flgVal)
Configures whether or not the output streams are left open until the archive is closed. |
void |
setLogFile(LogFile logFileObj)
Sets the log file. |
void |
setLogPrefixString(java.lang.String logPrefixString)
Sets the prefix to use for log output. |
void |
setPurgeIntoArchiveFlag(boolean flgVal)
Configures whether or not the 'purgeArchive()' method removes items from inside archive files. |
void |
setTimeCheckOffsetMs(int offsetMsVal)
Sets the time offset used when checking the archive-date of added items against the current system time. |
protected void |
writeItemToFile(Archivable item,
java.io.OutputStream outStm)
Does the actual writing of the item to the file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final java.lang.reflect.Constructor archivedClassConstructor
protected final java.lang.String archiveRootDirName
protected final java.lang.String archiveFileNameStr
protected java.io.OutputStream archiveOutStm
protected boolean archiveClosedFlag
protected java.lang.String archivedItemDelimiter
protected boolean assumeNewlineFlag
protected boolean purgeIntoArchiveFlag
protected boolean dontPurgeLastFileFlag
protected boolean leaveOutputStreamsOpenFlag
protected java.lang.String archivedFormPrefixStr
protected final java.lang.Object archiveAccessSyncObj
protected java.util.Vector filesForDateRangeVec
protected int timeCheckOffsetMs
protected java.util.Date lastItemArchiveDate
Constructor Detail |
public ArchiveManager(java.lang.Class classObj, java.lang.String archiveRootDirName, java.lang.String archiveFileNameStr) throws java.lang.NoSuchMethodException
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).
java.lang.NoSuchMethodException
- if a proper constructor does not exist
for the class.
java.lang.NullPointerException
- If archiveFileNameStr
is null
public ArchiveManager(java.lang.Class classObj, java.lang.String archiveFileNameStr) throws java.lang.NoSuchMethodException
classObj
- class object representing the class to be archived.archiveFileNameStr
- name to use for the archive file(s).
java.lang.NoSuchMethodException
- if a proper constructor does not exist
for the class.
java.lang.NullPointerException
- If archiveFileNameStr
is null
Method Detail |
public void setPurgeIntoArchiveFlag(boolean flgVal)
flgVal
- true to configure purging of items inside archive files.public boolean getPurgeIntoArchiveFlag()
public void setDontPurgeLastFileFlag(boolean flgVal)
flgVal
- true to configure the archive to not remove the "last"
file due to be purged (when not followed by another file); false to
purge the file (default).public boolean getDontPurgeLastFileFlag()
public void setLeaveOutputStreamsOpenFlag(boolean flgVal)
flgVal
- true to leave the output streams open until the archive is
closed.public boolean getLeaveOutputStreamsOpenFlag()
public void setArchivedItemDelimiter(java.lang.String str)
str
- the delimiter string to use, or null for the default ("\n").public java.lang.String getArchivedItemDelimiter()
public void setArchivedFormPrefixStr(java.lang.String str)
str
- the prefix string to use, or null for none.public java.lang.String getArchivedFormPrefixStr()
public LogFile getLogFile()
setLogFile, getLogPrefixString
public void setLogFile(LogFile logFileObj)
logFileObj
- the log file object.getLogFile, setLogPrefixString
public java.lang.String getLogPrefixString()
setLogPrefixString, getLogFile
public final void setLogPrefixString(java.lang.String logPrefixString)
logPrefixString
- the prefix to use for log output.getLogPrefixString, setLogFile
public void setTimeCheckOffsetMs(int offsetMsVal)
offsetMsVal
- the time offset value, in milliseconds.public int getTimeCheckOffsetMs()
public boolean archiveItem(Archivable item) throws java.io.IOException
item
- the item to be archived.
java.io.IOException
- if the archive file can not be written to.protected boolean archiveItem(Archivable item, boolean checkDateFlag) throws java.io.IOException
item
- the item to be archived.checkDateFlag
- true to check the date.
java.io.IOException
- if the archive file can not be written to.protected boolean checkItemArchiveDate(Archivable item)
item
- the item to be archived.
protected void writeItemToFile(Archivable item, java.io.OutputStream outStm) throws java.io.IOException
item
- the item to write.outStm
- the 'OutputStream' for the archive file to write to.
java.io.IOException
- if an error occurs.public void processArchivedItems(java.util.Date startDate, java.util.Date endDate, ArchiveManager.ProcessCallBack callBackObj, int maxCount)
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".maxCount
- the maximum number of objects to be returned,
or 0 for no limit.callBackObj
- the call-back object to use to process each item.public void processArchivedItems(java.util.Date startDate, java.util.Date endDate, ArchiveManager.ProcessCallBack callBackObj)
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".callBackObj
- the call-back object to use to process each item.public java.util.Vector getArchivedItemsVector(java.util.Date startDate, java.util.Date endDate, int maxCount)
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".maxCount
- the maximum number of objects to be returned,
or 0 for no limit.
public java.util.Vector getArchivedItemsVector(java.util.Date startDate, java.util.Date endDate)
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".
public java.util.Enumeration getArchivedItems(java.util.Date startDate, java.util.Date endDate, int maxCount)
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".maxCount
- the maximum number of objects to be returned,
or 0 for no limit.
public java.util.Enumeration getArchivedItems(java.util.Date startDate, java.util.Date endDate)
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".
protected java.lang.String getNextItemDataFromFile(java.io.InputStream stmObj)
stmObj
- the input stream to read archive-file data from.
protected java.lang.String getNextLineFromFile(java.io.BufferedReader rdrObj)
rdrObj
- the input stream to read data from.
protected Archivable convertStringToArchivable(java.lang.String str)
str
- the string to convert.
public boolean purgeArchive(java.util.Date cutoffDate)
cutoffDate
- the date of the oldest event to keep in the archive.
protected boolean deleteFile(java.io.File fileObj)
fileObj
- the file object.
true
if and only if the file is
successfully deleted; false
otherwiseprotected boolean renameTo(java.io.File fileObj, java.io.File dest)
fileObj
- the file object.dest
- the new file name.
true
if and only if the renaming succeeded;
false
otherwiseprotected void flush(java.io.OutputStream outStmObj)
outStmObj
- the output stream to flush.protected void close(java.io.InputStream inStmObj)
inStmObj
- the input stream to close.protected void close(java.io.OutputStream outStmObj)
outStmObj
- the output stream to close.protected void closeArchiveOutStms()
public void closeArchive()
public boolean isArchiveClosed()
public java.io.File getNewestArchiveFile()
public java.io.File getOldestArchiveFile()
public Archivable getNewestItemInArchiveFile(java.io.File fileObj)
fileObj
- the file to use.
public Archivable getNewestItemInEntireArchive()
public Archivable getOldestItemInArchiveFile(java.io.File fileObj)
fileObj
- the file to use.
public Archivable getOldestItemInEntireArchive()
public java.lang.Object getArchiveAccessSyncObj()
protected java.util.Vector getArchiveFilesForDateRange(java.util.Date startDate, java.util.Date endDate)
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".
protected java.lang.String getArchiveFileNameForDate(java.util.Date dateObj)
dateObj
- the date object to use.
protected java.io.File getArchiveFileForName(java.lang.String fNameStr)
fNameStr
- the file name to use.
protected java.io.OutputStream getOutputStreamForItem(Archivable item) throws java.io.IOException
item
- the item to be archived.
java.io.IOException
- if the archive file cannot be opened.protected boolean doesNextArchiveFileExist(java.lang.String fNameStr)
fNameStr
- name of archive file.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |