Class BoundedBuffer.RingBuffer<E>

    • Field Detail

      • buffer

        final java.util.concurrent.atomic.AtomicReferenceArray<E> buffer
    • Constructor Detail

      • RingBuffer

        public RingBuffer​(E e)
    • Method Detail

      • offer

        public int offer​(E e)
        Description copied from interface: Buffer
        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.
        Specified by:
        offer in interface Buffer<E>
        Parameters:
        e - the element to add
        Returns:
        1 if the buffer is full, -1 if the CAS failed, or 0 if added
      • drainTo

        public void drainTo​(java.util.function.Consumer<E> consumer)
        Description copied from interface: Buffer
        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.
        Specified by:
        drainTo in interface Buffer<E>
        Parameters:
        consumer - the action to perform on each element
      • reads

        public int reads()
        Description copied from interface: Buffer
        Returns the number of elements that have been read from the buffer.
        Specified by:
        reads in interface Buffer<E>
        Returns:
        the number of elements read from this buffer
      • writes

        public int writes()
        Description copied from interface: Buffer
        Returns the number of elements that have been written to the buffer.
        Specified by:
        writes in interface Buffer<E>
        Returns:
        the number of elements written to this buffer