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 () throws IOException, InterruptedException
void close (boolean sync)

Static Public Attributes

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

Private Member Functions

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

Static Private Member Functions

static 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<Integer,CacheFile>()
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

References getDefaultMaxFileSize().

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

References maxSize.


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

References com::cosylab::logging::engine::cache::CacheFile::close(), closed, files, inCacheFile, and outCacheFile.

Referenced by com::cosylab::logging::engine::ACS::ACSLogRetrieval::close(), and alma::acs::jlog::test::EngineCacheTest::tearDown().

int com::cosylab::logging::engine::cache::EngineCache::getActiveFilesSize (  )  [inline]
static 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

References DEFAULT_SIZE, and MAXSIZE_PROPERTY_NAME.

Referenced by EngineCache().

File com::cosylab::logging::engine::cache::EngineCache::getNewFile (  )  throws IOException [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
Exceptions:
If it was not possible to create a temporary file

Referenced by push().

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

References fileKey, and files.

Referenced by push().

String com::cosylab::logging::engine::cache::EngineCache::pop (  )  throws IOException, InterruptedException [inline]
void com::cosylab::logging::engine::cache::EngineCache::push ( String  string  )  throws IOException [inline]
boolean com::cosylab::logging::engine::cache::EngineCache::releaseFile ( CacheFile  itemToDel  )  [inline, private]
void com::cosylab::logging::engine::cache::EngineCache::run (  )  [inline]

The method to get and delete unused files

References closed, filesToDelete, and releaseFile().

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

Member Data Documentation

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

Referenced by close(), pop(), push(), and run().

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

Referenced by getDefaultMaxFileSize().

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

Referenced by pop(), push(), and size().

Each file of the cache is identified by a key.

The key is always positive.

Referenced by getNextFileKey().

LinkedHashMap<Integer,CacheFile> com::cosylab::logging::engine::cache::EngineCache::files = new LinkedHashMap<Integer,CacheFile>() [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

Referenced by close(), getActiveFilesSize(), getNextFileKey(), pop(), and push().

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

A list of keys of unused files to delete.

Referenced by pop(), and run().

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

Referenced by close(), and pop().

The max length of each file of the cache

Referenced by EngineCache(), and push().

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

Referenced by getDefaultMaxFileSize().

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.

Referenced by close(), and push().


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2