public class RrdDefTemplate extends XmlTemplate
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:
RrdDef
class methods. If you are not sure what some XML tag means, check javadoc
for the corresponding class.
<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:
<rrd_def> <path>${path}</path> <step>300</step> ...
RrdDefTemplate t = new RrdDefTemplate(new File(template.xml));
t.setVariable("path", "demo/test.rrd");
RrdDef def = t.getRrdDef(); RrdDb rrd = new RrdDb(def); rrd.close();
root
Constructor and Description |
---|
RrdDefTemplate(File xmlFile)
Creates RrdDefTemplate object from the file containing XML template.
|
RrdDefTemplate(InputSource xmlInputSource)
Creates RrdDefTemplate object from any parsable XML input source.
|
RrdDefTemplate(String xmlString)
Creates RrdDefTemplate object from the string containing XML template.
|
Modifier and Type | Method and Description |
---|---|
RrdDef |
getRrdDef()
Returns RrdDef object constructed from the underlying XML template.
|
clearValues, getChildNodes, getChildNodes, getChildValue, getChildValue, getChildValueAsBoolean, getChildValueAsDouble, getChildValueAsInt, getChildValueAsLong, getFirstChildNode, getValue, getValue, getValueAsBoolean, getValueAsColor, getValueAsDouble, getValueAsInt, getValueAsLong, getVariables, hasChildNode, hasVariables, isEmptyNode, setVariable, setVariable, setVariable, setVariable, setVariable, setVariable, setVariable, setVariable, validateTagsOnlyOnce
public RrdDefTemplate(InputSource xmlInputSource) throws IOException
xmlInputSource
- Xml input sourceIOException
- Thrown in case of I/O errorIllegalArgumentException
- Thrown in case of XML related error (parsing error, for example)public RrdDefTemplate(String xmlString) throws IOException
xmlString
- String containing XML templateIOException
- Thrown in case of I/O errorIllegalArgumentException
- Thrown in case of XML related error (parsing error, for example)public RrdDefTemplate(File xmlFile) throws IOException
xmlFile
- File object representing file with XML templateIOException
- Thrown in case of I/O errorIllegalArgumentException
- Thrown in case of XML related error (parsing error, for example)public RrdDef getRrdDef()
setVariable()
methods. Once this method
returns, all placeholder values are preserved. To remove them all, call inherited
clearValues()
method explicitly.IllegalArgumentException
- Thrown (in most cases) if the value for some placeholder
was not supplied through setVariable()
method callCopyright © 2015. All rights reserved.