Class PageReader

java.lang.Object
nz.org.riskscape.engine.task.PageReader
All Implemented Interfaces:
AutoCloseable, Iterator<nz.org.riskscape.engine.Tuple>, nz.org.riskscape.engine.relation.TupleIterator

public class PageReader extends Object implements nz.org.riskscape.engine.relation.TupleIterator

Reads tuples from a buffer 'page'. The ReadPageBuffer is potentially shared between multiple WorkerTask threads, and so is thread-safe. The PageReader is not thread-safe, however, it should only ever belong to a single WorkerTask (so there's no potential contention). Each WorkerTask deals with its own page, which they get one at a time from the ReadPageBuffer. The PageReader manages the page for a WorkerTask - it tracks where in the current page the task is up to and whether it needs a new one. Note that because the pipeline can potentially consume a lot of memory, we want to drop any references to tuple pages as soon as possible. Centralizing the page reading logic helps with that.

  • Field Summary

    Fields inherited from interface nz.org.riskscape.engine.relation.TupleIterator

    EMPTY
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
     
    long
     
    boolean
    Returns true if there is something for a worker task to do, i.e.
    boolean
     
    boolean
     
    boolean
     
    nz.org.riskscape.engine.Tuple
    Returns the next tuple in the page.
    nz.org.riskscape.engine.Tuple
    Returns the Tuple that will be returned by next() without advancing where we are currently up to in the page.
     

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface java.util.Iterator

    remove

    Methods inherited from interface nz.org.riskscape.engine.relation.TupleIterator

    close, collect, forEachRemaining
  • Constructor Details

  • Method Details

    • hasPageInProgress

      public boolean hasPageInProgress()
      Returns:
      true if there is currently a page we're in the middle of reading. Note that this is particularly important as a worker task should never complete while it still has a page in progress.
    • hasInput

      public boolean hasInput()

      Returns true if there is something for a worker task to do, i.e. there are tuples available to read.

    • isComplete

      public boolean isComplete()
      Returns:
      true if there are no more tuples left to read
    • peek

      public nz.org.riskscape.engine.Tuple peek()

      Returns the Tuple that will be returned by next() without advancing where we are currently up to in the page. Use this if you might have to stop halfway through processing a tuple and come back to it later, e.g. when the output buffer is full. (If it happens to be the last tuple in the page, then this prevents the PageWriter from incorrectly thinking the task worker is finished with the page.

      Returns:
      the next tuple to read, or null if there's no input available
    • next

      public nz.org.riskscape.engine.Tuple next()

      Returns the next tuple in the page. This handles reading a new page from the ReadPageBuffer if needed.

      Specified by:
      next in interface Iterator<nz.org.riskscape.engine.Tuple>
      Returns:
      the next tuple to read, or null if there's no input available
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<nz.org.riskscape.engine.Tuple>
      Returns:
      whether there is a next tuple available to read. Returning false means there's no tuple currently available to read (but there may be later, as more input gets added to the underlying PageBuffer.
    • toString

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

      public long getTuplesRead()
    • getPagesRead

      public long getPagesRead()