java.lang.Object
org.rrd4j.core.RrdPrimitive<U>
Type Parameters:
U - The type of RrdUpdater this primitive belongs to
Direct Known Subclasses:
RrdDouble, RrdDoubleArray, RrdDoubleMatrix, RrdEnum, RrdInt, RrdLong, RrdString

abstract class RrdPrimitive<U extends RrdUpdater<U>>extends Object
Abstract base class for all RRD primitive data types.

This class provides the foundation for storing different types of primitive data (int, long, double, string) in RRD files. It handles the low-level operations of reading and writing bytes to the backend storage, with support for caching and different data type sizes.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final RrdBackend
    Where the value is read and written.
    private final int
    Size of the value on disk, in bytes.
    private final boolean
    False to read every value from the backend.
    private final long
    Offset of the value within the backend.
    (package private) static final int
    Type identifier for double RRD primitives.
    (package private) static final int
    Type identifier for integer RRD primitives.
    (package private) static final int
    Type identifier for long RRD primitives.
    (package private) static final int[]
    Array containing the size in bytes for each RRD primitive type.
    (package private) static final int
    Type identifier for string RRD primitives.
    (package private) static final int
    Maximum length of string values stored in RRD primitives.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RrdPrimitive(RrdUpdater<U> updater, int type, boolean isConstant)
    Allocate a single-slot primitive in the updater's backend storage.
    RrdPrimitive(RrdUpdater<U> updater, int type, int count, boolean isConstant)
    Allocate a primitive array of the given length in the updater's backend storage.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    (package private) final boolean
    Checks if caching is allowed for this primitive.
    (package private) final byte[]
    Raw byte array from backend storage.
    (package private) final double
    Reads the double value from backend storage.
    (package private) final double
    readDouble(int index)
    Position in the primitive array.
    (package private) final double[]
    readDouble(int index, int count)
    Starting position in the primitive array.
    protected final <E extends Enum<E>>
    E
    readEnum(Class<E> clazz)
    Deserialize an enum value from backend storage.
    (package private) final int
    Reads the int value from backend storage.
    (package private) final long
    Reads the long value from backend storage.
    (package private) final String
    Reads the string value from backend storage.
    (package private) final void
    writeBytes(byte[] b)
    Byte array to write to backend storage.
    (package private) final void
    writeDouble(double value)
    Double value to write to backend storage.
    (package private) final void
    writeDouble(int index, double value)
    Position in the primitive array.
    (package private) final void
    writeDouble(int index, double[] values)
    Starting position in the primitive array.
    (package private) final void
    writeDouble(int index, double value, int count)
    Starting position in the primitive array.
    protected final <E extends Enum<E>>
    void
    writeEnum(E value)
    Serialize an enum value to backend storage.
    (package private) final void
    writeInt(int value)
    Int value to write to backend storage.
    (package private) final void
    writeLong(long value)
    Long value to write to backend storage.
    (package private) final void
    String value to write to backend storage.

    Methods inherited from class Object

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

    • STRING_LENGTH

      static final int STRING_LENGTH
      Maximum length of string values stored in RRD primitives.
      See Also:
    • RRD_INT

      static final int RRD_INT
      Type identifier for integer RRD primitives.
      See Also:
    • RRD_LONG

      static final int RRD_LONG
      Type identifier for long RRD primitives.
      See Also:
    • RRD_DOUBLE

      static final int RRD_DOUBLE
      Type identifier for double RRD primitives.
      See Also:
    • RRD_STRING

      static final int RRD_STRING
      Type identifier for string RRD primitives.
      See Also:
    • RRD_PRIM_SIZES

      static final int[] RRD_PRIM_SIZES
      Array containing the size in bytes for each RRD primitive type. Index corresponds to the type constants (RRD_INT, RRD_LONG, RRD_DOUBLE, RRD_STRING).
    • backend

      private final RrdBackend backend
      Where the value is read and written.
    • byteCount

      private final int byteCount
      Size of the value on disk, in bytes.
    • pointer

      private final long pointer
      Offset of the value within the backend.
    • cachingAllowed

      private final boolean cachingAllowed
      False to read every value from the backend.
  • Constructor Details

    • RrdPrimitive

      RrdPrimitive(RrdUpdater<U> updater, int type, boolean isConstant)
      Allocate a single-slot primitive in the updater's backend storage.
      Parameters:
      updater - the updater whose allocator and backend back this primitive
      type - one of the RRD_INT, RRD_LONG, RRD_DOUBLE or RRD_STRING constants, selecting the slot size
      isConstant - true if the value never changes, which permits caching
    • RrdPrimitive

      RrdPrimitive(RrdUpdater<U> updater, int type, int count, boolean isConstant)
      Allocate a primitive array of the given length in the updater's backend storage.
      Parameters:
      updater - the updater whose allocator and backend back this primitive
      type - one of the RRD_INT, RRD_LONG, RRD_DOUBLE or RRD_STRING constants, selecting the slot size
      count - the number of consecutive slots to allocate
      isConstant - true if the value never changes, which permits caching
  • Method Details

    • readBytes

      final byte[] readBytes() throws IOException
      Raw byte array from backend storage.
      Returns:
      the byteCount bytes stored at this primitive's pointer
      Throws:
      IOException - if the backend storage cannot be read
    • writeBytes

      final void writeBytes(byte[] b) throws IOException
      Byte array to write to backend storage.
      Parameters:
      b - byte array to write to backend storage
      Throws:
      IOException - if the backend storage cannot be written
    • readInt

      final int readInt() throws IOException
      Reads the int value from backend storage.
      Returns:
      the value stored at this primitive's pointer
      Throws:
      IOException - if the backend storage cannot be read
    • writeInt

      final void writeInt(int value) throws IOException
      Int value to write to backend storage.
      Parameters:
      value - int value to write to backend storage
      Throws:
      IOException - if the backend storage cannot be written
    • readLong

      final long readLong() throws IOException
      Reads the long value from backend storage.
      Returns:
      the value stored at this primitive's pointer
      Throws:
      IOException - if the backend storage cannot be read
    • writeLong

      final void writeLong(long value) throws IOException
      Long value to write to backend storage.
      Parameters:
      value - long value to write to backend storage
      Throws:
      IOException - if the backend storage cannot be written
    • readDouble

      final double readDouble() throws IOException
      Reads the double value from backend storage.
      Returns:
      the value stored at this primitive's pointer
      Throws:
      IOException - if the backend storage cannot be read
    • readDouble

      final double readDouble(int index) throws IOException
      Position in the primitive array.
      Parameters:
      index - position in the primitive array
      Returns:
      double value at the given array index
      Throws:
      IOException - if the backend storage cannot be read
    • readDouble

      final double[] readDouble(int index, int count) throws IOException
      Starting position in the primitive array.
      Parameters:
      index - starting position in the primitive array
      count - number of consecutive doubles to read
      Returns:
      array of double values
      Throws:
      IOException - if the backend storage cannot be read
    • writeDouble

      final void writeDouble(double value) throws IOException
      Double value to write to backend storage.
      Parameters:
      value - double value to write to backend storage
      Throws:
      IOException - if the backend storage cannot be written
    • writeDouble

      final void writeDouble(int index, double value) throws IOException
      Position in the primitive array.
      Parameters:
      index - position in the primitive array
      value - double value to write
      Throws:
      IOException - if the backend storage cannot be written
    • writeDouble

      final void writeDouble(int index, double value, int count) throws IOException
      Starting position in the primitive array.
      Parameters:
      index - starting position in the primitive array
      value - double value to write
      count - number of consecutive slots to fill
      Throws:
      IOException - if the backend storage cannot be written
    • writeDouble

      final void writeDouble(int index, double[] values) throws IOException
      Starting position in the primitive array.
      Parameters:
      index - starting position in the primitive array
      values - array of doubles to write
      Throws:
      IOException - if the backend storage cannot be written
    • readString

      final String readString() throws IOException
      Reads the string value from backend storage.
      Returns:
      the value stored at this primitive's pointer
      Throws:
      IOException - if the backend storage cannot be read
    • writeString

      final void writeString(String value) throws IOException
      String value to write to backend storage.
      Parameters:
      value - string value to write to backend storage
      Throws:
      IOException - if the backend storage cannot be written
    • readEnum

      protected final <E extends Enum<E>> E readEnum(Class<E> clazz) throws IOException
      Deserialize an enum value from backend storage.
      Type Parameters:
      E - enum type
      Parameters:
      clazz - enum class to deserialize
      Returns:
      the enum value, or null if the stored value is empty
      Throws:
      IOException - if the backend storage cannot be read
    • writeEnum

      protected final <E extends Enum<E>> void writeEnum(E value) throws IOException
      Serialize an enum value to backend storage.
      Type Parameters:
      E - the enum type
      Parameters:
      value - the value to store as its enum constant name
      Throws:
      IOException - if the backend storage cannot be written
    • isCachingAllowed

      final boolean isCachingAllowed()
      Checks if caching is allowed for this primitive.
      Returns:
      true if caching is allowed, false otherwise