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< ILogEntry > | iterator () |
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 |
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
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.
cacheSize | The size of the cache | |
writeBufferSize | The size of the write buffer |
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
LogCacheException |
synchronized int com.cosylab.logging.client.cache.LogBufferedFileCache.add | ( | ILogEntry | log | ) | throws LogCacheException |
Append a log to the cache
log | The log to append in the cache |
Implements com.cosylab.logging.client.cache.ILogMap.
References com.cosylab.logging.client.cache.LogBufferedFileCache.flushBuffer(), com.cosylab.logging.client.cache.LogFileCache.logID, and com.cosylab.logging.client.cache.LogFileCache.toCacheString().
Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.addLog().
synchronized void com.cosylab.logging.client.cache.LogBufferedFileCache.clear | ( | ) | throws LogCacheException |
Empty the cache
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
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
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 |
Flush all the logs on file
References com.cosylab.logging.client.cache.LogFileCache.file, com.cosylab.logging.client.cache.LogFileCache.index, and com.cosylab.logging.client.cache.LogFileCache.initCache().
Referenced by com.cosylab.logging.client.cache.LogBufferedFileCache.add(), and com.cosylab.logging.client.cache.MultiFileTableRecord.flushBuffer().
synchronized final int com.cosylab.logging.client.cache.LogBufferedFileCache.getBufferSize | ( | ) |
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.
IOException | in case of I/O error |
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.
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.
n | The desired number of keys of first logs | |
keys | The collection to add they keys to |
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
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
key | The key of the log |
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 | ( | ) |
Return the number of logs in cache
Implements com.cosylab.logging.client.cache.ILogMap.
Referenced by com.cosylab.logging.client.cache.MultiFileTableRecord.getNumOfLogs(), and com.cosylab.logging.client.cache.MultiFileTableRecord.isEmpty().
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
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
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().
final int com.cosylab.logging.client.cache.LogBufferedFileCache.DEFAULT_WRITEBUFFERSIZE = 8192 [static] |
final String com.cosylab.logging.client.cache.LogBufferedFileCache.WRITEBUFFERSIZE_PROPERTY_NAME = "jlog.cache.writebuffersize" [static] |