Public Member Functions | Static Public Attributes

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

Inheritance diagram for com.cosylab.logging.client.cache.LogMultiFileCache:
com.cosylab.logging.client.cache.ILogMap com.cosylab.logging.client.cache.LogCache

List of all members.

Public Member Functions

 LogMultiFileCache (long fileSize) throws LogCacheException
 LogMultiFileCache () throws LogCacheException
ILogEntry getLog (Integer logKey) throws LogCacheException
synchronized int add (ILogEntry log) throws LogCacheException
synchronized void deleteLog (Integer logKey) throws LogCacheException
int getSize ()
Integer getLastLog ()
Integer getFirstLog ()
void deleteLogs (Collection< Integer > keys) throws LogCacheException
synchronized void clear () throws LogCacheException
void replaceLog (Integer key, ILogEntry log) throws LogCacheException
Iterator< ILogEntryiterator ()
Set< Integer > keySet ()
int getFirstLogs (int n, Collection< Integer > keys)
long getLogFileSize () throws LogCacheException
synchronized long getFilesSize () throws IOException
long getMaxFileSize () throws LogCacheException
void setDebugTrace (boolean flag) throws LogCacheException
void printFileTableInfo () throws LogCacheException
int getNumberOfCacheFiles ()

Static Public Attributes

static final String FILEMAXSIZE_PROPERTY_NAME = "jlog.cache.fileMaxSize"
static final long DEFAULT_FILEMAXSIZE = 10000000

Detailed Description

This class manages a set of LogBufferedFileCache objects allowing the storing of logs in different files, though from the user point of view the logs are stored or retrieved from single data store.

This is due to the fact that files can grow up to a given size and hence setting a limit on the number of logs that can be collected.

Logs are added to a file until it reaches a given size, then a new file is created. Logs have different length and therefore the number of logs in each File Buffered Cache will be different (see example below).

Logs are accessible by the user through a keyword (logKey) which is implemented as an increased running number. On the other hand, within each File Buffered Cache they have their own numbering system which starts from 0 to the maximum number of logs.

Example :

logKey logCounter Buffered File Range Cache Range -------------------------------------------------------- 0 - 10 11 0 - 10 file1 11 - 25 15 0 - 14 file2 26 - 32 7 0 - 6 file3 33 - 50 18 0 - 18 file4

When logs are deleted they are no longer accessible : when all logs stored in a single file are marked as deleted the corresponding logCounter = 0 and as consequence the file itself is removed.

Using the example let's assume we delete the logs with the following keyword : 26,27,28,31,32, from now on these logs will not be accessible for the user.

logKey logCounter Buffered File Range Cache Range -------------------------------------------------------- 0 - 10 11 0 - 10 file1 11 - 25 15 0 - 14 file2 26 - 32 2 0 - 6 file3 33 - 50 18 0 - 18 file4

If we delete also logs with keywords 29 and 30 the logCounter will be zero and file3 will be deleted.

logKey Mapping When retrieving the log we need to re-map the global log keyword into the keyword used to add the log to the specific Buffered File Cache. This is done by simply subtracting the minimum key value from the logKey.

Example : Retrieve logKey 20. logKey 20 is stored in the second Buffered File Cache and it is accessible with the local key = (20 - 11) = 9

Author:
mcomin

Constructor & Destructor Documentation

com.cosylab.logging.client.cache.LogMultiFileCache.LogMultiFileCache ( long  fileSize  )  throws LogCacheException

Builds a LogMultiFileCache objects setting the maximum size of the cache files

Parameters:
fileSize The maximum size of cache files
com.cosylab.logging.client.cache.LogMultiFileCache.LogMultiFileCache (  )  throws LogCacheException

Constructor

The maximum size of the files is read from the system properties. If the property is not found a default value is used.


Member Function Documentation

synchronized void com.cosylab.logging.client.cache.LogMultiFileCache.clear (  )  throws LogCacheException

Clear the Map i.e. remove all the logs and keys from the map

Exceptions:
LogCacheException 
See also:
com.cosylab.logging.client.cache.ILogMap

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

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

Delete a set of logs

Parameters:
keys The keys of logs to delete
See also:
com.cosylab.logging.client.cache.ILogMap

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

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

synchronized long com.cosylab.logging.client.cache.LogMultiFileCache.getFilesSize (  )  throws IOException

Return the disk space used by all the files of the cache.

Returns:
The disk space used by all the files of the cache
Exceptions:
IOException In case of error getting the size of one of the files

Referenced by alma.acs.logging.table.LogEntryTableModelBase.usedDiskSpace().

Integer com.cosylab.logging.client.cache.LogMultiFileCache.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
See also:
com.cosylab.logging.client.cache.ILogMap
Exceptions:
In case of error getting the first log

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

References com.cosylab.logging.client.cache.MultiFileTableRecord.getFirstLog().

int com.cosylab.logging.client.cache.LogMultiFileCache.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
See also:
com.cosylab.logging.client.cache.ILogMap

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

Integer com.cosylab.logging.client.cache.LogMultiFileCache.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 change if such log has been deleted

Returns:
The key of the last inserted log null if the cache is empty
See also:
com.cosylab.logging.client.cache.ILogMap

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

References com.cosylab.logging.client.cache.MultiFileTableRecord.getLastLog().

ILogEntry com.cosylab.logging.client.cache.LogMultiFileCache.getLog ( Integer  logKey  )  throws LogCacheException

Retrieves a log by means of its keyword.

Parameters:
pos The key of the log to retrieve

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

References com.cosylab.logging.client.cache.MultiFileTableRecord.getLog().

long com.cosylab.logging.client.cache.LogMultiFileCache.getLogFileSize (  )  throws LogCacheException

Return the size of the last log file used by the cache (it is here for testing purposes)

See also:

References com.cosylab.logging.client.cache.MultiFileTableRecord.getFileSize().

long com.cosylab.logging.client.cache.LogMultiFileCache.getMaxFileSize (  )  throws LogCacheException

Return the current maximum size of the log file

See also:
int com.cosylab.logging.client.cache.LogMultiFileCache.getNumberOfCacheFiles (  ) 
Returns:
the number of the files used by the cache

Referenced by alma.acs.logging.table.LogEntryTableModelBase.numberOfUsedFiles().

int com.cosylab.logging.client.cache.LogMultiFileCache.getSize (  ) 
Iterator<ILogEntry> com.cosylab.logging.client.cache.LogMultiFileCache.iterator (  ) 

Return an Iterator to browse the logs in the map. The order the iterator returns the logs is that of the keys.

Returns:
an Iterator over the elements in this map
See also:
com.cosylab.logging.client.cache.ILogMap

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

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

The keys in the map

Returns:
The key in the map
See also:
com.cosylab.logging.client.cache.ILogMap

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

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

Replace the log in the given position with the new one

Parameters:
position The position of the log to replace
log The key (identifier) of the log
See also:
com.cosylab.logging.client.cache.ILogMap

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

References com.cosylab.logging.client.cache.MultiFileTableRecord.replaceLog().

Referenced by alma.acs.logging.table.LogEntryTableModelBase.replaceLog().

void com.cosylab.logging.client.cache.LogMultiFileCache.setDebugTrace ( boolean  flag  )  throws LogCacheException

Return the current maximum size of the log file

See also:

Member Data Documentation

The default max size of each file of the cache

final String com.cosylab.logging.client.cache.LogMultiFileCache.FILEMAXSIZE_PROPERTY_NAME = "jlog.cache.fileMaxSize" [static]

The name of the property defining the max size of each fileof the cache


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