

Public Member Functions | |
| LogCache () throws LogCacheException | |
| LogCache (int size) throws LogCacheException | |
| synchronized int | add (ILogEntry log) throws LogCacheException |
| LogTypeHelper | getLogType (Integer key) throws LogCacheException |
| Long | getLogTimestamp (Integer key) throws LogCacheException |
| synchronized ILogEntry | getLog (Integer key) throws LogCacheException |
| synchronized void | clear () throws LogCacheException |
| int | getCacheSize () |
| synchronized Calendar | getTimeFrame () |
| synchronized void | deleteLog (Integer key) throws LogCacheException |
| void | deleteLogs (final Integer[] keys) throws LogCacheException |
| synchronized Collection< Integer > | getLogExceedingTimeFrame (long timeframe) |
| Set< Integer > | keySet () |
| Iterator< ILogEntry > | iterator () |
Static Public Attributes | |
| static final String | CACHESIZE_PROPERTY_NAME = "jlog.cache.size" |
| static final int | DEFAULT_CACHESIZE = 16384 |
Private Member Functions | |
| synchronized ILogEntry | loadNewLog (Integer idx) throws LogCacheException |
| void | initCache () |
Static Private Member Functions | |
| static int | getDefaultCacheSize () |
Private Attributes | |
| final int | actualCacheSize |
| Map< Integer, ILogEntry > | cache |
| LinkedList< Integer > | manager = null |
| Map< Integer, LogTypeHelper > | logTypes |
| Map< Integer, Long > | logTimes |
The class extends the cache on file keeping a set of logs in memory to avoid to access the file for the most frequently accessed logs
The cache stores the logs into an HashMap using their indexes as keys. It also stores an array of times and level of logs to speed up the sorting done by the table.
| com::cosylab::logging::client::cache::LogCache::LogCache | ( | ) | throws LogCacheException [inline] |
Build a LogCache object
| IOException | The exception is thrown if the base class is not able to create the cache on a file |
References getDefaultCacheSize().
| com::cosylab::logging::client::cache::LogCache::LogCache | ( | int | size | ) | throws LogCacheException [inline] |
Build a logCache object of the given size
| size | The size of the cache |
| LogCacheException |
References actualCacheSize, and initCache().
| synchronized int com::cosylab::logging::client::cache::LogCache::add | ( | ILogEntry | log | ) | throws LogCacheException [inline] |
Adds a log in the cache. It does nothing because the adding is done by its parent class. What it does is to store the level and time of the log in the arrays
| log | The log to add in the cache |
| LogCacheException | If an error happened while adding the log |
Implements com::cosylab::logging::client::cache::ILogMap.
References logTimes, and logTypes.
Referenced by alma::acs::logging::table::LogEntryTableModelBase::appendLog(), com::cosylab::logging::CacheTest::fillCache(), com::cosylab::logging::CacheTest::testAddLog(), alma::acs::jlog::test::DeleteLogTest::testContent(), alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogCache(), alma::acs::jlog::test::DeleteLogTest::testLogCacheDelete(), com::cosylab::logging::CacheTest::testLogExceedingTimeFrame(), and com::cosylab::logging::CacheTest::testTimeFrameCalc().
| synchronized void com::cosylab::logging::client::cache::LogCache::clear | ( | ) | throws LogCacheException [inline] |
Empty the cache
Implements com::cosylab::logging::client::cache::ILogMap.
References cache, initCache(), logTimes, logTypes, and manager.
Referenced by alma::acs::logging::table::LogEntryTableModelBase::clearAll(), com::cosylab::logging::CacheTest::fillCache(), com::cosylab::logging::CacheTest::tearDown(), com::cosylab::logging::CacheTest::testClear(), alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogCache(), com::cosylab::logging::CacheTest::testLogExceedingTimeFrame(), and com::cosylab::logging::CacheTest::testTimeFrameCalc().
| synchronized void com::cosylab::logging::client::cache::LogCache::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 cache, logTimes, logTypes, and manager.
Referenced by alma::acs::logging::table::LogTableDataModel::deleteLogs(), deleteLogs(), and alma::acs::jlog::test::DeleteLogTest::testLogCacheDelete().
| void com::cosylab::logging::client::cache::LogCache::deleteLogs | ( | final Integer[] | keys | ) | throws LogCacheException [inline] |
Delete a collection of logs
| keys | The keys of the logs to delete |
References deleteLog().
Referenced by alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogCache().
| int com::cosylab::logging::client::cache::LogCache::getCacheSize | ( | ) | [inline] |
Gets the actual cache size, which may come from getDefaultCacheSize() or may be given in the constructor.
References actualCacheSize.
Referenced by com::cosylab::logging::CacheTest::fillCache().
| static int com::cosylab::logging::client::cache::LogCache::getDefaultCacheSize | ( | ) | [inline, static, private] |
Gets the default cache size, which comes either from the system property jlog.cache.size (see CACHESIZE_PROPERTY_NAME) or, if this property is undefined or invalid, from the fixed size given by DEFAULT_CACHESIZE.
References CACHESIZE_PROPERTY_NAME, and DEFAULT_CACHESIZE.
Referenced by LogCache().
| synchronized ILogEntry com::cosylab::logging::client::cache::LogCache::getLog | ( | Integer | key | ) | throws LogCacheException [inline] |
Return the log with the given key. The method is synchronized because both the HashMap and the LinkedList must be synchronized if there is a chance to acces these objects from more then one thread in the same time
| pos | The key of the log |
Implements com::cosylab::logging::client::cache::ILogMap.
References cache, and loadNewLog().
Referenced by alma::acs::logging::table::LogEntryTableModelBase::getVisibleLogEntry(), com::cosylab::logging::CacheTest::testAddLog(), alma::acs::jlog::test::DeleteLogTest::testContent(), alma::acs::jlog::test::DeleteLogTest::testDeleteLogsFromLogCache(), com::cosylab::logging::CacheTest::testGet(), com::cosylab::logging::CacheTest::testKeySet(), alma::acs::jlog::test::DeleteLogTest::testLogCacheDelete(), com::cosylab::logging::CacheTest::testLogExceedingTimeFrame(), com::cosylab::logging::CacheTest::testMemoryCache(), and com::cosylab::logging::CacheTest::testReplace().
| synchronized Collection<Integer> com::cosylab::logging::client::cache::LogCache::getLogExceedingTimeFrame | ( | long | timeframe | ) | [inline] |
Returns a set of number of logs (i.e. their position in cache) exceeding the given time frame. This operation is quite slow because it requires a double scan of the logTimes array
| timeframe | The time frame to check in millisecond |
References logTimes.
Referenced by alma::acs::logging::table::LogTableDataModel::checkTimeFrame(), and com::cosylab::logging::CacheTest::testLogExceedingTimeFrame().
| Long com::cosylab::logging::client::cache::LogCache::getLogTimestamp | ( | Integer | key | ) | throws LogCacheException [inline] |
| pos | The key of the log |
References logTimes.
Referenced by alma::acs::logging::table::LogEntryTableModelBase::getValueAt().
| LogTypeHelper com::cosylab::logging::client::cache::LogCache::getLogType | ( | Integer | key | ) | throws LogCacheException [inline] |
| pos | The key of the log |
References logTypes.
Referenced by alma::acs::logging::table::LogEntryTableModelBase::getValueAt().
| synchronized Calendar com::cosylab::logging::client::cache::LogCache::getTimeFrame | ( | ) | [inline] |
Calculate and return the time frame of the logs managed by the GUI The time frame is the number of hours/minutes/seconds between the newest and the oldest log in the GUI
I prefer to evaluate the frame instead of storing the min and max value because it works even if one log is deleted from the cache.
References logTimes.
Referenced by alma::acs::logging::table::LogEntryTableModelBase::getTimeFrame(), and com::cosylab::logging::CacheTest::testTimeFrameCalc().
| void com::cosylab::logging::client::cache::LogCache::initCache | ( | ) | [inline, private] |
| Iterator<ILogEntry> com::cosylab::logging::client::cache::LogCache::iterator | ( | ) | [inline] |
Return an iterator over the logs in cache
Implements com::cosylab::logging::client::cache::ILogMap.
Referenced by alma::acs::logging::io::IOLogsHelper::SaveLogs::run().
| Set<Integer> com::cosylab::logging::client::cache::LogCache::keySet | ( | ) | [inline] |
The keys in the map
Implements com::cosylab::logging::client::cache::ILogMap.
References logTimes.
Referenced by com::cosylab::logging::CacheTest::testKeySet().
| synchronized ILogEntry com::cosylab::logging::client::cache::LogCache::loadNewLog | ( | Integer | idx | ) | throws LogCacheException [inline, private] |
Get a log from the cache on disk updating all the internal lists
| idx | The position of the log |
References actualCacheSize, cache, and manager.
Referenced by getLog().
final int com::cosylab::logging::client::cache::LogCache::actualCacheSize [private] |
The size of the buffer of logs
Referenced by getCacheSize(), loadNewLog(), and LogCache().
Map<Integer,ILogEntry> com::cosylab::logging::client::cache::LogCache::cache [private] |
The logs are stored into an HashMap. The key is the index of the log. This choice make inefficient the deletion of a log. In fact when a log is removed, the logs having a greater position are shifted one position toward 0 (newPos=oldPos-1) but it is not possible to change the key of an entry in the HashMap.
Referenced by clear(), deleteLog(), getLog(), initCache(), and loadNewLog().
final String com::cosylab::logging::client::cache::LogCache::CACHESIZE_PROPERTY_NAME = "jlog.cache.size" [static] |
The name of the property to set the size of the cache. This is the size oif the logs buffered by LogCache
Referenced by getDefaultCacheSize().
final int com::cosylab::logging::client::cache::LogCache::DEFAULT_CACHESIZE = 16384 [static] |
The default size of the buffer of logs
Referenced by getDefaultCacheSize().
Map<Integer,Long> com::cosylab::logging::client::cache::LogCache::logTimes [private] |
The times of the logs Integer is the key of the log, Long is its timestamp
Referenced by add(), clear(), deleteLog(), getLogExceedingTimeFrame(), getLogTimestamp(), getTimeFrame(), initCache(), and keySet().
Map<Integer,LogTypeHelper> com::cosylab::logging::client::cache::LogCache::logTypes [private] |
The array with the level of each log in the cache (useful for setting the log level)
Referenced by add(), clear(), deleteLog(), getLogType(), and initCache().
LinkedList<Integer> com::cosylab::logging::client::cache::LogCache::manager = null [private] |
The following list is used to keep ordered the indexes in such a way it is fast to insert/remove logs in the cache.
The indexes contained in this object are the indexes in the cache TreeMap and the size of the TreeMap and the ArrayBlockingQueue is always the same.
The functioning is the following:
Referenced by clear(), deleteLog(), initCache(), and loadNewLog().
1.6.2