java.lang.Object
org.rrd4j.core.RrdBackend
org.rrd4j.core.RrdRandomAccessFileBackend
All Implemented Interfaces:
RrdFileBackend
Direct Known Subclasses:
RrdSafeFileBackend

public class RrdRandomAccessFileBackendextends RrdBackend implements RrdFileBackend
Backend which is used to store RRD data to ordinary files on the disk. This was the default factory before 1.4.0 version. This backend is based on the RandomAccessFile class (java.io.* package).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final RandomAccessFile
    Random access file handle.

    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
    RrdRandomAccessFileBackend(String path, boolean readOnly)
    Creates RrdFileBackend object for the given file path, backed by RandomAccessFile object.
  • Method Summary

    Public Methods
    Modifier and Type
    Method
    Description
    protected void
    Closes the underlying RRD file.
    Returns canonical path to the file on the disk.
    long
    Returns the number of RRD bytes in the underlying storage.
    void
    read(long offset, byte[] b)
    Reads a number of bytes from the RRD file on the disk
    protected void
    setLength(long length)
    Sets the number of bytes in the underlying RRD storage.
    protected void
    write(long offset, byte[] b)
    Writes bytes to the underlying RRD file on the disk

    Methods inherited from class RrdBackend

    done, getCharBuffer, getFactory, getPath, getUri, isCachingAllowed, isInstanceCreated, readAll, readDouble, readDouble, readInt, readLong, readShort, readString, rrdClose, writeDouble, writeDouble, writeDouble, writeInt, writeLong, writeShort, writeString, writeString
    Modifier and Type
    Method
    Description
    (package private) void
    Set the factory and reference for this backend.
    protected CharBuffer
    getCharBuffer(long offset, int size)
    Extract a CharBuffer from the backend, used by readString
    Get the factory for this backend.
    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 double
    readDouble(long offset)
    Reads a double value from the underlying storage at the given offset.
    protected 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 final String
    readString(long offset)
    Reads a string from the underlying storage at the given offset.
    protected void
    Closes the underlying backend.
    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 final void
    writeString(long offset, String value)
    Writes a string 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 Object

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

  • Constructor Details

    • RrdRandomAccessFileBackend

      protected RrdRandomAccessFileBackend(String path, boolean readOnly) throws IOException
      Creates RrdFileBackend object for the given file path, backed by RandomAccessFile object.
      Parameters:
      path - Path to a file
      readOnly - True, if file should be open in a read-only mode. False otherwise
      Throws:
      IOException - Thrown in case of I/O error
  • Method Details

    • close

      protected void close() throws IOException
      Closes the underlying RRD file.
      Specified by:
      close in class RrdBackend
      Throws:
      IOException - Thrown in case of I/O error
    • 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 - Thrown in case of I/O error
    • read

      public 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.
    • getCanonicalPath

      public String getCanonicalPath()
      Description copied from interface: RrdFileBackend
      Returns canonical path to the file on the disk.
      Specified by:
      getCanonicalPath in interface RrdFileBackend
      Returns:
      Canonical file path
    • getLength

      public long getLength() throws IOException
      Returns the number of RRD bytes in the underlying storage.
      Specified by:
      getLength in class RrdBackend
      Returns:
      Number of RRD bytes in the storage.
      Throws:
      IOException - Thrown in case of I/O error.
    • setLength

      protected void setLength(long length) throws IOException
      Sets the number of bytes in the underlying RRD storage. This method is called only once, immediately after a new RRD storage gets created.

      Sets length of the underlying RRD file. This method is called only once, immediately after a new RRD file gets created.

      Specified by:
      setLength in class RrdBackend
      Parameters:
      length - Length of the underlying RRD storage in bytes.
      Throws:
      IOException - Thrown in case of I/O error.