java.lang.Object
org.rrd4j.core.RobinArray
All Implemented Interfaces:
Robin, RrdUpdater<Robin>

class RobinArrayextends Object implements Robin
Class to represent archive values for a single datasource. Robin class is the heart of the so-called "round robin database" concept. Basically, each Robin object is a fixed length array of double values. Each double value represents consolidated, archived value for the specific timestamp. When the underlying array of double values gets completely filled, new values will replace the oldest ones.

Robin object does not hold values in memory - such object could be quite large. Instead of it, Robin reads them from the backend I/O only when necessary.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Archive
    The archive whose values are stored.
    private final RrdInt<Robin>
    Where the next value is written.
    private final int
    How many values the ring holds.
    private final RrdDoubleArray<Robin>
    The stored values, in a ring.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RobinArray(Archive parentArc, int rows, boolean shouldInitialize)
    Create robin array
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    void
    bulkStore(double newValue, int bulkCount)
    Appends one value repeatedly, for bulk updates.
    void
    Copies object's internal state to another Robin object.
    Renders the current row and values as text.
    void
    filterValues(double minValue, double maxValue)
    Filters values stored in this archive based on the given boundary.
    Fetches the archive this array belongs to.
    Fetches the parent archive's allocator.
    Fetches the parent archive's backend.
    int
    Counts the rows this array stores.
    double
    getValue(int index)
    Returns the i-th value from the Robin archive.
    double[]
    Getter for the field values.
    double[]
    getValues(int index, int count)
    Reads a run of values starting at a row index.
    void
    setValue(int index, double value)
    Sets the i-th value in the Robin archive.
    void
    setValues(double newValue)
    (Re)sets all values in this archive to the same value.
    void
    setValues(double... newValues)
    Updates archived values in bulk.
    void
    store(double newValue)
    Appends a single value at the current row pointer.
    void
    update(double[] newValues)
    Writes a full row of values into the archive.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • parentArc

      private final Archive parentArc
      The archive whose values are stored.
    • pointer

      private final RrdInt<Robin> pointer
      Where the next value is written.
    • values

      private final RrdDoubleArray<Robin> values
      The stored values, in a ring.
    • rows

      private final int rows
      How many values the ring holds.
  • Constructor Details

    • RobinArray

      RobinArray(Archive parentArc, int rows, boolean shouldInitialize) throws IOException
      Create robin array
      Parameters:
      parentArc - the archive whose single datasource this array stores
      rows - the number of rows the array holds, which fixes its size
      shouldInitialize - true to zero the pointer and fill the rows with NaN, false to leave whatever the storage already holds
      Throws:
      IOException - if the underlying storage cannot be written
  • Method Details

    • getValues

      public double[] getValues() throws IOException
      Getter for the field values.
      Specified by:
      getValues in interface Robin
      Returns:
      an array of double.
      Throws:
      IOException - if the backing file cannot be read.
    • store

      public void store(double newValue) throws IOException
      Appends a single value at the current row pointer.
      Specified by:
      store in interface Robin
      Parameters:
      newValue - a double.
      Throws:
      IOException - Thrown in case of I/O error
    • bulkStore

      public void bulkStore(double newValue, int bulkCount) throws IOException
      Appends one value repeatedly, for bulk updates.
      Specified by:
      bulkStore in interface Robin
      Parameters:
      newValue - a double.
      bulkCount - a int.
      Throws:
      IOException - Thrown in case of I/O error
    • update

      public void update(double[] newValues) throws IOException
      Writes a full row of values into the archive.
      Specified by:
      update in interface Robin
      Parameters:
      newValues - an array of double.
      Throws:
      IOException - if the backing file cannot be read.
    • setValues

      public void setValues(double... newValues) throws IOException
      Updates archived values in bulk.
      Specified by:
      setValues in interface Robin
      Parameters:
      newValues - Array of double values to be stored in the archive
      Throws:
      IOException - Thrown in case of I/O error
    • setValues

      public void setValues(double newValue) throws IOException
      (Re)sets all values in this archive to the same value.
      Specified by:
      setValues in interface Robin
      Parameters:
      newValue - New value
      Throws:
      IOException - Thrown in case of I/O error
    • dump

      public String dump() throws IOException
      Renders the current row and values as text.
      Specified by:
      dump in interface Robin
      Returns:
      a String object.
      Throws:
      IOException - if the backing file cannot be read.
    • getValue

      public double getValue(int index) throws IOException
      Returns the i-th value from the Robin archive.
      Specified by:
      getValue in interface Robin
      Parameters:
      index - Value index
      Returns:
      Value stored in the i-th position (the oldest value has zero index)
      Throws:
      IOException - Thrown in case of I/O specific error.
    • setValue

      public void setValue(int index, double value) throws IOException
      Sets the i-th value in the Robin archive.
      Specified by:
      setValue in interface Robin
      Parameters:
      index - index in the archive (the oldest value has zero index)
      value - value to be stored
      Throws:
      IOException - Thrown in case of I/O specific error.
    • getValues

      public double[] getValues(int index, int count) throws IOException
      Reads a run of values starting at a row index.
      Specified by:
      getValues in interface Robin
      Parameters:
      index - a int.
      count - a int.
      Returns:
      an array of double.
      Throws:
      IOException - Thrown in case of I/O error
    • getParent

      public Archive getParent()
      Fetches the archive this array belongs to.
      Specified by:
      getParent in interface Robin
      Returns:
      a Archive object.
    • getSize

      public int getSize()
      Counts the rows this array stores.
      Specified by:
      getSize in interface Robin
      Returns:
      the fixed capacity, so that valid row indexes run from 0 to this value exclusive
    • copyStateTo

      public void copyStateTo(Robin robin) throws IOException

      Copies object's internal state to another Robin object.

      Specified by:
      copyStateTo in interface Robin
      Specified by:
      copyStateTo in interface RrdUpdater<Robin>
      Parameters:
      robin - a RrdUpdater object.
      Throws:
      IOException - if the state cannot be read from the backend
    • filterValues

      public void filterValues(double minValue, double maxValue) throws IOException
      Filters values stored in this archive based on the given boundary. Archived values found to be outside of [minValue, maxValue] interval (inclusive) will be silently replaced with NaN.
      Specified by:
      filterValues in interface Robin
      Parameters:
      minValue - inclusive lower bound; values below it become NaN
      maxValue - inclusive upper bound; values above it become NaN
      Throws:
      IOException - Thrown in case of I/O error
    • getRrdBackend

      public RrdBackend getRrdBackend()
      Fetches the parent archive's backend.
      Specified by:
      getRrdBackend in interface Robin
      Specified by:
      getRrdBackend in interface RrdUpdater<Robin>
      Returns:
      a RrdBackend object.
    • getRrdAllocator

      public RrdAllocator getRrdAllocator()
      Fetches the parent archive's allocator.
      Specified by:
      getRrdAllocator in interface Robin
      Specified by:
      getRrdAllocator in interface RrdUpdater<Robin>
      Returns:
      a RrdAllocator object.