Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

com::cosylab::logging::client::cache::LogFileCache Class Reference

Inheritance diagram for com::cosylab::logging::client::cache::LogFileCache:

Inheritance graph
[legend]
Collaboration diagram for com::cosylab::logging::client::cache::LogFileCache:

Collaboration graph
[legend]
List of all members.

Public Member Functions

synchronized int getSize ()
long getFileSize () throws IOException
synchronized void clear () throws LogCacheException
synchronized ILogEntry getLog (Integer key) throws LogCacheException
synchronized int add (ILogEntry log) throws LogCacheException
void replaceLog (Integer key, ILogEntry log) throws LogCacheException
synchronized void deleteLog (Integer key) throws LogCacheException
synchronized void deleteLogs (Collection< Integer > keys) throws LogCacheException
Integer getFirstLog ()
int getFirstLogs (int n, Collection< Integer > keys)
Integer getLastLog ()
Set< Integer > keySet ()
Iterator< ILogEntryiterator ()

Protected Member Functions

void initCache () throws IOException
String toCacheString (ILogEntry log)

Protected Attributes

RandomAccessFile file = null
int logID = 0
TreeMap< Integer, LogCacheInfoindex = new TreeMap<IntegerLogCacheInfo>()
HashMap< Integer, ILogEntryreplacedLogs = new HashMap<IntegerILogEntry>()

Private Member Functions

String getFile ()
String getLogAsString (int idx)
ILogEntry fromCacheString (String str)

Private Attributes

String logFileName
StringBuilder sb = new StringBuilder()
final String SEPARATOR = new String (""+((char)0))

Detailed Description

This class implements the cache in order to be able to manage long log files. It is implemented by a file of logs and a data structure to associate the position in a file (LogCacheInfo) to each log. Such data structure is realized by a TreeMap whith the key given by the (progressive, unique) number of a log.

Actually it is not possible to remove a log from the file. To effectively delete logs from disk we need some kind of garbage collector that removes the logs marked as delete from the file. This garbage collector is needed to avoid the file on disk grows indefinitely.

Another potential problem is given by the integer identifier of the logs that grows indefinitely. A temporary solution could be that of using long instad of integers.

Author:
acaproni


Member Function Documentation

synchronized int com::cosylab::logging::client::cache::LogFileCache::add ILogEntry  log  )  throws LogCacheException [inline]
 

Append a log to the end of the cache

Parameters:
log The log to append in the cache
Returns:
The key in the cache of the added log

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

synchronized void com::cosylab::logging::client::cache::LogFileCache::clear  )  throws LogCacheException [inline]
 

Empty the cache.

Exceptions:
IOException 

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

synchronized void com::cosylab::logging::client::cache::LogFileCache::deleteLog Integer  key  )  throws LogCacheException [inline]
 

Delete a log The log is marked as deleted and moved from the index to the deleteLogIndex. The log still exists in the file but is not accessible.

Parameters:
pos The key of the log to remove

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

synchronized void com::cosylab::logging::client::cache::LogFileCache::deleteLogs Collection< Integer >  keys  )  throws LogCacheException [inline]
 

Delete a set of logs

Parameters:
keys The keys of logs to delete

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

ILogEntry com::cosylab::logging::client::cache::LogFileCache::fromCacheString String  str  )  [inline, private]
 

String com::cosylab::logging::client::cache::LogFileCache::getFile  )  [inline, private]
 

Create the file for the cache trying in several places before giving up.

@ return The name of the file for the temporary log file

long com::cosylab::logging::client::cache::LogFileCache::getFileSize  )  throws IOException [inline]
 

Return the length of the file on disk

Returns:
The size of the file cache
Exceptions:
IOException in case of I/O error
See also:
java.io.RandomAccessFile

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

Integer com::cosylab::logging::client::cache::LogFileCache::getFirstLog  )  [inline]
 

Return the key of the first valid log (FIFO). The key of the first log is 0 but it can change if the log 0 has been deleted.

Returns:
The key of the first log null if the cache is empty

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

int com::cosylab::logging::client::cache::LogFileCache::getFirstLogs int  n,
Collection< Integer >  keys
[inline]
 

Append at most n keys from the first valid logs to the collection. First here means first in the FIFO policy.

The number of added keys can be less then n if the cache doesn't contain enough logs.

Parameters:
n The desired number of keys of first logs
keys The collection to add they keys to
Returns:
The number of keys effectively added

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

Integer com::cosylab::logging::client::cache::LogFileCache::getLastLog  )  [inline]
 

Return the key of the last valid log (FIFO) The key of the last log is the key of the last inserted log but it can cheang if such log has been deleted

Returns:
The key of the last inserted log null if th cache is empty

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

synchronized ILogEntry com::cosylab::logging::client::cache::LogFileCache::getLog Integer  key  )  throws LogCacheException [inline]
 

Return the log in the given position

Parameters:
pos The position of the log
Returns:
The LogEntryXML or null in case of error

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

String com::cosylab::logging::client::cache::LogFileCache::getLogAsString int  idx  )  [inline, private]
 

Return the string representation (XML) of the log in position idx The string is read from the temporary file

Parameters:
idx The position of the log; valid position are between 0 and size-1
Returns:
A String representing the log in the given position

synchronized int com::cosylab::logging::client::cache::LogFileCache::getSize  )  [inline]
 

Returns:
The number of logs in cache

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

void com::cosylab::logging::client::cache::LogFileCache::initCache  )  throws IOException [inline, protected]
 

Init the file where the cache stores the logs If the file already exists it is truncated to 0 length this situation might happen whenever the cache is cleared

Exceptions:
IOException 

Iterator<ILogEntry> com::cosylab::logging::client::cache::LogFileCache::iterator  )  [inline]
 

Return an iterator over the logs in cache

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

Set<Integer> com::cosylab::logging::client::cache::LogFileCache::keySet  )  [inline]
 

Return a set with all the keys of the logs in cache

Returns:
The keys of the logs in cache

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

void com::cosylab::logging::client::cache::LogFileCache::replaceLog Integer  key,
ILogEntry  log
throws LogCacheException [inline]
 

Replace the log in the given position with the new one NOTE: the new log is kept in memory

Parameters:
position The position of the log to replace
log The key (identifier) ot the log

Implements com::cosylab::logging::client::cache::ILogMap.

Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.

String com::cosylab::logging::client::cache::LogFileCache::toCacheString ILogEntry  log  )  [inline, protected]
 


Member Data Documentation

RandomAccessFile com::cosylab::logging::client::cache::LogFileCache::file = null [protected]
 

TreeMap<Integer,LogCacheInfo> com::cosylab::logging::client::cache::LogFileCache::index = new TreeMap<IntegerLogCacheInfo>() [protected]
 

String com::cosylab::logging::client::cache::LogFileCache::logFileName [private]
 

int com::cosylab::logging::client::cache::LogFileCache::logID = 0 [protected]
 

HashMap<Integer,ILogEntry> com::cosylab::logging::client::cache::LogFileCache::replacedLogs = new HashMap<IntegerILogEntry>() [protected]
 

StringBuilder com::cosylab::logging::client::cache::LogFileCache::sb = new StringBuilder() [private]
 

final String com::cosylab::logging::client::cache::LogFileCache::SEPARATOR = new String (""+((char)0)) [private]
 


The documentation for this class was generated from the following file:
Generated on Thu Apr 30 03:13:04 2009 for ACS Java API by doxygen 1.3.8