Buffer specifications

Requirements

The buffer is the center of the memory caching. It has FIFO eviction policy that has to be activated when the total memory size of all objects in the buffer is above the buffer maximum size. Furthermore, it needs to enable the indexing of elements into the indexing structure and perform the calculations that will return the size of all objects in the buffer. It is important that buffer is correctly synchronized and thread-safe, because it is an intention that many threads work on the buffer.

Approach

The operations of the buffer can be divided in two groups. First set of operation are the one that are invoked outside of a buffer, thus operations like put, clear, search, etc.

In the second group are operations that perform the "maintenance" in the buffer. These operations are:

  • analyze - perform the size calculation for one object in the buffer; this operation has to be suspended while the buffer is empty, or all elements in the buffer are analyzed
  • index - perform the indexing of one object in the buffer; this operation has to be suspended while the buffer is empty, or all elements in the buffer are indexed
  • evict - perform the eviction of one object in the buffer (by FIFO policy); this operation has to be suspended while the size of all objects in the buffer is smaller than the buffer maximum size

These "maintenance" operations should be done in separate threads. The intention is to explore the parallelism as much as possible, so that buffer can perform all of them at the same time, and be able to respond to the requests coming from "outer world".

Realization

Buffer is realized in the way that every object that is to be inserted in the buffer is warped by IBufferElement. Buffer elements are connected in a queue, in the way that each buffer element knows what is the next buffer element in the queue.

Synchronization

The implementing class AtomicBuffer uses atomic values to enable the synchronization. For the suspending and activating the threads that work on "maintenance" operations, reentrant locks and their conditions are used.