java.lang.Object
org.rrd4j.core.Header
All Implemented Interfaces:
RrdUpdater<Header>

public class Headerextends Object implements RrdUpdater<Header>
Class to represent RRD header. Header information is mainly static (once set, it cannot be changed), with the exception of last update time (this value is changed whenever RRD gets updated).

Normally, you don't need to manipulate the Header object directly - Rrd4j framework does it for you.

This header contains metadata about the RRD file.

  • Field Details

    • SIGNATURE_LENGTH

      static final int SIGNATURE_LENGTH
      Length of the RRD signature string.
      See Also:
    • SIGNATURE

      static final String SIGNATURE
      RRD4J signature string used to identify RRD4J files.
      See Also:
    • DEFAULT_SIGNATURE

      static final String DEFAULT_SIGNATURE
      Default signature string for RRD files created by RRD4J.
      See Also:
    • RRDTOOL_VERSION1

      static final String RRDTOOL_VERSION1
      Version identifier for RRDTool version 1 compatibility.
      See Also:
    • RRDTOOL_VERSION3

      static final String RRDTOOL_VERSION3
      Version identifier for RRDTool version 3 compatibility.
      See Also:
    • VERSIONS

      private static final String[] VERSIONS
      The RRD file versions this library can read.
    • parentDb

      private final RrdDb parentDb
      The database whose header this is.
    • version

      private int version
      Index into VERSIONS, -1 until read.
    • signature

      private final RrdString<Header> signature
      The file's signature text.
    • step

      private final RrdLong<Header> step
      Base time step of the file, in seconds.
    • dsCount

      private final RrdInt<Header> dsCount
      Number of data sources in the file.
    • arcCount

      private final RrdInt<Header> arcCount
      Number of archives in the file.
    • lastUpdateTime

      private final RrdLong<Header> lastUpdateTime
      Time of the most recent update, in epoch seconds.
  • Constructor Details

    • Header

      Header(RrdDb parentDb, RrdDef rrdDef) throws IOException
      Construct a header from a definition, taking the version, step, arc and archive counts and start time from it. A null definition leaves the fields unset.
      Parameters:
      parentDb - the database this header belongs to
      rrdDef - the definition supplying the initial values, or null to leave them unset
      Throws:
      IOException - never thrown, declared for signature compatibility
    • Header

      Header(RrdDb parentDb, DataImporter reader) throws IOException
      Construct a header from an imported RRDtool file, mapping its version string onto the RRD4J version number.
      Parameters:
      parentDb - the database this header belongs to
      reader - the importer positioned at the header of a foreign RRD file
      Throws:
      IllegalArgumentException - if the imported version is not one this reader supports
      IOException - if the underlying backend cannot be read
  • Method Details

    • getSignature

      public String getSignature() throws IOException
      Returns RRD signature. Initially, the returned string will be of the form Rrd4j, version x.x.
      Returns:
      the RRD signature, identifying the file as RRD4J and its version
      Throws:
      IOException - if the signature cannot be read from the backend
    • getInfo

      public String getInfo() throws IOException
      Reads the info string following the signature prefix.
      Returns:
      the info string (everything after the signature prefix)
      Throws:
      IOException - if an I/O error occurs
    • setInfo

      public void setInfo(String info) throws IOException
      Override the info portion of the RRD signature.
      Parameters:
      info - the new info string, or null/empty to clear it
      Throws:
      IOException - if an I/O error occurs
    • getLastUpdateTime

      public long getLastUpdateTime() throws IOException
      Returns the last update time of the RRD.
      Returns:
      Timestamp (Unix epoch, no milliseconds) corresponding to the last update time.
      Throws:
      IOException - Thrown in case of I/O error
    • getStep

      public long getStep() throws IOException
      Returns primary RRD time step.
      Returns:
      Primary time step in seconds
      Throws:
      IOException - Thrown in case of I/O error
    • getDsCount

      public int getDsCount() throws IOException
      Returns the number of datasources defined in the RRD.
      Returns:
      Number of datasources defined
      Throws:
      IOException - Thrown in case of I/O error
    • getArcCount

      public int getArcCount() throws IOException
      Returns the number of archives defined in the RRD.
      Returns:
      Number of archives defined
      Throws:
      IOException - Thrown in case of I/O error
    • setLastUpdateTime

      void setLastUpdateTime(long lastUpdateTime) throws IOException
      Sets the last update time of the RRD.
      Parameters:
      lastUpdateTime - the last update time (Unix epoch)
      Throws:
      IOException - if an I/O error occurs
    • dump

      String dump() throws IOException
      Returns a string representation of the header information.
      Returns:
      a string containing header information
      Throws:
      IOException - if an I/O error occurs
    • appendXml

      void appendXml(XmlWriter writer) throws IOException
      Appends header information to XML writer.
      Parameters:
      writer - the XML writer to append to
      Throws:
      IOException - if an I/O error occurs
    • copyStateTo

      public void copyStateTo(Header header) throws IOException

      Copies object's internal state to another Header object.

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

      public RrdBackend getRrdBackend()
      Returns the underlying storage (backend) object which actually performs all I/O operations.
      Specified by:
      getRrdBackend in interface RrdUpdater<Header>
      Returns:
      I/O backend object
    • getVersion

      public int getVersion() throws IOException
      Return the RRD version.
      Returns:
      the RRD version number, 1 or 2
      Throws:
      IOException - if the signature cannot be read from the backend to determine it
    • isRrd4jHeader

      boolean isRrd4jHeader()
      True if the header matches RRD4J or JRobin format.
      Returns:
      true if the signature starts with RRD4J or JR, false on read errors
    • validateHeader

      void validateHeader() throws IOException
      InvalidRrdException if the header is not a valid RRD4J/RRD file.
      Throws:
      InvalidRrdException - if the header is not a valid RRD4J/RRD file
      IOException
    • getRrdAllocator

      public RrdAllocator getRrdAllocator()
      Required to implement RrdUpdater interface. You should never call this method directly.
      Specified by:
      getRrdAllocator in interface RrdUpdater<Header>
      Returns:
      the allocator owning the canonical numeric representation of this header's values