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

Collaboration diagram for com::cosylab::logging::engine::cache::CacheFile:
Collaboration graph
[legend]

List of all members.

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

Detailed Description

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.

Author:
acaproni

Constructor & Destructor Documentation

com::cosylab::logging::engine::cache::CacheFile::CacheFile ( String  fName,
Integer  key,
RandomAccessFile  rf,
File  f 
) [inline]

Constructor

Parameters:
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
See also:
CacheFile(String fName, Integer key)

References file, fileName, and raFile.


Member Function Documentation

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.

Returns:
The file
Exceptions:
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

Returns:
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.

Returns:
The file to read and/or write items
Exceptions:
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

Parameters:
entry The cache entry to saying how to read the entry
Returns:
The string read from the file

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.

Parameters:
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.

Parameters:
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.

Parameters:
str The string to write in the file
Returns:
The ending position of the string in the file

References file, key, openFile(), raFile, and writing.

Referenced by com::cosylab::logging::engine::cache::EngineCache::push().


Member Data Documentation

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

Signal if the file is used for reading

Referenced by checkRaFileUsage(), and readFromFile().

Signal if the file is used for writing

Referenced by checkRaFileUsage(), and writeOnFile().


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

Generated by  doxygen 1.6.2