java.lang.Object
org.rrd4j.core.Header
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionNumber of archives in the file.(package private) static final StringDefault signature string for RRD files created by RRD4J.Number of data sources in the file.Time of the most recent update, in epoch seconds.private final RrdDbThe database whose header this is.(package private) static final StringVersion identifier for RRDTool version 1 compatibility.(package private) static final StringVersion identifier for RRDTool version 3 compatibility.The file's signature text.(package private) static final StringRRD4J signature string used to identify RRD4J files.(package private) static final intLength of the RRD signature string.Base time step of the file, in seconds.private intIndex into VERSIONS, -1 until read.private static final String[]The RRD file versions this library can read.Constructor Summary
ConstructorsConstructorDescriptionHeader(RrdDb parentDb, DataImporter reader) Construct a header from an imported RRDtool file, mapping its version string onto the RRD4J version number.Construct a header from a definition, taking the version, step, arc and archive counts and start time from it.Method Summary
Public MethodsModifier and TypeMethodDescription(package private) voidAppends header information to XML writer.voidcopyStateTo(Header header) Copies object's internal state to another Header object.(package private) Stringdump()Returns a string representation of the header information.intReturns the number of archives defined in the RRD.intReturns the number of datasources defined in the RRD.getInfo()Reads the info string following the signature prefix.longReturns the last update time of the RRD.Required to implement RrdUpdater interface.Returns the underlying storage (backend) object which actually performs all I/O operations.Returns RRD signature.longgetStep()Returns primary RRD time step.intReturn the RRD version.(package private) booleanTrue if the header matches RRD4J or JRobin format.voidOverride the info portion of the RRD signature.(package private) voidsetLastUpdateTime(long lastUpdateTime) Sets the last update time of the RRD.(package private) voidInvalidRrdException if the header is not a valid RRD4J/RRD file.
Field Details
SIGNATURE_LENGTH
SIGNATURE
RRD4J signature string used to identify RRD4J files.- See Also:
DEFAULT_SIGNATURE
Default signature string for RRD files created by RRD4J.- See Also:
RRDTOOL_VERSION1
Version identifier for RRDTool version 1 compatibility.- See Also:
RRDTOOL_VERSION3
Version identifier for RRDTool version 3 compatibility.- See Also:
VERSIONS
The RRD file versions this library can read.parentDb
The database whose header this is.version
private int versionIndex into VERSIONS, -1 until read.signature
step
dsCount
arcCount
lastUpdateTime
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 torrdDef- 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 toreader- the importer positioned at the header of a foreign RRD file- Throws:
IllegalArgumentException- if the imported version is not one this reader supportsIOException- if the underlying backend cannot be read
Method Details
getSignature
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
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
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
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
Returns primary RRD time step.- Returns:
- Primary time step in seconds
- Throws:
IOException- Thrown in case of I/O error
getDsCount
Returns the number of datasources defined in the RRD.- Returns:
- Number of datasources defined
- Throws:
IOException- Thrown in case of I/O error
getArcCount
Returns the number of archives defined in the RRD.- Returns:
- Number of archives defined
- Throws:
IOException- Thrown in case of I/O error
setLastUpdateTime
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
Returns a string representation of the header information.- Returns:
- a string containing header information
- Throws:
IOException- if an I/O error occurs
appendXml
Appends header information to XML writer.- Parameters:
writer- the XML writer to append to- Throws:
IOException- if an I/O error occurs
copyStateTo
Copies object's internal state to another Header object.
- Specified by:
copyStateToin interfaceRrdUpdater<Header>- Parameters:
header- aRrdUpdaterobject.- Throws:
IOException- if the state cannot be read from the backend
getRrdBackend
Returns the underlying storage (backend) object which actually performs all I/O operations.- Specified by:
getRrdBackendin interfaceRrdUpdater<Header>- Returns:
- I/O backend object
getVersion
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
InvalidRrdException if the header is not a valid RRD4J/RRD file.- Throws:
InvalidRrdException- if the header is not a valid RRD4J/RRD fileIOException
getRrdAllocator
Required to implement RrdUpdater interface. You should never call this method directly.- Specified by:
getRrdAllocatorin interfaceRrdUpdater<Header>- Returns:
- the allocator owning the canonical numeric representation of this header's values