Classes | Public Member Functions | Protected Member Functions | Protected Attributes

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

Inheritance diagram for com.cosylab.logging.client.cache.LogFileCache:
com.cosylab.logging.client.cache.ILogMap com.cosylab.logging.client.cache.LogBufferedFileCache

List of all members.

Classes

class  LogCacheInfo

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<Integer,LogCacheInfo>()
HashMap< Integer, ILogEntryreplacedLogs = new HashMap<Integer,ILogEntry>()

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
synchronized void com.cosylab.logging.client.cache.LogFileCache.clear (  )  throws LogCacheException
synchronized void com.cosylab.logging.client.cache.LogFileCache.deleteLog ( Integer  key  )  throws LogCacheException

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.

References com.cosylab.logging.client.cache.LogFileCache.index, com.cosylab.logging.client.cache.LogFileCache.logID, and com.cosylab.logging.client.cache.LogFileCache.replacedLogs.

Referenced by com.cosylab.logging.client.cache.LogFileCache.deleteLogs().

synchronized void com.cosylab.logging.client.cache.LogFileCache.deleteLogs ( Collection< Integer >  keys  )  throws LogCacheException

Delete a set of logs

Parameters:
keys The keys of logs to delete

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

References com.cosylab.logging.client.cache.LogFileCache.deleteLog().

long com.cosylab.logging.client.cache.LogFileCache.getFileSize (  )  throws IOException

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

References com.cosylab.logging.client.cache.LogFileCache.file.

Integer com.cosylab.logging.client.cache.LogFileCache.getFirstLog (  ) 

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.

References com.cosylab.logging.client.cache.LogFileCache.index.

int com.cosylab.logging.client.cache.LogFileCache.getFirstLogs ( int  n,
Collection< Integer >  keys 
)

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.

References com.cosylab.logging.client.cache.LogFileCache.index.

Integer com.cosylab.logging.client.cache.LogFileCache.getLastLog (  ) 

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.

References com.cosylab.logging.client.cache.LogFileCache.index.

synchronized ILogEntry com.cosylab.logging.client.cache.LogFileCache.getLog ( Integer  key  )  throws LogCacheException

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.

References com.cosylab.logging.client.cache.LogFileCache.index, com.cosylab.logging.client.cache.LogFileCache.logID, and com.cosylab.logging.client.cache.LogFileCache.replacedLogs.

synchronized int com.cosylab.logging.client.cache.LogFileCache.getSize (  ) 
Returns:
The number of logs in cache

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

References com.cosylab.logging.client.cache.LogFileCache.index.

void com.cosylab.logging.client.cache.LogFileCache.initCache (  )  throws IOException [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 

References com.cosylab.logging.client.cache.LogFileCache.file, com.cosylab.logging.client.cache.LogFileCache.index, and com.cosylab.logging.client.cache.LogFileCache.replacedLogs.

Referenced by com.cosylab.logging.client.cache.LogFileCache.add(), and com.cosylab.logging.client.cache.LogBufferedFileCache.flushBuffer().

Iterator<ILogEntry> com.cosylab.logging.client.cache.LogFileCache.iterator (  ) 

Return an iterator over the logs in cache

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

Set<Integer> com.cosylab.logging.client.cache.LogFileCache.keySet (  ) 

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.

References com.cosylab.logging.client.cache.LogFileCache.index.

void com.cosylab.logging.client.cache.LogFileCache.replaceLog ( Integer  key,
ILogEntry  log 
) throws LogCacheException

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.

References com.cosylab.logging.client.cache.LogFileCache.index, and com.cosylab.logging.client.cache.LogFileCache.replacedLogs.


Member Data Documentation

Each log is identified by a unique integer used as key to get the log from the file (throw the index data structure) logID is incremented whenever a new log is added

NOTE: in this implementation this value is incremented without taking care of the logs deleted.

Referenced by com.cosylab.logging.client.cache.LogFileCache.add(), com.cosylab.logging.client.cache.LogBufferedFileCache.add(), com.cosylab.logging.client.cache.LogFileCache.clear(), com.cosylab.logging.client.cache.LogFileCache.deleteLog(), and com.cosylab.logging.client.cache.LogFileCache.getLog().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties