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

com::cosylab::logging::engine::cache::EngineCache Class Reference

Collaboration diagram for com::cosylab::logging::engine::cache::EngineCache:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 EngineCache ()
 EngineCache (long size)
void run ()
int size ()
int getActiveFilesSize ()
void push (String string) throws IOException
String pop (int timeout) throws IOException, InterruptedException
void close (boolean sync)

Static Public Attributes

long DEFAULT_SIZE = 1073741824
String MAXSIZE_PROPERTY_NAME = "jlog.enine.cache.maxFilesSize"

Private Member Functions

File getNewFile ()
boolean releaseFile (CacheFile itemToDel)
Integer getNextFileKey ()

Static Private Member Functions

long getDefaultMaxFileSize ()

Private Attributes

long maxSize
int fileKey = 0
volatile CacheFile outCacheFile = null
volatile CacheFile inCacheFile = null
CacheEntriesQueue entries = new CacheEntriesQueue()
LinkedBlockingQueue< CacheFilefilesToDelete = new LinkedBlockingQueue<CacheFile>()
LinkedHashMap< Integer, CacheFilefiles = new LinkedHashMap<IntegerCacheFile>()
volatile boolean closed = false

Detailed Description

Objects from this class implement a FIFO cache of String objects. The strings are written on disk by using several files: a new file is created whenever the dimension of the current file becomes greater then a fixed size. For each entry in cache, a record is created and kept in a in-memory list.

The cache is used by com.cosylab.logging.engine.ACS.ACSLogRetrieval, but can be used wherever a set of strings needs to be stored because there is no assumption about the content of the strings.

The logs are stored in a set of files and their ending position saved. When all the logs in a file have been red, the file is deleted optimizing the usage disk space. The deletion of unused files is done by a thread.

The length of each file of cache can be specified by a parameter in the constructor or by a java property. If both those values are not given, a default length is used.

files contains all the files used by the cache, identified by a key. When a file does not contain unread entries then its key is pushed into filesToDelete and deleted. The thread that deletes the files from disk, removes the CacheFile object from files too.

entries contains all the entries of in cache.

Author:
acaproni


Constructor & Destructor Documentation

com::cosylab::logging::engine::cache::EngineCache::EngineCache  )  [inline]
 

Build a cache.

The max size of each file of the cache is calculated in the following way: 1. if the java property is present, the size is taken from suc a property 2. the default size is used

com::cosylab::logging::engine::cache::EngineCache::EngineCache long  size  )  [inline]
 

Build the cache with the passed maximum size for each file of the cache

Parameters:
size The max size of each file of the cache


Member Function Documentation

void com::cosylab::logging::engine::cache::EngineCache::close boolean  sync  )  [inline]
 

Close the cache: delete all the entries and all the files the exit.

Note: this must be the last operation executed by the cache

Parameters:
sync true if must wait the termination of the threads before exiting

int com::cosylab::logging::engine::cache::EngineCache::getActiveFilesSize  )  [inline]
 

Returns:
The number of files used by the cache

long com::cosylab::logging::engine::cache::EngineCache::getDefaultMaxFileSize  )  [inline, static, private]
 

Get the max size of the files out of the system properties or uses the default value if the property does not exist

File com::cosylab::logging::engine::cache::EngineCache::getNewFile  )  [inline, private]
 

Attempts to create the file for the strings in several places before giving up.

Returns:
A new temporary file null if it was not possible to create a new file

Integer com::cosylab::logging::engine::cache::EngineCache::getNextFileKey  )  [inline, private]
 

Generate a new key for a file.

Each new key is generated by increasing the value of the current key. If the max integer value is reached then the key rests to the min value.

Returns:
A new key for a file

String com::cosylab::logging::engine::cache::EngineCache::pop int  timeout  )  throws IOException, InterruptedException [inline]
 

Get and remove the next string from the cache.

Parameters:
timeout The timeout to wait getting the new entry
Returns:
The next string entry in cache. null If the timeout happened
Exceptions:
IOException In case of error reading from the file
InterruptedException When the call to poll is interrupted

void com::cosylab::logging::engine::cache::EngineCache::push String  string  )  throws IOException [inline]
 

Push an entry in the cache. If the current file is null or its size is greater then maxSize, then a new file is created.

Parameters:
string The string to write in the cache
Exceptions:
IOException In case of error writing the string on disk

boolean com::cosylab::logging::engine::cache::EngineCache::releaseFile CacheFile  itemToDel  )  [inline, private]
 

Close and delete a file.

Parameters:
itemToDel The item to delete
Returns:
true if the file is deleted

void com::cosylab::logging::engine::cache::EngineCache::run  )  [inline]
 

The method to get and delete unused files

int com::cosylab::logging::engine::cache::EngineCache::size  )  [inline]
 

Return the number of entries in cache.

Returns:
the number of entries in cache


Member Data Documentation

volatile boolean com::cosylab::logging::engine::cache::EngineCache::closed = false [private]
 

true if the cache is closed. It signals the thread to terminate.

long com::cosylab::logging::engine::cache::EngineCache::DEFAULT_SIZE = 1073741824 [static]
 

The default max size for each file of the cache. The default value is used when the java property is not found and the size is not given explicitly.

NFS could be limited to 2GB depending on the installed version

CacheEntriesQueue com::cosylab::logging::engine::cache::EngineCache::entries = new CacheEntriesQueue() [private]
 

The entries in the cache.

The items of the list are organized in a FIFO policy. This is particularly important because this order is used to know when a file is not used anymore and can be deleted.

See also:
EngineCache.files

int com::cosylab::logging::engine::cache::EngineCache::fileKey = 0 [private]
 

Each file of the cache is identified by a key.

The key is always positive.

LinkedHashMap<Integer,CacheFile> com::cosylab::logging::engine::cache::EngineCache::files = new LinkedHashMap<IntegerCacheFile>() [private]
 

The files used by the cache.

The entries in this vector have the same order of the creation of the files: the last created file is in the last position of the vector.

This property can be used to verify for the correctness of the computation because every time we have to delete a file, it must be the first item of this vector

See also:
EngineCache.entries

LinkedBlockingQueue<CacheFile> com::cosylab::logging::engine::cache::EngineCache::filesToDelete = new LinkedBlockingQueue<CacheFile>() [private]
 

A list of keys of unused files to delete.

volatile CacheFile com::cosylab::logging::engine::cache::EngineCache::inCacheFile = null [private]
 

The file used to read the previous record. It is used to know when all the records in a file have been read.

long com::cosylab::logging::engine::cache::EngineCache::maxSize [private]
 

The max length of each file of the cache

String com::cosylab::logging::engine::cache::EngineCache::MAXSIZE_PROPERTY_NAME = "jlog.enine.cache.maxFilesSize" [static]
 

volatile CacheFile com::cosylab::logging::engine::cache::EngineCache::outCacheFile = null [private]
 

The file used to write the strings into. When the size of this file is greater then maxSize then a new file is created for output.


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