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 |
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).
| synchronized void com.cosylab.logging.engine.cache.CacheEntriesQueue.clear | ( | ) |
Clear the queue and the file (if any)
| synchronized CacheEntry com.cosylab.logging.engine.cache.CacheEntriesQueue.get | ( | ) | throws IOException |
Get the next value from the queue.
null if the queue is empty| IOException | In case of error during I/O |
References com.cosylab.logging.engine.cache.CacheEntriesQueue.THRESHOLD.
Referenced by com.cosylab.logging.engine.cache.EngineCache.pop().
| synchronized void com.cosylab.logging.engine.cache.CacheEntriesQueue.put | ( | CacheEntry | entry | ) | throws IOException |
Put an entry in Cache.
If the cache is full the entry is added to the buffer.
| entry | The not null CacheEntry to add to the queue |
| IOException | In case of I/O error while flushing the cache on disk |
References com.cosylab.logging.engine.cache.CacheEntriesQueue.MAX_QUEUE_LENGTH, and com.cosylab.logging.engine.cache.CacheEntriesQueue.PAGE_LEN.
Referenced by com.cosylab.logging.engine.cache.EngineCache.push().
| synchronized int com.cosylab.logging.engine.cache.CacheEntriesQueue.size | ( | ) |
Return the number of cache entries waiting in queue
References com.cosylab.logging.engine.cache.CacheEntriesQueue.PAGE_LEN.
Referenced by com.cosylab.logging.engine.cache.EngineCache.size().
final int com.cosylab.logging.engine.cache.CacheEntriesQueue.MAX_QUEUE_LENGTH = 20000 [static] |
The max number of entries kept in memory.
Referenced by com.cosylab.logging.engine.cache.CacheEntriesQueue.put().
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
Referenced by com.cosylab.logging.engine.cache.CacheEntriesQueue.put(), and com.cosylab.logging.engine.cache.CacheEntriesQueue.size().
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
Referenced by com.cosylab.logging.engine.cache.CacheEntriesQueue.get().
1.7.0