

Public Member Functions | |
| LogMultiFileCache (long fileSize) throws LogCacheException | |
| LogMultiFileCache () throws LogCacheException | |
| ILogEntry | getLog (Integer logKey) throws LogCacheException |
| synchronized int | add (ILogEntry log) throws LogCacheException |
| synchronized void | deleteLog (Integer logKey) throws LogCacheException |
| int | getSize () |
| Integer | getLastLog () |
| Integer | getFirstLog () |
| void | deleteLogs (Collection< Integer > keys) throws LogCacheException |
| synchronized void | clear () throws LogCacheException |
| void | replaceLog (Integer key, ILogEntry log) throws LogCacheException |
| Iterator< ILogEntry > | iterator () |
| Set< Integer > | keySet () |
| int | getFirstLogs (int n, Collection< Integer > keys) |
| long | getLogFileSize () throws LogCacheException |
| synchronized long | getFilesSize () throws IOException |
| long | getMaxFileSize () throws LogCacheException |
| void | setDebugTrace (boolean flag) throws LogCacheException |
| void | printFileTableInfo () throws LogCacheException |
| int | getNumberOfCacheFiles () |
Static Public Attributes | |
| static final String | FILEMAXSIZE_PROPERTY_NAME = "jlog.cache.fileMaxSize" |
| static final long | DEFAULT_FILEMAXSIZE = 10000000 |
Private Member Functions | |
| void | printDebugTrace (String traceInfo) |
| MultiFileTableRecord | createNewFileRecord () throws LogCacheException |
| MultiFileTableRecord | searchFileLogTable (Integer logKey) throws LogCacheException |
Static Private Member Functions | |
| static long | getDefaultMaxFileSize () |
Private Attributes | |
| boolean | debugTrace = false |
| long | fileMaxSize |
| Vector< MultiFileTableRecord > | logFileTable = new Vector<MultiFileTableRecord>() |
| volatile int | logsInCache = 0 |
| int | ID = -1 |
This class manages a set of LogBufferedFileCache objects allowing the storing of logs in different files, though from the user point of view the logs are stored or retrieved from single data store.
This is due to the fact that files can grow up to a given size and hence setting a limit on the number of logs that can be collected.
Logs are added to a file until it reaches a given size, then a new file is created. Logs have different length and therefore the number of logs in each File Buffered Cache will be different (see example below).
Logs are accessible by the user through a keyword (logKey) which is implemented as an increased running number. On the other hand, within each File Buffered Cache they have their own numbering system which starts from 0 to the maximum number of logs.
Example :
logKey logCounter Buffered File Range Cache Range -------------------------------------------------------- 0 - 10 11 0 - 10 file1 11 - 25 15 0 - 14 file2 26 - 32 7 0 - 6 file3 33 - 50 18 0 - 18 file4
When logs are deleted they are no longer accessible : when all logs stored in a single file are marked as deleted the corresponding logCounter = 0 and as consequence the file itself is removed.
Using the example let's assume we delete the logs with the following keyword : 26,27,28,31,32, from now on these logs will not be accessible for the user.
logKey logCounter Buffered File Range Cache Range -------------------------------------------------------- 0 - 10 11 0 - 10 file1 11 - 25 15 0 - 14 file2 26 - 32 2 0 - 6 file3 33 - 50 18 0 - 18 file4
If we delete also logs with keywords 29 and 30 the logCounter will be zero and file3 will be deleted.
logKey Mapping When retrieving the log we need to re-map the global log keyword into the keyword used to add the log to the specific Buffered File Cache. This is done by simply subtracting the minimum key value from the logKey.
Example : Retrieve logKey 20. logKey 20 is stored in the second Buffered File Cache and it is accessible with the local key = (20 - 11) = 9
| com::cosylab::logging::client::cache::LogMultiFileCache::LogMultiFileCache | ( | long | fileSize | ) | throws LogCacheException [inline] |
Builds a LogMultiFileCache objects setting the maximum size of the cache files
| fileSize | The maximum size of cache files |
References fileMaxSize, and printDebugTrace().
| com::cosylab::logging::client::cache::LogMultiFileCache::LogMultiFileCache | ( | ) | throws LogCacheException [inline] |
Constructor
The maximum size of the files is read from the system properties. If the property is not found a default value is used.
References getDefaultMaxFileSize().
| synchronized int com::cosylab::logging::client::cache::LogMultiFileCache::add | ( | ILogEntry | log | ) | throws LogCacheException [inline] |
Add a log to the cache
| log | The log to add to the cache |
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogCache.
References com::cosylab::logging::client::cache::MultiFileTableRecord::addLog(), createNewFileRecord(), fileMaxSize, com::cosylab::logging::client::cache::MultiFileTableRecord::flushBuffer(), com::cosylab::logging::client::cache::MultiFileTableRecord::getFileSize(), com::cosylab::logging::client::cache::MultiFileTableRecord::getMaxLogIdx(), com::cosylab::logging::client::cache::MultiFileTableRecord::getMinLogIdx(), com::cosylab::logging::client::cache::MultiFileTableRecord::getNumOfLogs(), ID, logFileTable, logsInCache, and printDebugTrace().
Referenced by alma::acs::jlog::test::MultiFileCacheTest::testClear(), alma::acs::jlog::test::MultiFileCacheTest::testFileCreation(), alma::acs::jlog::test::MultiFileCacheTest::testFileDeletion(), alma::acs::jlog::test::MultiFileCacheTest::testGet(), alma::acs::jlog::test::MultiFileCacheTest::testGetFirstLog(), alma::acs::jlog::test::MultiFileCacheTest::testGetLastLog(), alma::acs::jlog::test::MultiFileCacheTest::testGetSize(), alma::acs::jlog::test::MultiFileCacheTest::testkKeySet(), and alma::acs::jlog::test::MultiFileCacheTest::testReplace().
| synchronized void com::cosylab::logging::client::cache::LogMultiFileCache::clear | ( | ) | throws LogCacheException [inline] |
Clear the Map i.e. remove all the logs and keys from the map
| LogCacheException |
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogCache.
References logFileTable, and logsInCache.
Referenced by alma::acs::jlog::test::MultiFileCacheTest::tearDown(), and alma::acs::jlog::test::MultiFileCacheTest::testClear().
| MultiFileTableRecord com::cosylab::logging::client::cache::LogMultiFileCache::createNewFileRecord | ( | ) | throws LogCacheException [inline, private] |
Creates a new record for the log file table : min/max log indexes are initialized according to the total number of received logs.
The create LogFileTableRecord is added to the table of file records.
References logFileTable.
Referenced by add().
| synchronized void com::cosylab::logging::client::cache::LogMultiFileCache::deleteLog | ( | Integer | logKey | ) | 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.
Reimplemented in com::cosylab::logging::client::cache::LogCache.
References com::cosylab::logging::client::cache::MultiFileTableRecord::clear(), com::cosylab::logging::client::cache::MultiFileTableRecord::deleteLog(), com::cosylab::logging::client::cache::MultiFileTableRecord::getMaxLogIdx(), com::cosylab::logging::client::cache::MultiFileTableRecord::getMinLogIdx(), com::cosylab::logging::client::cache::MultiFileTableRecord::getNumOfLogs(), logFileTable, logsInCache, printDebugTrace(), and searchFileLogTable().
Referenced by deleteLogs(), alma::acs::jlog::test::MultiFileCacheTest::testFileCreation(), alma::acs::jlog::test::MultiFileCacheTest::testFileDeletion(), alma::acs::jlog::test::MultiFileCacheTest::testGetFirstLog(), alma::acs::jlog::test::MultiFileCacheTest::testGetLastLog(), alma::acs::jlog::test::MultiFileCacheTest::testGetSize(), and alma::acs::jlog::test::MultiFileCacheTest::testkKeySet().
| void com::cosylab::logging::client::cache::LogMultiFileCache::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.
References deleteLog().
| static long com::cosylab::logging::client::cache::LogMultiFileCache::getDefaultMaxFileSize | ( | ) | [inline, static, private] |
Get the max size of the file out of the system properties or uses the default value if the property does not exist
References DEFAULT_FILEMAXSIZE, and FILEMAXSIZE_PROPERTY_NAME.
Referenced by LogMultiFileCache().
| synchronized long com::cosylab::logging::client::cache::LogMultiFileCache::getFilesSize | ( | ) | throws IOException [inline] |
Return the disk space used by all the files of the cache.
| IOException | In case of error getting the size of one of the files |
References logFileTable.
Referenced by alma::acs::logging::table::LogEntryTableModelBase::usedDiskSpace().
| Integer com::cosylab::logging::client::cache::LogMultiFileCache::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.
| In | case of error getting the first log |
Implements com::cosylab::logging::client::cache::ILogMap.
References com::cosylab::logging::client::cache::MultiFileTableRecord::getFirstLog(), logFileTable, and logsInCache.
Referenced by alma::acs::jlog::test::MultiFileCacheTest::testClear(), alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogCache(), alma::acs::jlog::test::MultiFileCacheTest::testFileDeletion(), alma::acs::jlog::test::MultiFileCacheTest::testGet(), alma::acs::jlog::test::MultiFileCacheTest::testGetFirstLog(), com::cosylab::logging::CacheTest::testGetFirstLog(), alma::acs::jlog::test::MultiFileCacheTest::testGetLastLog(), alma::acs::jlog::test::MultiFileCacheTest::testGetSize(), alma::acs::jlog::test::MultiFileCacheTest::testkKeySet(), and alma::acs::jlog::test::MultiFileCacheTest::testReplace().
| int com::cosylab::logging::client::cache::LogMultiFileCache::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 logFileTable.
Referenced by com::cosylab::logging::CacheTest::testGetLogs().
| Integer com::cosylab::logging::client::cache::LogMultiFileCache::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 change if such log has been deleted
Implements com::cosylab::logging::client::cache::ILogMap.
References com::cosylab::logging::client::cache::MultiFileTableRecord::getLastLog(), logFileTable, and logsInCache.
Referenced by alma::acs::jlog::test::MultiFileCacheTest::testClear(), alma::acs::jlog::test::MultiFileCacheTest::testFileDeletion(), alma::acs::jlog::test::MultiFileCacheTest::testGet(), alma::acs::jlog::test::MultiFileCacheTest::testGetFirstLog(), alma::acs::jlog::test::MultiFileCacheTest::testGetLastLog(), com::cosylab::logging::CacheTest::testGetLastLog(), alma::acs::jlog::test::MultiFileCacheTest::testGetSize(), alma::acs::jlog::test::MultiFileCacheTest::testkKeySet(), and alma::acs::jlog::test::MultiFileCacheTest::testReplace().
| ILogEntry com::cosylab::logging::client::cache::LogMultiFileCache::getLog | ( | Integer | logKey | ) | throws LogCacheException [inline] |
Retrieves a log by means of its keyword.
| pos | The key of the log to retrieve |
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogCache.
References com::cosylab::logging::client::cache::MultiFileTableRecord::getLog(), and searchFileLogTable().
Referenced by alma::acs::jlog::test::MultiFileCacheTest::testGet(), alma::acs::jlog::test::MultiFileCacheTest::testkKeySet(), and alma::acs::jlog::test::MultiFileCacheTest::testReplace().
| long com::cosylab::logging::client::cache::LogMultiFileCache::getLogFileSize | ( | ) | throws LogCacheException [inline] |
Return the size of the last log file used by the cache (it is here for testing purposes)
References com::cosylab::logging::client::cache::MultiFileTableRecord::getFileSize(), and logFileTable.
Referenced by alma::acs::jlog::test::MultiFileCacheTest::testFileCreation().
| long com::cosylab::logging::client::cache::LogMultiFileCache::getMaxFileSize | ( | ) | throws LogCacheException [inline] |
Return the current maximum size of the log file
References fileMaxSize.
Referenced by alma::acs::jlog::test::MultiFileCacheTest::setUp().
| int com::cosylab::logging::client::cache::LogMultiFileCache::getNumberOfCacheFiles | ( | ) | [inline] |
References logFileTable.
Referenced by alma::acs::logging::table::LogEntryTableModelBase::numberOfUsedFiles(), alma::acs::jlog::test::MultiFileCacheTest::testClear(), and alma::acs::jlog::test::MultiFileCacheTest::testFileDeletion().
| int com::cosylab::logging::client::cache::LogMultiFileCache::getSize | ( | ) | [inline] |
Implements com::cosylab::logging::client::cache::ILogMap.
References logsInCache.
Referenced by alma::acs::logging::io::IOLogsHelper::SaveLogs::run(), com::cosylab::logging::CacheTest::testAddLog(), alma::acs::jlog::test::MultiFileCacheTest::testClear(), com::cosylab::logging::CacheTest::testClear(), alma::acs::jlog::test::DeleteLogTest::testContent(), alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogCache(), alma::acs::jlog::test::MultiFileCacheTest::testFileDeletion(), alma::acs::jlog::test::MultiFileCacheTest::testGet(), com::cosylab::logging::CacheTest::testGet(), alma::acs::jlog::test::MultiFileCacheTest::testGetFirstLog(), alma::acs::jlog::test::MultiFileCacheTest::testGetLastLog(), alma::acs::jlog::test::MultiFileCacheTest::testGetSize(), com::cosylab::logging::CacheTest::testKeySet(), alma::acs::jlog::test::MultiFileCacheTest::testkKeySet(), alma::acs::jlog::test::DeleteLogTest::testLogCacheDelete(), com::cosylab::logging::CacheTest::testLogExceedingTimeFrame(), com::cosylab::logging::CacheTest::testMemoryCache(), alma::acs::jlog::test::MultiFileCacheTest::testReplace(), com::cosylab::logging::CacheTest::testReplace(), com::cosylab::logging::CacheTest::testSize(), and alma::acs::logging::table::LogEntryTableModelBase::totalLogNumber().
| Iterator<ILogEntry> com::cosylab::logging::client::cache::LogMultiFileCache::iterator | ( | ) | [inline] |
Return an Iterator to browse the logs in the map. The order the iterator returns the logs is that of the keys.
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogCache.
| Set<Integer> com::cosylab::logging::client::cache::LogMultiFileCache::keySet | ( | ) | [inline] |
The keys in the map
Implements com::cosylab::logging::client::cache::ILogMap.
Reimplemented in com::cosylab::logging::client::cache::LogCache.
References logFileTable.
Referenced by alma::acs::jlog::test::MultiFileCacheTest::testkKeySet().
| void com::cosylab::logging::client::cache::LogMultiFileCache::printDebugTrace | ( | String | traceInfo | ) | [inline, private] |
Prints trace info if traceDebug flag is true
References debugTrace.
Referenced by add(), deleteLog(), and LogMultiFileCache().
| void com::cosylab::logging::client::cache::LogMultiFileCache::printFileTableInfo | ( | ) | throws LogCacheException [inline] |
Return the current maximum size of the log file
References com::cosylab::logging::client::cache::MultiFileTableRecord::getFileSize(), com::cosylab::logging::client::cache::MultiFileTableRecord::getMaxLogIdx(), com::cosylab::logging::client::cache::MultiFileTableRecord::getMinLogIdx(), com::cosylab::logging::client::cache::MultiFileTableRecord::getNumOfLogs(), logFileTable, and logsInCache.
Referenced by alma::acs::jlog::test::MultiFileCacheTest::testFileCreation(), alma::acs::jlog::test::MultiFileCacheTest::testFileDeletion(), and alma::acs::jlog::test::MultiFileCacheTest::testGetLastLog().
| void com::cosylab::logging::client::cache::LogMultiFileCache::replaceLog | ( | Integer | key, | |
| ILogEntry | log | |||
| ) | throws LogCacheException [inline] |
Replace the log in the given position with the new one
| 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::MultiFileTableRecord::replaceLog(), and searchFileLogTable().
Referenced by alma::acs::logging::table::LogEntryTableModelBase::replaceLog(), alma::acs::jlog::test::MultiFileCacheTest::testReplace(), and com::cosylab::logging::CacheTest::testReplace().
| MultiFileTableRecord com::cosylab::logging::client::cache::LogMultiFileCache::searchFileLogTable | ( | Integer | logKey | ) | throws LogCacheException [inline, private] |
Looks in the log file table in which file buffered cache the log has been stored.
The search is made by checking the min and max key of the logs contained in each record against the key of the searched log. As a consequence the record returned by this method is the only one record that can contain this log but it could be that the log is not there (for example it has been deleted)
| logKey | The key of the log to look for |
| LogCacheException | If no record is found or an error happened |
References logFileTable.
Referenced by deleteLog(), getLog(), and replaceLog().
| void com::cosylab::logging::client::cache::LogMultiFileCache::setDebugTrace | ( | boolean | flag | ) | throws LogCacheException [inline] |
Return the current maximum size of the log file
References debugTrace.
Referenced by alma::acs::jlog::test::MultiFileCacheTest::setUp(), and alma::acs::jlog::test::MultiFileCacheTest::testFileCreation().
boolean com::cosylab::logging::client::cache::LogMultiFileCache::debugTrace = false [private] |
Flag activating some info prints
Referenced by printDebugTrace(), and setDebugTrace().
final long com::cosylab::logging::client::cache::LogMultiFileCache::DEFAULT_FILEMAXSIZE = 10000000 [static] |
The default max size of each file of the cache
Referenced by getDefaultMaxFileSize().
This vector implement a table whose records are specified by the class LogFileTableRecord.
Referenced by add(), getMaxFileSize(), and LogMultiFileCache().
final String com::cosylab::logging::client::cache::LogMultiFileCache::FILEMAXSIZE_PROPERTY_NAME = "jlog.cache.fileMaxSize" [static] |
The name of the property defining the max size of each fileof the cache
Referenced by getDefaultMaxFileSize().
int com::cosylab::logging::client::cache::LogMultiFileCache::ID = -1 [private] |
The ID (i.e. the key) identifying each log
Referenced by add().
Vector<MultiFileTableRecord> com::cosylab::logging::client::cache::LogMultiFileCache::logFileTable = new Vector<MultiFileTableRecord>() [private] |
The vector of objects describing the buffers on disk
Referenced by add(), clear(), createNewFileRecord(), deleteLog(), getFilesSize(), getFirstLog(), getFirstLogs(), getLastLog(), getLogFileSize(), getNumberOfCacheFiles(), keySet(), printFileTableInfo(), and searchFileLogTable().
volatile int com::cosylab::logging::client::cache::LogMultiFileCache::logsInCache = 0 [private] |
The number of logs in cache
Referenced by add(), clear(), deleteLog(), getFirstLog(), getLastLog(), getSize(), and printFileTableInfo().
1.6.2