com.isti.util
Class IstiMessageObjectCache

java.lang.Object
  extended bycom.isti.util.IstiTimeObjectCache
      extended bycom.isti.util.IstiMessageObjectCache

public class IstiMessageObjectCache
extends IstiTimeObjectCache

Class IstiMessageObjectCache implements a message object cache. The 'removeOldObjects()' method should be called on a periodic basis to remove old objects from the cache.


Nested Class Summary
static class IstiMessageObjectCache.BasicMessageObjectEntry
          Message object entry class.
static interface IstiMessageObjectCache.MessageObjectEntry
          Interface for message object entry.
 
Nested classes inherited from class com.isti.util.IstiTimeObjectCache
IstiTimeObjectCache.BasicTimeObjectEntry, IstiTimeObjectCache.CacheInformation, IstiTimeObjectCache.TimeObjectEntry, IstiTimeObjectCache.VectorWithCount
 
Field Summary
protected  long lastMsgNumSeqBreakMsgNumLogged
           
protected  long lastMsgNumSeqBreakTime
           
protected  long lastMsgNumTracker
           
protected  java.io.FileDescriptor msgNumFDescObj
           
protected  java.lang.String msgNumFileName
           
protected  java.lang.Object msgNumFileSyncObj
           
protected  java.io.RandomAccessFile msgNumRAFileObj
           
 
Fields inherited from class com.isti.util.IstiTimeObjectCache
defaultRemoveAge, lastMsgTimeTracker, logObj, maximumObjectCount, maximumTotalDataSize, objectCache, tolerance, totalCacheDataSize, useLookupKeyFlag
 
Constructor Summary
IstiMessageObjectCache(LogFile logObj, long tolerance)
          Constructs a time object cache.
IstiMessageObjectCache(LogFile logObj, long tolerance, long removeAge)
          Constructs a message object cache with a default remove age.
IstiMessageObjectCache(LogFile logObj, long tolerance, long removeAge, boolean useLookupKeyFlag)
          Constructs a message object cache with a default remove age.
IstiMessageObjectCache(LogFile logObj, long tolerance, long removeAge, java.lang.String msgNumFileName)
          Constructs a message object cache.
IstiMessageObjectCache(LogFile logObj, long tolerance, long removeAge, java.lang.String msgNumFileName, boolean useLookupKeyFlag)
          Constructs a message object cache.
 
Method Summary
 void addMessage(long timeGenerated, java.lang.Object msgObj, java.lang.String msgStr, long msgNum)
          Adds the message.
 void addMsgObjEntry(IstiMessageObjectCache.MessageObjectEntry msgObj)
          Adds the message-object entry.
 void close()
          Deallocates resources associated with the cache.
 IstiMessageObjectCache.MessageObjectEntry getFirstMessage()
          Returns the first message object in the cache.
 IstiMessageObjectCache.MessageObjectEntry getLastMessage()
          Returns the last message object in the cache.
 long getLastMsgNum()
          Return the last message number.
 long getLastMsgNumSeqBreakTime()
          Returns the time for the last detected break in the message number sequence for messages added to the cache.
protected  java.lang.String getLogPrefixString()
          Returns the prefix to use for log output.
protected  IstiMessageObjectCache.MessageObjectEntry getMessage(int index)
          Returns the message entry at the given index.
 IstiTimeObjectCache.VectorWithCount getMessages(long beginTime, long beginMsgNum, long endTime, long endMsgNum)
          Retrieves a copy of messages in the specified time range.
 IstiTimeObjectCache.VectorWithCount getMessages(long beginTime, long beginMsgNum, long endTime, long endMsgNum, int maxCount)
          Retrieves a copy of messages in the specified time range.
protected  long getMsgTime(long msgNum)
          Gets the message time for the specified message number.
 IstiTimeObjectCache.VectorWithCount getNewerMessages(long time, long msgNum)
          Returns a list of messages newer or equal to the specified time value or later than the specified message number.
 IstiTimeObjectCache.VectorWithCount getNewerMessages(long time, long msgNum, int maxCount)
          Returns a list of messages newer or equal to the specified time value or later than the specified message number.
 IstiTimeObjectCache.VectorWithCount getOlderMessages(long time, long msgNum)
          Returns a list of messages older or equal to the specified time value or sooner than the specified message number.
 IstiTimeObjectCache.VectorWithCount getOlderMessages(long time, long msgNum, int maxCount)
          Returns a list of messages older or equal to the specified time value or sooner than the specified message number.
protected  void readMsgNumFile()
          Reads the last message number from the message-number file.
protected  IstiTimeObjectCache.VectorWithCount subListVector(long beginTime, long beginMsgNum, long endTime, long endMsgNum, int maxCount)
          Retrieves a sub list of objects.
protected  void writeMsgNumFile()
          Writes the last message number to the message-number file.
 
Methods inherited from class com.isti.util.IstiTimeObjectCache
add, add, checkRemoveViaTotalDataSize, clearCache, containsEntry, containsKey, containsObjectKey, getAllObjects, getCacheInformation, getFirstObject, getFirstObjects, getLastObject, getLogFile, getMaximumObjectCount, getMaximumTotalDataSize, getMessageCount, getNewerObjects, getNewerObjects, getObject, getObjects, getObjects, getOlderObjects, getOlderObjects, getTotalCacheDataSize, getUseLookupKeyFlag, isEmpty, removeOldObjects, removeOldObjects, setDefaultRemoveAge, setMaximumObjectCount, setMaximumTotalDataSize, size, subListVector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastMsgNumTracker

protected long lastMsgNumTracker

msgNumFileName

protected final java.lang.String msgNumFileName

msgNumRAFileObj

protected java.io.RandomAccessFile msgNumRAFileObj

msgNumFDescObj

protected java.io.FileDescriptor msgNumFDescObj

msgNumFileSyncObj

protected final java.lang.Object msgNumFileSyncObj

lastMsgNumSeqBreakTime

protected long lastMsgNumSeqBreakTime

lastMsgNumSeqBreakMsgNumLogged

protected long lastMsgNumSeqBreakMsgNumLogged
Constructor Detail

IstiMessageObjectCache

public IstiMessageObjectCache(LogFile logObj,
                              long tolerance)
Constructs a time object cache.

Parameters:
logObj - log file object to use or null for no logging.
tolerance - number of milliseconds for time tolerance that is used with time checks

IstiMessageObjectCache

public IstiMessageObjectCache(LogFile logObj,
                              long tolerance,
                              long removeAge)
Constructs a message object cache with a default remove age. The cache is setup to use the "keyStr" parameter (when adding) as a table-lookup key (which forces cache entries to have unique "keyStr" values).

Parameters:
logObj - log file object to use or null for no logging.
tolerance - number of milliseconds for time tolerance that is used with time checks
removeAge - number of milliseconds to keep objects in the cache or 0 for no default.

IstiMessageObjectCache

public IstiMessageObjectCache(LogFile logObj,
                              long tolerance,
                              long removeAge,
                              boolean useLookupKeyFlag)
Constructs a message object cache with a default remove age.

Parameters:
logObj - log file object to use or null for no logging.
tolerance - number of milliseconds for time tolerance that is used with time checks
removeAge - number of milliseconds to keep objects in the cache or 0 for no default.
useLookupKeyFlag - true to use the "keyStr" parameter (when adding) as a table-lookup key (which forces cache entries to have unique "keyStr" values).

IstiMessageObjectCache

public IstiMessageObjectCache(LogFile logObj,
                              long tolerance,
                              long removeAge,
                              java.lang.String msgNumFileName)
Constructs a message object cache. The cache is setup to use the "keyStr" parameter (when adding) as a table-lookup key (which forces cache entries to have unique "keyStr" values).

Parameters:
logObj - log file object to use or null for no logging.
tolerance - number of milliseconds for time tolerance that is used with time checks.
removeAge - number of milliseconds to keep messages in the cache.
msgNumFileName - message number file name or null for none.

IstiMessageObjectCache

public IstiMessageObjectCache(LogFile logObj,
                              long tolerance,
                              long removeAge,
                              java.lang.String msgNumFileName,
                              boolean useLookupKeyFlag)
Constructs a message object cache.

Parameters:
logObj - log file object to use or null for no logging.
tolerance - number of milliseconds for time tolerance that is used with time checks.
removeAge - number of milliseconds to keep messages in the cache.
msgNumFileName - message number file name or null for none.
useLookupKeyFlag - true to use the "keyStr" parameter (when adding) as a table-lookup key (which forces cache entries to have unique "keyStr" values).
Method Detail

addMsgObjEntry

public void addMsgObjEntry(IstiMessageObjectCache.MessageObjectEntry msgObj)
Adds the message-object entry.

Parameters:
msgObj - the message-object entry to add.

addMessage

public void addMessage(long timeGenerated,
                       java.lang.Object msgObj,
                       java.lang.String msgStr,
                       long msgNum)
Adds the message.

Parameters:
timeGenerated - the time the message was generated.
msgObj - message object.
msgStr - message string.
msgNum - message number.

getNewerMessages

public IstiTimeObjectCache.VectorWithCount getNewerMessages(long time,
                                                            long msgNum,
                                                            int maxCount)
Returns a list of messages newer or equal to the specified time value or later than the specified message number. If 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).

Parameters:
time - time in milliseconds.
msgNum - message number.
maxCount - the maximum number of messages to be returned, or 0 for no limit.
Returns:
A new 'VectorWithCount' of 'MessageObjectEntry' objects that also holds the requested number of items in its 'count' field.

getNewerMessages

public IstiTimeObjectCache.VectorWithCount getNewerMessages(long time,
                                                            long msgNum)
Returns a list of messages newer or equal to the specified time value or later than the specified message number. If 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).

Parameters:
time - time in milliseconds.
msgNum - message number.
Returns:
A new 'VectorWithCount' of 'MessageObjectEntry' objects that also holds the requested number of items in its 'count' field.

getMessages

public IstiTimeObjectCache.VectorWithCount getMessages(long beginTime,
                                                       long beginMsgNum,
                                                       long endTime,
                                                       long endMsgNum,
                                                       int maxCount)
Retrieves a copy of messages in the specified time range. Any specified begin or end message number is only used if the given begin or end time matches. Unlike the time values, the begin and end message numbers are considered non-inclusive.

Parameters:
beginTime - begin time in milliseconds or 0 for start of cache.
beginMsgNum - begin message number (objects with message numbers after this one are to be returned).
endTime - end time in milliseconds or 0 for end of cache
endMsgNum - end message number (objects with message numbers before this one are to be returned).
maxCount - the maximum number of messages to be returned, or 0 for no limit.
Returns:
A new 'VectorWithCount' of 'MessageObjectEntry' objects that also holds the requested number of items in its 'count' field.

getMessages

public IstiTimeObjectCache.VectorWithCount getMessages(long beginTime,
                                                       long beginMsgNum,
                                                       long endTime,
                                                       long endMsgNum)
Retrieves a copy of messages in the specified time range. Any specified begin or end message number is only used if the given begin or end time matches. Unlike the time values, the begin and end message numbers are considered non-inclusive.

Parameters:
beginTime - begin time in milliseconds or 0 for start of cache.
beginMsgNum - begin message number (objects with message numbers after this one are to be returned).
endTime - end time in milliseconds or 0 for end of cache
endMsgNum - end message number (objects with message numbers before this one are to be returned).
Returns:
A new 'VectorWithCount' of 'MessageObjectEntry' objects that also holds the requested number of items in its 'count' field.

getOlderMessages

public IstiTimeObjectCache.VectorWithCount getOlderMessages(long time,
                                                            long msgNum,
                                                            int maxCount)
Returns a list of messages older or equal to the specified time value or sooner than the specified message number. If a non-zero message number is given and the given time value matches then messages with message numbers less than the given message number are returned; otherwise messages older or equal to the specified time value are returned (within a tolerance value).

Parameters:
time - time in milliseconds.
msgNum - message number.
maxCount - the maximum number of messages to be returned, or 0 for no limit.
Returns:
A new 'VectorWithCount' of 'MessageObjectEntry' objects that also holds the requested number of items in its 'count' field.

getOlderMessages

public IstiTimeObjectCache.VectorWithCount getOlderMessages(long time,
                                                            long msgNum)
Returns a list of messages older or equal to the specified time value or sooner than the specified message number. If a non-zero message number is given and the given time value matches then messages with message numbers less than the given message number are returned; otherwise messages older or equal to the specified time value are returned (within a tolerance value).

Parameters:
time - time in milliseconds.
msgNum - message number.
Returns:
A new 'VectorWithCount' of 'MessageObjectEntry' objects that also holds the requested number of items in its 'count' field.

getFirstMessage

public IstiMessageObjectCache.MessageObjectEntry getFirstMessage()
Returns the first message object in the cache.

Returns:
The first ('TimeObjectEntry') message object in the cache, or null if the cache is empty.

getLastMessage

public IstiMessageObjectCache.MessageObjectEntry getLastMessage()
Returns the last message object in the cache.

Returns:
The last ('TimeObjectEntry') message object in the cache, or null if the cache is empty.

getLastMsgNum

public long getLastMsgNum()
Return the last message number.

Returns:
The last message number, or 0 if none have been entered.

getLogPrefixString

protected java.lang.String getLogPrefixString()
Returns the prefix to use for log output.

Overrides:
getLogPrefixString in class IstiTimeObjectCache
Returns:
the prefix to use for log output.

getMessage

protected IstiMessageObjectCache.MessageObjectEntry getMessage(int index)
Returns the message entry at the given index.

Parameters:
index - index of the entry.
Returns:
The message entry object.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index is negative or not less than the current size of the cache.

getMsgTime

protected long getMsgTime(long msgNum)
Gets the message time for the specified message number.

Parameters:
msgNum - the message number to use.
Returns:
The message time or 0 if not found.

subListVector

protected IstiTimeObjectCache.VectorWithCount subListVector(long beginTime,
                                                            long beginMsgNum,
                                                            long endTime,
                                                            long endMsgNum,
                                                            int maxCount)
Retrieves a sub list of objects. Any specified begin or end message number is only used if the given begin or end time matches. Unlike the time values, the begin and end message numbers are considered non-inclusive. The thread-sychronization lock for 'objectCache' should be held before this method is used.

Parameters:
beginTime - minimum time (in milliseconds, inclusive) for returned objects, or 0 for start of cache.
beginMsgNum - begin message number (objects with message numbers after this one are to be returned).
endTime - maximum time (in milliseconds, inclusive) for returned objects, or 0 for end of cache.
endMsgNum - end message number (objects with message numbers before this one are to be returned).
maxCount - the maximum number of message objects to be returned, or 0 for no limit.
Returns:
A new 'VectorWithCount' of 'MessageObjectEntry' objects that also holds the requested number of items in its 'count' field.

getLastMsgNumSeqBreakTime

public long getLastMsgNumSeqBreakTime()
Returns the time for the last detected break in the message number sequence for messages added to the cache.

Returns:
The time for the last detected break in the message number sequence, or 0 if no breaks were detected.

readMsgNumFile

protected void readMsgNumFile()
Reads the last message number from the message-number file.


writeMsgNumFile

protected void writeMsgNumFile()
Writes the last message number to the message-number file.


close

public void close()
Deallocates resources associated with the cache.

Overrides:
close in class IstiTimeObjectCache