

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 |
Static Private Member Functions | |
| static int | getDefaultWriteCacheSize () |
Private Attributes | |
| TreeMap< Integer, BufferedCacheItem > | buffer = new TreeMap<Integer,BufferedCacheItem>() |
| int | size |
| volatile long | bufferFileSize = 0 |
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 [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.
| 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 |
References size.
| com::cosylab::logging::client::cache::LogBufferedFileCache::LogBufferedFileCache | ( | ) | throws LogCacheException [inline] |
Build a LogBufferedFileCache with the default sizes for the write buffer
| LogCacheException |
References getDefaultWriteCacheSize().
| synchronized int com::cosylab::logging::client::cache::LogBufferedFileCache::add | ( | ILogEntry | log | ) | throws LogCacheException [inline] |
Append a log to the cache
| log | The log to append in the cache |
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer, bufferFileSize, flushBuffer(), com::cosylab::logging::client::cache::LogBufferedFileCache::BufferedCacheItem::getLogCacheString(), com::cosylab::logging::client::cache::LogFileCache::logID, size, and com::cosylab::logging::client::cache::LogFileCache::toCacheString().
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::addLog(), alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogBufferedFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetFirstLogLogBufferedFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogBufferedFileCache(), and alma::acs::jlog::test::DeleteLogTest::testLogBufferedFileCacheDelete().
| synchronized void com::cosylab::logging::client::cache::LogBufferedFileCache::clear | ( | ) | throws LogCacheException [inline] |
Empty the cache
| IOException |
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer, and bufferFileSize.
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::clear(), and alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogBufferedFileCache().
| synchronized void com::cosylab::logging::client::cache::LogBufferedFileCache::deleteLog | ( | Integer | key | ) | throws LogCacheException [inline] |
Delete a log with the given key
| pos | The key of the log to delete |
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer, bufferFileSize, and com::cosylab::logging::client::cache::LogBufferedFileCache::BufferedCacheItem::getLogCacheString().
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::deleteLog(), alma::acs::jlog::test::DeleteLogTest::testGetFirstLogLogBufferedFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogBufferedFileCache(), and alma::acs::jlog::test::DeleteLogTest::testLogBufferedFileCacheDelete().
| synchronized void com::cosylab::logging::client::cache::LogBufferedFileCache::deleteLogs | ( | Collection< Integer > | keys | ) | throws LogCacheException [inline] |
Delete a collection of logs
| keys | The keys of the logs to remove from the cache |
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer, bufferFileSize, and com::cosylab::logging::client::cache::LogBufferedFileCache::BufferedCacheItem::getLogCacheString().
Referenced by alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogBufferedFileCache().
| void com::cosylab::logging::client::cache::LogBufferedFileCache::flushBuffer | ( | ) | throws LogCacheException [inline] |
Flush all the logs on file
References buffer, bufferFileSize, com::cosylab::logging::client::cache::LogFileCache::file, com::cosylab::logging::client::cache::LogBufferedFileCache::BufferedCacheItem::getLogCacheString(), com::cosylab::logging::client::cache::LogFileCache::index, and com::cosylab::logging::client::cache::LogFileCache::initCache().
Referenced by add(), and com::cosylab::logging::client::cache::MultiFileTableRecord::flushBuffer().
| synchronized final int com::cosylab::logging::client::cache::LogBufferedFileCache::getBufferSize | ( | ) | [inline] |
References buffer.
Referenced by alma::acs::jlog::test::DeleteLogTest::testGetFirstLogLogBufferedFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogBufferedFileCache(), and alma::acs::jlog::test::DeleteLogTest::testLogBufferedFileCacheDelete().
| static 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.
References DEFAULT_WRITEBUFFERSIZE, and WRITEBUFFERSIZE_PROPERTY_NAME.
Referenced by LogBufferedFileCache().
| 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.
| IOException | in case of I/O error |
Reimplemented from com::cosylab::logging::client::cache::LogFileCache.
References bufferFileSize.
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::getFileSize().
| 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.
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer.
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::getFirstLog(), alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogBufferedFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetFirstLogLogBufferedFileCache(), and alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogBufferedFileCache().
| 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.
| n | The desired number of keys of first logs | |
| keys | The collection to add they keys to |
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer.
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::getFirstLogs().
| 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
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer.
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::getLastLog(), and alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogBufferedFileCache().
| synchronized ILogEntry com::cosylab::logging::client::cache::LogBufferedFileCache::getLog | ( | Integer | key | ) | throws LogCacheException [inline] |
Return the log with the given key
| key | The key of the log |
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer, and com::cosylab::logging::client::cache::LogBufferedFileCache::BufferedCacheItem::getLogEntry().
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::getLog(), alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogBufferedFileCache(), and alma::acs::jlog::test::DeleteLogTest::testLogBufferedFileCacheDelete().
| synchronized int com::cosylab::logging::client::cache::LogBufferedFileCache::getSize | ( | ) | [inline] |
Return the number of logs in cache
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer.
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::getNumOfLogs(), com::cosylab::logging::client::cache::MultiFileTableRecord::isEmpty(), alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogBufferedFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetFirstLogLogBufferedFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogBufferedFileCache(), and alma::acs::jlog::test::DeleteLogTest::testLogBufferedFileCacheDelete().
| 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
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer.
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::keySet().
| 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
| position | The position of the log to replace | |
| log | The key (identifier) of the log |
Implements com::cosylab::logging::client::cache::ILogMap.
References buffer, bufferFileSize, com::cosylab::logging::client::cache::LogBufferedFileCache::BufferedCacheItem::getLogCacheString(), and com::cosylab::logging::client::cache::LogFileCache::toCacheString().
Referenced by com::cosylab::logging::client::cache::MultiFileTableRecord::replaceLog().
TreeMap<Integer,BufferedCacheItem> com::cosylab::logging::client::cache::LogBufferedFileCache::buffer = new TreeMap<Integer,BufferedCacheItem>() [private] |
Referenced by add(), clear(), deleteLog(), deleteLogs(), flushBuffer(), getBufferSize(), getFirstLog(), getFirstLogs(), getLastLog(), getLog(), getSize(), keySet(), and replaceLog().
volatile long com::cosylab::logging::client::cache::LogBufferedFileCache::bufferFileSize = 0 [private] |
Referenced by add(), clear(), deleteLog(), deleteLogs(), flushBuffer(), getFileSize(), and replaceLog().
final int com::cosylab::logging::client::cache::LogBufferedFileCache::DEFAULT_WRITEBUFFERSIZE = 8192 [static] |
Referenced by getDefaultWriteCacheSize().
Referenced by add(), and LogBufferedFileCache().
final String com::cosylab::logging::client::cache::LogBufferedFileCache::WRITEBUFFERSIZE_PROPERTY_NAME = "jlog.cache.writebuffersize" [static] |
Referenced by getDefaultWriteCacheSize().
1.6.2