Class LinkedListBuffer

java.lang.Object
nz.org.riskscape.engine.sched.LinkedListBuffer
All Implemented Interfaces:
PageBuffer, ReadPageBuffer, WritePageBuffer

public class LinkedListBuffer extends Object implements PageBuffer
  • Field Details

  • Constructor Details

    • LinkedListBuffer

      protected LinkedListBuffer()
    • LinkedListBuffer

      protected LinkedListBuffer(int pageSize, int pageCapacity)

      Create a buffer with a fixed page-size and a maximum number of pages it can hold at any one time. This is mostly used for testing.

    • LinkedListBuffer

      public LinkedListBuffer(PageAllocator allocator, int tupleCapacity)
  • Method Details

    • withMaxPageSize

      public LinkedListBuffer withMaxPageSize(int pageSize)
      Returns:
      a new buffer with all the same settings, except for a new maximum page size.
    • getMaxPageSize

      public int getMaxPageSize()
      Returns:
      the max number of tuples that could potentially fill in one page
    • newPage

      public Page newPage()
      Description copied from interface: WritePageBuffer

      Allocates a new page to write Tuples to. Note that WritePageBuffer.add(Page page) actually adds the Tuples to the buffer.

      Specified by:
      newPage in interface WritePageBuffer
    • add

      public void add(Page page)
      Description copied from interface: WritePageBuffer

      Adds a page of output Tuples to the buffer.

      Specified by:
      add in interface WritePageBuffer
    • isFull

      public boolean isFull()
      Specified by:
      isFull in interface WritePageBuffer
      Returns:
      true if the WritePageBuffer has reached capacity. If so, the downstream worker task needs to read pages from the buffer before more can be written. Note that due to supporting multi-threaded writers, this is a polite back-off that the writing worker task should honour, rather than a hard limit, i.e. WritePageBuffer.newPage() and WritePageBuffer.add(Page page) will not strictly enforce the capacity limit.
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface ReadPageBuffer
      Returns:
      true if there are no more pages in the buffer to read (because we're waiting for the upstream worker task to write more).
    • read

      public Page.ReadOnlyPage read()
      Specified by:
      read in interface ReadPageBuffer
      Returns:
      a page of Tuples to read, or null if there's no Tuples to read
    • markComplete

      public void markComplete()
      Description copied from interface: WritePageBuffer

      Signals to the downstream worker task that this process has now completed writing all its output to the buffer.

      Specified by:
      markComplete in interface WritePageBuffer
    • isComplete

      public boolean isComplete()
      Specified by:
      isComplete in interface ReadPageBuffer
      Returns:
      true if there are no more pages in the buffer to read (because the upstream worker task has finished writing all its output).
    • size

      public int size()
      Specified by:
      size in interface ReadPageBuffer
      Returns:
      the current number of unread tuples in the buffer.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • newReaderClone

      public ReadPageBuffer newReaderClone()
      Specified by:
      newReaderClone in interface PageBuffer
      Returns:
      a clone of the ReadPageBuffer. This allows multiple different threads to read from the same input buffer without interfering with each other. Both the cloned and the original ReadPageBuffer will get all the same input Tuples/pages, without actually duplicating the underlying input memory-wise.
    • numTuplesWritten

      public long numTuplesWritten()
      Specified by:
      numTuplesWritten in interface WritePageBuffer
      Returns:
      the total number of Tuples written to this buffer (for diagnostics).
    • numTuplesRead

      public long numTuplesRead()
      Specified by:
      numTuplesRead in interface ReadPageBuffer
      Specified by:
      numTuplesRead in interface WritePageBuffer
      Returns:
      the total number of Tuples read from the buffer (for diagnostics).
    • getTupleCapacity

      public int getTupleCapacity()

      the maximum number of tuples we can have present in the buffer at once before it is considered full. Note that this capacity can be overshot slightly, as pages can be different sizes.

      Specified by:
      getTupleCapacity in interface WritePageBuffer