java.lang.Object
org.rrd4j.core.RrdBackend
org.rrd4j.core.ByteBufferBackend
Direct Known Subclasses:
RrdByteArrayBackend, RrdMemoryBackend, RrdNioBackend

public abstract class ByteBufferBackendextends RrdBackend
A backend that store and provides access to data using a ByteBuffer, using java internal methods for long, integer and others types.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private ByteBuffer
    The file contents held in memory.
    private boolean
    True while the buffer holds changes not yet written.

    Fields inherited from class RrdBackend

    BYTEORDER
    Modifier and Type
    Field
    Description
    protected static final ByteOrder
    All ByteBuffer usage should use this standard order.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructs a ByteBufferBackend with the given file path.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Ensure that the conversion from long offset to integer offset will not overflow
    protected void
    Closes the underlying backend.
    protected CharBuffer
    getCharBuffer(long offset, int size)
    Extract a CharBuffer from the backend, used by readString
    protected boolean
    Check whether the buffer has been modified since the last sync.
    protected void
    read(long offset, byte[] b)
    Reads a number of bytes from the RRD file on the disk
    double
    readDouble(long offset)
    Reads a double value from the underlying storage at the given offset.
    double[]
    readDouble(long offset, int count)
    Reads an array of double values from the underlying storage at the given offset.
    protected int
    readInt(long offset)
    Reads an integer value from the underlying storage at the given offset.
    protected long
    readLong(long offset)
    Reads a long value from the underlying storage at the given offset.
    protected short
    readShort(long offset)
    Reads a short value from the underlying storage at the given offset.
    protected void
    Closes the underlying backend.
    protected void
    Set the byte buffer to use for backing storage.
    protected void
    write(long offset, byte[] b)
    Writes bytes to the underlying RRD file on the disk
    protected void
    writeDouble(long offset, double value)
    Writes a double value to the underlying storage at the given offset.
    protected void
    writeDouble(long offset, double[] values)
    Writes an array of double values to the underlying storage at the given offset.
    protected void
    writeDouble(long offset, double value, int count)
    Writes multiple copies of a double value to the underlying storage at the given offset.
    protected void
    writeInt(long offset, int value)
    Writes an integer value to the underlying storage at the given offset.
    protected void
    writeLong(long offset, long value)
    Writes a long value to the underlying storage at the given offset.
    protected void
    writeShort(long offset, short value)
    Writes a short value to the underlying storage at the given offset.
    protected void
    writeString(long offset, String value, int length)
    Writes a string to the underlying storage at the given offset with a fixed length.

    Methods inherited from class RrdBackend

    done, getFactory, getLength, getPath, getUri, isCachingAllowed, isInstanceCreated, readAll, readString, setLength, writeString
    Modifier and Type
    Method
    Description
    (package private) void
    Set the factory and reference for this backend.
    Get the factory for this backend.
    abstract long
    Returns the number of RRD bytes in the underlying storage.
    Returns path to the storage.
    Return the URI associated to this backend, using the factory to generate it from the path.
    protected boolean
    This method suggests the caching policy to the Rrd4j frontend (high-level) classes.
    (package private) static boolean
    Checks if a backend instance has been created.
    final byte[]
    Reads all RRD bytes from the underlying storage.
    protected final String
    readString(long offset)
    Reads a string from the underlying storage at the given offset.
    protected abstract void
    setLength(long length)
    Sets the number of bytes in the underlying RRD storage.
    protected final void
    writeString(long offset, String value)
    Writes a string to the underlying storage at the given offset.

    Methods inherited from class Object

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

    • dirty

      private volatile boolean dirty
      True while the buffer holds changes not yet written.
    • byteBuffer

      private ByteBuffer byteBuffer
      The file contents held in memory.
  • Constructor Details

    • ByteBufferBackend

      protected ByteBufferBackend(String path)
      Constructs a ByteBufferBackend with the given file path.
      Parameters:
      path - the file path
  • Method Details

    • setByteBuffer

      protected void setByteBuffer(ByteBuffer byteBuffer)
      Set the byte buffer to use for backing storage.
      Parameters:
      byteBuffer - the byte buffer to set
    • write

      protected void write(long offset, byte[] b) throws IOException
      Writes bytes to the underlying RRD file on the disk
      Specified by:
      write in class RrdBackend
      Parameters:
      offset - Starting file offset
      b - Bytes to be written.
      Throws:
      IOException - if the backend is read-only
      IllegalArgumentException - if offset is bigger that the possible mapping position (2GiB).
    • writeShort

      protected void writeShort(long offset, short value) throws IOException
      Description copied from class: RrdBackend
      Writes a short value to the underlying storage at the given offset.
      Overrides:
      writeShort in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      value - Short value to write.
      Throws:
      IOException - Thrown in case of I/O error.
    • writeInt

      protected void writeInt(long offset, int value) throws IOException
      Description copied from class: RrdBackend
      Writes an integer value to the underlying storage at the given offset.
      Overrides:
      writeInt in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      value - Integer value to write.
      Throws:
      IOException - Thrown in case of I/O error.
    • writeLong

      protected void writeLong(long offset, long value) throws IOException
      Description copied from class: RrdBackend
      Writes a long value to the underlying storage at the given offset.
      Overrides:
      writeLong in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      value - Long value to write.
      Throws:
      IOException - Thrown in case of I/O error.
    • writeDouble

      protected void writeDouble(long offset, double value) throws IOException
      Description copied from class: RrdBackend
      Writes a double value to the underlying storage at the given offset.
      Overrides:
      writeDouble in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      value - Double value to write.
      Throws:
      IOException - Thrown in case of I/O error.
    • writeDouble

      protected void writeDouble(long offset, double value, int count) throws IOException
      Description copied from class: RrdBackend
      Writes multiple copies of a double value to the underlying storage at the given offset.
      Overrides:
      writeDouble in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      value - Double value to write.
      count - Number of times to write the value.
      Throws:
      IOException - Thrown in case of I/O error.
    • writeDouble

      protected void writeDouble(long offset, double[] values) throws IOException
      Description copied from class: RrdBackend
      Writes an array of double values to the underlying storage at the given offset.
      Overrides:
      writeDouble in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      values - Array of double values to write.
      Throws:
      IOException - Thrown in case of I/O error.
    • writeString

      protected void writeString(long offset, String value, int length) throws IOException
      Description copied from class: RrdBackend
      Writes a string to the underlying storage at the given offset with a fixed length.
      Overrides:
      writeString in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      value - String value to write.
      length - Fixed length for the string storage.
      Throws:
      IOException - Thrown in case of I/O error.
    • read

      protected void read(long offset, byte[] b) throws IOException
      Reads a number of bytes from the RRD file on the disk
      Specified by:
      read in class RrdBackend
      Parameters:
      offset - Starting file offset
      b - Buffer which receives bytes read from the file.
      Throws:
      IOException - Thrown in case of I/O error.
      IllegalArgumentException - if offset is bigger that the possible mapping position (2GiB).
    • readShort

      protected short readShort(long offset) throws IOException
      Description copied from class: RrdBackend
      Reads a short value from the underlying storage at the given offset.
      Overrides:
      readShort in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      Returns:
      The short value read from storage.
      Throws:
      IOException - Thrown in case of I/O error.
    • readInt

      protected int readInt(long offset) throws IOException
      Description copied from class: RrdBackend
      Reads an integer value from the underlying storage at the given offset.
      Overrides:
      readInt in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      Returns:
      The integer value read from storage.
      Throws:
      IOException - Thrown in case of I/O error.
    • readLong

      protected long readLong(long offset) throws IOException
      Description copied from class: RrdBackend
      Reads a long value from the underlying storage at the given offset.
      Overrides:
      readLong in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      Returns:
      The long value read from storage.
      Throws:
      IOException - Thrown in case of I/O error.
    • readDouble

      public double readDouble(long offset) throws IOException
      Description copied from class: RrdBackend
      Reads a double value from the underlying storage at the given offset.
      Overrides:
      readDouble in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      Returns:
      The double value read from storage.
      Throws:
      IOException - Thrown in case of I/O error.
    • readDouble

      public double[] readDouble(long offset, int count) throws IOException
      Description copied from class: RrdBackend
      Reads an array of double values from the underlying storage at the given offset.
      Overrides:
      readDouble in class RrdBackend
      Parameters:
      offset - Byte offset into the RRD storage.
      count - Number of double values to read.
      Returns:
      Array of double values read from storage.
      Throws:
      IOException - Thrown in case of I/O error.
    • getCharBuffer

      protected CharBuffer getCharBuffer(long offset, int size) throws RrdException
      Description copied from class: RrdBackend
      Extract a CharBuffer from the backend, used by readString
      Overrides:
      getCharBuffer in class RrdBackend
      Parameters:
      offset - the offset in the rrd
      size - the size of the buffer, in character
      Returns:
      a new CharBuffer
      Throws:
      RrdException
    • close

      protected void close() throws IOException
      Description copied from class: RrdBackend
      Closes the underlying backend. Used internally, should not be called from external code.
      Specified by:
      close in class RrdBackend
      Throws:
      IOException - Thrown in case of I/O error
    • checkOffsetAndByteBuffer

      private void checkOffsetAndByteBuffer(long offset) throws RrdException
      Ensure that the conversion from long offset to integer offset will not overflow
      Parameters:
      offset - the position in the file, from 0 to Integer.MAX_VALUE
      Throws:
      RrdException - if the backing buffer is null (empty rrd)
      IllegalArgumentException - if the offset is negative or too large
    • isDirty

      protected boolean isDirty()
      Check whether the buffer has been modified since the last sync.
      Returns:
      true if the buffer has been modified since last sync
    • rrdClose

      protected void rrdClose() throws IOException
      Description copied from class: RrdBackend
      Closes the underlying backend. Call by RrdDb#close() when it's closed. All subclass must keep calling it.
      Overrides:
      rrdClose in class RrdBackend
      Throws:
      IOException - Thrown in case of I/O error