org.jrobin.core

Class RrdDefTemplate

public class RrdDefTemplate extends XmlTemplate

Class used to create an arbitrary number of RrdDef (RRD definition) objects from a single XML template. XML template can be supplied as an XML InputSource, XML file or XML formatted string.

Here is an example of a properly formatted XML template with all available options in it (unwanted options can be removed):

 <rrd_def>
     <path>test.rrd</path>
     <!-- not mandatory -->
     <start>1000123456</start>
     <!-- not mandatory -->
     <step>300</step>
     <!-- at least one datasource must be supplied -->
     <datasource>
         <name>input</name>
         <type>COUNTER</type>
         <heartbeat>300</heartbeat>
         <min>0</min>
         <max>U</max>
     </datasource>
     <datasource>
         <name>temperature</name>
         <type>GAUGE</type>
         <heartbeat>400</heartbeat>
         <min>U</min>
         <max>1000</max>
     </datasource>
     <!-- at least one archive must be supplied -->
     <archive>
         <cf>AVERAGE</cf>
         <xff>0.5</xff>
         <steps>1</steps>
         <rows>600</rows>
     </archive>
     <archive>
         <cf>MAX</cf>
         <xff>0.6</xff>
         <steps>6</steps>
         <rows>7000</rows>
     </archive>
 </rrd_def>
 
Notes on the template syntax:

Any template value (text between <some_tag> and </some_tag>) can be replaced with a variable of the following form: ${variable_name}. Use setVariable() methods from the base class to replace template variables with real values at runtime.

Typical usage scenario:

You should create new RrdDefTemplate object only once for each XML template. Single template object can be reused to create as many RrdDef objects as needed, with different values specified for template variables. XML synatax check is performed only once - the first definition object gets created relatively slowly, but it will be created much faster next time.
Constructor Summary
RrdDefTemplate(InputSource xmlInputSource)
Creates RrdDefTemplate object from any parsable XML input source.
RrdDefTemplate(String xmlString)
Creates RrdDefTemplate object from the string containing XML template.
RrdDefTemplate(File xmlFile)
Creates RrdDefTemplate object from the file containing XML template.
Method Summary
RrdDefgetRrdDef()
Returns RrdDef object constructed from the underlying XML template.

Constructor Detail

RrdDefTemplate

public RrdDefTemplate(InputSource xmlInputSource)
Creates RrdDefTemplate object from any parsable XML input source. Read general information for this class to find an example of a properly formatted RrdDef XML source.

Parameters: xmlInputSource Xml input source

Throws: IOException Thrown in case of I/O error RrdException Thrown in case of XML related error (parsing error, for example)

RrdDefTemplate

public RrdDefTemplate(String xmlString)
Creates RrdDefTemplate object from the string containing XML template. Read general information for this class to see an example of a properly formatted XML source.

Parameters: xmlString String containing XML template

Throws: IOException Thrown in case of I/O error RrdException Thrown in case of XML related error (parsing error, for example)

RrdDefTemplate

public RrdDefTemplate(File xmlFile)
Creates RrdDefTemplate object from the file containing XML template. Read general information for this class to see an example of a properly formatted XML source.

Parameters: xmlFile File object representing file with XML template

Throws: IOException Thrown in case of I/O error RrdException Thrown in case of XML related error (parsing error, for example)

Method Detail

getRrdDef

public RrdDef getRrdDef()
Returns RrdDef object constructed from the underlying XML template. Before this method is called, values for all non-optional placeholders must be supplied. To specify placeholder values at runtime, use some of the overloaded setVariable() methods. Once this method returns, all placeholder values are preserved. To remove them all, call inhereted clearValues() method explicitly.

Returns: RrdDef object constructed from the underlying XML template, with all placeholders replaced with real values. This object can be passed to the constructor of the new RrdDb object.

Throws: RrdException Thrown (in most cases) if the value for some placeholder was not supplied through setVariable() method call