java.lang.Object
com.orientechnologies.orient.core.storage.cache.chm.readbuffer.BoundedBuffer
Type Parameters:
E - the type of elements maintained by this buffer
All Implemented Interfaces:
Buffer

public final class BoundedBuffer extends Object
A striped, non-blocking, bounded buffer.
Author:
ben.manes@gmail.com (Ben Manes)
  • Field Summary

    Fields inherited from interface com.orientechnologies.orient.core.storage.cache.chm.readbuffer.Buffer

    FAILED, FULL, SUCCESS
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Buffer
    Creates a new buffer instance after resizing to accommodate a producer.
    void
    Drains the buffer, sending each element to the consumer for processing.
    int
    Inserts the specified element into this buffer if it is possible to do so immediately without violating capacity restrictions.
    int
    Returns the number of elements that have been read from the buffer.
    int
    Returns the number of elements that have been written to the buffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.orientechnologies.orient.core.storage.cache.chm.readbuffer.Buffer

    size
  • Constructor Details

    • BoundedBuffer

      public BoundedBuffer()
  • Method Details

    • create

      protected Buffer create(OCacheEntry e)
      Creates a new buffer instance after resizing to accommodate a producer.
      Parameters:
      e - the producer's element
      Returns:
      a newly created buffer populated with a single element
    • offer

      public int offer(OCacheEntry 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
      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(WTinyLFUPolicy 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
      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
      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
      Returns:
      the number of elements written to this buffer