Class PageWriter

java.lang.Object
nz.org.riskscape.engine.task.PageWriter

public class PageWriter extends Object

Writes tuples to a buffer 'page'. The WritePageBuffer is potentially shared between multiple WorkerTask threads, and so is thread-safe. The PageWriter 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 WritePageBuffer. The PageWriter 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.

  • 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.
    • isFull

      public boolean isFull()
      Returns:
      true if there's currently no space available to write new tuples to.
    • hasSpace

      public boolean hasSpace()
    • flushPage

      public void flushPage()

      Flushes any unwritten tuples, i.e. we have a partially written page that has not been added to the WritePageBuffer yet (because the page isn't full yet). Note that it is particularly important to always call flushPage() before the worker tasks completes, so that output tuples don't get lost.

    • add

      public void add(nz.org.riskscape.engine.Tuple tuple)

      Adds a tuple to the output WritePageBuffer. Note that you should check isFull() beforehand to avoid over-filling the output buffer.

    • toString

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

      public long getTuplesWritten()
    • getPagesWritten

      public long getPagesWritten()