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

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

List of all members.

Public Member Functions

synchronized void put (CacheEntry entry) throws IOException
synchronized CacheEntry get () throws IOException
synchronized void clear ()
synchronized int size ()

Static Public Attributes

static final int MAX_QUEUE_LENGTH = 20000
static final int PAGE_LEN = 5000
static final int THRESHOLD = 12500

Private Member Functions

File getNewFile () throws IOException
void flushEntriesInQueue () throws IOException
void readNextPageFromFile () throws IOException
void writePageOnFile () throws IOException

Private Attributes

final List< CacheEntryinMemoryQueue = new LinkedList<CacheEntry>()
byte[] fileBuffer = new byte[PAGE_SIZE]
byte[] entryBuffer = new byte[CacheEntry.ENTRY_LENGTH]
List< CacheEntrycachedEntries = new LinkedList<CacheEntry>()
File file = null
RandomAccessFile raFile = null
volatile int pagesOnFile = 0
volatile int nextPageToRead = 0

Static Private Attributes

static final int PAGE_SIZE = PAGE_LEN*CacheEntry.ENTRY_LENGTH

Detailed Description

The queue of entries.

This class has been introduced to avoid keeping in memory a never ending queue of CacheEntry and reduce the chance to face an out of memory at run-time.
This class is composed of two lists and a file. inMemoryQueue is the list of the entries to get. When this list contains few items then some more items are read from the file.
The other list, CacheEntriesQueue, is a buffer where the entries are stored ready to be flushed on disk. This is done to write more entries at once reducing the I/O and increasing the performances.

Implementation note
CacheEntry items are read only with the get method and pushed with the put.

Adding entries:
If there is enough room in inMemoryQueue (i.e. inMemoryQueue.size()<MAX_QUEUE_LENGTH) then a new entry is stored directly in that list; otherwise it is added to cachedEntries ready to be written on file. If the size of cachedEntries is greater then PAGE_LEN, the size of a page, then a page is flushed on disk. Note that what is in the list, cacheEntries is added at the end of the file.

Getting entries:
The entry to get is always in inMemoryQueue. After getting an entry, it checks if the the size of the queue allows to get new entries from the file or from the cachedEntries. Note that the right order is first the file and then cachedEntries. In fact cachedEntries, contains the last received entries, packed to be transferred on a new page on disk while the first entries to push in the queue are on a page disk (if any).

Author:
acaproni

Member Function Documentation

synchronized void com::cosylab::logging::engine::cache::CacheEntriesQueue::clear (  )  [inline]
void com::cosylab::logging::engine::cache::CacheEntriesQueue::flushEntriesInQueue (  )  throws IOException [inline, private]

Move the entries from the file or the vector into the queue

The vector contains the last added entries so if there are pages in the file they are flushed before the vector

Exceptions:
IOException In case of error during I/O

References cachedEntries, inMemoryQueue, pagesOnFile, and readNextPageFromFile().

Referenced by get().

synchronized CacheEntry com::cosylab::logging::engine::cache::CacheEntriesQueue::get (  )  throws IOException [inline]
File com::cosylab::logging::engine::cache::CacheEntriesQueue::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:
IOException In case of error creating the temporary file

Referenced by writePageOnFile().

synchronized void com::cosylab::logging::engine::cache::CacheEntriesQueue::put ( CacheEntry  entry  )  throws IOException [inline]
void com::cosylab::logging::engine::cache::CacheEntriesQueue::readNextPageFromFile (  )  throws IOException [inline, private]

Read page from the file putting all the CacheEntry it contains in the queue.

Exceptions:
IOException In case of error during I/O

References cachedEntries, entryBuffer, file, fileBuffer, inMemoryQueue, nextPageToRead, PAGE_LEN, PAGE_SIZE, pagesOnFile, and raFile.

Referenced by flushEntriesInQueue().

synchronized int com::cosylab::logging::engine::cache::CacheEntriesQueue::size (  )  [inline]
void com::cosylab::logging::engine::cache::CacheEntriesQueue::writePageOnFile (  )  throws IOException [inline, private]

Write a page of CacheEntry in the file

Exceptions:
IOException In case of error creating a new temporary file

References cachedEntries, file, fileBuffer, getNewFile(), PAGE_LEN, pagesOnFile, raFile, and com::cosylab::logging::engine::cache::CacheEntry::toHexadecimal().

Referenced by put().


Member Data Documentation

This Vector contains the entries that will be written on the file.

Referenced by clear(), flushEntriesInQueue(), get(), put(), readNextPageFromFile(), size(), and writePageOnFile().

The buffer containing the hexadecimal string of a CacheEntry

Referenced by clear(), and readNextPageFromFile().

The file to buffer entries on disk.

Referenced by clear(), readNextPageFromFile(), and writePageOnFile().

The buffer for each I/O

Referenced by clear(), readNextPageFromFile(), and writePageOnFile().

The entries to keep in memory.

Referenced by clear(), flushEntriesInQueue(), get(), put(), readNextPageFromFile(), and size().

The max number of entries kept in memory.

Referenced by put().

The number of the next page to read from file.

Note: a new page is always added at the end of the file while the reading happens in a different order.

Referenced by clear(), and readNextPageFromFile().

The number of CacheEntry to read/write from/to disk on each I/O

Referenced by put(), readNextPageFromFile(), size(), and writePageOnFile().

The size (in bytes) of a page

Referenced by readNextPageFromFile().

The number of pages written on file and not yet read

Referenced by clear(), flushEntriesInQueue(), get(), put(), readNextPageFromFile(), size(), and writePageOnFile().

The RandomAccessFile to read/write entries created from bufferFile.

The I/O is paginated i.e. each read or write is done for a block of PAGE_LEN entries.

Referenced by clear(), readNextPageFromFile(), and writePageOnFile().

When in the LinkedBlockingQueue there are less entries then the THRESHOLD then the entries in the buffer are flushed in the queue

Referenced by get().


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

Generated by  doxygen 1.6.2