Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

com::cosylab::logging::client::cache::LogCache Class Reference

Inheritance diagram for com::cosylab::logging::client::cache::LogCache:

Inheritance graph
[legend]
Collaboration diagram for com::cosylab::logging::client::cache::LogCache:

Collaboration graph
[legend]
List of all members.

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< ILogEntryiterator ()

Static Public Attributes

final String CACHESIZE_PROPERTY_NAME = "jlog.cache.size"
final int DEFAULT_CACHESIZE = 16384

Private Member Functions

synchronized ILogEntry loadNewLog (Integer idx) throws LogCacheException
void initCache ()

Static Private Member Functions

int getDefaultCacheSize ()

Private Attributes

final int actualCacheSize
Map< Integer, ILogEntrycache
LinkedList< Integer > manager = null
Map< Integer, LogTypeHelperlogTypes
Map< Integer, Long > logTimes

Detailed Description

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.

Author:
acaproni


Constructor & Destructor Documentation

com::cosylab::logging::client::cache::LogCache::LogCache  )  throws LogCacheException [inline]
 

Build a LogCache object

Exceptions:
IOException The exception is thrown if the base class is not able to create the cache on a file

com::cosylab::logging::client::cache::LogCache::LogCache int  size  )  throws LogCacheException [inline]
 

Build a logCache object of the given size

Parameters:
size The size of the cache
Exceptions:
LogCacheException 


Member Function Documentation

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

Parameters:
log The log to add in the cache
Returns:
The key of the added log in the cache
Exceptions:
LogCacheException If an error happened while adding the log

Implements com::cosylab::logging::client::cache::ILogMap.

synchronized void com::cosylab::logging::client::cache::LogCache::clear  )  throws LogCacheException [inline]
 

Empty the cache

Implements com::cosylab::logging::client::cache::ILogMap.

synchronized void com::cosylab::logging::client::cache::LogCache::deleteLog Integer  key  )  throws LogCacheException [inline]
 

Delete a log with the given key

Parameters:
pos The key of the log to delete

Implements com::cosylab::logging::client::cache::ILogMap.

void com::cosylab::logging::client::cache::LogCache::deleteLogs final Integer[]  keys  )  throws LogCacheException [inline]
 

Delete a collection of logs

Parameters:
keys The keys of the logs to delete

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.

Returns:

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.

Returns:
the default cache size to be used if none is given in the constructor

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

See also:
java.util.LinkedList

java.util.HashMap

Parameters:
pos The key of the log
Returns:
The LogEntryXML or null in case of error

Implements com::cosylab::logging::client::cache::ILogMap.

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

Parameters:
timeframe The time frame to check in millisecond
Returns:
A collection of number of logs exceedding the given timeframe

Long com::cosylab::logging::client::cache::LogCache::getLogTimestamp Integer  key  )  throws LogCacheException [inline]
 

Parameters:
pos The key of the log
Returns:
The timestamp of the log with the given key

LogTypeHelper com::cosylab::logging::client::cache::LogCache::getLogType Integer  key  )  throws LogCacheException [inline]
 

Parameters:
pos The key of the log
Returns:
The type of the log with the given key

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.

Returns:
The time frame

void com::cosylab::logging::client::cache::LogCache::initCache  )  [inline, private]
 

Build the HashMaps and the LinkedList used by the cache;

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.

Set<Integer> com::cosylab::logging::client::cache::LogCache::keySet  )  [inline]
 

The keys in the map

Returns:
The keys in the map

Implements com::cosylab::logging::client::cache::ILogMap.

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

Parameters:
idx The position of the log
Returns:
The log read from the cache on disk


Member Data Documentation

final int com::cosylab::logging::client::cache::LogCache::actualCacheSize [private]
 

The size of the buffer of logs

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.

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

final int com::cosylab::logging::client::cache::LogCache::DEFAULT_CACHESIZE = 16384 [static]
 

The default size of the buffer of logs

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

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)

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:

  • new elements are added in the tail
  • old elements are removed from the head
  • whenever an elements is accessed it is moved of one position toward the tail reducing the chance to be removed The moving operation is performed swapping the accessed elements with its neighborhood


The documentation for this class was generated from the following file:
Generated on Thu Apr 30 03:13:04 2009 for ACS Java API by doxygen 1.3.8