Interface Buffer
- Type Parameters:
E- the type of elements maintained by this buffer
- All Known Implementing Classes:
BoundedBuffer
public interface Buffer
A multiple-producer / single-consumer buffer that rejects new elements if it is full or fails
spuriously due to contention. Unlike a queue and stack, a buffer does not guarantee an ordering
of elements in either FIFO or LIFO order. Beware that it is the responsibility of the caller to
ensure that a consumer has exclusive read access to the buffer. This implementation does
not include fail-fast behavior to guard against incorrect consumer usage.
- Author:
- ben.manes@gmail.com (Ben Manes)
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoiddrainTo(WTinyLFUPolicy consumer) Drains the buffer, sending each element to the consumer for processing.intoffer(OCacheEntry e) Inserts the specified element into this buffer if it is possible to do so immediately without violating capacity restrictions.intreads()Returns the number of elements that have been read from the buffer.default intsize()Returns the number of elements residing in the buffer.intwrites()Returns the number of elements that have been written to the buffer.
-
Field Details
-
FULL
static final int FULL- See Also:
-
SUCCESS
static final int SUCCESS- See Also:
-
FAILED
static final int FAILED- See Also:
-
-
Method Details
-
offer
Inserts the specified element into this buffer if it is possible to do so immediately without violating capacity restrictions. The addition is allowed to fail spuriously if multiple threads insert concurrently.- Parameters:
e- the element to add- Returns:
1if the buffer is full,-1if the CAS failed, or0if added
-
drainTo
Drains the buffer, sending each element to the consumer for processing. The caller must ensure that a consumer has exclusive read access to the buffer.- Parameters:
consumer- the action to perform on each element
-
size
default int size()Returns the number of elements residing in the buffer.- Returns:
- the number of elements in this buffer
-
reads
int reads()Returns the number of elements that have been read from the buffer.- Returns:
- the number of elements read from this buffer
-
writes
int writes()Returns the number of elements that have been written to the buffer.- Returns:
- the number of elements written to this buffer
-