Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

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

List of all members.

Public Member Functions

 CacheEntriesQueue ()
Override void put (CacheEntry entry) throws InterruptedException
Override CacheEntry poll (long timeout, TimeUnit unit) throws InterruptedException
Override void clear ()
Override int size ()

Static Public Attributes

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

Private Member Functions

File getNewFile ()
synchronized void flushEntriesInQueue ()
synchronized void readNextPageFromFile ()
synchronized void writePageOnFile ()

Private Attributes

byte[] fileBuffer = null
byte[] entryBuffer = null
Vector< CacheEntrycachedEntries = new Vector<CacheEntry>()
File file = null
RandomAccessFile raFile = null
volatile int pagesOnFile = 0
volatile int nextPageToRead = 0
Object semaphore = new Object()

Static Private Attributes

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.

CacheEntriesQueue extends LinkedBlockingQueue by keeping in memory only a defined subset of items. All exceeding items are flushed on disk.

Implementation note
CacheEntry items are read only with the poll or an equivalent method and pushed with put.

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

Getting entries:
The entry to get is always in the queue. After getting the entry, it checks if the the size of the queue allows to get new entries from the file (i.e. read a new page) or from the vector. Note that the right order is first the file and then the vector. In fact the vector, 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


Constructor & Destructor Documentation

com::cosylab::logging::engine::cache::CacheEntriesQueue::CacheEntriesQueue  )  [inline]
 

Constructor


Member Function Documentation

Override void com::cosylab::logging::engine::cache::CacheEntriesQueue::clear  )  [inline]
 

Clear the queue and the file (if any)

synchronized void com::cosylab::logging::engine::cache::CacheEntriesQueue::flushEntriesInQueue  )  [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

File com::cosylab::logging::engine::cache::CacheEntriesQueue::getNewFile  )  [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

Override CacheEntry com::cosylab::logging::engine::cache::CacheEntriesQueue::poll long  timeout,
TimeUnit  unit
throws InterruptedException [inline]
 

Get the next value from the queue.

Override void com::cosylab::logging::engine::cache::CacheEntriesQueue::put CacheEntry  entry  )  throws InterruptedException [inline]
 

Put an entry in Cache.

If the cache is full the entry is added to the buffer.

synchronized void com::cosylab::logging::engine::cache::CacheEntriesQueue::readNextPageFromFile  )  [inline, private]
 

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

Override int com::cosylab::logging::engine::cache::CacheEntriesQueue::size  )  [inline]
 

Return the number of cache entries waiting in queue

synchronized void com::cosylab::logging::engine::cache::CacheEntriesQueue::writePageOnFile  )  [inline, private]
 

Write a page of CacheEntry in the file


Member Data Documentation

Vector<CacheEntry> com::cosylab::logging::engine::cache::CacheEntriesQueue::cachedEntries = new Vector<CacheEntry>() [private]
 

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

byte [] com::cosylab::logging::engine::cache::CacheEntriesQueue::entryBuffer = null [private]
 

The buffer containing the hexadecimal string of a CacheEntry

File com::cosylab::logging::engine::cache::CacheEntriesQueue::file = null [private]
 

The file to buffer entries on disk.

byte [] com::cosylab::logging::engine::cache::CacheEntriesQueue::fileBuffer = null [private]
 

The buffer for each I/O

final int com::cosylab::logging::engine::cache::CacheEntriesQueue::MAX_QUEUE_LENGTH = 20000 [static]
 

The max number of entries kept in memory.

volatile int com::cosylab::logging::engine::cache::CacheEntriesQueue::nextPageToRead = 0 [private]
 

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.

final int com::cosylab::logging::engine::cache::CacheEntriesQueue::PAGE_LEN = 5000 [static]
 

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

final int com::cosylab::logging::engine::cache::CacheEntriesQueue::PAGE_SIZE = PAGE_LEN*CacheEntry.ENTRY_LENGTH [static, private]
 

The size (in bytes) of a page

volatile int com::cosylab::logging::engine::cache::CacheEntriesQueue::pagesOnFile = 0 [private]
 

The number of pages written on file and not yet read

RandomAccessFile com::cosylab::logging::engine::cache::CacheEntriesQueue::raFile = null [private]
 

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.

Object com::cosylab::logging::engine::cache::CacheEntriesQueue::semaphore = new Object() [private]
 

The object to wait events from

final int com::cosylab::logging::engine::cache::CacheEntriesQueue::THRESHOLD = 12500 [static]
 

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


The documentation for this class was generated from the following file:
Generated on Thu Apr 30 03:13:10 2009 for ACS Java API by doxygen 1.3.8