Classes | Public Member Functions | Static Public Attributes

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

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

List of all members.

Classes

class  BufferedCacheItem

Public Member Functions

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

Static Public Attributes

static final String WRITEBUFFERSIZE_PROPERTY_NAME = "jlog.cache.writebuffersize"
static final int DEFAULT_WRITEBUFFERSIZE = 8192

Detailed Description

This class extends the LogFileCache adding the buffering of the logs that must be written on disk.

It uses a WriteBuffer to store the logs to write on disk. The purpose of this class is to write several logs at once reducing the write operations on disk.

The buffer stores the logs when they are added. It flushes the buffer on disk when the number of logs in memory exceeds the maximum size. This means that the number of chars written on the file cache at once is not fixed but depends on the lengths of the logs stored in this buffer. To enhance performance and to have the size of the file always available, the buffer stores the log together with other info in Map of BufferedCacheItem

Author:
acaproni

Constructor & Destructor Documentation

com.cosylab.logging.client.cache.LogBufferedFileCache.LogBufferedFileCache ( int  writeBufferSize  )  throws LogCacheException

Build a LogBufferedFileCache with the given size for the cache and the write buffer. If there isn't enough memory for the cache, tries with a smmaller size.

Parameters:
cacheSize The size of the cache
writeBufferSize The size of the write buffer
Exceptions:
LogCacheException If there is'nt enough memory for a buffer of at least 32 logs
com.cosylab.logging.client.cache.LogBufferedFileCache.LogBufferedFileCache (  )  throws LogCacheException

Build a LogBufferedFileCache with the default sizes for the write buffer

Exceptions:
LogCacheException 
See also:
LogBufferedFileCache.getDefaultWriteCacheSize

Member Function Documentation

synchronized int com.cosylab.logging.client.cache.LogBufferedFileCache.add ( ILogEntry  log  )  throws LogCacheException
synchronized void com.cosylab.logging.client.cache.LogBufferedFileCache.clear (  )  throws LogCacheException

Empty the cache

Exceptions:
IOException 

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

Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.clear().

synchronized void com.cosylab.logging.client.cache.LogBufferedFileCache.deleteLog ( Integer  key  )  throws LogCacheException

Delete a log with the given key

Parameters:
pos The key of the log to delete

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

Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.deleteLog().

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

Delete a collection of logs

Parameters:
keys The keys of the logs to remove from the cache

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

synchronized final int com.cosylab.logging.client.cache.LogBufferedFileCache.getBufferSize (  ) 
Returns:
The number of logs actually in the buffer
long com.cosylab.logging.client.cache.LogBufferedFileCache.getFileSize (  )  throws IOException

Return the length of the file on disk taking into account the length of the string to write on the disk for the logs in the buffer.

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

Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.getFileSize().

Integer com.cosylab.logging.client.cache.LogBufferedFileCache.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.

Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.getFirstLog().

int com.cosylab.logging.client.cache.LogBufferedFileCache.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.

Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.getFirstLogs().

Integer com.cosylab.logging.client.cache.LogBufferedFileCache.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.

Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.getLastLog().

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

Return the log with the given key

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

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

Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.getLog().

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

Return an iterator over the logs in cache

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

Set<Integer> com.cosylab.logging.client.cache.LogBufferedFileCache.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.

Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.keySet().

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

Replace the log in the given position with the new one

If the log to replace is not in the buffer, LogBufferedFileCache delegated to LogFileCache

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

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

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

Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.replaceLog().


Member Data Documentation


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