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::LogBufferedFileCache Class Reference

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

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

Collaboration graph
[legend]
List of all members.

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 ()
Override synchronized void replaceLog (Integer key, ILogEntry log) throws LogCacheException

Static Public Attributes

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

Static Private Member Functions

int getDefaultWriteCacheSize ()

Private Attributes

TreeMap< Integer, BufferedCacheItembuffer = new TreeMap<IntegerBufferedCacheItem>()
int size
volatile long bufferFileSize = 0

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 [inline]
 

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 [inline]
 

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 [inline]
 

Append a log to the cache

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

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

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

Empty the cache

Exceptions:
IOException 

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

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

Delete a log with the given key

Parameters:
pos The key of the log to delete

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

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

Delete a collection of logs

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

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

void com::cosylab::logging::client::cache::LogBufferedFileCache::flushBuffer  )  throws LogCacheException [inline]
 

Flush all the logs on file

synchronized final int com::cosylab::logging::client::cache::LogBufferedFileCache::getBufferSize  )  [inline]
 

Returns:
The number of logs actually in the buffer

int com::cosylab::logging::client::cache::LogBufferedFileCache::getDefaultWriteCacheSize  )  [inline, static, private]
 

Gets the default size ot the write buffer, which comes either from the system property jlog.cache.writebuffersize (see WRITEBUFFERSIZE_PROPERTY_NAME) or, if this property is undefined or invalid, from the fixed size given by DEFAULT_WRITEBUFFERSIZE.

Returns:
the default size of the write buffer to be used if none is given in the constructor

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

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

Reimplemented from com::cosylab::logging::client::cache::LogFileCache.

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

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

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

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

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.

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

Return the number of logs in cache

Returns:
The number of logs in cache

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

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

Return an iterator over the logs in cache

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

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

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

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.


Member Data Documentation

TreeMap<Integer,BufferedCacheItem> com::cosylab::logging::client::cache::LogBufferedFileCache::buffer = new TreeMap<IntegerBufferedCacheItem>() [private]
 

volatile long com::cosylab::logging::client::cache::LogBufferedFileCache::bufferFileSize = 0 [private]
 

final int com::cosylab::logging::client::cache::LogBufferedFileCache::DEFAULT_WRITEBUFFERSIZE = 8192 [static]
 

int com::cosylab::logging::client::cache::LogBufferedFileCache::size [private]
 

final String com::cosylab::logging::client::cache::LogBufferedFileCache::WRITEBUFFERSIZE_PROPERTY_NAME = "jlog.cache.writebuffersize" [static]
 


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