
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< CacheFile > | filesToDelete = new LinkedBlockingQueue<CacheFile>() |
| LinkedHashMap< Integer, CacheFile > | files = new LinkedHashMap<Integer,CacheFile>() |
| volatile boolean | closed = false |
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.
| 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
| size | The max size of each file of the cache |
References maxSize.
| 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
| 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] |
References files.
Referenced by alma::acs::jlog::test::EngineCacheTest::setUp(), alma::acs::jlog::test::EngineCacheTest::testPushPopSeveralFiles(), and alma::acs::jlog::test::EngineCacheTest::testPushPopSingleFile().
| 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.
null if it was not possible to create a new file | If | it was not possible to create a temporary file |
Referenced by push().
| Integer com::cosylab::logging::engine::cache::EngineCache::getNextFileKey | ( | ) | [inline, private] |
| String com::cosylab::logging::engine::cache::EngineCache::pop | ( | ) | throws IOException, InterruptedException [inline] |
Get and remove the next string from the cache.
null If the timeout happened | IOException | In case of error reading from the file | |
| InterruptedException | When the call to poll is interrupted |
References closed, entries, files, filesToDelete, com::cosylab::logging::engine::cache::CacheEntriesQueue::get(), inCacheFile, com::cosylab::logging::engine::cache::CacheFile::key, com::cosylab::logging::engine::cache::CacheEntry::key, com::cosylab::logging::engine::cache::CacheFile::readFromFile(), releaseFile(), and com::cosylab::logging::engine::cache::CacheFile::setReadingMode().
Referenced by com::cosylab::logging::engine::ACS::ACSLogRetrieval::run(), alma::acs::jlog::test::EngineCacheTest::testPushPopSeveralFiles(), and alma::acs::jlog::test::EngineCacheTest::testPushPopSingleFile().
| 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.
| string | The string to write in the cache |
| IOException | In case of error writing the string on disk |
References closed, entries, files, com::cosylab::logging::engine::cache::CacheFile::getFileLength(), getNewFile(), getNextFileKey(), com::cosylab::logging::engine::cache::CacheFile::key, maxSize, outCacheFile, com::cosylab::logging::engine::cache::CacheEntriesQueue::put(), com::cosylab::logging::engine::cache::CacheFile::setWritingMode(), and com::cosylab::logging::engine::cache::CacheFile::writeOnFile().
Referenced by com::cosylab::logging::engine::ACS::ACSLogRetrieval::addLog(), alma::acs::jlog::test::EngineCacheTest::testPushPopSeveralFiles(), and alma::acs::jlog::test::EngineCacheTest::testPushPopSingleFile().
| boolean com::cosylab::logging::engine::cache::EngineCache::releaseFile | ( | CacheFile | itemToDel | ) | [inline, private] |
Close and delete a file.
| itemToDel | The item to delete |
References com::cosylab::logging::engine::cache::CacheFile::close(), com::cosylab::logging::engine::cache::CacheFile::fileName, com::cosylab::logging::engine::cache::CacheFile::getFile(), and com::cosylab::logging::engine::cache::CacheFile::key.
| 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] |
Return the number of entries in cache.
References entries, and com::cosylab::logging::engine::cache::CacheEntriesQueue::size().
Referenced by com::cosylab::logging::engine::ACS::ACSLogRetrieval::hasPendingEntries(), com::cosylab::logging::engine::ACS::ACSLogRetrieval::run(), alma::acs::jlog::test::EngineCacheTest::setUp(), com::cosylab::logging::engine::ACS::ACSLogRetrieval::size(), alma::acs::jlog::test::EngineCacheTest::testPushPopSeveralFiles(), and alma::acs::jlog::test::EngineCacheTest::testPushPopSingleFile().
volatile boolean com::cosylab::logging::engine::cache::EngineCache::closed = false [private] |
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
Referenced by getDefaultMaxFileSize().
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.
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.
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
Referenced by close(), getActiveFilesSize(), getNextFileKey(), pop(), and push().
LinkedBlockingQueue<CacheFile> com::cosylab::logging::engine::cache::EngineCache::filesToDelete = new LinkedBlockingQueue<CacheFile>() [private] |
volatile CacheFile com::cosylab::logging::engine::cache::EngineCache::inCacheFile = null [private] |
long com::cosylab::logging::engine::cache::EngineCache::maxSize [private] |
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().
volatile CacheFile com::cosylab::logging::engine::cache::EngineCache::outCacheFile = null [private] |
1.6.2