Top Description Fields Methods
com.github.benmanes.caffeine.cache

pack-priv Interface Buffer<E>

Additional top-level class in compilation unit: DisabledBuffer.

Known Direct Implementers
com.github.benmanes.caffeine.cache.DisabledBuffer, com.github.benmanes.caffeine.cache.StripedBuffer, com.github.benmanes.caffeine.cache.BoundedBuffer.RingBuffer
Type Parameters
<E>
the type of elements maintained by this buffer
Imports
java.util.function.Consumer

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
[email protected] (Ben Manes)

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int

Method Summary

Modifier and TypeMethod and Description
public static <E> Buffer<E>
disabled()

Returns a no-op implementation.

public void
drainTo(Consumer<E>
the action to perform on each element
consumer
)

Drains the buffer, sending each element to the consumer for processing.

public int

Returns:

Buffer.SUCCESS, Buffer.FAILED, or Buffer.FULL
offer
(E
the element to add
e
)

Inserts the specified element into this buffer if it is possible to do so immediately without violating capacity restrictions.

public long

Returns:

the number of elements read from this buffer
reads
()

Returns the number of elements that have been read from the buffer.

public default long

Returns:

the number of elements in this buffer
size
()

Returns the number of elements residing in the buffer.

public long

Returns:

the number of elements written to this buffer
writes
()

Returns the number of elements that have been written to the buffer.

Field Detail

FAILEDback to summary
public static final int FAILED
FULLback to summary
public static final int FULL
SUCCESSback to summary
public static final int SUCCESS

Method Detail

disabledback to summary
public static <E> Buffer<E> disabled()

Returns a no-op implementation.

Annotations
@SuppressWarnings:unchecked
drainToback to summary
public void drainTo(Consumer<E> consumer)

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:Consumer<E>

the action to perform on each element

offerback to summary
public int offer(E e)

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:E

the element to add

Returns:int

Buffer.SUCCESS, Buffer.FAILED, or Buffer.FULL

readsback to summary
public long reads()

Returns the number of elements that have been read from the buffer.

Returns:long

the number of elements read from this buffer

sizeback to summary
public default long size()

Returns the number of elements residing in the buffer.

Returns:long

the number of elements in this buffer

writesback to summary
public long writes()

Returns the number of elements that have been written to the buffer.

Returns:long

the number of elements written to this buffer