
Public Member Functions | |
| CacheFile (String fName, Integer key, RandomAccessFile rf, File f) | |
| File | getFile () throws FileNotFoundException |
| void | close () |
| long | getFileLength () |
| synchronized CacheEntry | writeOnFile (String str, Integer key) throws IOException |
| synchronized String | readFromFile (CacheEntry entry) throws IOException |
| synchronized void | setReadingMode (boolean reading) |
| synchronized void | setWritingMode (boolean writing) |
Public Attributes | |
| final String | fileName |
| final Integer | key |
Private Member Functions | |
| void | openFile () throws FileNotFoundException |
| void | checkRaFileUsage () |
Private Attributes | |
| RandomAccessFile | raFile = null |
| File | file = null |
| boolean | reading = false |
| boolean | writing = false |
Each file used by the cache.
The cache is composed by
There are two booleans signaling if the file is used for reading and writing. In this way we know when the reads and writes are terminated close the file.
| com::cosylab::logging::engine::cache::CacheFile::CacheFile | ( | String | fName, | |
| Integer | key, | |||
| RandomAccessFile | rf, | |||
| File | f | |||
| ) | [inline] |
Constructor
| fName | The name of the file | |
| key | The key of this entry | |
| rf | The RandomAccessFile used for I/O | |
| f | The File used to get the length |
| void com::cosylab::logging::engine::cache::CacheFile::checkRaFileUsage | ( | ) | [inline, private] |
Check if the file is used for reading or writing and if not used, close the random file.
References file, fileName, raFile, reading, and writing.
Referenced by setReadingMode(), and setWritingMode().
| void com::cosylab::logging::engine::cache::CacheFile::close | ( | ) | [inline] |
Release all the resources (for instance it releases the random file).
References file, fileName, and raFile.
Referenced by com::cosylab::logging::engine::cache::EngineCache::close(), and com::cosylab::logging::engine::cache::EngineCache::releaseFile().
| File com::cosylab::logging::engine::cache::CacheFile::getFile | ( | ) | throws FileNotFoundException [inline] |
An helper methods that returns the File.
As soon as raFile is not null, file is not null too.
A new File is built if file is null otherwise the method returns a reference to file.
| FileNotFoundException | If the file does not exist |
References file, and fileName.
Referenced by openFile(), and com::cosylab::logging::engine::cache::EngineCache::releaseFile().
| long com::cosylab::logging::engine::cache::CacheFile::getFileLength | ( | ) | [inline] |
Return the size of the file
References file.
Referenced by com::cosylab::logging::engine::cache::EngineCache::push().
| void com::cosylab::logging::engine::cache::CacheFile::openFile | ( | ) | throws FileNotFoundException [inline, private] |
An helper method that returns a RandomAccessFile by the file name fileName.
The random access file is built from the fileName.
| IOException | In case of error creating the File. | |
| FileNotFoundException | If the file does not exist |
References getFile(), and raFile.
Referenced by readFromFile(), and writeOnFile().
| synchronized String com::cosylab::logging::engine::cache::CacheFile::readFromFile | ( | CacheEntry | entry | ) | throws IOException [inline] |
Read a string from the file
| entry | The cache entry to saying how to read the entry |
References key, openFile(), raFile, and reading.
Referenced by com::cosylab::logging::engine::cache::EngineCache::pop().
| synchronized void com::cosylab::logging::engine::cache::CacheFile::setReadingMode | ( | boolean | reading | ) | [inline] |
Set the reading mode of the file.
| reading | true if the file is used for reading |
References checkRaFileUsage().
Referenced by com::cosylab::logging::engine::cache::EngineCache::pop().
| synchronized void com::cosylab::logging::engine::cache::CacheFile::setWritingMode | ( | boolean | writing | ) | [inline] |
Set the writing mode of the file.
| reading | true if the file is used for writing |
References checkRaFileUsage().
Referenced by com::cosylab::logging::engine::cache::EngineCache::push().
| synchronized CacheEntry com::cosylab::logging::engine::cache::CacheFile::writeOnFile | ( | String | str, | |
| Integer | key | |||
| ) | throws IOException [inline] |
Write the passed string in the file.
| str | The string to write in the file |
References file, key, openFile(), raFile, and writing.
Referenced by com::cosylab::logging::engine::cache::EngineCache::push().
File com::cosylab::logging::engine::cache::CacheFile::file = null [private] |
The file used to build raFile.
It is not null as soon as raFile is not null
Referenced by CacheFile(), checkRaFileUsage(), close(), getFile(), getFileLength(), and writeOnFile().
The name of the file
Referenced by CacheFile(), checkRaFileUsage(), close(), getFile(), and com::cosylab::logging::engine::cache::EngineCache::releaseFile().
| final Integer com::cosylab::logging::engine::cache::CacheFile::key |
The key identifying this file.
The key is stored only to perform run-time tests of correctness.
Referenced by com::cosylab::logging::engine::cache::EngineCache::pop(), com::cosylab::logging::engine::cache::EngineCache::push(), readFromFile(), com::cosylab::logging::engine::cache::EngineCache::releaseFile(), and writeOnFile().
RandomAccessFile com::cosylab::logging::engine::cache::CacheFile::raFile = null [private] |
The RandomAccessFile of the file of this entry.
This is not null only when used for I/O.
Referenced by CacheFile(), checkRaFileUsage(), close(), openFile(), readFromFile(), and writeOnFile().
boolean com::cosylab::logging::engine::cache::CacheFile::reading = false [private] |
Signal if the file is used for reading
Referenced by checkRaFileUsage(), and readFromFile().
boolean com::cosylab::logging::engine::cache::CacheFile::writing = false [private] |
Signal if the file is used for writing
Referenced by checkRaFileUsage(), and writeOnFile().
1.6.2