

Classes | |
| class | LogCacheInfo |
Public Member Functions | |
| synchronized int | getSize () |
| long | getFileSize () throws IOException |
| synchronized void | clear () throws LogCacheException |
| synchronized ILogEntry | getLog (Integer key) throws LogCacheException |
| synchronized int | add (ILogEntry log) throws LogCacheException |
| void | replaceLog (Integer key, ILogEntry log) throws LogCacheException |
| synchronized void | deleteLog (Integer key) throws LogCacheException |
| synchronized void | deleteLogs (Collection< Integer > keys) throws LogCacheException |
| Integer | getFirstLog () |
| int | getFirstLogs (int n, Collection< Integer > keys) |
| Integer | getLastLog () |
| Set< Integer > | keySet () |
| Iterator< ILogEntry > | iterator () |
Protected Member Functions | |
| void | initCache () throws IOException |
| String | toCacheString (ILogEntry log) |
Protected Attributes | |
| RandomAccessFile | file = null |
| int | logID = 0 |
| TreeMap< Integer, LogCacheInfo > | index = new TreeMap<Integer,LogCacheInfo>() |
| HashMap< Integer, ILogEntry > | replacedLogs = new HashMap<Integer,ILogEntry>() |
Private Member Functions | |
| String | getFile () throws IOException |
| String | getLogAsString (int idx) |
| ILogEntry | fromCacheString (String str) |
Private Attributes | |
| String | logFileName |
| StringBuilder | sb = new StringBuilder() |
Static Private Attributes | |
| static final String | SEPARATOR = new String (""+((char)0)) |
This class implements the cache in order to be able to manage long log files. It is implemented by a file of logs and a data structure to associate the position in a file (LogCacheInfo) to each log. Such data structure is realized by a TreeMap whith the key given by the (progressive, unique) number of a log.
Actually it is not possible to remove a log from the file. To effectively delete logs from disk we need some kind of garbage collector that removes the logs marked as delete from the file. This garbage collector is needed to avoid the file on disk grows indefinitely.
Another potential problem is given by the integer identifier of the logs that grows indefinitely. A temporary solution could be that of using long instad of integers.
| synchronized int com::cosylab::logging::client::cache::LogFileCache::add | ( | ILogEntry | log | ) | throws LogCacheException [inline] |
Append a log to the end of the cache
| log | The log to append in the cache |
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References file, index, initCache(), logID, and toCacheString().
Referenced by alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetFirstLogLogFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogFileCache(), and alma::acs::jlog::test::DeleteLogTest::testLogFileCacheDelete().
| synchronized void com::cosylab::logging::client::cache::LogFileCache::clear | ( | ) | throws LogCacheException [inline] |
Empty the cache.
| IOException |
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References file, index, logFileName, and logID.
Referenced by alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogFileCache().
| synchronized void com::cosylab::logging::client::cache::LogFileCache::deleteLog | ( | Integer | key | ) | throws LogCacheException [inline] |
Delete a log The log is marked as deleted and moved from the index to the deleteLogIndex. The log still exists in the file but is not accessible.
| pos | The key of the log to remove |
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References index, logID, and replacedLogs.
Referenced by deleteLogs(), alma::acs::jlog::test::DeleteLogTest::testGetFirstLogLogFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogFileCache(), and alma::acs::jlog::test::DeleteLogTest::testLogFileCacheDelete().
| synchronized void com::cosylab::logging::client::cache::LogFileCache::deleteLogs | ( | Collection< Integer > | keys | ) | throws LogCacheException [inline] |
Delete a set of logs
| keys | The keys of logs to delete |
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References deleteLog().
Referenced by alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogFileCache().
| ILogEntry com::cosylab::logging::client::cache::LogFileCache::fromCacheString | ( | String | str | ) | [inline, private] |
| String com::cosylab::logging::client::cache::LogFileCache::getFile | ( | ) | throws IOException [inline, private] |
Create the file for the cache trying in several places before giving up.
@ return The name of the file for the temporary log file
| IOException | If an error happened while creating the new file |
References logFileName.
Referenced by initCache().
| long com::cosylab::logging::client::cache::LogFileCache::getFileSize | ( | ) | throws IOException [inline] |
Return the length of the file on disk
| IOException | in case of I/O error |
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References file.
| Integer com::cosylab::logging::client::cache::LogFileCache::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.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References index.
Referenced by alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetFirstLogLogFileCache(), and alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogFileCache().
| int com::cosylab::logging::client::cache::LogFileCache::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.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References index.
| Integer com::cosylab::logging::client::cache::LogFileCache::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.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References index.
Referenced by alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogFileCache().
| synchronized ILogEntry com::cosylab::logging::client::cache::LogFileCache::getLog | ( | Integer | key | ) | throws LogCacheException [inline] |
Return the log in the given position
| pos | The position of the log |
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References fromCacheString(), getLogAsString(), index, logID, and replacedLogs.
Referenced by alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogFileCache(), and alma::acs::jlog::test::DeleteLogTest::testLogFileCacheDelete().
| String com::cosylab::logging::client::cache::LogFileCache::getLogAsString | ( | int | idx | ) | [inline, private] |
Return the string representation (XML) of the log in position idx The string is read from the temporary file
| idx | The position of the log; valid position are between 0 and size-1 |
References file, index, com::cosylab::logging::client::cache::LogFileCache::LogCacheInfo::len, logID, and com::cosylab::logging::client::cache::LogFileCache::LogCacheInfo::start.
Referenced by getLog().
| synchronized int com::cosylab::logging::client::cache::LogFileCache::getSize | ( | ) | [inline] |
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References index.
Referenced by alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetFirstLogLogFileCache(), alma::acs::jlog::test::DeleteLogTest::testGetLastLogLogFileCache(), and alma::acs::jlog::test::DeleteLogTest::testLogFileCacheDelete().
| void com::cosylab::logging::client::cache::LogFileCache::initCache | ( | ) | throws IOException [inline, protected] |
Init the file where the cache stores the logs If the file already exists it is truncated to 0 length this situation might happen whenever the cache is cleared
| IOException |
References file, getFile(), index, and replacedLogs.
Referenced by add(), and com::cosylab::logging::client::cache::LogBufferedFileCache::flushBuffer().
| Iterator<ILogEntry> com::cosylab::logging::client::cache::LogFileCache::iterator | ( | ) | [inline] |
Return an iterator over the logs in cache
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
| Set<Integer> com::cosylab::logging::client::cache::LogFileCache::keySet | ( | ) | [inline] |
Return a set with all the keys of the logs in cache
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References index.
| void com::cosylab::logging::client::cache::LogFileCache::replaceLog | ( | Integer | key, | |
| ILogEntry | log | |||
| ) | throws LogCacheException [inline] |
Replace the log in the given position with the new one NOTE: the new log is kept in memory
| position | The position of the log to replace | |
| log | The key (identifier) ot the log |
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogBufferedFileCache.
References index, and replacedLogs.
| String com::cosylab::logging::client::cache::LogFileCache::toCacheString | ( | ILogEntry | log | ) | [inline, protected] |
References com::cosylab::logging::engine::log::ILogEntry::getAdditionalData(), com::cosylab::logging::engine::log::ILogEntry::getField(), com::cosylab::logging::engine::log::ILogEntry::hasDatas(), sb, and SEPARATOR.
Referenced by add(), com::cosylab::logging::client::cache::LogBufferedFileCache::add(), and com::cosylab::logging::client::cache::LogBufferedFileCache::replaceLog().
RandomAccessFile com::cosylab::logging::client::cache::LogFileCache::file = null [protected] |
The file of logs is accessed in a random way (the positions are stored in the index)
Referenced by add(), clear(), com::cosylab::logging::client::cache::LogBufferedFileCache::flushBuffer(), getFileSize(), getLogAsString(), and initCache().
TreeMap<Integer,LogCacheInfo> com::cosylab::logging::client::cache::LogFileCache::index = new TreeMap<Integer,LogCacheInfo>() [protected] |
The index of the log is a SortedMap having the number identifying a log as key. Each entry is a LogCacheInfo containing the starting and ending position of the log in the file
Referenced by add(), clear(), deleteLog(), com::cosylab::logging::client::cache::LogBufferedFileCache::flushBuffer(), getFirstLog(), getFirstLogs(), getLastLog(), getLog(), getLogAsString(), getSize(), initCache(), keySet(), and replaceLog().
String com::cosylab::logging::client::cache::LogFileCache::logFileName [private] |
int com::cosylab::logging::client::cache::LogFileCache::logID = 0 [protected] |
Each log is identified by a unique integer used as key to get the log from the file (throw the index data structure) logID is incremented whenever a new log is added
NOTE: in this implementation this value is incremented without taking care of the logs deleted.
Referenced by add(), com::cosylab::logging::client::cache::LogBufferedFileCache::add(), clear(), deleteLog(), getLog(), and getLogAsString().
HashMap<Integer,ILogEntry> com::cosylab::logging::client::cache::LogFileCache::replacedLogs = new HashMap<Integer,ILogEntry>() [protected] |
The logs replaced (for example the logs with some info added) They are usually a few so we keep them in memory
Referenced by deleteLog(), getLog(), initCache(), and replaceLog().
StringBuilder com::cosylab::logging::client::cache::LogFileCache::sb = new StringBuilder() [private] |
The buffer to build the logs to write in cache
Referenced by toCacheString().
final String com::cosylab::logging::client::cache::LogFileCache::SEPARATOR = new String (""+((char)0)) [static, private] |
The separator between the field of the logs written in cache
Referenced by fromCacheString(), and toCacheString().
1.6.2