You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(11) |
Oct
(60) |
Nov
(68) |
Dec
(10) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(10) |
Feb
(15) |
Mar
(30) |
Apr
(20) |
May
(32) |
Jun
(30) |
Jul
(61) |
Aug
(13) |
Sep
(14) |
Oct
(13) |
Nov
(28) |
Dec
(10) |
| 2005 |
Jan
(7) |
Feb
(5) |
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
|
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(15) |
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(20) |
Aug
(35) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(14) |
Sep
(2) |
Oct
|
Nov
|
Dec
|
| 2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <sa...@us...> - 2004-02-23 16:03:18
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11576/org/jrobin/core Added Files: RrdDefTemplate.java XmlTemplate.java Log Message: XML templates revisited --- NEW FILE: RrdDefTemplate.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.core; import org.xml.sax.InputSource; import org.w3c.dom.Node; import java.io.IOException; import java.io.File; /** * Class to represent RrdDef XML template. Use this class to produce similar RRD definitions * (RrdDef objects) from the same XML template. Use <code>${placeholder_name}</code> placeholders * in the XML source to mark XML code which will be modified (replaced) at run time.<p> * * Here is a self-explaining example of a valid XML definition:<p> * * <pre><code> * <rrd_def> * <path>${path}</path> * <!-- not mandatory --> * <start>1000123456</start> * <!-- not mandatory --> * <step>${step}</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>${rows}</rows> * </archive> * <archive> * <cf>MAX</cf> * <xff>0.6</xff> * <steps>6</steps> * <rows>7000</rows> * </archive> * </rrd_def> * </code></pre> * XML template can be embedded in a String or a file - the class provides constructors in both * cases. <p> * * Note that the above XML definition contains three placeholders (<code>${path}</code>, * <code>${step}</code> and <code>${rows}</code>) - these placeholders must be replaced with * real values before the RrdDef object is requested by calling {@link #getRrdDef getRrdDef()} * method. To replace placeholders with real values at run time use inhereted * (and overloaded) public {@link XmlTemplate#setMapping(String, String) setMapping()} * methods.<p> * * You are free to use the same template object to create as many RrdDef objects as needed * (probably with different placeholder-value mappings).<p> * * Here is an example how to create two different RRD files using the template given above:<p> * * <pre> * // 'template.xml' file contains XML template already specified * File file = new File("template.xml"); * RrdDefTemplate t = new RrdDefTemplate(file); * * // replace ${path} placeholder with the real value (test1.rrd) * t.setMapping("path", "test1.rrd"); * * // replace ${step} placeholder with the real value (600) * t.setMapping("step", 600); * * // replace ${rows} placeholder with the real value (800) * t.setMapping("rows", 800); * * // get RrdDef from the template object... * RrdDef def = t.getRrdDef(); * * // ...and use it to construct the first RRD file * RrdDb rrd = new RrdDb(def); rrd.close(); * * // note that all mappings are still active * // change the value for some (or all) placeholders * // to construct the second database * // with different parameters * t.setMapping("path", "test2.rrd"); * def = t.getRrdDef(); * * // the second RRD file will be also created with step=600, rows=800 * rrd = new RrdDb(def); rrd.close(); * </pre> */ public class RrdDefTemplate extends XmlTemplate { /** * 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. * @param xmlInputSource Xml input source * @throws IOException Thrown in case of I/O error * @throws RrdException Thrown in case of XML related error (parsing error, for example) */ public RrdDefTemplate(InputSource xmlInputSource) throws IOException, RrdException { super(xmlInputSource); } /** * 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. * @param xmlString String containing XML template * @throws IOException Thrown in case of I/O error * @throws RrdException Thrown in case of XML related error (parsing error, for example) */ public RrdDefTemplate(String xmlString) throws IOException, RrdException { super(xmlString); } /** * 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. * @param xmlFile File object representing file with XML template * @throws IOException Thrown in case of I/O error * @throws RrdException Thrown in case of XML related error (parsing error, for example) */ public RrdDefTemplate(File xmlFile) throws IOException, RrdException { super(xmlFile); } /** * 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 * {@link XmlTemplate#setMapping(String, String) setMapping()} methods. Once this method * returns, all placeholder values are preserved. To remove them all, call inhereted * {@link XmlTemplate#clearValues() clearValues()} method explicitly.<p> * * @return 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 {@link XmlTemplate#setMapping(String, String) setMapping()} * method call */ public RrdDef getRrdDef() throws RrdException { if (!root.getTagName().equals("rrd_def")) { throw new RrdException("XML definition must start with <rrd_def>"); } // PATH must be supplied or exception is thrown String path = getChildValue(root, "path"); RrdDef rrdDef = new RrdDef(path); try { long start = getChildValueAsLong(root, "start"); rrdDef.setStartTime(start); } catch (RrdException e) { // START is not mandatory } try { long step = getChildValueAsLong(root, "step"); rrdDef.setStep(step); } catch (RrdException e) { // STEP is not mandatory } // datsources Node[] dsNodes = getChildNodes(root, "datasource"); for (int i = 0; i < dsNodes.length; i++) { String name = getChildValue(dsNodes[i], "name"); String type = getChildValue(dsNodes[i], "type"); long heartbeat = getChildValueAsLong(dsNodes[i], "heartbeat"); double min = getChildValueAsDouble(dsNodes[i], "min"); double max = getChildValueAsDouble(dsNodes[i], "max"); rrdDef.addDatasource(name, type, heartbeat, min, max); } // archives Node[] arcNodes = getChildNodes(root, "archive"); for (int i = 0; i < arcNodes.length; i++) { String consolFun = getChildValue(arcNodes[i], "cf"); double xff = getChildValueAsDouble(arcNodes[i], "xff"); int steps = getChildValueAsInt(arcNodes[i], "steps"); int rows = getChildValueAsInt(arcNodes[i], "rows"); rrdDef.addArchive(consolFun, xff, steps, rows); } return rrdDef; } /* public static void main(String[] args) throws RrdException, IOException { String s = "<rrd_def> " + " <path>${path}</path> " + " <start>1000000000</start> " + " <step>${step}</step> " + " <datasource> " + " <name>input</name> " + " <type>COUNTER</type> " + " <heartbeat>300</heartbeat> " + " <min>10</min> " + " <max>U</max> " + " </datasource> " + " <datasource> " + " <name>temperature</name> " + " <type>GAUGE</type> " + " <heartbeat>400</heartbeat> " + " <min>U</min> " + " <max>1000</max> " + " </datasource> " + " <archive> " + " <cf>AVERAGE</cf> " + " <xff>0.5</xff> " + " <steps>1</steps> " + " <rows>${rows}</rows> " + " </archive> " + " <archive> " + " <cf>MAX</cf> " + " <xff>0.6</xff> " + " <steps>6</steps> " + " <rows>7000</rows> " + " </archive> " + "</rrd_def> "; RrdDefTemplate t = new RrdDefTemplate(s); // works as well: // File f = new File("test.xml"); // RrdDefTemplate t = new RrdDefTemplate(f); t.setMapping("path", "test1.rrd"); t.setMapping("step", 310); t.setMapping("rows", 888); RrdDef def = t.getRrdDef(); System.out.println(def.dump()); new RrdDb(def).close(); t.setMapping("path", "test2.rrd"); t.setMapping("step", 320); t.setMapping("rows", 999); def = t.getRrdDef(); System.out.println(def.dump()); new RrdDb(def).close(); } */ } --- NEW FILE: XmlTemplate.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.core; import org.w3c.dom.Node; import org.w3c.dom.Element; import org.xml.sax.InputSource; import java.io.IOException; import java.io.File; import java.util.HashMap; /** * Class used as a base class for various XML template related classes. Class provides * methods for XML source parsing and XML tree traversing. XML source may have unlimited * number of placeholders in the format <code>${placeholder_name}</code>. Methods are provided * to specify values of placeholders at runtime. Note that this class has limited functionality: * XML source gets parsed, and placeholder values are collected. You have to extend this class * to do anything more useful.<p> */ public abstract class XmlTemplate { /** * root element of the DOM hierarchy representing XML source */ protected Element root; private HashMap valueMap = new HashMap(); /** * Creates XmlTemplate object from any parsable XML input source * @param xmlSource Any parsable XML input source * @throws IOException thrown in case of I/O error * @throws RrdException thrown (in most cases) when the source has invalid XML syntax * (cannot be parsed at all) */ protected XmlTemplate(InputSource xmlSource) throws IOException, RrdException { root = Util.Xml.getRootElement(xmlSource); } /** * Creates XmlTemplate object from a string containing properly formatted XML * @param xmlString parsable XML string * @throws IOException thrown in case of I/O error * @throws RrdException thrown (in most cases) when the source has invalid XML syntax * (cannot be parsed at all) */ protected XmlTemplate(String xmlString) throws IOException, RrdException { root = Util.Xml.getRootElement(xmlString); } /** * Creates XmlTemplate object from a file containing properly formatted XML * @param xmlFile File object representing file containing parsable XML source * @throws IOException thrown in case of I/O error * @throws RrdException thrown (in most cases) when the source has invalid XML syntax * (cannot be parsed at all) */ protected XmlTemplate(File xmlFile) throws IOException, RrdException { root = Util.Xml.getRootElement(xmlFile); } /** * Removes all placeholder-value mappings. */ public void clearValues() { valueMap.clear(); } /** * Sets value for the given placeholder. Placeholder should be supplied by its name. * For example, for a placeholder <code>${param}</code> specify just <code>param</code> * for its name. * @param name Name of the placeholder (placeholder without leading '${' and ending '}'). * @param value Value to replace placeholder with. */ public void setMapping(String name, String value) { valueMap.put(name, value); } /** * Sets value for the given placeholder. Placeholder should be supplied by its name. * For example, for a placeholder <code>${param}</code> specify just <code>param</code> * for its name. * @param name Name of the placeholder (placeholder without leading '${' and ending '}'). * @param value Value to replace placeholder with. */ public void setMapping(String name, int value) { valueMap.put(name, new Integer(value)); } /** * Sets value for the given placeholder. Placeholder should be supplied by its name. * For example, for a placeholder <code>${param}</code> specify just <code>param</code> * for its name. * @param name Name of the placeholder (placeholder without leading '${' and ending '}'). * @param value Value to replace placeholder with. */ public void setMapping(String name, long value) { valueMap.put(name, new Long(value)); } /** * Sets value for the given placeholder. Placeholder should be supplied by its name. * For example, for a placeholder <code>${param}</code> specify just <code>param</code> * for its name. * @param name Name of the placeholder (placeholder without leading '${' and ending '}'). * @param value Value to replace placeholder with. */ public void setMapping(String name, double value) { valueMap.put(name, new Double(value)); } /** * Returns all child nodes with the given tag * belonging to the specified parent Node * @param parentNode Parent node * @param childName Child node tag * @return Array of child nodes with the specified parent and with the given tag name */ protected static Node[] getChildNodes(Node parentNode, String childName) { return Util.Xml.getChildNodes(parentNode, childName); } /** * Returns the first child node with the given parent and the given tag. * @param parentNode Parent node * @param childName Child node tag * @return First child node with the given parent node and the given tag. * @throws RrdException Thrown if no such child can be found */ protected static Node getFirstChildNode(Node parentNode, String childName) throws RrdException { return Util.Xml.getFirstChildNode(parentNode, childName); } /** * Returns the 'value' of the child node with the given parent and the given tag name. * For example, in a DOM-tree created from the following XML source:<p> * <pre> * ...<root><branch>abc</branch></root>... * </pre> * and assuming that <code>parentNode</code> points to the <code><root></code> element, * the following call:<p> * <pre> * getChildValue(parentNode, "branch"); * </pre> * returns:<p> * <code>abc</code><p> * @param parentNode Parent DOM node * @param childName Child node tag * @return XML 'value' of the child node (trimmed content between <childName> and </childName> * tags) * @throws RrdException Thrown if no such child node exists. */ protected String getChildValue(Node parentNode, String childName) throws RrdException { String value = Util.Xml.getChildValue(parentNode, childName); if(value.startsWith("${") && value.endsWith("}")) { // template variable found, remove leading "${" and trailing "}" String var = value.substring(2, value.length() - 1); if(valueMap.containsKey(var)) { // mapping found value = valueMap.get(var).toString(); } else { // no mapping found - this is illegal throw new RrdException("No mapping found for template variable " + value); } } return value; } /** * Returns the 'value' of the child node with the given parent and the given tag name. * For example, in a DOM-tree created from the following XML source:<p> * <pre> * ...<root><branch>123</branch></root>... * </pre> * and assuming that <code>parentNode</code> points to the <code><root></code> element, * the following call:<p> * <pre> * getChildValue(parentNode, "branch"); * </pre> * returns:<p> * <code>123</code><p> * @param parentNode Parent DOM node * @param childName Child node tag * @return XML 'value' of the child node (trimmed content between <childName> and </childName> * tags) * @throws RrdException Thrown if no such child node exists. */ protected int getChildValueAsInt(Node parentNode, String childName) throws RrdException, NumberFormatException { String valueStr = getChildValue(parentNode, childName); return Integer.parseInt(valueStr); } /** * Returns the 'value' of the child node with the given parent and the given tag name. * For example, in a DOM-tree created from the following XML source:<p> * <pre> * ...<root><branch>123</branch></root>... * </pre> * and assuming that <code>parentNode</code> points to the <code><root></code> element, * the following call:<p> * <pre> * getChildValue(parentNode, "branch"); * </pre> * returns:<p> * <code>123</code><p> * @param parentNode Parent DOM node * @param childName Child node tag * @return XML 'value' of the child node (trimmed content between <childName> and </childName> * tags) * @throws RrdException Thrown if no such child node exists. */ protected long getChildValueAsLong(Node parentNode, String childName) throws RrdException, NumberFormatException { String valueStr = getChildValue(parentNode, childName); return Long.parseLong(valueStr); } /** * Returns the 'value' of the child node with the given parent and the given tag name. * For example, in a DOM-tree created from the following XML source:<p> * <pre> * ...<root><branch>123.45</branch></root>... * </pre> * and assuming that <code>parentNode</code> points to the <code><root></code> element, * the following call:<p> * <pre> * getChildValue(parentNode, "branch"); * </pre> * returns:<p> * <code>123.45</code><p> * @param parentNode Parent DOM node * @param childName Child node tag * @return XML 'value' of the child node (trimmed content between <childName> and </childName> * tags) * @throws RrdException Thrown if no such child node exists. */ protected double getChildValueAsDouble(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Util.parseDouble(valueStr); } } |
|
From: <sa...@us...> - 2004-02-23 16:02:15
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11365/org/jrobin/core Modified Files: RrdToolkit.java Util.java XmlReader.java Log Message: XML templates revisited Index: RrdToolkit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdToolkit.java 19 Feb 2004 10:48:12 -0000 1.7 --- RrdToolkit.java 23 Feb 2004 15:48:41 -0000 1.8 *************** *** 25,35 **** package org.jrobin.core; - import org.xml.sax.InputSource; - import org.xml.sax.SAXException; - import org.w3c.dom.Element; - import org.w3c.dom.Node; - import javax.xml.parsers.FactoryConfigurationError; - import javax.xml.parsers.ParserConfigurationException; import java.io.*; /** * <p>Class used to perform various complex operations on RRD files. Use an instance of the --- 25,30 ---- package org.jrobin.core; import java.io.*; + /** * <p>Class used to perform various complex operations on RRD files. Use an instance of the *************** *** 73,80 **** public void addDatasource(String sourcePath, String destPath, DsDef newDatasource) throws IOException, RrdException { ! if(Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } ! RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); --- 68,75 ---- public void addDatasource(String sourcePath, String destPath, DsDef newDatasource) throws IOException, RrdException { ! if (Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } ! RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); *************** *** 121,128 **** public void removeDatasource(String sourcePath, String destPath, String dsName) throws IOException, RrdException { ! if(Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } ! RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); --- 116,123 ---- public void removeDatasource(String sourcePath, String destPath, String dsName) throws IOException, RrdException { ! if (Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } ! RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); *************** *** 169,176 **** public void addArchive(String sourcePath, String destPath, ArcDef newArchive) throws IOException, RrdException { ! if(Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } ! RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); --- 164,171 ---- public void addArchive(String sourcePath, String destPath, ArcDef newArchive) throws IOException, RrdException { ! if (Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } ! RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); *************** *** 218,225 **** public void removeArchive(String sourcePath, String destPath, String consolFun, int steps) throws IOException, RrdException { ! if(Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } ! RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); --- 213,220 ---- public void removeArchive(String sourcePath, String destPath, String consolFun, int steps) throws IOException, RrdException { ! if (Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } ! RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); *************** *** 259,272 **** File source = new File(sourcePath); File dest = new File(destPath); ! if(saveBackup) { String backupPath = destPath + ".bak"; File backup = new File(backupPath); deleteFile(backup); ! if(!dest.renameTo(backup)) { throw new IOException("Could not create backup file " + backupPath); } } deleteFile(dest); ! if(!source.renameTo(dest)) { throw new IOException("Could not create file " + destPath + " from " + sourcePath); } --- 254,267 ---- File source = new File(sourcePath); File dest = new File(destPath); ! if (saveBackup) { String backupPath = destPath + ".bak"; File backup = new File(backupPath); deleteFile(backup); ! if (!dest.renameTo(backup)) { throw new IOException("Could not create backup file " + backupPath); } } deleteFile(dest); ! if (!source.renameTo(dest)) { throw new IOException("Could not create file " + destPath + " from " + sourcePath); } *************** *** 282,286 **** */ public void setDsHeartbeat(String sourcePath, String datasourceName, ! long newHeartbeat) throws RrdException, IOException { RrdDb rrd = new RrdDb(sourcePath); Datasource ds = rrd.getDatasource(datasourceName); --- 277,281 ---- */ public void setDsHeartbeat(String sourcePath, String datasourceName, ! long newHeartbeat) throws RrdException, IOException { RrdDb rrd = new RrdDb(sourcePath); Datasource ds = rrd.getDatasource(datasourceName); *************** *** 300,304 **** */ public void setDsMinValue(String sourcePath, String datasourceName, ! double newMinValue, boolean filterArchivedValues) throws RrdException, IOException { RrdDb rrd = new RrdDb(sourcePath); Datasource ds = rrd.getDatasource(datasourceName); --- 295,299 ---- */ public void setDsMinValue(String sourcePath, String datasourceName, ! double newMinValue, boolean filterArchivedValues) throws RrdException, IOException { RrdDb rrd = new RrdDb(sourcePath); Datasource ds = rrd.getDatasource(datasourceName); *************** *** 318,322 **** */ public void setDsMaxValue(String sourcePath, String datasourceName, ! double newMaxValue, boolean filterArchivedValues) throws RrdException, IOException { RrdDb rrd = new RrdDb(sourcePath); Datasource ds = rrd.getDatasource(datasourceName); --- 313,317 ---- */ public void setDsMaxValue(String sourcePath, String datasourceName, ! double newMaxValue, boolean filterArchivedValues) throws RrdException, IOException { RrdDb rrd = new RrdDb(sourcePath); Datasource ds = rrd.getDatasource(datasourceName); *************** *** 337,341 **** */ public void setDsMinMaxValue(String sourcePath, String datasourceName, ! double newMinValue, double newMaxValue, boolean filterArchivedValues) throws RrdException, IOException { RrdDb rrd = new RrdDb(sourcePath); --- 332,336 ---- */ public void setDsMinMaxValue(String sourcePath, String datasourceName, ! double newMinValue, double newMaxValue, boolean filterArchivedValues) throws RrdException, IOException { RrdDb rrd = new RrdDb(sourcePath); *************** *** 355,360 **** */ public void setArcXff(String sourcePath, String consolFun, int steps, ! double newXff) throws RrdException, IOException { ! RrdDb rrd = new RrdDb(sourcePath); Archive arc = rrd.getArchive(consolFun, steps); arc.setXff(newXff); --- 350,355 ---- */ public void setArcXff(String sourcePath, String consolFun, int steps, ! double newXff) throws RrdException, IOException { ! RrdDb rrd = new RrdDb(sourcePath); Archive arc = rrd.getArchive(consolFun, steps); arc.setXff(newXff); *************** *** 377,390 **** int numSteps, int newRows) throws IOException, RrdException { ! if(Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } ! if(newRows < 2) { throw new RrdException("New arcihve size must be at least 2"); } ! RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); ArcDef arcDef = rrdDef.findArchive(consolFun, numSteps); ! if(arcDef.getRows() != newRows) { arcDef.setRows(newRows); rrdDef.setPath(destPath); --- 372,385 ---- int numSteps, int newRows) throws IOException, RrdException { ! if (Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } ! if (newRows < 2) { throw new RrdException("New arcihve size must be at least 2"); } ! RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); ArcDef arcDef = rrdDef.findArchive(consolFun, numSteps); ! if (arcDef.getRows() != newRows) { arcDef.setRows(newRows); rrdDef.setPath(destPath); *************** *** 417,600 **** private static void deleteFile(File file) throws IOException { ! if(file.exists() && !file.delete()) { throw new IOException("Could not delete file: " + file.getCanonicalPath()); } } - - /** - * Creates RrdDef object from its XML string equivalent. The format of the input string is - * the same as the format described in - * {@link #createRrdDefFromXmlFile createRrdDefFromXmlFile} method. - * @param xmlString XML formatted string containing complete RRD definition - * @return RrdDef object which can be used to create new RrdDb object - * @throws RrdException thrown in case of bad XML format or bad RRD definition parameters - * @throws IOException thrown in case of I/O error - */ - public RrdDef createRrdDefFromXmlString(String xmlString) throws RrdException, IOException { - return createRrdDefFromXmlSource(new InputSource(new StringReader(xmlString))); - } - - /** - * Creates RrdDef object from the file containing its XML equivalent. Here is an example - * of a properly formatted XML file:</p> - * <pre><code> - * <rrd_def> - * <path>test.rrd</path> - * <!-- not mandatory --> - * <start>1000123123</start> - * <!-- not mandatory --> - * <step>150</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>700</rows> - * </archive> - * <archive> - * <cf>MAX</cf> - * <xff>0.6</xff> - * <steps>6</steps> - * <rows>7000</rows> - * </archive> - * </rrd_def> - * </code></pre> - * - * @param filepath path containing XML formatted RRD definition (like the one given above) - * @return RrdDef object which can be used to create new RrdDb object - * @throws RrdException thrown in case of bad XML format or bad RRD definition parameters - * @throws IOException thrown in case of I/O error - */ - public RrdDef createRrdDefFromXmlFile(String filepath) throws RrdException, IOException { - FileReader fileReader = null; - try { - fileReader = new FileReader(filepath); - return createRrdDefFromXmlSource(new InputSource(fileReader)); - } - finally { - if(fileReader != null) { - fileReader.close(); - } - } - } - - /** - * Creates RrdDef object from any parsable XML source. The format of the underlying input - * source data must conform to the format described for the - * {@link #createRrdDefFromXmlFile createRrdDefFromXmlFile} method. - * @param inputSource parsable XML source containing complete RRD definition - * @return RrdDef object which can be used to create new RrdDb object - * @throws RrdException thrown in case of bad XML format or bad RRD definition parameters - * @throws IOException thrown in case of I/O error - */ - public RrdDef createRrdDefFromXmlSource(InputSource inputSource) throws RrdException, IOException { - try { - Element root = XmlReader.getRootElement(inputSource); - // must start with <rrd_def> - if(!root.getTagName().equals("rrd_def")) { - throw new RrdException("XML definition must start with <rrd_def>"); - } - // PATH must be supplied or exception is thrown - String path = XmlReader.getChildValue(root, "path"); - RrdDef rrdDef = new RrdDef(path); - try { - // START is not mandatory - long start = XmlReader.getChildValueAsLong(root, "start"); - rrdDef.setStartTime(start); - } - catch(RrdException e) { } - try { - // STEP is not mandatory - long step = XmlReader.getChildValueAsLong(root, "step"); - rrdDef.setStep(step); - } - catch(RrdException e) { - // NOP - } - // datsources - Node[] dsNodes = XmlReader.getChildNodes(root, "datasource"); - for(int i = 0; i < dsNodes.length; i++) { - String name = XmlReader.getChildValue(dsNodes[i], "name"); - String type = XmlReader.getChildValue(dsNodes[i], "type"); - long heartbeat = XmlReader.getChildValueAsLong(dsNodes[i], "heartbeat"); - double min = XmlReader.getChildValueAsDouble(dsNodes[i], "min"); - double max = XmlReader.getChildValueAsDouble(dsNodes[i], "max"); - rrdDef.addDatasource(name, type, heartbeat, min, max); - } - // archives - Node[] arcNodes = XmlReader.getChildNodes(root, "archive"); - for(int i = 0; i < arcNodes.length; i++) { - String consolFun = XmlReader.getChildValue(arcNodes[i], "cf"); - double xff = XmlReader.getChildValueAsDouble(arcNodes[i], "xff"); - int steps = XmlReader.getChildValueAsInt(arcNodes[i], "steps"); - int rows = XmlReader.getChildValueAsInt(arcNodes[i], "rows"); - rrdDef.addArchive(consolFun, xff, steps, rows); - } - return rrdDef; - } catch (FactoryConfigurationError e) { - throw new RrdException("XML error: " + e); - } catch (ParserConfigurationException e) { - throw new RrdException("XML error: " + e); - } catch (SAXException e) { - throw new RrdException("XML error: " + e); - } catch(NumberFormatException e) { - throw new RrdException("XML error: " + e); - } - } - - /* - public static void main(String[] args) throws RrdException, IOException { - String s = - "<rrd_def> " + - " <path>test.rrd</path> " + - " <start>1000000000</start> " + - " <step>151</step> " + - " <datasource> " + - " <name>input</name> " + - " <type>COUNTER</type> " + - " <heartbeat>300</heartbeat> " + - " <min>10</min> " + - " <max>U</max> " + - " </datasource> " + - " <datasource> " + - " <name>temperature</name> " + - " <type>GAUGE</type> " + - " <heartbeat>400</heartbeat> " + - " <min>U</min> " + - " <max>1000</max> " + - " </datasource> " + - " <archive> " + - " <cf>AVERAGE</cf> " + - " <xff>0.5</xff> " + - " <steps>1</steps> " + - " <rows>700</rows> " + - " </archive> " + - " <archive> " + - " <cf>MAX</cf> " + - " <xff>0.6</xff> " + - " <steps>6</steps> " + - " <rows>7000</rows> " + - " </archive> " + - "</rrd_def> "; - RrdDef def = RrdToolkit.getInstance().createRrdDefFromXmlString(s); - RrdDb db = new RrdDb(def); - db.close(); - } - */ } --- 412,419 ---- private static void deleteFile(File file) throws IOException { ! if (file.exists() && !file.delete()) { throw new IOException("Could not delete file: " + file.getCanonicalPath()); } } } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Util.java 19 Feb 2004 13:05:04 -0000 1.8 --- Util.java 23 Feb 2004 15:48:42 -0000 1.9 *************** *** 26,29 **** --- 26,39 ---- package org.jrobin.core; + import org.w3c.dom.Node; + import org.w3c.dom.NodeList; + import org.w3c.dom.Element; + import org.w3c.dom.Document; + import org.xml.sax.InputSource; + import org.xml.sax.SAXException; + + import javax.xml.parsers.ParserConfigurationException; + import javax.xml.parsers.DocumentBuilderFactory; + import javax.xml.parsers.DocumentBuilder; import java.text.DecimalFormat; import java.text.NumberFormat; *************** *** 31,36 **** import java.util.Locale; import java.util.GregorianCalendar; ! import java.io.File; ! import java.io.IOException; /** --- 41,46 ---- import java.util.Locale; import java.util.GregorianCalendar; ! import java.util.ArrayList; ! import java.io.*; /** *************** *** 245,248 **** --- 255,338 ---- return File.createTempFile("JROBIN_", ".tmp").getCanonicalPath(); } + + static class Xml { + static Node[] getChildNodes(Node parentNode, String childName) { + ArrayList nodes = new ArrayList(); + NodeList nodeList = parentNode.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + if (node.getNodeName().equals(childName)) { + nodes.add(node); + } + } + return (Node[]) nodes.toArray(new Node[0]); + } + + static Node getFirstChildNode(Node parentNode, String childName) throws RrdException { + Node[] childs = getChildNodes(parentNode, childName); + if (childs.length > 0) { + return childs[0]; + } + throw new RrdException("XML Error, no such child: " + childName); + } + + static String getChildValue(Node parentNode, String childName) throws RrdException { + NodeList children = parentNode.getChildNodes(); + for (int i = 0; i < children.getLength(); i++) { + Node child = children.item(i); + if (child.getNodeName().equals(childName)) { + return child.getFirstChild().getNodeValue().trim(); + } + } + throw new RrdException("XML Error, no such child: " + childName); + } + + static int getChildValueAsInt(Node parentNode, String childName) throws RrdException { + String valueStr = getChildValue(parentNode, childName); + return Integer.parseInt(valueStr); + } + + static long getChildValueAsLong(Node parentNode, String childName) throws RrdException { + String valueStr = getChildValue(parentNode, childName); + return Long.parseLong(valueStr); + } + + static double getChildValueAsDouble(Node parentNode, String childName) throws RrdException { + String valueStr = getChildValue(parentNode, childName); + return Util.parseDouble(valueStr); + } + + static Element getRootElement(InputSource inputSource) throws RrdException, IOException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setValidating(false); + factory.setNamespaceAware(false); + try { + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.parse(inputSource); + return doc.getDocumentElement(); + } catch (ParserConfigurationException e) { + throw new RrdException(e); + } catch (SAXException e) { + throw new RrdException(e); + } + } + + static Element getRootElement(String xmlString) throws RrdException, IOException { + return getRootElement(new InputSource(new StringReader(xmlString))); + } + + static Element getRootElement(File xmlFile) throws RrdException, IOException { + Reader reader = null; + try { + reader = new FileReader(xmlFile); + return getRootElement(new InputSource(reader)); + } + finally { + if(reader != null) { + reader.close(); + } + } + } + } } Index: XmlReader.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlReader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** XmlReader.java 19 Feb 2004 10:48:12 -0000 1.3 --- XmlReader.java 23 Feb 2004 15:48:42 -0000 1.4 *************** *** 26,40 **** package org.jrobin.core; - import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; - import org.w3c.dom.NodeList; - import org.xml.sax.SAXException; - import org.xml.sax.InputSource; - - import javax.xml.parsers.*; import java.io.IOException; ! import java.io.FileReader; ! import java.util.ArrayList; class XmlReader { --- 26,33 ---- package org.jrobin.core; import org.w3c.dom.Element; import org.w3c.dom.Node; import java.io.IOException; ! import java.io.File; class XmlReader { *************** *** 44,78 **** XmlReader(String xmlFilePath) throws IOException, RrdException { ! FileReader fileReader = null; ! try { ! fileReader = new FileReader(xmlFilePath); ! InputSource source = new InputSource(fileReader); ! root = getRootElement(source); ! dsNodes = getChildNodes(root, "ds"); ! arcNodes = getChildNodes(root, "rra"); ! } catch (FactoryConfigurationError e) { ! throw new RrdException("XML error: " + e); ! } catch (ParserConfigurationException e) { ! throw new RrdException("XML error: " + e); ! } catch (SAXException e) { ! throw new RrdException("XML error: " + e); ! } ! finally { ! if(fileReader != null) { ! fileReader.close(); ! } ! } } String getVersion() throws RrdException { ! return getChildValue(root, "version"); } long getLastUpdateTime() throws RrdException { ! return getChildValueAsLong(root, "lastupdate"); } long getStep() throws RrdException { ! return getChildValueAsLong(root, "step"); } --- 37,55 ---- XmlReader(String xmlFilePath) throws IOException, RrdException { ! root = Util.Xml.getRootElement(new File(xmlFilePath)); ! dsNodes = Util.Xml.getChildNodes(root, "ds"); ! arcNodes = Util.Xml.getChildNodes(root, "rra"); } String getVersion() throws RrdException { ! return Util.Xml.getChildValue(root, "version"); } long getLastUpdateTime() throws RrdException { ! return Util.Xml.getChildValueAsLong(root, "lastupdate"); } long getStep() throws RrdException { ! return Util.Xml.getChildValueAsLong(root, "step"); } *************** *** 86,156 **** String getDsName(int dsIndex) throws RrdException { ! return getChildValue(dsNodes[dsIndex], "name"); } String getDsType(int dsIndex) throws RrdException { ! return getChildValue(dsNodes[dsIndex], "type"); } long getHeartbeat(int dsIndex) throws RrdException { ! return getChildValueAsLong(dsNodes[dsIndex], "minimal_heartbeat"); } double getMinValue(int dsIndex) throws RrdException { ! return getChildValueAsDouble(dsNodes[dsIndex], "min"); } double getMaxValue(int dsIndex) throws RrdException { ! return getChildValueAsDouble(dsNodes[dsIndex], "max"); } double getLastValue(int dsIndex) throws RrdException { ! return getChildValueAsDouble(dsNodes[dsIndex], "last_ds"); } double getAccumValue(int dsIndex) throws RrdException { ! return getChildValueAsDouble(dsNodes[dsIndex], "value"); } long getNanSeconds(int dsIndex) throws RrdException { ! return getChildValueAsLong(dsNodes[dsIndex], "unknown_sec"); } String getConsolFun(int arcIndex) throws RrdException { ! return getChildValue(arcNodes[arcIndex], "cf"); } double getXff(int arcIndex) throws RrdException { ! return getChildValueAsDouble(arcNodes[arcIndex], "xff"); } int getSteps(int arcIndex) throws RrdException { ! return getChildValueAsInt(arcNodes[arcIndex], "pdp_per_row"); } double getStateAccumValue(int arcIndex, int dsIndex) throws RrdException { ! Node cdpNode = getFirstChildNode(arcNodes[arcIndex], "cdp_prep"); ! Node[] dsNodes = getChildNodes(cdpNode, "ds"); ! return getChildValueAsDouble(dsNodes[dsIndex], "value"); } int getStateNanSteps(int arcIndex, int dsIndex) throws RrdException { ! Node cdpNode = getFirstChildNode(arcNodes[arcIndex], "cdp_prep"); ! Node[] dsNodes = getChildNodes(cdpNode, "ds"); ! return getChildValueAsInt(dsNodes[dsIndex], "unknown_datapoints"); } int getRows(int arcIndex) throws RrdException { ! Node dbNode = getFirstChildNode(arcNodes[arcIndex], "database"); ! Node[] rows = getChildNodes(dbNode, "row"); return rows.length; } double[] getValues(int arcIndex, int dsIndex) throws RrdException { ! Node dbNode = getFirstChildNode(arcNodes[arcIndex], "database"); ! Node[] rows = getChildNodes(dbNode, "row"); double[] values = new double[rows.length]; for(int i = 0; i < rows.length; i++) { ! Node[] vNodes = getChildNodes(rows[i], "v"); Node vNode = vNodes[dsIndex]; values[i] = Util.parseDouble(vNode.getFirstChild().getNodeValue().trim()); --- 63,133 ---- String getDsName(int dsIndex) throws RrdException { ! return Util.Xml.getChildValue(dsNodes[dsIndex], "name"); } String getDsType(int dsIndex) throws RrdException { ! return Util.Xml.getChildValue(dsNodes[dsIndex], "type"); } long getHeartbeat(int dsIndex) throws RrdException { ! return Util.Xml.getChildValueAsLong(dsNodes[dsIndex], "minimal_heartbeat"); } double getMinValue(int dsIndex) throws RrdException { ! return Util.Xml.getChildValueAsDouble(dsNodes[dsIndex], "min"); } double getMaxValue(int dsIndex) throws RrdException { ! return Util.Xml.getChildValueAsDouble(dsNodes[dsIndex], "max"); } double getLastValue(int dsIndex) throws RrdException { ! return Util.Xml.getChildValueAsDouble(dsNodes[dsIndex], "last_ds"); } double getAccumValue(int dsIndex) throws RrdException { ! return Util.Xml.getChildValueAsDouble(dsNodes[dsIndex], "value"); } long getNanSeconds(int dsIndex) throws RrdException { ! return Util.Xml.getChildValueAsLong(dsNodes[dsIndex], "unknown_sec"); } String getConsolFun(int arcIndex) throws RrdException { ! return Util.Xml.getChildValue(arcNodes[arcIndex], "cf"); } double getXff(int arcIndex) throws RrdException { ! return Util.Xml.getChildValueAsDouble(arcNodes[arcIndex], "xff"); } int getSteps(int arcIndex) throws RrdException { ! return Util.Xml.getChildValueAsInt(arcNodes[arcIndex], "pdp_per_row"); } double getStateAccumValue(int arcIndex, int dsIndex) throws RrdException { ! Node cdpNode = Util.Xml.getFirstChildNode(arcNodes[arcIndex], "cdp_prep"); ! Node[] dsNodes = Util.Xml.getChildNodes(cdpNode, "ds"); ! return Util.Xml.getChildValueAsDouble(dsNodes[dsIndex], "value"); } int getStateNanSteps(int arcIndex, int dsIndex) throws RrdException { ! Node cdpNode = Util.Xml.getFirstChildNode(arcNodes[arcIndex], "cdp_prep"); ! Node[] dsNodes = Util.Xml.getChildNodes(cdpNode, "ds"); ! return Util.Xml.getChildValueAsInt(dsNodes[dsIndex], "unknown_datapoints"); } int getRows(int arcIndex) throws RrdException { ! Node dbNode = Util.Xml.getFirstChildNode(arcNodes[arcIndex], "database"); ! Node[] rows = Util.Xml.getChildNodes(dbNode, "row"); return rows.length; } double[] getValues(int arcIndex, int dsIndex) throws RrdException { ! Node dbNode = Util.Xml.getFirstChildNode(arcNodes[arcIndex], "database"); ! Node[] rows = Util.Xml.getChildNodes(dbNode, "row"); double[] values = new double[rows.length]; for(int i = 0; i < rows.length; i++) { ! Node[] vNodes = Util.Xml.getChildNodes(rows[i], "v"); Node vNode = vNodes[dsIndex]; values[i] = Util.parseDouble(vNode.getFirstChild().getNodeValue().trim()); *************** *** 159,218 **** } - // utility functions for DOM tree traversing - - static Node[] getChildNodes(Node parentNode, String childName) { - ArrayList nodes = new ArrayList(); - NodeList nodeList = parentNode.getChildNodes(); - for(int i = 0; i < nodeList.getLength(); i++) { - Node node = nodeList.item(i); - if(node.getNodeName().equals(childName)) { - nodes.add(node); - } - } - return (Node[]) nodes.toArray(new Node[0]); - } - - static Node getFirstChildNode(Node parentNode, String childName) throws RrdException { - Node[] childs = getChildNodes(parentNode, childName); - if(childs.length > 0) { - return childs[0]; - } - throw new RrdException("XML Error, no such child: " + childName); - } - - static String getChildValue(Node parentNode, String childName) throws RrdException { - NodeList children = parentNode.getChildNodes(); - for(int i = 0; i < children.getLength(); i++) { - Node child = children.item(i); - if(child.getNodeName().equals(childName)) { - return child.getFirstChild().getNodeValue().trim(); - } - } - throw new RrdException("XML Error, no such child: " + childName); - } - - static int getChildValueAsInt(Node parentNode, String childName) throws RrdException { - String valueStr = getChildValue(parentNode, childName); - return Integer.parseInt(valueStr); - } - - static long getChildValueAsLong(Node parentNode, String childName) throws RrdException { - String valueStr = getChildValue(parentNode, childName); - return Long.parseLong(valueStr); - } - - static double getChildValueAsDouble(Node parentNode, String childName) throws RrdException { - String valueStr = getChildValue(parentNode, childName); - return Util.parseDouble(valueStr); - } - - static Element getRootElement(InputSource inputSource) - throws ParserConfigurationException, IOException, SAXException { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setValidating(false); - factory.setNamespaceAware(false); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document doc = builder.parse(inputSource); - return doc.getDocumentElement(); - } } \ No newline at end of file --- 136,138 ---- |
|
From: <sa...@us...> - 2004-02-19 13:15:25
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20910/org/jrobin/core Modified Files: Util.java Log Message: minor improvements Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Util.java 20 Jan 2004 09:09:33 -0000 1.7 --- Util.java 19 Feb 2004 13:05:04 -0000 1.8 *************** *** 190,194 **** /** ! * Returns path to directory used for placement of JRobin demo graphs. and creates it * if necessary. * @return Path to demo directory (defaults to $HOME/jrobin/) if directory exists or --- 190,194 ---- /** ! * Returns path to directory used for placement of JRobin demo graphs and creates it * if necessary. * @return Path to demo directory (defaults to $HOME/jrobin/) if directory exists or *************** *** 199,202 **** --- 199,218 ---- } + /** + * Returns full path to the file stored in the demo directory of JRobin + * @param filename Partial path to the file stored in the demo directory of JRobin + * (just name and extension, without parent directories) + * @return Full path to the file + */ + public static String getJRobinDemoPath(String filename) { + String demoDir = getJRobinDemoDirectory(); + if(demoDir != null) { + return demoDir + filename; + } + else { + return null; + } + } + static boolean sameFilePath(String path1, String path2) throws IOException { File file1 = new File(path1); |
|
From: <sa...@us...> - 2004-02-19 13:15:25
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20910 Modified Files: ComplexDemo.java Demo.java PlottableDemo.java Log Message: minor improvements Index: ComplexDemo.java =================================================================== RCS file: /cvsroot/jrobin/src/ComplexDemo.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ComplexDemo.java 10 Nov 2003 08:52:27 -0000 1.4 --- ComplexDemo.java 19 Feb 2004 13:05:04 -0000 1.5 *************** *** 42,50 **** private static String getPath(String ext) { ! return Util.getJRobinDemoDirectory() + filename + "." + ext; } private static String getPath(int version, String ext) { ! return Util.getJRobinDemoDirectory() + filename + version + "." + ext; } --- 42,50 ---- private static String getPath(String ext) { ! return Util.getJRobinDemoPath(filename + "." + ext); } private static String getPath(int version, String ext) { ! return Util.getJRobinDemoPath(filename + version + "." + ext); } Index: Demo.java =================================================================== RCS file: /cvsroot/jrobin/src/Demo.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Demo.java 19 Feb 2004 12:23:56 -0000 1.9 --- Demo.java 19 Feb 2004 13:05:04 -0000 1.10 *************** *** 39,43 **** static final Random RANDOM = new Random(SEED); - static final String HOME = Util.getJRobinDemoDirectory(); static final String FILE = "demo"; --- 39,42 ---- *************** *** 55,65 **** long start = START; long end = END; ! String rrdPath = getFullPath(FILE + ".rrd"); ! String xmlPath = getFullPath(FILE + ".xml"); ! String rrdRestoredPath = getFullPath(FILE + "_restored.rrd"); ! String pngPath = getFullPath(FILE + ".png"); ! String jpegPath = getFullPath(FILE + ".jpeg"); ! String gifPath = getFullPath(FILE + ".gif"); ! String logPath = getFullPath(FILE + ".log"); PrintWriter log = new PrintWriter( new BufferedOutputStream(new FileOutputStream(logPath, false)) --- 54,64 ---- long start = START; long end = END; ! String rrdPath = Util.getJRobinDemoPath(FILE + ".rrd"); ! String xmlPath = Util.getJRobinDemoPath(FILE + ".xml"); ! String rrdRestoredPath = Util.getJRobinDemoPath(FILE + "_restored.rrd"); ! String pngPath = Util.getJRobinDemoPath(FILE + ".png"); ! String jpegPath = Util.getJRobinDemoPath(FILE + ".jpeg"); ! String gifPath = Util.getJRobinDemoPath(FILE + ".gif"); ! String logPath = Util.getJRobinDemoPath(FILE + ".log"); PrintWriter log = new PrintWriter( new BufferedOutputStream(new FileOutputStream(logPath, false)) *************** *** 175,182 **** System.out.println(msg); } - - static String getFullPath(String path) { - return HOME + path; - } } --- 174,177 ---- Index: PlottableDemo.java =================================================================== RCS file: /cvsroot/jrobin/src/PlottableDemo.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PlottableDemo.java 26 Jan 2004 12:38:01 -0000 1.2 --- PlottableDemo.java 19 Feb 2004 13:05:04 -0000 1.3 *************** *** 1,4 **** --- 1,6 ---- import org.jrobin.graph.*; import org.jrobin.core.RrdException; + import org.jrobin.core.Util; + import java.awt.*; import java.io.IOException; *************** *** 38,42 **** gdef.setTimeAxis(TimeAxisUnit.DAY, 1, TimeAxisUnit.DAY, 1, "dd", true); RrdGraph g = new RrdGraph(gdef); ! g.saveAsPNG("plottable2.png", 400, 200); } } --- 40,46 ---- gdef.setTimeAxis(TimeAxisUnit.DAY, 1, TimeAxisUnit.DAY, 1, "dd", true); RrdGraph g = new RrdGraph(gdef); ! String filename = Util.getJRobinDemoPath("plottable.png"); ! g.saveAsPNG(filename, 400, 200); ! System.out.println("Graph saved to " + filename); } } |
|
From: <sa...@us...> - 2004-02-19 12:34:15
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12822 Modified Files: Demo.java Log Message: Minor improvements (FetchData dump to XML) Index: Demo.java =================================================================== RCS file: /cvsroot/jrobin/src/Demo.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Demo.java 27 Nov 2003 10:22:58 -0000 1.8 --- Demo.java 19 Feb 2004 12:23:56 -0000 1.9 *************** *** 62,66 **** String gifPath = getFullPath(FILE + ".gif"); String logPath = getFullPath(FILE + ".log"); ! PrintWriter pw = new PrintWriter( new BufferedOutputStream(new FileOutputStream(logPath, false)) ); --- 62,66 ---- String gifPath = getFullPath(FILE + ".gif"); String logPath = getFullPath(FILE + ".log"); ! PrintWriter log = new PrintWriter( new BufferedOutputStream(new FileOutputStream(logPath, false)) ); *************** *** 80,84 **** rrdDef.addArchive("MAX", 0.5, 288, 797); println(rrdDef.dump()); ! pw.println(rrdDef.dump()); RrdDb rrdDb = new RrdDb(rrdDef); rrdDb.close(); --- 80,84 ---- rrdDef.addArchive("MAX", 0.5, 288, 797); println(rrdDef.dump()); ! log.println(rrdDef.dump()); RrdDb rrdDb = new RrdDb(rrdDef); rrdDb.close(); *************** *** 97,101 **** sample.setValue("sun", sunSource.getValue()); sample.setValue("shade", shadeSource.getValue()); ! pw.println(sample.dump()); sample.update(); --- 97,101 ---- sample.setValue("sun", sunSource.getValue()); sample.setValue("shade", shadeSource.getValue()); ! log.println(sample.dump()); sample.update(); *************** *** 113,117 **** FetchRequest request = rrdDb.createFetchRequest("AVERAGE", start, end); println(request.dump()); ! pw.println(request.dump()); FetchData fetchData = request.fetchData(); println("== Data fetched. " + fetchData.getRowCount() + " points obtained"); --- 113,117 ---- FetchRequest request = rrdDb.createFetchRequest("AVERAGE", start, end); println(request.dump()); ! log.println(request.dump()); FetchData fetchData = request.fetchData(); println("== Data fetched. " + fetchData.getRowCount() + " points obtained"); *************** *** 119,125 **** println(fetchData.getRow(i).dump()); } println("== Fetch completed"); println("== Dumping RRD file to XML file " + xmlPath + " (can be restored with RRDTool)"); ! rrdDb.dumpXml(xmlPath); println("== Creating RRD file " + rrdRestoredPath + " from XML file " + xmlPath); RrdDb rrdRestoredDb = new RrdDb(rrdRestoredPath, xmlPath); --- 119,129 ---- println(fetchData.getRow(i).dump()); } + println("== Dumping fetch data to XML format"); + println(fetchData.exportXml()); println("== Fetch completed"); + + // dump to XML file println("== Dumping RRD file to XML file " + xmlPath + " (can be restored with RRDTool)"); ! rrdDb.exportXml(xmlPath); println("== Creating RRD file " + rrdRestoredPath + " from XML file " + xmlPath); RrdDb rrdRestoredDb = new RrdDb(rrdRestoredPath, xmlPath); *************** *** 163,167 **** // demo ends ! pw.close(); println("== Demo completed in " + ((System.currentTimeMillis() - startMillis) / 1000.0) + " sec"); --- 167,171 ---- // demo ends ! log.close(); println("== Demo completed in " + ((System.currentTimeMillis() - startMillis) / 1000.0) + " sec"); |
|
From: <sa...@us...> - 2004-02-19 12:34:14
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12822/org/jrobin/core Modified Files: FetchData.java RrdDb.java RrdFile.java Log Message: Minor improvements (FetchData dump to XML) Index: FetchData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchData.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FetchData.java 10 Nov 2003 08:52:27 -0000 1.2 --- FetchData.java 19 Feb 2004 12:23:57 -0000 1.3 *************** *** 27,30 **** --- 27,33 ---- import java.io.IOException; + import java.io.OutputStream; + import java.io.FileOutputStream; + import java.io.ByteArrayOutputStream; /** *************** *** 342,344 **** --- 345,414 ---- } + /** + * Dumps fetch data to output stream in XML format. + * @param outputStream Output stream to dump fetch data to + * @throws IOException Thrown in case of I/O error + */ + public void exportXml(OutputStream outputStream) throws IOException { + XmlWriter writer = new XmlWriter(outputStream); + writer.startTag("fetch_data"); + writer.startTag("request"); + writer.writeTag("file", request.getParentDb().getRrdFile().getCanonicalFilePath()); + writer.writeComment(Util.getDate(request.getFetchStart())); + writer.writeTag("start", request.getFetchStart()); + writer.writeComment(Util.getDate(request.getFetchEnd())); + writer.writeTag("end", request.getFetchEnd()); + writer.writeTag("resolution", request.getResolution()); + writer.writeTag("cf", request.getConsolFun()); + writer.closeTag(); // request + writer.startTag("datasources"); + for(int i = 0; i < dsNames.length; i++) { + writer.writeTag("name", dsNames[i]); + } + writer.closeTag(); // datasources + writer.startTag("data"); + for(int i = 0; i < timestamps.length; i++) { + writer.startTag("row"); + writer.writeComment(Util.getDate(timestamps[i])); + writer.writeTag("timestamp", timestamps[i]); + writer.startTag("values"); + for(int j = 0; j < dsNames.length; j++) { + writer.writeTag("v", values[j][i]); + } + writer.closeTag(); // values + writer.closeTag(); // row + } + writer.closeTag(); // data + writer.closeTag(); // fetch_data + writer.finish(); + } + + /** + * Dumps fetch data to file in XML format. + * @param filepath Path to destination file + * @throws IOException Thrown in case of I/O error + */ + public void exportXml(String filepath) throws IOException { + OutputStream outputStream = null; + try { + outputStream = new FileOutputStream(filepath); + exportXml(outputStream); + } + finally { + if(outputStream != null) { + outputStream.close(); + } + } + } + + /** + * Dumps fetch data in XML format. + * @return String containing XML formatted fetch data + * @throws IOException Thrown in case of I/O error + */ + public String exportXml() throws IOException { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exportXml(outputStream); + return outputStream.toString(); + } } Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RrdDb.java 2 Dec 2003 10:18:17 -0000 1.9 --- RrdDb.java 19 Feb 2004 12:23:57 -0000 1.10 *************** *** 517,520 **** --- 517,528 ---- /** + * This method is just an alias for {@link #dumpXml(OutputStream) dumpXml} method. + * @throws IOException Thrown in case of I/O related error + */ + public synchronized void exportXml(OutputStream destination) throws IOException { + dumpXml(destination); + } + + /** * <p>Returns string representing internal state of RRD file in XML format. This format * is fully compatible with RRDTool's XML dump format and can be used for conversion *************** *** 531,534 **** --- 539,552 ---- /** + * This method is just an alias for {@link #getXml() getXml} method. + * @return Internal state of RRD file in XML format. + * @throws IOException Thrown in case of I/O related error + * @throws RrdException Thrown in case of JRobin specific error + */ + public synchronized String exportXml() throws IOException, RrdException { + return getXml(); + } + + /** * <p>Dumps internal state of RRD file to XML file. * Use this XML file to convert your JRobin RRD file to RRDTool format.</p> *************** *** 549,557 **** * @throws RrdException Thrown in case of JRobin related error. */ - public synchronized void dumpXml(String filename) throws IOException, RrdException { ! OutputStream destination = new FileOutputStream(filename, false); ! dumpXml(destination); ! destination.close(); } --- 567,590 ---- * @throws RrdException Thrown in case of JRobin related error. */ public synchronized void dumpXml(String filename) throws IOException, RrdException { ! OutputStream outputStream = null; ! try { ! outputStream = new FileOutputStream(filename, false); ! dumpXml(outputStream); ! } ! finally { ! if(outputStream != null) { ! outputStream.close(); ! } ! } ! } ! ! /** ! * This method is just an alias for {@link #dumpXml(String) dumpXml(String)} method. ! * @throws IOException Thrown in case of I/O related error ! * @throws RrdException Thrown in case of JRobin specific error ! */ ! public synchronized void exportXml(String filename) throws IOException, RrdException { ! dumpXml(filename); } Index: RrdFile.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFile.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdFile.java 27 Nov 2003 10:22:58 -0000 1.3 --- RrdFile.java 19 Feb 2004 12:23:57 -0000 1.4 *************** *** 142,146 **** return filePath; } ! /** * Returns canonical path to RRD file on disk. --- 142,146 ---- return filePath; } ! /** * Returns canonical path to RRD file on disk. |
|
From: <sa...@us...> - 2004-02-19 10:58:28
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28339/org/jrobin/core Modified Files: ArcDef.java RrdToolkit.java XmlReader.java Log Message: Added method(s) to RRDToolkit class to create RrdDef object from various XML sources Index: ArcDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcDef.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ArcDef.java 8 Dec 2003 13:47:40 -0000 1.4 --- ArcDef.java 19 Feb 2004 10:48:12 -0000 1.5 *************** *** 110,114 **** throw new RrdException("Invalid consolidation function specified: " + consolFun); } ! if(xff < 0.0 || xff >= 1.0) { throw new RrdException("Invalid xff, must be >= 0 and < 1: " + xff); } --- 110,114 ---- throw new RrdException("Invalid consolidation function specified: " + consolFun); } ! if(Double.isNaN(xff) || xff < 0.0 || xff >= 1.0) { throw new RrdException("Invalid xff, must be >= 0 and < 1: " + xff); } Index: RrdToolkit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdToolkit.java 8 Dec 2003 13:47:40 -0000 1.6 --- RrdToolkit.java 19 Feb 2004 10:48:12 -0000 1.7 *************** *** 25,30 **** package org.jrobin.core; ! import java.io.IOException; ! import java.io.File; /** * <p>Class used to perform various complex operations on RRD files. Use an instance of the --- 25,35 ---- package org.jrobin.core; ! import org.xml.sax.InputSource; ! import org.xml.sax.SAXException; ! import org.w3c.dom.Element; ! import org.w3c.dom.Node; ! import javax.xml.parsers.FactoryConfigurationError; ! import javax.xml.parsers.ParserConfigurationException; ! import java.io.*; /** * <p>Class used to perform various complex operations on RRD files. Use an instance of the *************** *** 417,420 **** --- 422,600 ---- } + /** + * Creates RrdDef object from its XML string equivalent. The format of the input string is + * the same as the format described in + * {@link #createRrdDefFromXmlFile createRrdDefFromXmlFile} method. + * @param xmlString XML formatted string containing complete RRD definition + * @return RrdDef object which can be used to create new RrdDb object + * @throws RrdException thrown in case of bad XML format or bad RRD definition parameters + * @throws IOException thrown in case of I/O error + */ + public RrdDef createRrdDefFromXmlString(String xmlString) throws RrdException, IOException { + return createRrdDefFromXmlSource(new InputSource(new StringReader(xmlString))); + } + + /** + * Creates RrdDef object from the file containing its XML equivalent. Here is an example + * of a properly formatted XML file:</p> + * <pre><code> + * <rrd_def> + * <path>test.rrd</path> + * <!-- not mandatory --> + * <start>1000123123</start> + * <!-- not mandatory --> + * <step>150</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>700</rows> + * </archive> + * <archive> + * <cf>MAX</cf> + * <xff>0.6</xff> + * <steps>6</steps> + * <rows>7000</rows> + * </archive> + * </rrd_def> + * </code></pre> + * + * @param filepath path containing XML formatted RRD definition (like the one given above) + * @return RrdDef object which can be used to create new RrdDb object + * @throws RrdException thrown in case of bad XML format or bad RRD definition parameters + * @throws IOException thrown in case of I/O error + */ + public RrdDef createRrdDefFromXmlFile(String filepath) throws RrdException, IOException { + FileReader fileReader = null; + try { + fileReader = new FileReader(filepath); + return createRrdDefFromXmlSource(new InputSource(fileReader)); + } + finally { + if(fileReader != null) { + fileReader.close(); + } + } + } + + /** + * Creates RrdDef object from any parsable XML source. The format of the underlying input + * source data must conform to the format described for the + * {@link #createRrdDefFromXmlFile createRrdDefFromXmlFile} method. + * @param inputSource parsable XML source containing complete RRD definition + * @return RrdDef object which can be used to create new RrdDb object + * @throws RrdException thrown in case of bad XML format or bad RRD definition parameters + * @throws IOException thrown in case of I/O error + */ + public RrdDef createRrdDefFromXmlSource(InputSource inputSource) throws RrdException, IOException { + try { + Element root = XmlReader.getRootElement(inputSource); + // must start with <rrd_def> + if(!root.getTagName().equals("rrd_def")) { + throw new RrdException("XML definition must start with <rrd_def>"); + } + // PATH must be supplied or exception is thrown + String path = XmlReader.getChildValue(root, "path"); + RrdDef rrdDef = new RrdDef(path); + try { + // START is not mandatory + long start = XmlReader.getChildValueAsLong(root, "start"); + rrdDef.setStartTime(start); + } + catch(RrdException e) { } + try { + // STEP is not mandatory + long step = XmlReader.getChildValueAsLong(root, "step"); + rrdDef.setStep(step); + } + catch(RrdException e) { + // NOP + } + // datsources + Node[] dsNodes = XmlReader.getChildNodes(root, "datasource"); + for(int i = 0; i < dsNodes.length; i++) { + String name = XmlReader.getChildValue(dsNodes[i], "name"); + String type = XmlReader.getChildValue(dsNodes[i], "type"); + long heartbeat = XmlReader.getChildValueAsLong(dsNodes[i], "heartbeat"); + double min = XmlReader.getChildValueAsDouble(dsNodes[i], "min"); + double max = XmlReader.getChildValueAsDouble(dsNodes[i], "max"); + rrdDef.addDatasource(name, type, heartbeat, min, max); + } + // archives + Node[] arcNodes = XmlReader.getChildNodes(root, "archive"); + for(int i = 0; i < arcNodes.length; i++) { + String consolFun = XmlReader.getChildValue(arcNodes[i], "cf"); + double xff = XmlReader.getChildValueAsDouble(arcNodes[i], "xff"); + int steps = XmlReader.getChildValueAsInt(arcNodes[i], "steps"); + int rows = XmlReader.getChildValueAsInt(arcNodes[i], "rows"); + rrdDef.addArchive(consolFun, xff, steps, rows); + } + return rrdDef; + } catch (FactoryConfigurationError e) { + throw new RrdException("XML error: " + e); + } catch (ParserConfigurationException e) { + throw new RrdException("XML error: " + e); + } catch (SAXException e) { + throw new RrdException("XML error: " + e); + } catch(NumberFormatException e) { + throw new RrdException("XML error: " + e); + } + } + + /* + public static void main(String[] args) throws RrdException, IOException { + String s = + "<rrd_def> " + + " <path>test.rrd</path> " + + " <start>1000000000</start> " + + " <step>151</step> " + + " <datasource> " + + " <name>input</name> " + + " <type>COUNTER</type> " + + " <heartbeat>300</heartbeat> " + + " <min>10</min> " + + " <max>U</max> " + + " </datasource> " + + " <datasource> " + + " <name>temperature</name> " + + " <type>GAUGE</type> " + + " <heartbeat>400</heartbeat> " + + " <min>U</min> " + + " <max>1000</max> " + + " </datasource> " + + " <archive> " + + " <cf>AVERAGE</cf> " + + " <xff>0.5</xff> " + + " <steps>1</steps> " + + " <rows>700</rows> " + + " </archive> " + + " <archive> " + + " <cf>MAX</cf> " + + " <xff>0.6</xff> " + + " <steps>6</steps> " + + " <rows>7000</rows> " + + " </archive> " + + "</rrd_def> "; + RrdDef def = RrdToolkit.getInstance().createRrdDefFromXmlString(s); + RrdDb db = new RrdDb(def); + db.close(); + } + */ } Index: XmlReader.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XmlReader.java 10 Nov 2003 08:52:27 -0000 1.2 --- XmlReader.java 19 Feb 2004 10:48:12 -0000 1.3 *************** *** 31,38 **** import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import javax.xml.parsers.*; import java.io.IOException; ! import java.io.File; import java.util.ArrayList; --- 31,39 ---- import org.w3c.dom.NodeList; import org.xml.sax.SAXException; + import org.xml.sax.InputSource; import javax.xml.parsers.*; import java.io.IOException; ! import java.io.FileReader; import java.util.ArrayList; *************** *** 43,53 **** XmlReader(String xmlFilePath) throws IOException, RrdException { try { ! DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ! factory.setValidating(false); ! factory.setNamespaceAware(false); ! DocumentBuilder builder = factory.newDocumentBuilder(); ! Document doc = builder.parse(new File(xmlFilePath)); ! root = doc.getDocumentElement(); dsNodes = getChildNodes(root, "ds"); arcNodes = getChildNodes(root, "rra"); --- 44,52 ---- XmlReader(String xmlFilePath) throws IOException, RrdException { + FileReader fileReader = null; try { ! fileReader = new FileReader(xmlFilePath); ! InputSource source = new InputSource(fileReader); ! root = getRootElement(source); dsNodes = getChildNodes(root, "ds"); arcNodes = getChildNodes(root, "rra"); *************** *** 59,62 **** --- 58,66 ---- throw new RrdException("XML error: " + e); } + finally { + if(fileReader != null) { + fileReader.close(); + } + } } *************** *** 202,204 **** --- 206,218 ---- return Util.parseDouble(valueStr); } + + static Element getRootElement(InputSource inputSource) + throws ParserConfigurationException, IOException, SAXException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setValidating(false); + factory.setNamespaceAware(false); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.parse(inputSource); + return doc.getDocumentElement(); + } } \ No newline at end of file |
|
From: <sa...@us...> - 2004-02-19 10:56:25
|
Update of /cvsroot/jrobin/src/org/jrobin/convertor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27887/org/jrobin/convertor Modified Files: Convertor.java Log Message: Nice utility to convert RRD files from RRDTool format to JRobin native format Index: Convertor.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/convertor/Convertor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Convertor.java 27 Jan 2004 10:49:42 -0000 1.1 --- Convertor.java 19 Feb 2004 10:46:08 -0000 1.2 *************** *** 24,28 **** private void convert() { ! println("Conversion started"); long start = System.currentTimeMillis(); if(!workingDirectory.endsWith(SEPARATOR)) { --- 24,31 ---- private void convert() { ! println("Converting RRDTool files to JRobin native format"); ! println("Converted files will be placed in the same directory, with " + ! suffix + " suffix appended"); ! println("=========================================="); long start = System.currentTimeMillis(); if(!workingDirectory.endsWith(SEPARATOR)) { *************** *** 43,46 **** --- 46,50 ---- File[] files = parent.listFiles(filter); for(int i = 0; i < files.length; i++) { + print("[" + i + "/" + files.length + "] "); convertFile(files[i]); } *************** *** 62,78 **** private long convertFile(File rrdFile) { long start = System.currentTimeMillis(); try { String sourcePath = rrdFile.getCanonicalPath(); ! String xmlPath = sourcePath + ".xml"; ! String destPath = sourcePath + suffix; print(rrdFile.getName() + " "); - // dump to XML file xmlDump(sourcePath, xmlPath); - // create RRD file from XML file RrdDb rrd = new RrdDb(destPath, xmlPath); rrd.close(); rrd = null; System.gc(); - new File(xmlPath).delete(); okCount++; long elapsed = System.currentTimeMillis() - start; --- 66,80 ---- private long convertFile(File rrdFile) { long start = System.currentTimeMillis(); + String xmlPath = null, destPath = null; try { String sourcePath = rrdFile.getCanonicalPath(); ! xmlPath = sourcePath + ".xml"; ! destPath = sourcePath + suffix; print(rrdFile.getName() + " "); xmlDump(sourcePath, xmlPath); RrdDb rrd = new RrdDb(destPath, xmlPath); rrd.close(); rrd = null; System.gc(); okCount++; long elapsed = System.currentTimeMillis() - start; *************** *** 80,91 **** --- 82,105 ---- return elapsed; } catch (IOException e) { + removeFile(destPath); badCount++; println("[IO ERROR]"); return -1; } catch (RrdException e) { + removeFile(destPath); badCount++; println("[RRD ERROR]"); return -2; } + finally { + removeFile(xmlPath); + } + } + + private static boolean removeFile(String filePath) { + if(filePath != null) { + return new File(filePath).delete(); + } + return true; } *************** *** 94,99 **** Process p = RUNTIME.exec(cmd); OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xmlPath, false)); ! readStream(p.getInputStream(), outStream); ! readStream(p.getErrorStream(), null); try { p.waitFor(); --- 108,113 ---- Process p = RUNTIME.exec(cmd); OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xmlPath, false)); ! transportStream(p.getInputStream(), outStream); ! transportStream(p.getErrorStream(), null); try { p.waitFor(); *************** *** 102,107 **** // NOP } - outStream.flush(); - outStream.close(); } --- 116,119 ---- *************** *** 125,133 **** } ! private static void readStream(InputStream in, OutputStream out) throws IOException { ! int b; ! while((b = in.read()) != -1) { if(out != null) { ! out.write(b); } } --- 137,154 ---- } ! private static void transportStream(InputStream in, OutputStream out) throws IOException { ! try { ! int b; ! while((b = in.read()) != -1) { ! if(out != null) { ! out.write(b); ! } ! } ! } ! finally { ! in.close(); if(out != null) { ! out.flush(); ! out.close(); } } |
|
From: <sa...@pr...> - 2004-01-27 10:50:44
|
Update of /cvsroot/jrobin/src/org/jrobin/convertor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4469/org/jrobin/convertor Added Files: Convertor.java Log Message: Added nice command line utility to convert RRDTool files to Jrobin RRD file format in bulk... --- NEW FILE: Convertor.java --- package org.jrobin.convertor; import org.jrobin.core.RrdDb; import org.jrobin.core.RrdException; import java.io.*; class Convertor { static final String SUFFIX = ".jrb"; static final String SEPARATOR = System.getProperty("file.separator"); static final Runtime RUNTIME = Runtime.getRuntime(); private String rrdtoolBinary; private String workingDirectory; private String suffix; private int okCount, badCount; private Convertor(String rrdtoolBinary, String workingDirectory, String suffix) { this.rrdtoolBinary = rrdtoolBinary; this.workingDirectory = workingDirectory; this.suffix = suffix; } private void convert() { println("Conversion started"); long start = System.currentTimeMillis(); if(!workingDirectory.endsWith(SEPARATOR)) { workingDirectory += SEPARATOR; } File parent = new File(workingDirectory); if(parent.isDirectory() && parent.exists()) { // directory FileFilter filter = new FileFilter() { public boolean accept(File f) { try { return !f.isDirectory() && f.getCanonicalPath().endsWith(".rrd"); } catch (IOException e) { return false; } } }; File[] files = parent.listFiles(filter); for(int i = 0; i < files.length; i++) { convertFile(files[i]); } } else if(!parent.isDirectory() && parent.exists()) { // single file convertFile(parent); } else { println("Nothing to do"); } println("Conversion finished, " + okCount + " files ok, " + badCount + " files bad"); long secs = (System.currentTimeMillis() - start + 500L) / 1000L; long mins = secs / 60; secs %= 60; println("Time elapsed: " + mins + ":" + ((secs < 10)? "0": "") + secs); } private long convertFile(File rrdFile) { long start = System.currentTimeMillis(); try { String sourcePath = rrdFile.getCanonicalPath(); String xmlPath = sourcePath + ".xml"; String destPath = sourcePath + suffix; print(rrdFile.getName() + " "); // dump to XML file xmlDump(sourcePath, xmlPath); // create RRD file from XML file RrdDb rrd = new RrdDb(destPath, xmlPath); rrd.close(); rrd = null; System.gc(); new File(xmlPath).delete(); okCount++; long elapsed = System.currentTimeMillis() - start; println("[OK, " + (elapsed / 1000.0) + "]"); return elapsed; } catch (IOException e) { badCount++; println("[IO ERROR]"); return -1; } catch (RrdException e) { badCount++; println("[RRD ERROR]"); return -2; } } private void xmlDump(String sourcePath, String xmlPath) throws IOException { String[] cmd = new String[] { rrdtoolBinary, "dump", sourcePath }; Process p = RUNTIME.exec(cmd); OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xmlPath, false)); readStream(p.getInputStream(), outStream); readStream(p.getErrorStream(), null); try { p.waitFor(); } catch(InterruptedException ie) { // NOP } outStream.flush(); outStream.close(); } public static void main(String[] args) { if(args.length < 2 || args.length > 3) { println("Usage: java -jar convertor.jar " + "<path to RRDTool binary> <RRD directory/file path> [converted file suffix]"); } else { Convertor c = new Convertor(args[0], args[1], args.length == 3? args[2]: SUFFIX); c.convert(); } } private final static void println(String msg) { System.out.println(msg); } private final static void print(String msg) { System.out.print(msg); } private static void readStream(InputStream in, OutputStream out) throws IOException { int b; while((b = in.read()) != -1) { if(out != null) { out.write(b); } } } } |
|
From: <sa...@pr...> - 2004-01-27 10:49:13
|
Update of /cvsroot/jrobin/src/org/jrobin/convertor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4015/convertor Log Message: Directory /cvsroot/jrobin/src/org/jrobin/convertor added to the repository |
|
From: <sa...@pr...> - 2004-01-26 12:38:55
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11013 Modified Files: PlottableDemo.java Log Message: Nice plottable demo Index: PlottableDemo.java =================================================================== RCS file: /cvsroot/jrobin/src/PlottableDemo.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PlottableDemo.java 20 Jan 2004 15:59:01 -0000 1.1 --- PlottableDemo.java 26 Jan 2004 12:38:01 -0000 1.2 *************** *** 3,46 **** import java.awt.*; import java.io.IOException; ! import java.util.GregorianCalendar; class PlottableDemo { public static void main(String[] args) throws RrdException, IOException { ! // create plottable datasource ! GregorianCalendar[] gc = { ! new GregorianCalendar(2004, 0, 1), ! new GregorianCalendar(2004, 0, 4), ! new GregorianCalendar(2004, 0, 6), ! new GregorianCalendar(2004, 0, 12), ! new GregorianCalendar(2004, 0, 18), ! new GregorianCalendar(2004, 0, 19), ! new GregorianCalendar(2004, 0, 21) ! }; ! double values[] = { ! 1.2, 3.4, 2.7, 3.0, 1.1, 1.2, 1.6 }; ! // four different imterpolation methods ! LinearInterpolator i1 = new LinearInterpolator(gc, values); // defaults to INTERPOLATE_LINEAR ! LinearInterpolator i2 = new LinearInterpolator(gc, values); ! i2.setInterpolationMethod(LinearInterpolator.INTERPOLATE_LEFT); ! LinearInterpolator i3 = new LinearInterpolator(gc, values); ! i3.setInterpolationMethod(LinearInterpolator.INTERPOLATE_RIGHT); ! CubicSplineInterpolator i4 = new CubicSplineInterpolator(gc, values); // graph definition ! RrdGraphDef gdef = new RrdGraphDef(gc[0], gc[gc.length - 1]); gdef.setTitle("Plottable demonstration"); gdef.setTimeAxisLabel("days of our lives"); gdef.setVerticalLabel("inspiration"); gdef.datasource("linear", i1); ! gdef.datasource("left", i2); ! gdef.datasource("right", i3); ! gdef.datasource("spline", i4); ! gdef.area("linear", Color.RED, "Linear"); ! gdef.line("left", Color.BLUE, "Left", 2); ! gdef.line("right", Color.GREEN, "Right@L", 2); ! gdef.line("spline", Color.MAGENTA, "Spline@R", 2); gdef.setTimeAxis(TimeAxisUnit.DAY, 1, TimeAxisUnit.DAY, 1, "dd", true); RrdGraph g = new RrdGraph(gdef); ! g.saveAsPNG("plottable.png", 500, 250); } } --- 3,42 ---- import java.awt.*; import java.io.IOException; ! import java.util.Date; class PlottableDemo { public static void main(String[] args) throws RrdException, IOException { ! final long t0 = new Date().getTime() / 1000L, dt = 86400L; ! final int n = 10; ! final long t1 = t0 + (n - 1) * dt; ! Plottable p = new Plottable() { ! public double getValue(long t) { ! double x = (t - t0) / (double)(t1 - t0); ! return Math.exp(-x * 2) * Math.cos(x * 7 * Math.PI); ! } }; ! ! long t[] = new long[n]; ! double x[] = new double[n]; ! for(int i = 0; i < n; i++) { ! t[i] = t0 + i * dt; ! x[i] = p.getValue(t[i]); ! } ! LinearInterpolator i1 = new LinearInterpolator(t, x); // defaults to INTERPOLATE_LINEAR ! CubicSplineInterpolator i2 = new CubicSplineInterpolator(t, x); // graph definition ! RrdGraphDef gdef = new RrdGraphDef(t0, t1); gdef.setTitle("Plottable demonstration"); gdef.setTimeAxisLabel("days of our lives"); gdef.setVerticalLabel("inspiration"); + gdef.datasource("real", p); gdef.datasource("linear", i1); ! gdef.datasource("spline", i2); ! gdef.line("real", Color.BLUE, "Real values", 1); ! gdef.line("linear", Color.RED, "Linear interpolation", 1); ! gdef.line("spline", Color.MAGENTA, "Spline interpolation@r", 1); gdef.setTimeAxis(TimeAxisUnit.DAY, 1, TimeAxisUnit.DAY, 1, "dd", true); RrdGraph g = new RrdGraph(gdef); ! g.saveAsPNG("plottable2.png", 400, 200); } } |
|
From: <sa...@us...> - 2004-01-20 15:59:05
|
Update of /cvsroot/jrobin/src
In directory sc8-pr-cvs1:/tmp/cvs-serv27785
Added Files:
PlottableDemo.java
Log Message:
CubicSplineInterpolator introduced
--- NEW FILE: PlottableDemo.java ---
import org.jrobin.graph.*;
import org.jrobin.core.RrdException;
import java.awt.*;
import java.io.IOException;
import java.util.GregorianCalendar;
class PlottableDemo {
public static void main(String[] args) throws RrdException, IOException {
// create plottable datasource
GregorianCalendar[] gc = {
new GregorianCalendar(2004, 0, 1),
new GregorianCalendar(2004, 0, 4),
new GregorianCalendar(2004, 0, 6),
new GregorianCalendar(2004, 0, 12),
new GregorianCalendar(2004, 0, 18),
new GregorianCalendar(2004, 0, 19),
new GregorianCalendar(2004, 0, 21)
};
double values[] = {
1.2, 3.4, 2.7, 3.0, 1.1, 1.2, 1.6
};
// four different imterpolation methods
LinearInterpolator i1 = new LinearInterpolator(gc, values); // defaults to INTERPOLATE_LINEAR
LinearInterpolator i2 = new LinearInterpolator(gc, values);
i2.setInterpolationMethod(LinearInterpolator.INTERPOLATE_LEFT);
LinearInterpolator i3 = new LinearInterpolator(gc, values);
i3.setInterpolationMethod(LinearInterpolator.INTERPOLATE_RIGHT);
CubicSplineInterpolator i4 = new CubicSplineInterpolator(gc, values);
// graph definition
RrdGraphDef gdef = new RrdGraphDef(gc[0], gc[gc.length - 1]);
gdef.setTitle("Plottable demonstration");
gdef.setTimeAxisLabel("days of our lives");
gdef.setVerticalLabel("inspiration");
gdef.datasource("linear", i1);
gdef.datasource("left", i2);
gdef.datasource("right", i3);
gdef.datasource("spline", i4);
gdef.area("linear", Color.RED, "Linear");
gdef.line("left", Color.BLUE, "Left", 2);
gdef.line("right", Color.GREEN, "Right@L", 2);
gdef.line("spline", Color.MAGENTA, "Spline@R", 2);
gdef.setTimeAxis(TimeAxisUnit.DAY, 1, TimeAxisUnit.DAY, 1, "dd", true);
RrdGraph g = new RrdGraph(gdef);
g.saveAsPNG("plottable.png", 500, 250);
}
}
|
|
From: <sa...@us...> - 2004-01-20 15:59:05
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1:/tmp/cvs-serv27785/org/jrobin/graph Added Files: CubicSplineInterpolator.java Log Message: CubicSplineInterpolator introduced --- NEW FILE: CubicSplineInterpolator.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.graph; import org.jrobin.core.RrdException; import org.jrobin.core.Util; import java.util.Date; import java.util.GregorianCalendar; /** * Class used to interpolate datasource values from the collection of (timestamp, values) * points using natural cubic spline interpolation.<p> * * <b>WARNING</b>: So far, this class cannot handle NaN datasource values * (an exception will be thrown by the constructor). Future releases might change this. * * Pass instances of this class to {@link RrdGraphDef#datasource(String, Plottable) * RrdGraphDef.datasource()} to provide spline-interpolated datasource values to JRobin grapher.<p> */ public class CubicSplineInterpolator extends Plottable { private double[] x; private double[] y; // second derivates come here private double[] y2; // internal spline variables private int n, klo, khi; /** * Creates cubic spline interpolator from arrays of timestamps and corresponding * datasource values. * @param timestamps timestamps in seconds * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least 3 values, or if * timestamps are not ordered, or array lengths are not equal, or some datasource value is NaN. */ public CubicSplineInterpolator(long[] timestamps, double[] values) throws RrdException { this.x = new double[timestamps.length]; for(int i = 0; i < timestamps.length; i++) { this.x[i] = timestamps[i]; } this.y = values; validate(); spline(); } /** * Creates cubic spline interpolator from arrays of Date objects and corresponding * datasource values. * @param dates Array of Date objects * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least 3 values, or if * timestamps are not ordered, or array lengths are not equal, or some datasource value is NaN. */ public CubicSplineInterpolator(Date[] dates, double[] values) throws RrdException { this.x = new double[dates.length]; for(int i = 0; i < dates.length; i++) { this.x[i] = Util.getTimestamp(dates[i]); } this.y = values; validate(); spline(); } /** * Creates cubic spline interpolator from arrays of GregorianCalendar objects and corresponding * datasource values. * @param dates Array of GregorianCalendar objects * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least 3 values, or if * timestamps are not ordered, or array lengths are not equal, or some datasource value is NaN. */ public CubicSplineInterpolator(GregorianCalendar[] dates, double[] values) throws RrdException { this.x = new double[dates.length]; for(int i = 0; i < dates.length; i++) { this.x[i] = Util.getTimestamp(dates[i]); } this.y = values; validate(); spline(); } /** * Creates cubic spline interpolator for an array of 2D-points. * @param x x-axis point coordinates * @param y y-axis point coordinates * @throws RrdException Thrown if supplied arrays do not contain at least 3 values, or if * timestamps are not ordered, or array lengths are not equal, or some datasource value is NaN. */ public CubicSplineInterpolator(double[] x, double[] y) throws RrdException { this.x = x; this.y = y; validate(); spline(); } private void validate() throws RrdException { boolean ok = true; if(x.length != y.length || x.length < 3) { ok = false; } for(int i = 0; i < x.length - 1 && ok; i++) { if(x[i] >= x[i + 1] || Double.isNaN(y[i])) { ok = false; } } if(!ok) { throw new RrdException("Invalid plottable data supplied"); } } private void spline() { n = x.length; y2 = new double[n]; double[] u = new double[n - 1]; y2[0] = y2[n - 1] = 0.0; u[0] = 0.0; // natural spline for (int i = 1; i <= n - 2; i++) { double sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]); double p = sig * y2[i - 1] + 2.0; y2[i] = (sig - 1.0) / p; u[i] = (y[i + 1] - y[i]) / (x[i + 1] - x[i]) - (y[i] - y[i - 1]) / (x[i] - x[i - 1]); u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p; } for (int k = n - 2; k >= 0; k--) { y2[k] = y2[k] * y2[k + 1] + u[k]; } // prepare everything for getValue() klo = 0; khi = n - 1; } /** * Calculates spline-interpolated y-value for the corresponding x-value. Call * this if you need spline-interpolated values in your code. * @param xval x-value * @return inteprolated y-value */ public double getValue(double xval) { if(xval < x[0] || xval > x[n - 1]) { return Double.NaN; } if(xval < x[klo] || xval > x[khi]) { // out of bounds klo = 0; khi = n - 1; } while (khi - klo > 1) { // find bounding interval using bisection method int k = (khi + klo) / 2; if (x[k] > xval) { khi = k; } else { klo = k; } } double h = x[khi] - x[klo]; double a = (x[khi] - xval) / h; double b = (xval - x[klo]) / h; return a * y[klo] + b * y[khi] + ((a * a * a - a) * y2[klo] + (b * b * b - b) * y2[khi]) * (h * h) / 6.0; } /** * Method overriden from the base class. This method will be called by the framework. Call * this method only if you need spline-interpolated values in your code. * @param timestamp timestamp in seconds * @return inteprolated datasource value */ public double getValue(long timestamp) { return getValue((double)timestamp); } } |
|
From: <sa...@us...> - 2004-01-20 10:07:53
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server
In directory sc8-pr-cvs1:/tmp/cvs-serv24108/org/jrobin/mrtg/server
Modified Files:
Listener.java Server.java
Log Message:
Minor changes to mrtg server app
Index: Listener.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Listener.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Listener.java 9 Dec 2003 12:22:04 -0000 1.1
--- Listener.java 20 Jan 2004 10:07:50 -0000 1.2
***************
*** 30,34 ****
import org.jrobin.mrtg.MrtgException;
- import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
--- 30,33 ----
***************
*** 38,53 ****
private WebServer webServer;
! Listener() throws MrtgException {
! start();
! }
!
! private void start() throws MrtgException {
! try {
! webServer = new WebServer(SERVER_PORT);
! webServer.addHandler("mrtg", new EventHandler());
! Debug.print("XmlRpcServer started on port " + SERVER_PORT);
! } catch (IOException e) {
! throw new MrtgException(e);
}
}
--- 37,51 ----
private WebServer webServer;
! Listener(String[] clients) throws MrtgException {
! webServer = new WebServer(SERVER_PORT);
! webServer.addHandler("mrtg", new EventHandler());
! if(clients != null && clients.length > 0) {
! webServer.setParanoid(true);
! for(int i = 0; i < clients.length; i++) {
! webServer.acceptClient(clients[i]);
! }
}
+ webServer.start();
+ Debug.print("XmlRpcServer started on port " + SERVER_PORT);
}
***************
*** 55,65 ****
if(webServer != null) {
webServer.shutdown();
- /*
- // HACK: this takes some time - wait a few seconds before proceeding
- try {
- Thread.sleep(5000L);
- } catch (InterruptedException e) {
- }
- */
Debug.print("XmlRpcServer closed");
webServer = null;
--- 53,56 ----
***************
*** 71,83 ****
}
- void setParanoid(String[] clients) {
- if(clients.length > 0 && webServer != null) {
- webServer.setParanoid(true);
- for(int i = 0; i < clients.length; i++) {
- webServer.acceptClient(clients[i]);
- }
- }
- }
-
public class EventHandler {
public int addRouter(String host, String community, String descr, boolean active) {
--- 62,65 ----
Index: Server.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Server.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Server.java 9 Dec 2003 12:22:04 -0000 1.4
--- Server.java 20 Jan 2004 10:07:50 -0000 1.5
***************
*** 68,72 ****
}
! public synchronized void start() throws MrtgException {
if(active) {
throw new MrtgException("Cannot start Server, already started");
--- 68,72 ----
}
! public synchronized void start(String[] acceptedClients) throws MrtgException {
if(active) {
throw new MrtgException("Cannot start Server, already started");
***************
*** 82,86 ****
rrdWriter = new RrdWriter();
timer = new Timer();
! listener = new Listener();
startDate = new Date();
active = true;
--- 82,86 ----
rrdWriter = new RrdWriter();
timer = new Timer();
! listener = new Listener(acceptedClients);
startDate = new Date();
active = true;
***************
*** 193,196 ****
--- 193,199 ----
int retCode = deviceList.removeLink(host, ifDescr);
saveHardware();
+ // remove the underlying RRD file
+ String rrdFile = RrdWriter.getRrdFilename(host, ifDescr);
+ new File(rrdFile).delete();
return retCode;
}
***************
*** 242,256 ****
}
! public void setParanoid(String[] clients) {
! listener.setParanoid(clients);
! }
!
! public static void main(String[] args) throws Exception {
Server s = Server.getInstance();
! s.start();
! s.setParanoid(args);
! // this will end the server process
! // System.out.println("Exiting");
! // s.stop();
}
}
--- 245,251 ----
}
! public static void main(String[] acceptedClients) throws Exception {
Server s = Server.getInstance();
! s.start(acceptedClients);
}
}
|
|
From: <sa...@us...> - 2004-01-20 09:09:36
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1:/tmp/cvs-serv13566/org/jrobin/graph Added Files: LinearInterpolator.java Log Message: LinearInterpolator added (makes use of Plottable interface) --- NEW FILE: LinearInterpolator.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.graph; import org.jrobin.core.RrdException; import org.jrobin.core.Util; import java.util.Date; import java.util.GregorianCalendar; /** * Class used to interpolate datasource values from the collection of (timestamp, values) * points. This class is suitable for linear interpolation only. <p> * * Interpolation algorithm returns different values based on the value passed to * {@link #setInterpolationMethod(int) setInterpolationMethod()}. If not set, interpolation * method defaults to standard linear interpolation. Interpolation method handles NaN datasource * values gracefully.<p> * * Pass instances of this class to {@link RrdGraphDef#datasource(String, Plottable) * RrdGraphDef.datasource()} to provide interpolated datasource values to JRobin grapher.<p> */ public class LinearInterpolator extends Plottable { /** constant used to specify LEFT interpolation. * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_LEFT = 0; /** constant used to specify RIGHT interpolation. * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_RIGHT = 1; /** constant used to specify LINEAR interpolation (default interpolation method). * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_LINEAR = 2; private int lastIndexUsed = 0; private int interpolationMethod = INTERPOLATE_LINEAR; private long[] timestamps; private double[] values; /** * Creates LinearInterpolator from arrays of timestamps and corresponding datasource values. * @param timestamps timestamps in seconds * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least two values, or if * timestamps are not ordered, or array lengths are not equal. */ public LinearInterpolator(long[] timestamps, double[] values) throws RrdException { this.timestamps = timestamps; this.values = values; validate(); } /** * Creates LinearInterpolator from arrays of timestamps and corresponding datasource values. * @param dates Array of Date objects * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least two values, or if * timestamps are not ordered, or array lengths are not equal. */ public LinearInterpolator(Date[] dates, double[] values) throws RrdException { this.values = values; timestamps = new long[dates.length]; for(int i = 0; i < dates.length; i++) { timestamps[i] = Util.getTimestamp(dates[i]); } validate(); } /** * Creates LinearInterpolator from arrays of timestamps and corresponding datasource values. * @param dates array of GregorianCalendar objects * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least two values, or if * timestamps are not ordered, or array lengths are not equal. */ public LinearInterpolator(GregorianCalendar[] dates, double[] values) throws RrdException { this.values = values; timestamps = new long[dates.length]; for(int i = 0; i < dates.length; i++) { timestamps[i] = Util.getTimestamp(dates[i]); } validate(); } private void validate() throws RrdException { boolean ok = true; if(timestamps.length != values.length || timestamps.length < 2) { ok = false; } for(int i = 0; i < timestamps.length - 1 && ok; i++) { if(timestamps[i] >= timestamps[i + 1]) { ok = false; } } if(!ok) { throw new RrdException("Invalid plottable data supplied"); } } /** * Sets interpolation method to be used. Suppose that we have two timestamp/value pairs:<br> * <code>(t, 100)</code> and <code>(t + 100, 300)</code>. Here are the results interpolator * returns for t + 50 seconds, for various <code>interpolationMethods</code>:<p> * <ul> * <li><code>INTERPOLATE_LEFT: 100</code> * <li><code>INTERPOLATE_RIGHT: 300</code> * <li><code>INTERPOLATE_LINEAR: 200</code> * </ul> * If not set, interpolation method defaults to <code>INTERPOLATE_LINEAR</code>. * @param interpolationMethod Should be <code>INTERPOLATE_LEFT</code>, * <code>INTERPOLATE_RIGHT</code> or <code>INTERPOLATE_LINEAR</code>. */ public void setInterpolationMethod(int interpolationMethod) { this.interpolationMethod = interpolationMethod; } /** * Method overriden from the base class. This method will be called by the framework. Call * this method only if you need interpolated values in your code. * @param timestamp timestamp in seconds * @return inteprolated datasource value */ public double getValue(long timestamp) { int count = timestamps.length; // check if out of range if(timestamp < timestamps[0] || timestamp > timestamps[count - 1]) { return Double.NaN; } // find matching segment int startIndex = lastIndexUsed; if(timestamp < timestamps[lastIndexUsed]) { // backward reading, shift to the first timestamp startIndex = 0; } for(int i = startIndex; i < count; i++) { if(timestamps[i] == timestamp) { return values[i]; } if(i < count - 1 && timestamps[i] < timestamp && timestamp < timestamps[i + 1]) { // matching segment found lastIndexUsed = i; switch(interpolationMethod) { case INTERPOLATE_LEFT: return values[i]; case INTERPOLATE_RIGHT: return values[i + 1]; case INTERPOLATE_LINEAR: double slope = (values[i + 1] - values[i]) / (timestamps[i + 1] - timestamps[i]); return values[i] + slope * (timestamp - timestamps[i]); default: return Double.NaN; } } } // should not be here ever, but let's satisfy the compiler return Double.NaN; } } |
|
From: <sa...@us...> - 2004-01-20 09:09:36
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv13566/org/jrobin/core
Modified Files:
Util.java
Log Message:
LinearInterpolator added (makes use of Plottable interface)
Index: Util.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Util.java 28 Nov 2003 13:24:46 -0000 1.6
--- Util.java 20 Jan 2004 09:09:33 -0000 1.7
***************
*** 205,210 ****
}
! static int getMatchingDatasourceIndex(RrdDb rrd1, int dsIndex, RrdDb rrd2)
! throws IOException {
String dsName = rrd1.getDatasource(dsIndex).getDsName();
try {
--- 205,209 ----
}
! static int getMatchingDatasourceIndex(RrdDb rrd1, int dsIndex, RrdDb rrd2) {
String dsName = rrd1.getDatasource(dsIndex).getDsName();
try {
|
|
From: <cob...@us...> - 2004-01-16 16:36:59
|
Update of /cvsroot/jrobin/src/org/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv10372/src/org/jrobin/graph
Modified Files:
Pdef.java RrdGraphDef.java Plottable.java
Log Message:
JRobin 1.2.3-dev
- Switched to abstract Plottable class instead of interface
Index: Pdef.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Pdef.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Pdef.java 15 Jan 2004 22:24:30 -0000 1.1
--- Pdef.java 16 Jan 2004 16:36:54 -0000 1.2
***************
*** 28,32 ****
* <p>Plottable Def, reprents a custom datasource that can be graphed by JRobin.
* All the Pdef needs, is a reference to a Plottable class, and it will get the datapoint values (based
! * on timestamps) from that external class. Any class implementing the public Plottable interface will do,
* meaning that the class could get its values from ANY source... like a RDBMS for example.
* </p>
--- 28,32 ----
* <p>Plottable Def, reprents a custom datasource that can be graphed by JRobin.
* All the Pdef needs, is a reference to a Plottable class, and it will get the datapoint values (based
! * on timestamps) from that external class. Any class extending the public Plottable class will do,
* meaning that the class could get its values from ANY source... like a RDBMS for example.
* </p>
***************
*** 47,51 ****
* (represented as a Plottable class) that can be graphed by JRobin.
* @param name Name of the datasource in the graph definition.
! * @param plottable Reference to the class implementing the Plottable interface and providing the datapoints.
*/
Pdef( String name, Plottable plottable )
--- 47,51 ----
* (represented as a Plottable class) that can be graphed by JRobin.
* @param name Name of the datasource in the graph definition.
! * @param plottable Reference to the class extending Plottable and providing the datapoints.
*/
Pdef( String name, Plottable plottable )
***************
*** 59,63 ****
* (represented as a Plottable class) that can be graphed by JRobin.
* @param name Name of the datasource in the graph definition.
! * @param plottable Reference to the class implementing the Plottable interface and providing the datapoints.
* @param index Integer number used for referring to the series of datapoints to use in the Plottable class.
*/
--- 59,63 ----
* (represented as a Plottable class) that can be graphed by JRobin.
* @param name Name of the datasource in the graph definition.
! * @param plottable Reference to the class extending Plottable and providing the datapoints.
* @param index Integer number used for referring to the series of datapoints to use in the Plottable class.
*/
***************
*** 74,78 ****
* (represented as a Plottable class) that can be graphed by JRobin.
* @param name Name of the datasource in the graph definition.
! * @param plottable Reference to the class implementing the Plottable interface and providing the datapoints.
* @param sourceName String used for referring to the series of datapoints to use in the Plottable class.
*/
--- 74,78 ----
* (represented as a Plottable class) that can be graphed by JRobin.
* @param name Name of the datasource in the graph definition.
! * @param plottable Reference to the class extending Plottable and providing the datapoints.
* @param sourceName String used for referring to the series of datapoints to use in the Plottable class.
*/
Index: RrdGraphDef.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RrdGraphDef.java 15 Jan 2004 22:24:30 -0000 1.4
--- RrdGraphDef.java 16 Jan 2004 16:36:54 -0000 1.5
***************
*** 661,668 ****
/**
* <p>Adds a custom graph source with the given name to the graph definition.
! * The datapoints should be made available by a class implementing the Plottable interface.</p>
*
* @param name Graph source name.
! * @param plottable Class that implements plottable interface and is suited for graphing.
*/
public void datasource( String name, Plottable plottable )
--- 661,668 ----
/**
* <p>Adds a custom graph source with the given name to the graph definition.
! * The datapoints should be made available by a class extending Plottable.</p>
*
* @param name Graph source name.
! * @param plottable Class that extends Plottable class and is suited for graphing.
*/
public void datasource( String name, Plottable plottable )
***************
*** 673,680 ****
/**
* <p>Adds a custom graph source with the given name to the graph definition.
! * The datapoints should be made available by a class implementing the Plottable interface.</p>
*
* @param name Graph source name.
! * @param plottable Class that implements plottable interface and is suited for graphing.
* @param index Integer referring to the datasource in the Plottable class.
*/
--- 673,680 ----
/**
* <p>Adds a custom graph source with the given name to the graph definition.
! * The datapoints should be made available by a class extending Plottable.</p>
*
* @param name Graph source name.
! * @param plottable Class that extends Plottable class and is suited for graphing.
* @param index Integer referring to the datasource in the Plottable class.
*/
***************
*** 686,693 ****
/**
* <p>Adds a custom graph source with the given name to the graph definition.
! * The datapoints should be made available by a class implementing the Plottable interface.</p>
*
* @param name Graph source name.
! * @param plottable Class that implements plottable interface and is suited for graphing.
* @param sourceName String name referring to the datasource in the Plottable class.
*/
--- 686,693 ----
/**
* <p>Adds a custom graph source with the given name to the graph definition.
! * The datapoints should be made available by a class extending Plottable.</p>
*
* @param name Graph source name.
! * @param plottable Class that extends Plottable class and is suited for graphing.
* @param sourceName String name referring to the datasource in the Plottable class.
*/
Index: Plottable.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Plottable.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Plottable.java 15 Jan 2004 22:24:30 -0000 1.1
--- Plottable.java 16 Jan 2004 16:36:54 -0000 1.2
***************
*** 28,37 ****
* <p>Interface to be used for custom datasources.
* If you wish to use a custom datasource in a graph, you should create a class implementing this interface
! * that represents that datasource, and then pass this class on to the RrdGraphDef.
! * </p>
*
* @author Arne Vandamme <cob...@ch...>
*/
! public interface Plottable
{
/**
--- 28,36 ----
* <p>Interface to be used for custom datasources.
* If you wish to use a custom datasource in a graph, you should create a class implementing this interface
! * that represents that datasource, and then pass this class on to the RrdGraphDef.</p>
*
* @author Arne Vandamme <cob...@ch...>
*/
! public abstract class Plottable
{
/**
***************
*** 41,45 ****
* @return Double value of the datapoint.
*/
! public double getValue( long timestamp );
/**
--- 40,46 ----
* @return Double value of the datapoint.
*/
! public double getValue( long timestamp ) {
! return Double.NaN;
! }
/**
***************
*** 49,53 ****
* @return Double value of the datapoint.
*/
! public double getValue( long timestamp, int index );
/**
--- 50,56 ----
* @return Double value of the datapoint.
*/
! public double getValue( long timestamp, int index ) {
! return Double.NaN;
! }
/**
***************
*** 57,60 ****
* @return Double value of the datapoint.
*/
! public double getValue( long timestamp, String fieldName );
}
--- 60,65 ----
* @return Double value of the datapoint.
*/
! public double getValue( long timestamp, String fieldName ) {
! return Double.NaN;
! }
}
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1:/tmp/cvs-serv3268/src/org/jrobin/graph Modified Files: Legend.java RrdGraphDef.java Area.java Grapher.java Comment.java Line.java Cdef.java FetchSource.java Gprint.java PlotDef.java TimeAxisLabel.java Source.java CustomArea.java Stack.java Added Files: XmlGraphDefConvertor.java Plottable.java Pdef.java Log Message: JRobin 1.2.3-dev - Added Plottable interface, support for custom graph sources - Added basic XML input for RrdGraphDef - Added basic XML output for RrdGraphDef (getJRobinXml()) --- NEW FILE: XmlGraphDefConvertor.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.graph; import javax.xml.parsers.*; import java.io.*; import java.awt.Color; import org.xml.sax.*; import org.xml.sax.helpers.*; import org.jrobin.core.RrdException; /** * <p>JRobin</p> * * @author Arne Vandamme <cob...@ch...> */ class XmlGraphDefConvertor extends DefaultHandler { // ---------------------------------------- private final static Byte BLOCK_ROOT = new Byte((byte)0); private final static Byte BLOCK_GENERAL = new Byte((byte)1); private final static Byte BLOCK_DATASOURCES = new Byte((byte)2); private final static Byte BLOCK_GRAPHING = new Byte((byte)3); private final static Byte EL_NONE = new Byte((byte)0); private final static Byte EL_DEF = new Byte((byte)1); private final static Byte EL_CDEF = new Byte((byte)2); private final static Byte EL_GENERAL = new Byte((byte)3); private final static Byte EL_DATASOURCES = new Byte((byte)4); private final static Byte EL_GRAPHING = new Byte((byte)5); private final static Byte EL_DEF_FILE = new Byte((byte)6); private final static Byte EL_DEF_DSNAME = new Byte((byte)7); private final static Byte EL_DEF_CF = new Byte((byte)8); private final static Byte EL_COMMENT = new Byte((byte)9); private final static Byte EL_LINE = new Byte((byte)10); private final static Byte EL_LINE_DS = new Byte((byte)11); private final static Byte EL_PERIOD = new Byte((byte)12); private final static Byte EL_LINE_LEGEND = new Byte((byte)13); private final static Byte EL_LINE_WIDTH = new Byte((byte)14); private final static Byte EL_PERIOD_START = new Byte((byte)15); private final static Byte EL_PERIOD_STOP = new Byte((byte)16); private final static Byte EL_LINE_COLOR = new Byte((byte)17); private final static Byte EL_AREA = new Byte((byte)18); private final static Byte EL_TITLE = new Byte((byte)19); private final static Byte EL_IMGBORDER = new Byte((byte)20); private final static Byte EL_BORDERWIDTH = new Byte((byte)21); private final static Byte EL_COLORS = new Byte((byte)22); private final static Byte EL_CLR_BACKGROUND = new Byte((byte)23); private final static Byte EL_CLR_CANVAS = new Byte((byte)24); private final static Byte EL_SIGNATURE = new Byte((byte)25); private RrdGraphDef def; private String[] params = new String[6]; private Color colorParam = null; private int intParam = 0; private int numParams = 1; private java.util.Stack tags = new java.util.Stack(); private int level = 0; private Byte block = BLOCK_ROOT; private Byte element = EL_NONE; XmlGraphDefConvertor( String xml, RrdGraphDef def ) throws RrdException { this.def = def; tags.push( EL_NONE ); try { SAXParserFactory factory = SAXParserFactory.newInstance(); // Parse the input SAXParser saxParser = factory.newSAXParser(); saxParser.parse( new ByteArrayInputStream( xml.getBytes() ), this ); } catch ( Exception e ) { //throw new RrdException( "Could not parse XML string." ); e.printStackTrace(); } } /** * */ public void startElement(String namespaceURI, String lName, String qName, Attributes attrs) throws SAXException { level++; Byte parent = (Byte) tags.peek(); if ( qName.equals("color") || ( parent == EL_COLORS && ( qName.equals("background") || qName.equals("canvas") ) ) ) { colorParam = new Color( Integer.parseInt(attrs.getValue("r")), Integer.parseInt(attrs.getValue("g")), Integer.parseInt(attrs.getValue("b")) ); numParams |= 2; } if ( parent == EL_COLORS ) { if ( qName.equals("background") ) tags.push( EL_CLR_BACKGROUND ); else if ( qName.equals("canvas") ) tags.push( EL_CLR_CANVAS ); } if ( parent == EL_DEF ) { if ( qName.equals("file") ) tags.push( EL_DEF_FILE ); else if ( qName.equals("ds-name") ) tags.push( EL_DEF_DSNAME ); else if ( qName.equals("cf") ) tags.push( EL_DEF_CF ); } else if ( parent == EL_LINE || parent == EL_AREA ) { if ( qName.equals("datasource") ) tags.push( EL_LINE_DS ); else if ( qName.equals("legend") ) tags.push( EL_LINE_LEGEND ); else if ( qName.equals("width") ) tags.push( EL_LINE_WIDTH ); else if ( qName.equals("color") ) tags.push( EL_LINE_COLOR ); } else if ( parent == EL_IMGBORDER ) { if ( qName.equals("width") ) tags.push( EL_BORDERWIDTH ); } else { if ( qName.equals("general") ) tags.push( EL_GENERAL ); else if ( qName.equals("datasources") ) tags.push( EL_DATASOURCES ); else if ( qName.equals("graphing") ) tags.push( EL_GRAPHING ); else if ( qName.equals("title") ) tags.push( EL_TITLE ); else if ( qName.equals("period") ) tags.push( EL_PERIOD ); else if ( qName.equals("start") ) tags.push( EL_PERIOD_START ); else if ( qName.equals("end") ) tags.push( EL_PERIOD_STOP ); else if ( qName.equals("def") ) // DEF { params[0] = "def"; params[1] = attrs.getValue("name"); tags.push( EL_DEF ); } else if ( qName.equals("cdef") ) // CDEF { params[0] = "cdef"; params[1] = attrs.getValue("name"); tags.push( EL_CDEF ); } else if ( qName.equals("comment") ) tags.push( EL_COMMENT ); else if ( qName.equals("line") ) tags.push( EL_LINE ); else if ( qName.equals("area") ) tags.push( EL_AREA ); else if ( qName.equals("colors") ) tags.push( EL_COLORS ); else if ( qName.equals("signature") ) tags.push( EL_SIGNATURE ); else if ( qName.equals("image-border") ) { tags.push( EL_IMGBORDER ); intParam = 1; // Default border of 1 } else tags.push( EL_NONE ); } } /** * */ public void endElement(String namespaceURI, String sName, String qName) throws SAXException { Byte tag = (Byte) tags.pop(); // Remove tag from the stack try { if ( qName.equals("general") || qName.equals("datasources") || qName.equals("graphing") ) block = BLOCK_ROOT; else if ( tag == EL_DEF || tag == EL_CDEF ) addDatasource(); else if ( tag == EL_LINE || tag == EL_AREA ) addPlotDef( tag ); else if ( tag == EL_PERIOD ) def.setTimePeriod( Long.parseLong(params[0]), Long.parseLong(params[1]) ); else if ( tag == EL_IMGBORDER ) def.setImageBorder( colorParam, intParam ); else if ( tag == EL_CLR_BACKGROUND ) def.setBackColor( colorParam ); else if ( tag == EL_CLR_CANVAS ) def.setCanvasColor( colorParam ); } catch ( RrdException e ) { throw new SAXException( e ); } level--; } /** * */ public void characters(char buf[], int offset, int len) throws SAXException { String value = new String(buf, offset, len); // remove whitespace Byte tag = (Byte) tags.peek(); if ( level < 3 ) return; try { if ( tag == EL_LINE_DS || tag == EL_PERIOD_START ) params[0] = value; else if ( tag == EL_LINE_LEGEND || tag == EL_PERIOD_STOP ) params[1] = value; else if ( tag == EL_CDEF || tag == EL_DEF_FILE ) // RPN expressions are param 2 params[2] = value; else if ( tag == EL_DEF_DSNAME ) params[3] = value; else if ( tag == EL_DEF_CF ) params[4] = value; else if ( tag == EL_COMMENT ) // Add comment def.comment( value ); else if ( tag == EL_TITLE ) // Set title def.setTitle( value ); else if ( tag == EL_SIGNATURE ) // Set signature visibility def.setShowSignature( !value.equalsIgnoreCase("no") ); else if ( tag == EL_LINE_WIDTH || tag == EL_BORDERWIDTH ) { intParam = Integer.parseInt( value ); numParams |= 4; } } catch ( Exception e ) { e.printStackTrace(); } } /** * * @throws RrdException */ private void addDatasource() throws RrdException { String dsType = params[0]; if ( dsType.equals("def") ) // name file dsname consolfunc def.datasource( params[1], params[2], params[3], params[4] ); else if ( dsType.equals("cdef") ) // name rpn def.datasource( params[1], params[2] ); } /** * * @throws RrdException */ private void addPlotDef( Byte graphType ) throws RrdException { int width = 1; Color color = null; if ( graphType == EL_LINE ) { if ( (numParams & 4) == 4 ) width = intParam; if ( (numParams & 2) == 2 ) color = colorParam; def.line( params[0], color, params[1], width ); } else if ( graphType == EL_AREA ) { if ( (numParams & 2) == 2 ) color = colorParam; def.area( params[0], color, params[1] ); } numParams = 0; } } --- NEW FILE: Plottable.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.graph; /** * <p>Interface to be used for custom datasources. * If you wish to use a custom datasource in a graph, you should create a class implementing this interface * that represents that datasource, and then pass this class on to the RrdGraphDef. * </p> * * @author Arne Vandamme <cob...@ch...> */ public interface Plottable { /** * Retrieves datapoint value based on a given timestamp. * Use this method if you only have one series of data in this class. * @param timestamp Timestamp in seconds for the datapoint. * @return Double value of the datapoint. */ public double getValue( long timestamp ); /** * Retrieves datapoint value based on a given timestamp. * @param timestamp Timestamp in seconds for the datapoint. * @param index Integer referring to the series containing the specific datapoint. * @return Double value of the datapoint. */ public double getValue( long timestamp, int index ); /** * Retrieves datapoint value based on a given timestamp. * @param timestamp Timestamp in seconds for the datapoint. * @param fieldName String that refers to the series containing the datapoint. * @return Double value of the datapoint. */ public double getValue( long timestamp, String fieldName ); } --- NEW FILE: Pdef.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.graph; /** * <p>Plottable Def, reprents a custom datasource that can be graphed by JRobin. * All the Pdef needs, is a reference to a Plottable class, and it will get the datapoint values (based * on timestamps) from that external class. Any class implementing the public Plottable interface will do, * meaning that the class could get its values from ANY source... like a RDBMS for example. * </p> * * @author Arne Vandamme <cob...@ch...> */ class Pdef extends Source { private Plottable plottable; private int index = 0; private String sourceName = null; private boolean indexed = false; private boolean named = false; /** * Constructs a new Plottable Def: a custom external datasource * (represented as a Plottable class) that can be graphed by JRobin. * @param name Name of the datasource in the graph definition. * @param plottable Reference to the class implementing the Plottable interface and providing the datapoints. */ Pdef( String name, Plottable plottable ) { super(name ); this.plottable = plottable; } /** * Constructs a new Plottable Def: a custom external datasource * (represented as a Plottable class) that can be graphed by JRobin. * @param name Name of the datasource in the graph definition. * @param plottable Reference to the class implementing the Plottable interface and providing the datapoints. * @param index Integer number used for referring to the series of datapoints to use in the Plottable class. */ Pdef( String name, Plottable plottable, int index ) { super(name ); this.plottable = plottable; this.index = index; indexed = true; } /** * Constructs a new Plottable Def: a custom external datasource * (represented as a Plottable class) that can be graphed by JRobin. * @param name Name of the datasource in the graph definition. * @param plottable Reference to the class implementing the Plottable interface and providing the datapoints. * @param sourceName String used for referring to the series of datapoints to use in the Plottable class. */ Pdef( String name, Plottable plottable, String sourceName) { super(name ); this.plottable = plottable; this.sourceName = sourceName; named = true; } /** * Prepares the array that will hold the values. * @param numPoints Number of datapoints that will be used. */ void prepare( int numPoints ) { // Create values table of correct size values = new double[numPoints]; } /** * Sets the value of a specific datapoint for this Pdef. The Pdef gets the datapoint by retrieving * the value from the Plottable interface using an appropriate getValue() method. * @param pos Position (index in the value table) of the new datapoint. * @param timestamp Timestamp of the new datapoint in number of seconds. */ void set( int pos, long timestamp ) { double val = Double.NaN; if ( indexed ) val = plottable.getValue( timestamp, index ); else if ( named ) val = plottable.getValue( timestamp, sourceName ); else val = plottable.getValue( timestamp ); super.set( pos, timestamp, val ); values[pos] = val; } } Index: Legend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Legend.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Legend.java 7 Nov 2003 08:23:19 -0000 1.1 --- Legend.java 15 Jan 2004 22:24:30 -0000 1.2 *************** *** 40,45 **** // -- Members // ================================================================ ! private Color color = Color.WHITE; ! // ================================================================ --- 40,45 ---- // -- Members // ================================================================ ! private Color color = Color.WHITE; ! private int refPlotDef = -1; // ================================================================ *************** *** 67,72 **** { super(text); ! this.commentType = Comment.CMT_LEGEND; ! this.color = color; } --- 67,89 ---- { super(text); ! if ( text == null ) ! this.commentType = Comment.CMT_NOLEGEND; ! else ! this.commentType = Comment.CMT_LEGEND; ! this.color = color; ! } ! ! /** ! * ! * @param text ! * @param color ! * @param referredPlotDef ! * @throws RrdException ! */ ! Legend( String text, Color color, int referredPlotDef ) throws RrdException ! { ! this( text, color ); ! ! refPlotDef = referredPlotDef; } *************** *** 78,80 **** --- 95,101 ---- return color; } + + int getPlofDefIndex() { + return refPlotDef; + } } Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdGraphDef.java 20 Nov 2003 09:28:00 -0000 1.3 --- RrdGraphDef.java 15 Jan 2004 22:24:30 -0000 1.4 *************** *** 33,36 **** --- 33,37 ---- import java.util.Vector; import java.util.HashMap; + import java.util.Iterator; import java.util.GregorianCalendar; import java.text.SimpleDateFormat; *************** *** 69,72 **** --- 70,74 ---- private Title title = null; // no title private String valueAxisLabel = null; // no vertical label + private TimeAxisLabel timeAxisLabel = null; // no horizontal label private boolean gridX = true; // hide entire X axis grid (default: no) *************** *** 115,118 **** --- 117,121 ---- private HashMap fetchSources = new HashMap(); // holds the list of FetchSources private Vector cdefList = new Vector(); // holds the list of Cdef datasources + private Vector pdefList = new Vector(); // holds the list of Plottable datasources private Vector plotDefs = new Vector(); // holds the list of PlotDefs private Vector comments = new Vector(); // holds the list of comment items *************** *** 127,130 **** --- 130,138 ---- public RrdGraphDef() { } + + public RrdGraphDef( String jrobinXml ) throws RrdException + { + new XmlGraphDefConvertor( jrobinXml, this ); + } /** *************** *** 170,173 **** --- 178,182 ---- /** * Sets time span to be presented on the graph using timestamps in number of seconds. + * An end time of 0 means JRobin will try to use the last available update time. * @param startTime Starting timestamp in seconds. * @param endTime Ending timestamp in secons. *************** *** 176,180 **** public void setTimePeriod( long startTime, long endTime ) throws RrdException { ! if ( startTime < 0 || endTime <= startTime ) throw new RrdException( "Invalid graph start/end time: " + startTime + "/" + endTime ); --- 185,189 ---- public void setTimePeriod( long startTime, long endTime ) throws RrdException { ! if ( startTime < 0 || ( endTime != 0 && endTime <= startTime ) ) throw new RrdException( "Invalid graph start/end time: " + startTime + "/" + endTime ); *************** *** 242,250 **** if ( label != null ) { ! TimeAxisLabel cmt = new TimeAxisLabel( label ); ! commentLines += cmt.getLineCount(); ! commentLineShift = (cmt.isCompleteLine() ? 0 : 1); ! comments.add( 0, cmt ); } } --- 251,259 ---- if ( label != null ) { ! timeAxisLabel = new TimeAxisLabel( label ); ! commentLines += timeAxisLabel.getLineCount(); ! commentLineShift = (timeAxisLabel.isCompleteLine() ? 0 : 1); ! comments.add( 0, timeAxisLabel ); } } *************** *** 651,654 **** --- 660,701 ---- /** + * <p>Adds a custom graph source with the given name to the graph definition. + * The datapoints should be made available by a class implementing the Plottable interface.</p> + * + * @param name Graph source name. + * @param plottable Class that implements plottable interface and is suited for graphing. + */ + public void datasource( String name, Plottable plottable ) + { + pdefList.add( new Pdef(name, plottable) ); + } + + /** + * <p>Adds a custom graph source with the given name to the graph definition. + * The datapoints should be made available by a class implementing the Plottable interface.</p> + * + * @param name Graph source name. + * @param plottable Class that implements plottable interface and is suited for graphing. + * @param index Integer referring to the datasource in the Plottable class. + */ + public void datasource( String name, Plottable plottable, int index ) + { + pdefList.add( new Pdef(name, plottable, index) ); + } + + /** + * <p>Adds a custom graph source with the given name to the graph definition. + * The datapoints should be made available by a class implementing the Plottable interface.</p> + * + * @param name Graph source name. + * @param plottable Class that implements plottable interface and is suited for graphing. + * @param sourceName String name referring to the datasource in the Plottable class. + */ + public void datasource( String name, Plottable plottable, String sourceName ) + { + pdefList.add( new Pdef(name, plottable, sourceName) ); + } + + /** * Adds line plot to the graph definition, using the specified color and legend. This method * takes exactly the same parameters as RRDTool's LINE1 directive (line width *************** *** 857,861 **** addComment( new Gprint(sourceName, consolFun, format) ); } ! // ================================================================ --- 904,1014 ---- addComment( new Gprint(sourceName, consolFun, format) ); } ! ! /** ! * ! * @return ! */ ! public String getJRobinXml() ! { ! StringBuffer xml = new StringBuffer( "" ); ! ! // -- Create the general block ! xml.append( "\t<general>\n" ); ! ! // Time period ! xml.append( "\t\t<period>\n" ); ! xml.append( "\t\t\t<start>" + startTime + "</start>\n" ); ! xml.append( "\t\t\t<end>" + endTime + "</end>\n" ); ! xml.append( "\t\t</period>\n" ); ! ! // Labels ! if ( title != null || valueAxisLabel != null || timeAxisLabel != null ) ! { ! xml.append( "\t\t<labels>\n" ); ! if ( title != null ) ! xml.append( "\t\t\t<title>" + title.text + "</title>\n" ); ! if ( valueAxisLabel != null ) ! xml.append( "\t\t\t<vertical-label>" + valueAxisLabel + "</vertical-label>\n" ); ! if ( timeAxisLabel != null ) ! xml.append( "\t\t\t<horizontal-label>" + timeAxisLabel.text + "</horizontal-label>\n" ); ! xml.append( "\t\t</labels>\n" ); ! } ! ! // General colors ! xml.append( "\t\t<colors>\n" ); ! xml.append( "\t\t\t<background r=\"" + backColor.getRed() + "\" g=\"" + backColor.getGreen() + "\" b=\"" + backColor.getBlue() + "\" />\n" ); ! xml.append( "\t\t\t<canvas r=\"" + canvasColor.getRed() + "\" g=\"" + canvasColor.getGreen() + "\" b=\"" + canvasColor.getBlue() + "\" />\n" ); ! xml.append( "\t\t</colors>\n" ); ! ! // General data information ! ! // General visual options ! xml.append( "\t\t<visual>\n" ); ! xml.append( "\t\t\t<show-legend>" + (showLegend ? "yes" : "no") + "</show-legend>\n" ); ! if ( background != null ) ! xml.append( "\t\t\t<background-image>" + background.getAbsolutePath() + "</background-image>\n" ); ! if ( overlay != null ) ! xml.append( "\t\t\t<overlay-image>" + overlay.getAbsolutePath() + "</overlay-image>\n" ); ! if ( borderStroke != null ) ! { ! xml.append( "\t\t\t<image-border>\n" ); ! xml.append( "\t\t\t\t<width>" + borderStroke.getLineWidth() + "</width>\n" ); ! xml.append( "\t\t\t\t<color r=\"" + borderColor.getRed() + "\" g=\"" + borderColor.getGreen() + "\" b=\"" + borderColor.getBlue() + "\" />\n" ); ! xml.append( "\t\t\t</image-border>\n" ); ! } ! if ( gridRange != null ) ! { ! xml.append( "\t\t\t<grid>\n" ); ! xml.append( "\t\t\t\t<lower>" + gridRange.getLowerValue() + "</lower>\n" ); ! xml.append( "\t\t\t\t<upper>" + gridRange.getUpperValue() + "</upper>\n" ); ! xml.append( "\t\t\t\t<rigid>" + (gridRange.isRigid() ? "yes" : "no") + "</rigid>\n" ); ! xml.append( "\t\t\t</grid>\n" ); ! } ! //xml.append( "\t\t\t<canvas r=\"" + canvasColor.getRed() + "\" g=\"" + canvasColor.getGreen() + "\" b=\"" + canvasColor.getBlue() + "\" />\n" ); ! xml.append( "\t\t</visual>\n" ); ! ! xml.append( "\t</general>\n" ); ! // ------------------------------------------------------------- ! ! ! // -- Create the datasources block ! xml.append( "\t<datasources>\n" ); ! ! // Add all defs ! Iterator fsIterator = fetchSources.values().iterator(); ! while ( fsIterator.hasNext() ) ! xml.append( ((FetchSource) fsIterator.next()).getXml() ); ! ! // Add all cdefs ! for ( int i = 0; i < cdefList.size(); i++ ) ! xml.append( ((Cdef) cdefList.elementAt(i)).getXml() ); ! ! xml.append( "\t</datasources>\n" ); ! // ------------------------------------------------------------- ! ! ! // -- Create the graphing block ! // Run through the comments, if its a legend or nolegend, get the plotdef xml ! // else get the comment or gprint xml ! xml.append( "\t<graphing>\n" ); ! for ( int i = 0; i < comments.size(); i++ ) ! { ! Comment cmt = (Comment) comments.elementAt(i); ! if ( cmt.commentType == Comment.CMT_LEGEND || cmt.commentType == Comment.CMT_NOLEGEND ) ! { ! PlotDef pDef = (PlotDef) plotDefs.elementAt( ((Legend) cmt).getPlofDefIndex() ); ! xml.append( pDef.getXml(cmt.text) ); ! } ! else ! xml.append( cmt.getXml() ); ! } ! xml.append( "\t</graphing>\n" ); ! // ------------------------------------------------------------- ! ! xml.insert( 0, "<jrobin-graph>\n"); ! xml.append( "</jrobin-graph>\n" ); ! ! return xml.toString(); ! } // ================================================================ *************** *** 1039,1042 **** --- 1192,1200 ---- } + protected Pdef[] getPdefs() + { + return (Pdef[]) pdefList.toArray( new Pdef[] {} ); + } + protected HashMap getFetchSources() { *************** *** 1057,1062 **** private void addLegend( String legend, Color color ) throws RrdException { ! if ( legend != null && color != null ) ! addComment( new Legend(legend, color) ); } } --- 1215,1221 ---- private void addLegend( String legend, Color color ) throws RrdException { ! // Always add the item, even if it's empty, always add the index ! // of the graph this legend is for ! addComment( new Legend(legend, color, plotDefs.size() - 1 ) ); } } Index: Area.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Area.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Area.java 20 Nov 2003 09:28:00 -0000 1.2 --- Area.java 15 Jan 2004 22:24:30 -0000 1.3 *************** *** 122,124 **** --- 122,139 ---- } } + + String getXml( String legend ) + { + StringBuffer xml = new StringBuffer(); + + xml.append( "\t\t<area>\n" ); + xml.append( "\t\t\t<datasource>" + sourceName + "</datasource>\n" ); + if ( color != null ) + xml.append( "\t\t\t<color r=\"" + color.getRed() + "\" g=\"" + color.getGreen() + "\" b=\"" + color.getBlue() + "\" />\n" ); + if ( legend != null ) + xml.append( "\t\t\t<legend>" + legend + "</legend>\n" ); + xml.append( "\t\t</area>\n" ); + + return xml.toString(); + } } Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Grapher.java 20 Nov 2003 20:56:32 -0000 1.5 --- Grapher.java 15 Jan 2004 22:24:30 -0000 1.6 *************** *** 101,104 **** --- 101,106 ---- private TimeGrid tGrid; + private long calculatedEndTime; + // ================================================================ *************** *** 277,283 **** --- 279,288 ---- RrdDb rrd; String[] varList; + long finalEndTime = 0; + boolean changingEndTime = false; long startTime = graphDef.getStartTime(); long endTime = graphDef.getEndTime(); + changingEndTime = (endTime == 0); int numDefs = graphDef.getNumDefs(); *************** *** 285,292 **** Cdef[] cdefList = graphDef.getCdefs(); int numCdefs = cdefList.length; ! // Set up the array with all datasources (both Def and Cdef) ! sources = new Source[ numDefs + numCdefs ]; ! sourceIndex = new HashMap( numDefs + numCdefs ); int tblPos = 0; int vePos = 0; --- 290,300 ---- Cdef[] cdefList = graphDef.getCdefs(); int numCdefs = cdefList.length; + + Pdef[] pdefList = graphDef.getPdefs(); + int numPdefs = pdefList.length; ! // Set up the array with all datasources (both Def, Cdef and Pdef) ! sources = new Source[ numDefs + numCdefs + numPdefs ]; ! sourceIndex = new HashMap( numDefs + numCdefs + numPdefs ); int tblPos = 0; int vePos = 0; *************** *** 299,304 **** // Get the rrdDb src = (FetchSource) fetchSources.next(); ! rrd = rrdGraph.getRrd( src.getRrdFile() ); ! // Fetch all required datasources ve = src.fetch( rrd, startTime, endTime ); --- 307,321 ---- // Get the rrdDb src = (FetchSource) fetchSources.next(); ! rrd = rrdGraph.getRrd( src.getRrdFile() ); ! ! // If the endtime is 0, use the last time a database was updated ! if ( changingEndTime ) { ! endTime = rrd.getLastUpdateTime(); ! endTime -= (endTime % rrd.getHeader().getStep()); ! ! if ( endTime > finalEndTime ) ! finalEndTime = endTime; ! } ! // Fetch all required datasources ve = src.fetch( rrd, startTime, endTime ); *************** *** 313,316 **** --- 330,342 ---- } + // Add all Pdefs to the source table + for ( int i = 0; i < pdefList.length; i++ ) + { + pdefList[i].prepare( numPoints ); + + sources[tblPos] = pdefList[i]; + sourceIndex.put( pdefList[i].getName(), new Integer(tblPos++) ); + } + // Add all Cdefs to the source table // Reparse all RPN datasources to use indices of the correct variables *************** *** 328,332 **** // Fill the array for all datasources timestamps = new long[numPoints]; ! for (int i = 0; i < numPoints; i++) { --- 354,363 ---- // Fill the array for all datasources timestamps = new long[numPoints]; ! ! if ( changingEndTime ) { ! endTime = finalEndTime; ! calculatedEndTime = endTime; ! } ! for (int i = 0; i < numPoints; i++) { *************** *** 337,341 **** for (int j = 0; j < veList.length; j++) pos = veList[j].extract( t, sources, i, pos ); ! // Get all combined datasources for (int j = pos; j < sources.length; j++) --- 368,377 ---- for (int j = 0; j < veList.length; j++) pos = veList[j].extract( t, sources, i, pos ); ! ! // Get all custom datasources ! for (int j = pos; j < pos + numPdefs; j++) ! ((Pdef) sources[j]).set( i, t ); ! pos += numPdefs; ! // Get all combined datasources for (int j = pos; j < sources.length; j++) *************** *** 482,486 **** vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis() ); ! tGrid = new TimeGrid( graphDef.getStartTime(), graphDef.getEndTime(), graphDef.getTimeAxis() ); lowerValue = vGrid.getLowerValue(); --- 518,522 ---- vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis() ); ! tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis() ); lowerValue = vGrid.getLowerValue(); *************** *** 741,744 **** --- 777,781 ---- // Plot the string if ( drawText ) { + graphString( g, tmpStr.toString(), posx, posy ); tmpStr = new StringBuffer(""); Index: Comment.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Comment.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Comment.java 7 Nov 2003 08:23:19 -0000 1.1 --- Comment.java 15 Jan 2004 22:24:30 -0000 1.2 *************** *** 42,45 **** --- 42,46 ---- protected static final int CMT_LEGEND = 1; protected static final int CMT_GPRINT = 2; + protected static final int CMT_NOLEGEND = 3; protected static final Byte TKN_ALF = new Byte( (byte) 1); // Align left with Linefeed *************** *** 78,82 **** { this.text = text; ! parseComment(); } --- 79,85 ---- { this.text = text; ! ! if ( text != null ) ! parseComment(); } *************** *** 246,248 **** --- 249,260 ---- return trimString; } + + String getXml() + { + StringBuffer xml = new StringBuffer(); + + xml.append( "\t\t<comment>" + text + "</comment>\n" ); + + return xml.toString(); + } } Index: Line.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Line.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Line.java 20 Nov 2003 09:28:00 -0000 1.2 --- Line.java 15 Jan 2004 22:24:30 -0000 1.3 *************** *** 131,133 **** --- 131,149 ---- return lineWidth; } + + String getXml( String legend ) + { + StringBuffer xml = new StringBuffer(); + + xml.append( "\t\t<line>\n" ); + xml.append( "\t\t\t<datasource>" + sourceName + "</datasource>\n" ); + if ( color != null ) + xml.append( "\t\t\t<color r=\"" + color.getRed() + "\" g=\"" + color.getGreen() + "\" b=\"" + color.getBlue() + "\" />\n" ); + if ( legend != null ) + xml.append( "\t\t\t<legend>" + legend + "</legend>\n" ); + xml.append( "\t\t\t<width>" + lineWidth + "</width>\n" ); + xml.append( "\t\t</line>\n" ); + + return xml.toString(); + } } Index: Cdef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Cdef.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Cdef.java 7 Nov 2003 09:53:35 -0000 1.2 --- Cdef.java 15 Jan 2004 22:24:30 -0000 1.3 *************** *** 208,211 **** --- 208,232 ---- } + String getRpnString() + { + StringBuffer tmpStr = new StringBuffer(""); + for (int i = 0; i < strTokens.length - 1; i++) { + tmpStr.append( strTokens[i] ); + tmpStr.append( ',' ); + } + if ( strTokens.length > 0 ) + tmpStr.append( strTokens[strTokens.length - 1] ); + + return tmpStr.toString(); + } + + public String getXml() + { + StringBuffer xml = new StringBuffer( "" ); + + xml.append( "\t\t<cdef name=\"" + this.getName() + "\">" + getRpnString() + "</cdef>\n"); + + return xml.toString(); + } // ================================================================ Index: FetchSource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/FetchSource.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FetchSource.java 7 Nov 2003 08:23:19 -0000 1.1 --- FetchSource.java 15 Jan 2004 22:24:30 -0000 1.2 *************** *** 92,95 **** --- 92,115 ---- } + public String getXml() + { + StringBuffer xml = new StringBuffer( "" ); + + for ( int i = 0; i < datasources.length; i++ ) { + for ( int j = 0; j < datasources[i].size(); j++ ) { + String[] pair = (String[]) datasources[i].elementAt(j); + + xml.append( "\t\t<def name=\"" + pair[1] + "\">\n" ); + xml.append( "\t\t\t<file>" + rrdFile + "</file>\n" ); + xml.append( "\t\t\t<ds-name>" + pair[0] + "</ds-name>\n" ); + xml.append( "\t\t\t<cf>" + cfNames[i] + "</cf>\n" ); + xml.append( "\t\t</def>\n" ); + //<file>test.rrd</file> + //<ds-name>ifInOctets</ds-name> + //<cf>AVERAGE</cf> + } + } + return xml.toString(); + } // ================================================================ Index: Gprint.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Gprint.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Gprint.java 7 Nov 2003 08:23:19 -0000 1.1 --- Gprint.java 15 Jan 2004 22:24:30 -0000 1.2 *************** *** 175,177 **** --- 175,193 ---- } + /** + * + */ + String getXml() + { + StringBuffer xml = new StringBuffer(); + + xml.append( "\t\t<gprint>\n" ); + xml.append( "\t\t\t<datasource>" + sourceName + "</datasource>\n" ); + xml.append( "\t\t\t<cf>" + Source.aggregates[aggregate] + "</cf>\n" ); + xml.append( "\t\t\t<text>" + text + "</text>\n" ); + xml.append( "\t\t</gprint>\n" ); + + return xml.toString(); + } + } Index: PlotDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/PlotDef.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PlotDef.java 7 Nov 2003 08:23:19 -0000 1.1 --- PlotDef.java 15 Jan 2004 22:24:30 -0000 1.2 *************** *** 129,132 **** --- 129,138 ---- abstract void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException; + /** + * Abstract getXml method, must be implemented in all child classes. + * This method is reponsible for returning a corresponding JRobin XML string for the PlotDef. + */ + abstract String getXml( String legend ); + Source getSource() { return source; Index: TimeAxisLabel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeAxisLabel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TimeAxisLabel.java 20 Nov 2003 09:28:00 -0000 1.1 --- TimeAxisLabel.java 15 Jan 2004 22:24:30 -0000 1.2 *************** *** 60,62 **** --- 60,66 ---- } } + + String getXml() { + return ""; + } } Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Source.java 24 Nov 2003 10:15:43 -0000 1.3 --- Source.java 15 Jan 2004 22:24:30 -0000 1.4 *************** *** 43,46 **** --- 43,47 ---- protected static final int AGG_LAST = 4; + protected static final String[] aggregates = { "MINIMUM", "MAXIMUM", "AVERAGE", "FIRST", "LAST" }; private String name; protected double[] values; Index: CustomArea.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/CustomArea.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CustomArea.java 7 Nov 2003 08:23:19 -0000 1.1 --- CustomArea.java 15 Jan 2004 22:24:30 -0000 1.2 *************** *** 168,170 **** --- 168,185 ---- void setSource( Source[] sources, HashMap sourceIndex ) throws RrdException { } + + String getXml( String legend ) + { + StringBuffer xml = new StringBuffer(); + + xml.append( "\t\t<custom-area>\n" ); + xml.append( "\t\t\t<datasource>" + sourceName + "</datasource>\n" ); + if ( color != null ) + xml.append( "\t\t\t<color r=\"" + color.getRed() + "\" g=\"" + color.getGreen() + "\" b=\"" + color.getBlue() + "\" />\n" ); + if ( legend != null ) + xml.append( "\t\t\t<legend>" + legend + "</legend>\n" ); + xml.append( "\t\t</custom-area>\n" ); + + return xml.toString(); + } } Index: Stack.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Stack.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Stack.java 7 Nov 2003 08:23:19 -0000 1.1 --- Stack.java 15 Jan 2004 22:24:30 -0000 1.2 *************** *** 82,84 **** --- 82,102 ---- } + + /** + * + */ + String getXml( String legend ) + { + StringBuffer xml = new StringBuffer(); + + xml.append( "\t\t<stack>\n" ); + xml.append( "\t\t\t<datasource>" + sourceName + "</datasource>\n" ); + if ( color != null ) + xml.append( "\t\t\t<color r=\"" + color.getRed() + "\" g=\"" + color.getGreen() + "\" b=\"" + color.getBlue() + "\" />\n" ); + if ( legend != null ) + xml.append( "\t\t\t<legend>" + legend + "</legend>\n" ); + xml.append( "\t\t</stack>\n" ); + + return xml.toString(); + } } |
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1:/tmp/cvs-serv14419/org/jrobin/mrtg/server Removed Files: Archiver.java Collector.java Grapher.java Hardware.java Link.java Router.java RpcServer.java Scheduler.java SnmpCommunicator.java Log Message: Minor changes --- Archiver.java DELETED --- --- Collector.java DELETED --- --- Grapher.java DELETED --- --- Hardware.java DELETED --- --- Link.java DELETED --- --- Router.java DELETED --- --- RpcServer.java DELETED --- --- Scheduler.java DELETED --- --- SnmpCommunicator.java DELETED --- |
|
From: <sa...@us...> - 2003-12-09 12:22:07
|
Update of /cvsroot/jrobin/src/org/jrobin/inspector In directory sc8-pr-cvs1:/tmp/cvs-serv13997/org/jrobin/inspector Added Files: EditArchiveDialog.java EditDatasourceDialog.java Util.java Log Message: Minor changes --- NEW FILE: EditArchiveDialog.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import org.jrobin.core.RrdException; import org.jrobin.core.ArcDef; import javax.swing.*; import java.awt.*; import java.awt.event.WindowEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; class EditArchiveDialog extends JDialog { private static final int FIELD_SIZE = 20; private static final String TITLE_NEW = "New archive"; private static final String TITLE_EDIT = "Edit archive"; private JLabel consolFunLabel = new JLabel("Consolidation function: "); private JLabel xffLabel = new JLabel("X-files factor: "); private JLabel stepsLabel = new JLabel("Steps: "); private JLabel rowsLabel = new JLabel("Rows: "); private JComboBox consolFunCombo = new JComboBox(); private JTextField xffField = new JTextField(FIELD_SIZE); private JTextField stepsField = new JTextField(FIELD_SIZE); private JTextField rowsField = new JTextField(FIELD_SIZE); private JButton okButton = new JButton("OK"); private JButton cancelButton = new JButton("Cancel"); private ArcDef arcDef; EditArchiveDialog(Frame parent, ArcDef arcDef) { super(parent, arcDef == null? TITLE_NEW: TITLE_EDIT, true); constructUI(arcDef); pack(); Util.centerOnScreen(this); setVisible(true); } private void constructUI(ArcDef arcDef) { // fill controls String[] funs = ArcDef.CONSOL_FUNS; for (int i = 0; i < funs.length; i++) { consolFunCombo.addItem(funs[i]); } consolFunCombo.setSelectedIndex(0); if(arcDef == null) { // NEW xffField.setText("" + 0.5); } else { // EDIT consolFunCombo.setSelectedItem(arcDef.getConsolFun()); consolFunCombo.setEnabled(false); xffField.setText("" + arcDef.getXff()); stepsField.setText("" + arcDef.getSteps()); stepsField.setEnabled(false); rowsField.setText("" + arcDef.getRows()); // rowsField.setEnabled(false); } // layout JPanel content = (JPanel) getContentPane(); GridBagLayout layout = new GridBagLayout(); content.setLayout(layout); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(3, 3, 3, 3); gbc.gridx = 0; gbc.gridy = 0; gbc.anchor = GridBagConstraints.EAST; layout.setConstraints(consolFunLabel, gbc); content.add(consolFunLabel); gbc.gridy = 1; layout.setConstraints(xffLabel, gbc); content.add(xffLabel); gbc.gridy = 2; layout.setConstraints(stepsLabel, gbc); content.add(stepsLabel); gbc.gridy = 3; layout.setConstraints(rowsLabel, gbc); content.add(rowsLabel); gbc.gridy = 4; layout.setConstraints(okButton, gbc); okButton.setPreferredSize(cancelButton.getPreferredSize()); content.add(okButton); gbc.gridx = 1; gbc.gridy = 0; gbc.anchor = GridBagConstraints.WEST; layout.setConstraints(consolFunCombo, gbc); content.add(consolFunCombo); gbc.gridy = 1; layout.setConstraints(xffField, gbc); content.add(xffField); gbc.gridy = 2; layout.setConstraints(stepsField, gbc); content.add(stepsField); gbc.gridy = 3; layout.setConstraints(rowsField, gbc); content.add(rowsField); gbc.gridy = 4; layout.setConstraints(cancelButton, gbc); content.add(cancelButton); getRootPane().setDefaultButton(okButton); // actions okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ok(); } }); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancel(); } }); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); } private void ok() { arcDef = createArcDef(); if(arcDef != null) { close(); } } private void close() { dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); } private void cancel() { close(); } private ArcDef createArcDef() { String consolFun = (String) consolFunCombo.getSelectedItem(); double xff; try { xff = Double.parseDouble(xffField.getText()); if(xff < 0 || xff >= 1D) { throw new NumberFormatException(); } } catch(NumberFormatException nfe) { Util.error(this, "X-files factor must be a number not less than 0.0 and less than 1.0"); return null; } int steps; try { steps = Integer.parseInt(stepsField.getText()); if(steps <= 0) { throw new NumberFormatException(); } } catch (NumberFormatException nfe) { Util.error(this, "Number of steps must be a positive integer"); return null; } int rows; try { rows = Integer.parseInt(rowsField.getText()); if(rows <= 0) { throw new NumberFormatException(); } } catch (NumberFormatException nfe) { Util.error(this, "Number of rows must be a positive integer"); return null; } try { return new ArcDef(consolFun, xff, steps, rows); } catch(RrdException e) { // should not be hear ever! e.printStackTrace(); return null; } } ArcDef getArcDef() { return arcDef; } } --- NEW FILE: EditDatasourceDialog.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import org.jrobin.core.DsDef; import org.jrobin.core.RrdException; import javax.swing.*; import java.awt.*; import java.awt.event.WindowEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; class EditDatasourceDialog extends JDialog { private static final int FIELD_SIZE = 20; private static final String TITLE_NEW = "New datasource"; private static final String TITLE_EDIT = "Edit datasource"; private JLabel nameLabel = new JLabel("Datasource name: "); private JLabel typeLabel = new JLabel("Datasource type: "); private JLabel heartbeatLabel = new JLabel("Heartbeat: "); private JLabel minLabel = new JLabel("Min value: "); private JLabel maxLabel = new JLabel("Max value: "); private JTextField nameField = new JTextField(FIELD_SIZE); private JComboBox typeCombo = new JComboBox(); private JTextField heartbeatField = new JTextField(FIELD_SIZE); private JTextField minField = new JTextField(FIELD_SIZE); private JTextField maxField = new JTextField(FIELD_SIZE); private JButton okButton = new JButton("OK"); private JButton cancelButton = new JButton("Cancel"); private DsDef dsDef; EditDatasourceDialog(Frame parent, DsDef dsDef) { super(parent, dsDef == null? TITLE_NEW: TITLE_EDIT, true); constructUI(dsDef); pack(); Util.centerOnScreen(this); setVisible(true); } private void constructUI(DsDef dsDef) { // fill controls String[] types = DsDef.DS_TYPES; for (int i = 0; i < types.length; i++) { typeCombo.addItem(types[i]); } typeCombo.setSelectedIndex(0); if(dsDef == null) { // NEW minField.setText("U"); maxField.setText("U"); } else { // EDIT nameField.setText(dsDef.getDsName()); nameField.setEnabled(false); typeCombo.setSelectedItem(dsDef.getDsType()); typeCombo.setEnabled(false); heartbeatField.setText("" + dsDef.getHeartbeat()); minField.setText("" + dsDef.getMinValue()); maxField.setText("" + dsDef.getMaxValue()); } // layout JPanel content = (JPanel) getContentPane(); GridBagLayout layout = new GridBagLayout(); content.setLayout(layout); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(3, 3, 3, 3); gbc.gridx = 0; gbc.gridy = 0; gbc.anchor = GridBagConstraints.EAST; layout.setConstraints(nameLabel, gbc); content.add(nameLabel); gbc.gridy = 1; layout.setConstraints(typeLabel, gbc); content.add(typeLabel); gbc.gridy = 2; layout.setConstraints(heartbeatLabel, gbc); content.add(heartbeatLabel); gbc.gridy = 3; layout.setConstraints(minLabel, gbc); content.add(minLabel); gbc.gridy = 4; layout.setConstraints(maxLabel, gbc); content.add(maxLabel); gbc.gridy = 5; layout.setConstraints(okButton, gbc); okButton.setPreferredSize(cancelButton.getPreferredSize()); content.add(okButton); gbc.gridx = 1; gbc.gridy = 0; gbc.anchor = GridBagConstraints.WEST; layout.setConstraints(nameField, gbc); content.add(nameField); gbc.gridy = 1; layout.setConstraints(typeCombo, gbc); content.add(typeCombo); gbc.gridy = 2; layout.setConstraints(heartbeatField, gbc); content.add(heartbeatField); gbc.gridy = 3; layout.setConstraints(minField, gbc); content.add(minField); gbc.gridy = 4; layout.setConstraints(maxField, gbc); content.add(maxField); gbc.gridy = 5; layout.setConstraints(cancelButton, gbc); content.add(cancelButton); getRootPane().setDefaultButton(okButton); // actions okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ok(); } }); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancel(); } }); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); } private void ok() { dsDef = createDsDef(); if(dsDef != null) { close(); } } private void close() { dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); } private void cancel() { close(); } private DsDef createDsDef() { String name = nameField.getText(); if(name == null || name.length() < 1 || name.length() > 20) { Util.error(this, "Datasource name must be a non-empty string up to 20 chars long"); return null; } String type = (String) typeCombo.getSelectedItem(); long heartbeat; try { heartbeat = Long.parseLong(heartbeatField.getText()); if(heartbeat <= 0) { throw new NumberFormatException(); } } catch(NumberFormatException nfe) { Util.error(this, "Heartbeat must be a positive integer number"); return null; } double min = Double.NaN, max = Double.NaN; try { min = Double.parseDouble(minField.getText()); } catch (NumberFormatException nfe) { // NOP, leave NaN } try { max = Double.parseDouble(maxField.getText()); } catch (NumberFormatException nfe) { // NOP, leave NaN } if(!Double.isNaN(min) && !Double.isNaN(max) && min >= max) { Util.error(this, "Min value must be less than max value"); return null; } try { return new DsDef(name, type, heartbeat, min, max); } catch(RrdException e) { // should not be hear ever! e.printStackTrace(); return null; } } DsDef getDsDef() { return dsDef; } } --- NEW FILE: Util.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...); * * (C) Copyright 2003, by Sasa Markovic. * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package org.jrobin.inspector; import javax.swing.*; import java.awt.*; class Util { static void centerOnScreen(Window window) { Toolkit t = Toolkit.getDefaultToolkit(); Dimension screenSize = t.getScreenSize(); Dimension frameSize = window.getPreferredSize(); double x = (screenSize.getWidth() - frameSize.getWidth()) / 2; double y = (screenSize.getHeight() - frameSize.getHeight()) / 2; window.setLocation((int) x, (int) y); } static void error(Component parent, String message) { JOptionPane.showMessageDialog(parent, message, "Error", JOptionPane.ERROR_MESSAGE); } } |
|
From: <sa...@us...> - 2003-12-09 12:22:07
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/client In directory sc8-pr-cvs1:/tmp/cvs-serv13997/org/jrobin/mrtg/client Modified Files: Client.java RpcClient.java Log Message: Minor changes Index: Client.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/Client.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Client.java 4 Dec 2003 13:21:03 -0000 1.4 --- Client.java 9 Dec 2003 12:22:04 -0000 1.5 *************** *** 26,31 **** package org.jrobin.mrtg.client; - import org.jrobin.mrtg.MrtgException; import org.apache.xmlrpc.XmlRpcException; import javax.swing.*; --- 26,31 ---- package org.jrobin.mrtg.client; import org.apache.xmlrpc.XmlRpcException; + import org.jrobin.mrtg.MrtgException; import javax.swing.*; Index: RpcClient.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/RpcClient.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RpcClient.java 10 Nov 2003 08:52:29 -0000 1.2 --- RpcClient.java 9 Dec 2003 12:22:04 -0000 1.3 *************** *** 25,31 **** package org.jrobin.mrtg.client; - import org.jrobin.mrtg.MrtgConstants; import org.apache.xmlrpc.XmlRpcClient; import org.apache.xmlrpc.XmlRpcException; import java.io.IOException; --- 25,31 ---- package org.jrobin.mrtg.client; import org.apache.xmlrpc.XmlRpcClient; import org.apache.xmlrpc.XmlRpcException; + import org.jrobin.mrtg.MrtgConstants; import java.io.IOException; |
|
From: <sa...@us...> - 2003-12-09 12:22:07
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg
In directory sc8-pr-cvs1:/tmp/cvs-serv13997/org/jrobin/mrtg
Modified Files:
Debug.java MrtgConstants.java MrtgException.java
Log Message:
Minor changes
Index: Debug.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/Debug.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Debug.java 10 Nov 2003 08:52:28 -0000 1.2
--- Debug.java 9 Dec 2003 12:22:03 -0000 1.3
***************
*** 33,38 ****
* To change this template use Options | File Templates.
*/
! public class Debug {
! static final boolean DEBUG = false;
public static void print(String msg) {
--- 33,37 ----
* To change this template use Options | File Templates.
*/
! public class Debug implements MrtgConstants {
public static void print(String msg) {
Index: MrtgConstants.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/MrtgConstants.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** MrtgConstants.java 10 Nov 2003 08:52:28 -0000 1.2
--- MrtgConstants.java 9 Dec 2003 12:22:03 -0000 1.3
***************
*** 27,30 ****
--- 27,36 ----
public interface MrtgConstants {
+ boolean DEBUG = false;
+
int SERVER_PORT = 35353;
+
+ int SCHEDULER_RESOLUTION = 3; // run Scheduler each 3 seconds
+
+ int GRAPH_WIDTH = 502, GRAPH_HEIGHT = 234;
}
Index: MrtgException.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/MrtgException.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** MrtgException.java 10 Nov 2003 08:52:28 -0000 1.4
--- MrtgException.java 9 Dec 2003 12:22:03 -0000 1.5
***************
*** 27,30 ****
--- 27,31 ----
public class MrtgException extends Exception {
+
public MrtgException(String cause) {
super(cause);
|
|
From: <sa...@us...> - 2003-12-08 13:47:44
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv6289/org/jrobin/core
Modified Files:
ArcDef.java Archive.java Robin.java RrdDef.java
RrdToolkit.java
Log Message:
Finished RRDToolkit class. It is now possible to resize RRAs, but preserving already archived values.
Index: ArcDef.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/ArcDef.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ArcDef.java 10 Nov 2003 08:52:27 -0000 1.3
--- ArcDef.java 8 Dec 2003 13:47:40 -0000 1.4
***************
*** 158,160 ****
--- 158,164 ----
}
+ void setRows(int rows) {
+ this.rows = rows;
+ }
+
}
Index: Archive.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Archive.java 2 Dec 2003 10:18:17 -0000 1.9
--- Archive.java 8 Dec 2003 13:47:40 -0000 1.10
***************
*** 399,405 ****
throw new RrdException("Incompatible number of steps");
}
- if(arc.rows.get() != rows.get()) {
- throw new RrdException("Incompatible number of rows");
- }
int count = parentDb.getHeader().getDsCount();
for(int i = 0; i < count; i++) {
--- 399,402 ----
Index: Robin.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Robin.java 30 Nov 2003 08:14:11 -0000 1.6
--- Robin.java 8 Dec 2003 13:47:40 -0000 1.7
***************
*** 1,160 ****
! /* ============================================================
! * JRobin : Pure java implementation of RRDTool's functionality
! * ============================================================
! *
! * Project Info: http://www.jrobin.org
! * Project Lead: Sasa Markovic (sa...@jr...);
! *
! * (C) Copyright 2003, by Sasa Markovic.
! *
! * This library is free software; you can redistribute it and/or modify it under the terms
! * of the GNU Lesser General Public License as published by the Free Software Foundation;
! * either version 2.1 of the License, or (at your option) any later version.
! *
! * Developers: Sasa Markovic (sa...@jr...)
! * Arne Vandamme (cob...@jr...)
! *
! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
! * See the GNU Lesser General Public License for more details.
! *
! * You should have received a copy of the GNU Lesser General Public License along with this
! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
! * Boston, MA 02111-1307, USA.
! */
!
! package org.jrobin.core;
!
! import java.io.IOException;
!
! /**
! * Class to represent archive values for a single datasource. Robin class is the heart of
! * the so-called "round robin database" concept. Basically, each Robin object is a
! * fixed length array of double values. Each double value reperesents consolidated archive
! * value for the specific timestamp. When the underlying array of double values gets completely
! * filled, new values will replace the oldest entries.<p>
! *
! * Robin object does not hold values in memory - such object could be quite large.
! * Instead of it, Robin stores all values on the disk and reads them only when necessary.
! *
! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a>
! */
! public class Robin implements RrdUpdater {
! private Archive parentArc;
! private RrdInt pointer;
! private RrdDoubleArray values;
! private int rows;
!
! Robin(Archive parentArc, int rows) throws IOException {
! this.parentArc = parentArc;
! this.rows = rows;
! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) {
! pointer = new RrdInt(0, this);
! values = new RrdDoubleArray(this, rows, Double.NaN);
! }
! else {
! pointer = new RrdInt(this);
! values = new RrdDoubleArray(this, rows);
! }
! }
!
! /**
! * Fetches all Robin archive values from the disk.
! *
! * @return Array of double archive values, starting from the oldest one.
! * @throws IOException Thrown in case of IO specific error.
! */
! public double[] getValues() throws IOException {
! double[] result = new double[rows];
! int start = pointer.get();
! for(int i = start, j = 0; i < start + rows; i++, j++) {
! result[j] = values.get(i % rows);
! }
! return result;
! }
!
! void store(double newValue) throws IOException {
! int position = pointer.get();
! values.set(position, newValue);
! pointer.set((position + 1) % rows);
! }
!
! /**
! * Returns the underlying RrdFile object.
! * @return Underlying RrdFile object
! */
! public RrdFile getRrdFile() {
! return parentArc.getRrdFile();
! }
!
! String dump() throws IOException {
! StringBuffer buffer = new StringBuffer("Robin " + pointer.get() + "/" + rows + ": ");
! int startPos = pointer.get();
! for(int i = startPos; i < startPos + rows; i++) {
! buffer.append(Util.formatDouble(values.get(i % rows), true) + " ");
! }
! buffer.append("\n");
! return buffer.toString();
! }
!
! /**
! * Returns the i-th value from the Robin archive.
! * @param index Value index
! * @return Value stored in the i-th position (the oldest value has zero index)
! */
! public double getValue(int index) throws IOException {
! return values.get((pointer.get() + index) % rows);
! }
!
! /**
! * Returns the Archive object to which this Robin object belongs.
! *
! * @return Parent Archive object
! */
! public Archive getParent() {
! return parentArc;
! }
!
! /**
! * Returns the size of the underlying array of archive values.
! *
! * @return Number of stored values
! */
! public int getSize() {
! return rows;
! }
!
! /**
! * Copies object's internal state to another Robin object.
! * @param other New Robin object to copy state to
! * @throws IOException Thrown in case of I/O error
! * @throws RrdException Thrown if supplied argument is not a Robin object or
! * is a Robin object with different number of rows
! */
! public void copyStateTo(RrdUpdater other) throws IOException, RrdException {
! if(!(other instanceof Robin)) {
! throw new RrdException(
! "Cannot copy Archive object to " + other.getClass().getName());
! }
! Robin robin = (Robin) other;
! if(rows != robin.rows) {
! throw new RrdException("Incompatible number of rows: " + rows +
! " != " + robin.rows);
! }
! robin.pointer.set(pointer.get());
! // BULK operation, will speed things up
! robin.values.writeBytes(values.readBytes());
! }
!
! void filterValues(double minValue, double maxValue) throws IOException {
! for(int i = 0; i < rows; i++) {
! double value = values.get(i);
! if(!Double.isNaN(minValue) && !Double.isNaN(value) && minValue > value) {
! values.set(i, Double.NaN);
! }
! if(!Double.isNaN(maxValue) && !Double.isNaN(value) && maxValue < value) {
! values.set(i, Double.NaN);
! }
! }
! }
! }
--- 1,165 ----
! /* ============================================================
! * JRobin : Pure java implementation of RRDTool's functionality
! * ============================================================
! *
! * Project Info: http://www.jrobin.org
! * Project Lead: Sasa Markovic (sa...@jr...);
! *
! * (C) Copyright 2003, by Sasa Markovic.
! *
! * This library is free software; you can redistribute it and/or modify it under the terms
! * of the GNU Lesser General Public License as published by the Free Software Foundation;
! * either version 2.1 of the License, or (at your option) any later version.
! *
! * Developers: Sasa Markovic (sa...@jr...)
! * Arne Vandamme (cob...@jr...)
! *
! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
! * See the GNU Lesser General Public License for more details.
! *
! * You should have received a copy of the GNU Lesser General Public License along with this
! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
! * Boston, MA 02111-1307, USA.
! */
!
! package org.jrobin.core;
!
! import java.io.IOException;
!
! /**
! * Class to represent archive values for a single datasource. Robin class is the heart of
! * the so-called "round robin database" concept. Basically, each Robin object is a
! * fixed length array of double values. Each double value reperesents consolidated archive
! * value for the specific timestamp. When the underlying array of double values gets completely
! * filled, new values will replace the oldest entries.<p>
! *
! * Robin object does not hold values in memory - such object could be quite large.
! * Instead of it, Robin stores all values on the disk and reads them only when necessary.
! *
! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a>
! */
! public class Robin implements RrdUpdater {
! private Archive parentArc;
! private RrdInt pointer;
! private RrdDoubleArray values;
! private int rows;
!
! Robin(Archive parentArc, int rows) throws IOException {
! this.parentArc = parentArc;
! this.rows = rows;
! if(getRrdFile().getMode() == RrdFile.MODE_CREATE) {
! pointer = new RrdInt(0, this);
! values = new RrdDoubleArray(this, rows, Double.NaN);
! }
! else {
! pointer = new RrdInt(this);
! values = new RrdDoubleArray(this, rows);
! }
! }
!
! /**
! * Fetches all Robin archive values from the disk.
! *
! * @return Array of double archive values, starting from the oldest one.
! * @throws IOException Thrown in case of IO specific error.
! */
! public double[] getValues() throws IOException {
! double[] result = new double[rows];
! int start = pointer.get();
! for(int i = start, j = 0; i < start + rows; i++, j++) {
! result[j] = values.get(i % rows);
! }
! return result;
! }
!
! void store(double newValue) throws IOException {
! int position = pointer.get();
! values.set(position, newValue);
! pointer.set((position + 1) % rows);
! }
!
! /**
! * Returns the underlying RrdFile object.
! * @return Underlying RrdFile object
! */
! public RrdFile getRrdFile() {
! return parentArc.getRrdFile();
! }
!
! String dump() throws IOException {
! StringBuffer buffer = new StringBuffer("Robin " + pointer.get() + "/" + rows + ": ");
! int startPos = pointer.get();
! for(int i = startPos; i < startPos + rows; i++) {
! buffer.append(Util.formatDouble(values.get(i % rows), true) + " ");
! }
! buffer.append("\n");
! return buffer.toString();
! }
!
! /**
! * Returns the i-th value from the Robin archive.
! * @param index Value index
! * @return Value stored in the i-th position (the oldest value has zero index)
! */
! public double getValue(int index) throws IOException {
! return values.get((pointer.get() + index) % rows);
! }
!
! /**
! * Returns the Archive object to which this Robin object belongs.
! *
! * @return Parent Archive object
! */
! public Archive getParent() {
! return parentArc;
! }
!
! /**
! * Returns the size of the underlying array of archive values.
! *
! * @return Number of stored values
! */
! public int getSize() {
! return rows;
! }
!
! /**
! * Copies object's internal state to another Robin object.
! * @param other New Robin object to copy state to
! * @throws IOException Thrown in case of I/O error
! * @throws RrdException Thrown if supplied argument is not a Robin object
! */
! public void copyStateTo(RrdUpdater other) throws IOException, RrdException {
! if(!(other instanceof Robin)) {
! throw new RrdException(
! "Cannot copy Robin object to " + other.getClass().getName());
! }
! Robin robin = (Robin) other;
! int rowsDiff = rows - robin.rows;
! if(rowsDiff == 0) {
! // Identical dimensions. Do copy in BULK to speed things up
! robin.pointer.set(pointer.get());
! robin.values.writeBytes(values.readBytes());
! }
! else {
! // different sizes
! for(int i = 0; i < robin.rows; i++) {
! int j = i + rowsDiff;
! robin.store(j >= 0? getValue(j): Double.NaN);
! }
! }
! }
!
! void filterValues(double minValue, double maxValue) throws IOException {
! for(int i = 0; i < rows; i++) {
! double value = values.get(i);
! if(!Double.isNaN(minValue) && !Double.isNaN(value) && minValue > value) {
! values.set(i, Double.NaN);
! }
! if(!Double.isNaN(maxValue) && !Double.isNaN(value) && maxValue < value) {
! values.set(i, Double.NaN);
! }
! }
! }
! }
Index: RrdDef.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** RrdDef.java 28 Nov 2003 13:24:46 -0000 1.5
--- RrdDef.java 8 Dec 2003 13:47:40 -0000 1.6
***************
*** 321,329 ****
void removeArchive(String consolFun, int steps) throws RrdException {
for(int i = 0; i < arcDefs.size(); i++) {
ArcDef arcDef = (ArcDef) arcDefs.get(i);
if(arcDef.getConsolFun().equals(consolFun) && arcDef.getSteps() == steps) {
! arcDefs.remove(i);
! return;
}
}
--- 321,335 ----
void removeArchive(String consolFun, int steps) throws RrdException {
+ ArcDef arcDef = findArchive(consolFun, steps);
+ if(!arcDefs.remove(arcDef)) {
+ throw new RrdException("Could not remove archive " + consolFun + "/" + steps);
+ }
+ }
+
+ ArcDef findArchive(String consolFun, int steps) throws RrdException {
for(int i = 0; i < arcDefs.size(); i++) {
ArcDef arcDef = (ArcDef) arcDefs.get(i);
if(arcDef.getConsolFun().equals(consolFun) && arcDef.getSteps() == steps) {
! return arcDef;
}
}
Index: RrdToolkit.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** RrdToolkit.java 4 Dec 2003 13:21:03 -0000 1.5
--- RrdToolkit.java 8 Dec 2003 13:47:40 -0000 1.6
***************
*** 357,360 ****
--- 357,414 ----
}
+ /**
+ * Creates new RRD file based on the existing one, but with a different
+ * size (number of rows) for a single archive. The archive to be resized
+ * is identified by its consolidation function and the number of steps.
+ * @param sourcePath Path to the source RRD file (will not be modified)
+ * @param destPath Path to the new RRD file (will be created)
+ * @param consolFun Consolidation function of the archive to be resized
+ * @param numSteps Number of steps of the archive to be resized
+ * @param newRows New archive size (number of archive rows)
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown in case of JRobin specific error
+ */
+ public void resizeArchive(String sourcePath, String destPath, String consolFun,
+ int numSteps, int newRows)
+ throws IOException, RrdException {
+ if(Util.sameFilePath(sourcePath, destPath)) {
+ throw new RrdException("Source and destination paths are the same");
+ }
+ if(newRows < 2) {
+ throw new RrdException("New arcihve size must be at least 2");
+ }
+ RrdDb rrdSource = new RrdDb(sourcePath);
+ RrdDef rrdDef = rrdSource.getRrdDef();
+ ArcDef arcDef = rrdDef.findArchive(consolFun, numSteps);
+ if(arcDef.getRows() != newRows) {
+ arcDef.setRows(newRows);
+ rrdDef.setPath(destPath);
+ RrdDb rrdDest = new RrdDb(rrdDef);
+ rrdSource.copyStateTo(rrdDest);
+ rrdDest.close();
+ }
+ rrdSource.close();
+ }
+
+ /**
+ * Modifies existing RRD file, by resizing its chosen archive. The archive to be resized
+ * is identified by its consolidation function and the number of steps.
+ * @param sourcePath Path to the RRD file (will be modified)
+ * @param consolFun Consolidation function of the archive to be resized
+ * @param numSteps Number of steps of the archive to be resized
+ * @param newRows New archive size (number of archive rows)
+ * @param saveBackup true, if backup of the original file should be created;
+ * false, otherwise
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown in case of JRobin specific error
+ */
+ public void resizeArchive(String sourcePath, String consolFun,
+ int numSteps, int newRows, boolean saveBackup)
+ throws IOException, RrdException {
+ String destPath = Util.getTmpFilename();
+ resizeArchive(sourcePath, destPath, consolFun, numSteps, newRows);
+ copyFile(destPath, sourcePath, saveBackup);
+ }
+
private static void deleteFile(File file) throws IOException {
if(file.exists() && !file.delete()) {
|
|
From: <sa...@us...> - 2003-12-08 13:47:44
|
Update of /cvsroot/jrobin/src/org/jrobin/inspector In directory sc8-pr-cvs1:/tmp/cvs-serv6289/org/jrobin/inspector Modified Files: RrdInspector.java Log Message: Finished RRDToolkit class. It is now possible to resize RRAs, but preserving already archived values. Index: RrdInspector.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/RrdInspector.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdInspector.java 4 Dec 2003 13:21:03 -0000 1.3 --- RrdInspector.java 8 Dec 2003 13:47:41 -0000 1.4 *************** *** 363,368 **** --- 363,372 ---- // action! RrdToolkit toolkit = RrdToolkit.getInstance(); + // fix X-files factor toolkit.setArcXff(sourcePath, newArcDef.getConsolFun(), newArcDef.getSteps(), newArcDef.getXff()); + // fix archive size + toolkit.resizeArchive(sourcePath, newArcDef.getConsolFun(), + newArcDef.getSteps(), newArcDef.getRows(), SHOULD_CREATE_BACKUPS); inspectorModel.refresh(); tabbedPane.setSelectedIndex(0); |
Update of /cvsroot/jrobin/src/org/jrobin/inspector
In directory sc8-pr-cvs1:/tmp/cvs-serv7205/org/jrobin/inspector
Modified Files:
ArchiveTableModel.java DataTableModel.java
DatasourceTableModel.java HeaderTableModel.java
InspectorModel.java MainTreeModel.java RrdInspector.java
Log Message:
Major enhancements to Inspector swing app. Supports interactive add/edit/remove operations on RRD datasources/archives. Several methods added to RrdToolkit - no plans to extend it further.
Index: ArchiveTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/ArchiveTableModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ArchiveTableModel.java 13 Nov 2003 15:33:28 -0000 1.4
--- ArchiveTableModel.java 4 Dec 2003 13:21:03 -0000 1.5
***************
*** 71,78 ****
void setFile(File newFile) {
! if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) {
! file = newFile;
! setIndex(-1, -1);
! }
}
--- 71,76 ----
void setFile(File newFile) {
! file = newFile;
! setIndex(-1, -1);
}
Index: DataTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/DataTableModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** DataTableModel.java 13 Nov 2003 15:33:28 -0000 1.4
--- DataTableModel.java 4 Dec 2003 13:21:03 -0000 1.5
***************
*** 65,72 ****
void setFile(File newFile) {
! if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) {
! file = newFile;
! setIndex(-1, -1);
! }
}
--- 65,70 ----
void setFile(File newFile) {
! file = newFile;
! setIndex(-1, -1);
}
Index: DatasourceTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/DatasourceTableModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** DatasourceTableModel.java 13 Nov 2003 15:33:28 -0000 1.4
--- DatasourceTableModel.java 4 Dec 2003 13:21:03 -0000 1.5
***************
*** 70,77 ****
void setFile(File newFile) {
! if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) {
! file = newFile;
! setIndex(-1);
! }
}
--- 70,75 ----
void setFile(File newFile) {
! file = newFile;
! setIndex(-1);
}
Index: HeaderTableModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/HeaderTableModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** HeaderTableModel.java 13 Nov 2003 15:33:28 -0000 1.4
--- HeaderTableModel.java 4 Dec 2003 13:21:03 -0000 1.5
***************
*** 37,41 ****
class HeaderTableModel extends AbstractTableModel {
private static final Object[] DESCRIPTIONS = {"path", "signature", "step", "last timestamp",
! "datasources", "archives", "size"};
private static final String[] COLUMN_NAMES = {"description", "value"};
--- 37,41 ----
class HeaderTableModel extends AbstractTableModel {
private static final Object[] DESCRIPTIONS = {"path", "signature", "step", "last timestamp",
! "datasources", "archives", "size"};
private static final String[] COLUMN_NAMES = {"description", "value"};
***************
*** 47,63 ****
}
! public int getColumnCount() {
return COLUMN_NAMES.length;
}
public Object getValueAt(int rowIndex, int columnIndex) {
! if(columnIndex == 0) {
return DESCRIPTIONS[rowIndex];
! }
! else if(columnIndex == 1) {
! if(values != null) {
return values[rowIndex];
! }
! else {
return "--";
}
--- 47,61 ----
}
! public int getColumnCount() {
return COLUMN_NAMES.length;
}
public Object getValueAt(int rowIndex, int columnIndex) {
! if (columnIndex == 0) {
return DESCRIPTIONS[rowIndex];
! } else if (columnIndex == 1) {
! if (values != null) {
return values[rowIndex];
! } else {
return "--";
}
***************
*** 71,98 ****
void setFile(File newFile) {
! if(file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) {
! try {
! file = newFile;
! values = null;
! String path = file.getAbsolutePath();
! RrdDb rrd = new RrdDb(path);
! Header header = rrd.getHeader();
! String signature = header.getSignature();
! String step = "" + header.getStep();
! String lastTimestamp = header.getLastUpdateTime() + " [" +
! new Date(header.getLastUpdateTime() * 1000L) + "]";
! String datasources = "" + header.getDsCount();
! String archives = "" + header.getArcCount();
! String size = rrd.getRrdFile().getFileSize() + " bytes";
! rrd.close();
! values = new Object[] {
! path, signature, step, lastTimestamp, datasources, archives, size
! };
! fireTableDataChanged();
! }
! catch (IOException e) {
! }
! catch (RrdException e) {
! }
}
}
--- 69,94 ----
void setFile(File newFile) {
! try {
! file = newFile;
! values = null;
! String path = file.getAbsolutePath();
! RrdDb rrd = new RrdDb(path);
! Header header = rrd.getHeader();
! String signature = header.getSignature();
! String step = "" + header.getStep();
! String lastTimestamp = header.getLastUpdateTime() + " [" +
! new Date(header.getLastUpdateTime() * 1000L) + "]";
! String datasources = "" + header.getDsCount();
! String archives = "" + header.getArcCount();
! String size = rrd.getRrdFile().getFileSize() + " bytes";
! rrd.close();
! values = new Object[]{
! path, signature, step, lastTimestamp, datasources, archives, size
! };
! fireTableDataChanged();
! } catch (IOException e) {
! e.printStackTrace();
! } catch (RrdException e) {
! e.printStackTrace();
}
}
Index: InspectorModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/InspectorModel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** InspectorModel.java 10 Nov 2003 08:52:28 -0000 1.2
--- InspectorModel.java 4 Dec 2003 13:21:03 -0000 1.3
***************
*** 29,38 ****
import java.text.DecimalFormat;
- /**
- * Created by saxon
- * User: stalker
- * Date: Oct 5, 2003
- * Time: 11:26:05 AM
- */
class InspectorModel {
private MainTreeModel mainTreeModel = new MainTreeModel();
--- 29,32 ----
***************
*** 41,44 ****
--- 35,40 ----
private ArchiveTableModel archiveTableModel = new ArchiveTableModel();
private DataTableModel dataTableModel = new DataTableModel();
+ private File file;
+ private boolean ok = false;
MainTreeModel getMainTreeModel() {
***************
*** 63,67 ****
void setFile(File file) {
! mainTreeModel.setFile(file);
generalTableModel.setFile(file);
datasourceTableModel.setFile(file);
--- 59,64 ----
void setFile(File file) {
! this.file = file;
! this.ok = mainTreeModel.setFile(file);
generalTableModel.setFile(file);
datasourceTableModel.setFile(file);
***************
*** 70,77 ****
--- 67,86 ----
}
+ void refresh() {
+ setFile(file);
+ }
+
void selectModel(int dsIndex, int arcIndex) {
datasourceTableModel.setIndex(dsIndex);
archiveTableModel.setIndex(dsIndex, arcIndex);
dataTableModel.setIndex(dsIndex, arcIndex);
+ }
+
+ File getFile() {
+ return file;
+ }
+
+ boolean isOk() {
+ return ok;
}
Index: MainTreeModel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/MainTreeModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** MainTreeModel.java 13 Nov 2003 15:33:28 -0000 1.4
--- MainTreeModel.java 4 Dec 2003 13:21:03 -0000 1.5
***************
*** 44,75 ****
}
! void setFile(File newFile) {
! if (file == null || !file.getAbsolutePath().equals(newFile.getAbsolutePath())) {
! try {
! file = newFile;
! RrdDb rrd = new RrdDb(file.getAbsolutePath());
! DefaultMutableTreeNode root = new DefaultMutableTreeNode(new RrdNode(rrd));
! int dsCount = rrd.getRrdDef().getDsCount();
! int arcCount = rrd.getRrdDef().getArcCount();
! for (int dsIndex = 0; dsIndex < dsCount; dsIndex++) {
! DefaultMutableTreeNode dsNode =
! new DefaultMutableTreeNode(new RrdNode(rrd, dsIndex));
! for (int arcIndex = 0; arcIndex < arcCount; arcIndex++) {
! DefaultMutableTreeNode arcNode =
! new DefaultMutableTreeNode(new RrdNode(rrd, dsIndex, arcIndex));
! dsNode.add(arcNode);
! }
! root.add(dsNode);
}
! rrd.close();
! setRoot(root);
! }
! catch (IOException e) {
! setRoot(INVALID_NODE);
! }
! catch (RrdException e) {
! setRoot(INVALID_NODE);
}
}
}
}
--- 44,73 ----
}
! boolean setFile(File newFile) {
! try {
! file = newFile;
! RrdDb rrd = new RrdDb(file.getAbsolutePath());
! DefaultMutableTreeNode root = new DefaultMutableTreeNode(new RrdNode(rrd));
! int dsCount = rrd.getRrdDef().getDsCount();
! int arcCount = rrd.getRrdDef().getArcCount();
! for (int dsIndex = 0; dsIndex < dsCount; dsIndex++) {
! DefaultMutableTreeNode dsNode =
! new DefaultMutableTreeNode(new RrdNode(rrd, dsIndex));
! for (int arcIndex = 0; arcIndex < arcCount; arcIndex++) {
! DefaultMutableTreeNode arcNode =
! new DefaultMutableTreeNode(new RrdNode(rrd, dsIndex, arcIndex));
! dsNode.add(arcNode);
}
! root.add(dsNode);
}
+ rrd.close();
+ setRoot(root);
+ return true;
+ } catch (IOException e) {
+ setRoot(INVALID_NODE);
+ } catch (RrdException e) {
+ setRoot(INVALID_NODE);
}
+ return false;
}
}
Index: RrdInspector.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/RrdInspector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RrdInspector.java 10 Nov 2003 08:52:28 -0000 1.2
--- RrdInspector.java 4 Dec 2003 13:21:03 -0000 1.3
***************
*** 26,29 ****
--- 26,31 ----
package org.jrobin.inspector;
+ import org.jrobin.core.*;
+
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
***************
*** 36,42 ****
--- 38,48 ----
import java.awt.event.*;
import java.io.File;
+ import java.io.IOException;
class RrdInspector extends JFrame {
static final String TITLE = "RRD File Inspector";
+ static final boolean SHOULD_FIX_ARCHIVED_VALUES = false;
+ static final boolean SHOULD_CREATE_BACKUPS = true;
+
static Dimension MAIN_TREE_SIZE = new Dimension(250, 400);
static Dimension INFO_PANE_SIZE = new Dimension(450, 400);
***************
*** 51,55 ****
private InspectorModel inspectorModel = new InspectorModel();
! RrdInspector() {
super(TITLE);
constructUI();
--- 57,63 ----
private InspectorModel inspectorModel = new InspectorModel();
! private String lastDirectory = null;
!
! RrdInspector() {
super(TITLE);
constructUI();
***************
*** 69,73 ****
private void constructUI() {
! JPanel content = (JPanel) getContentPane();
content.setLayout(new BorderLayout());
--- 77,81 ----
private void constructUI() {
! JPanel content = (JPanel) getContentPane();
content.setLayout(new BorderLayout());
***************
*** 76,89 ****
leftPanel.setLayout(new BorderLayout());
JScrollPane treePane = new JScrollPane(mainTree);
! leftPanel.add(treePane);
leftPanel.setPreferredSize(MAIN_TREE_SIZE);
content.add(leftPanel, BorderLayout.WEST);
mainTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
mainTree.addTreeSelectionListener(new TreeSelectionListener() {
! public void valueChanged(TreeSelectionEvent e) { nodeChangedAction(); }
});
mainTree.setModel(inspectorModel.getMainTreeModel());
// EAST, tabbed pane
// GENERAL TAB
--- 84,101 ----
leftPanel.setLayout(new BorderLayout());
JScrollPane treePane = new JScrollPane(mainTree);
! leftPanel.add(treePane);
leftPanel.setPreferredSize(MAIN_TREE_SIZE);
content.add(leftPanel, BorderLayout.WEST);
mainTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
mainTree.addTreeSelectionListener(new TreeSelectionListener() {
! public void valueChanged(TreeSelectionEvent e) {
! nodeChangedAction();
! }
});
mainTree.setModel(inspectorModel.getMainTreeModel());
+ ////////////////////////////////////////////
// EAST, tabbed pane
+ ////////////////////////////////////////////
// GENERAL TAB
***************
*** 94,98 ****
generalTable.getColumnModel().getColumn(0).setPreferredWidth(150);
generalTable.getColumnModel().getColumn(0).setMaxWidth(150);
! //generalTable.getColumnModel().getColumn(0).setMinWidth(150);
// DATASOURCE TAB
JScrollPane spDatasource = new JScrollPane(datasourceTable);
--- 106,110 ----
generalTable.getColumnModel().getColumn(0).setPreferredWidth(150);
generalTable.getColumnModel().getColumn(0).setMaxWidth(150);
!
// DATASOURCE TAB
JScrollPane spDatasource = new JScrollPane(datasourceTable);
***************
*** 102,106 ****
datasourceTable.getColumnModel().getColumn(0).setPreferredWidth(150);
datasourceTable.getColumnModel().getColumn(0).setMaxWidth(150);
! //datasourceTable.getColumnModel().getColumn(0).setMinWidth(150);
// ARCHIVE TAB
JScrollPane spArchive = new JScrollPane(archiveTable);
--- 114,118 ----
datasourceTable.getColumnModel().getColumn(0).setPreferredWidth(150);
datasourceTable.getColumnModel().getColumn(0).setMaxWidth(150);
!
// ARCHIVE TAB
JScrollPane spArchive = new JScrollPane(archiveTable);
***************
*** 108,114 ****
archiveTable.getColumnModel().getColumn(0).setPreferredWidth(150);
archiveTable.getColumnModel().getColumn(0).setMaxWidth(150);
- //archiveTable.getColumnModel().getColumn(0).setMinWidth(150);
spArchive.setPreferredSize(INFO_PANE_SIZE);
! tabbedPane.add("Archive info", spArchive);
// DATA TAB
JScrollPane spData = new JScrollPane(dataTable);
--- 120,126 ----
archiveTable.getColumnModel().getColumn(0).setPreferredWidth(150);
archiveTable.getColumnModel().getColumn(0).setMaxWidth(150);
spArchive.setPreferredSize(INFO_PANE_SIZE);
! tabbedPane.add("Archive info", spArchive);
!
// DATA TAB
JScrollPane spData = new JScrollPane(dataTable);
***************
*** 122,127 ****
--- 134,142 ----
content.add(tabbedPane, BorderLayout.CENTER);
+ ////////////////////////////////////////
// MENU
+ ////////////////////////////////////////
JMenuBar menuBar = new JMenuBar();
+ // FILE
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
***************
*** 133,136 ****
--- 148,196 ----
});
fileMenu.add(fileMenuItem);
+ fileMenu.addSeparator();
+ JMenuItem addDatasourceMenuItem = new JMenuItem("Add datasource...");
+ addDatasourceMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ addDatasource();
+ }
+ });
+ fileMenu.add(addDatasourceMenuItem);
+ JMenuItem editDatasourceMenuItem = new JMenuItem("Edit datasource...");
+ editDatasourceMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ editDatasource();
+ }
+ });
+ fileMenu.add(editDatasourceMenuItem);
+ JMenuItem removeDatasourceMenuItem = new JMenuItem("Remove datasource");
+ removeDatasourceMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ removeDatasource();
+ }
+ });
+ fileMenu.add(removeDatasourceMenuItem);
+ fileMenu.addSeparator();
+ JMenuItem addArchiveMenuItem = new JMenuItem("Add archive...");
+ addArchiveMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ addArchive();
+ }
+ });
+ fileMenu.add(addArchiveMenuItem);
+ JMenuItem editArchiveMenuItem = new JMenuItem("Edit archive...");
+ editArchiveMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ editArchive();
+ }
+ });
+ fileMenu.add(editArchiveMenuItem);
+ JMenuItem removeArchiveMenuItem = new JMenuItem("Remove archive...");
+ removeArchiveMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ removeArchive();
+ }
+ });
+ fileMenu.add(removeArchiveMenuItem);
+ fileMenu.addSeparator();
JMenuItem exitMenuItem = new JMenuItem("Exit", KeyEvent.VK_X);
exitMenuItem.addActionListener(new ActionListener() {
***************
*** 139,143 ****
}
});
- fileMenu.addSeparator();
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
--- 199,202 ----
***************
*** 146,150 ****
// finalize UI
addWindowListener(new WindowAdapter() {
! public void windowClosing(WindowEvent e) { System.exit(0); }
});
--- 205,211 ----
// finalize UI
addWindowListener(new WindowAdapter() {
! public void windowClosing(WindowEvent e) {
! System.exit(0);
! }
});
***************
*** 152,185 ****
private void nodeChangedAction() {
TreePath path = mainTree.getSelectionPath();
! if(path != null) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object obj = node.getUserObject();
! if(obj instanceof RrdNode) {
RrdNode rrdNode = (RrdNode) obj;
! inspectorModel.selectModel(rrdNode.getDsIndex(), rrdNode.getArcIndex());
! if(rrdNode.getDsIndex() >= 0 && rrdNode.getArcIndex() >= 0) {
! // archive node
! if(tabbedPane.getSelectedIndex() < 2) {
! tabbedPane.setSelectedIndex(2);
! }
! }
! else if(rrdNode.getDsIndex() >= 0) {
! tabbedPane.setSelectedIndex(1);
! }
! else {
! tabbedPane.setSelectedIndex(0);
! }
}
}
}
private void selectFile() {
! JFileChooser chooser = new JFileChooser();
FileFilter filter = new FileFilter() {
public boolean accept(File f) {
! return f.isDirectory()? true:
f.getAbsolutePath().toLowerCase().endsWith(".rrd");
}
public String getDescription() {
return "JRobin RRD files";
--- 213,253 ----
private void nodeChangedAction() {
+ RrdNode rrdNode = getSelectedRrdNode();
+ if (rrdNode != null) {
+ inspectorModel.selectModel(rrdNode.getDsIndex(), rrdNode.getArcIndex());
+ if (rrdNode.getDsIndex() >= 0 && rrdNode.getArcIndex() >= 0) {
+ // archive node
+ if (tabbedPane.getSelectedIndex() < 2) {
+ tabbedPane.setSelectedIndex(2);
+ }
+ } else if (rrdNode.getDsIndex() >= 0) {
+ tabbedPane.setSelectedIndex(1);
+ } else {
+ tabbedPane.setSelectedIndex(0);
+ }
+ }
+ }
+
+ private RrdNode getSelectedRrdNode() {
TreePath path = mainTree.getSelectionPath();
! if (path != null) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object obj = node.getUserObject();
! if (obj instanceof RrdNode) {
RrdNode rrdNode = (RrdNode) obj;
! return rrdNode;
}
}
+ return null;
}
private void selectFile() {
! JFileChooser chooser = new JFileChooser(lastDirectory);
FileFilter filter = new FileFilter() {
public boolean accept(File f) {
! return f.isDirectory() ? true :
f.getAbsolutePath().toLowerCase().endsWith(".rrd");
}
+
public String getDescription() {
return "JRobin RRD files";
***************
*** 188,195 ****
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(this);
! if(returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
inspectorModel.setFile(file);
tabbedPane.setSelectedIndex(0);
}
}
--- 256,432 ----
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(this);
! if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
+ lastDirectory = file.getParent();
inspectorModel.setFile(file);
tabbedPane.setSelectedIndex(0);
+ }
+ }
+
+ private void addDatasource() {
+ if (!inspectorModel.isOk()) {
+ Util.error(this, "Open a valid RRD file first.");
+ return;
+ }
+ DsDef newDsDef = new EditDatasourceDialog(this, null).getDsDef();
+ if (newDsDef != null) {
+ // action
+ RrdToolkit toolkit = RrdToolkit.getInstance();
+ try {
+ String sourcePath = inspectorModel.getFile().getCanonicalPath();
+ toolkit.addDatasource(sourcePath, newDsDef, SHOULD_CREATE_BACKUPS);
+ inspectorModel.refresh();
+ tabbedPane.setSelectedIndex(0);
+ } catch (IOException e) {
+ Util.error(this, e.toString());
+ } catch (RrdException e) {
+ Util.error(this, e.toString());
+ }
+ }
+ }
+
+ private void addArchive() {
+ if (!inspectorModel.isOk()) {
+ Util.error(this, "Open a valid RRD file first.");
+ return;
+ }
+ ArcDef newArcDef = new EditArchiveDialog(this, null).getArcDef();
+ if (newArcDef != null) {
+ // action
+ RrdToolkit toolkit = RrdToolkit.getInstance();
+ try {
+ String sourcePath = inspectorModel.getFile().getCanonicalPath();
+ toolkit.addArchive(sourcePath, newArcDef, SHOULD_CREATE_BACKUPS);
+ inspectorModel.refresh();
+ tabbedPane.setSelectedIndex(0);
+ } catch (IOException e) {
+ Util.error(this, e.toString());
+ } catch (RrdException e) {
+ Util.error(this, e.toString());
+ }
+ }
+ }
+
+ private void editDatasource() {
+ if (!inspectorModel.isOk()) {
+ Util.error(this, "Open a valid RRD file first.");
+ return;
+ }
+ RrdNode rrdNode = getSelectedRrdNode();
+ int dsIndex = -1;
+ if(rrdNode == null || (dsIndex = rrdNode.getDsIndex()) < 0) {
+ Util.error(this, "Select datasource first");
+ return;
+ }
+ try {
+ String sourcePath = inspectorModel.getFile().getCanonicalPath();
+ RrdDb rrd = new RrdDb(sourcePath);
+ DsDef dsDef = rrd.getRrdDef().getDsDefs()[dsIndex];
+ rrd.close();
+ DsDef newDsDef = new EditDatasourceDialog(this, dsDef).getDsDef();
+ if(newDsDef != null) {
+ // action!
+ RrdToolkit toolkit = RrdToolkit.getInstance();
+ toolkit.setDsHeartbeat(sourcePath, newDsDef.getDsName(),
+ newDsDef.getHeartbeat());
+ toolkit.setDsMinMaxValue(sourcePath, newDsDef.getDsName(),
+ newDsDef.getMinValue(), newDsDef.getMaxValue(), SHOULD_FIX_ARCHIVED_VALUES);
+ inspectorModel.refresh();
+ tabbedPane.setSelectedIndex(0);
+ }
+ rrd.close();
+ } catch (IOException e) {
+ Util.error(this, e.toString());
+ } catch (RrdException e) {
+ Util.error(this, e.toString());
+ }
+ }
+
+ private void editArchive() {
+ if (!inspectorModel.isOk()) {
+ Util.error(this, "Open a valid RRD file first.");
+ return;
+ }
+ RrdNode rrdNode = getSelectedRrdNode();
+ int arcIndex = -1;
+ if(rrdNode == null || (arcIndex = rrdNode.getArcIndex()) < 0) {
+ Util.error(this, "Select archive first");
+ return;
+ }
+ try {
+ String sourcePath = inspectorModel.getFile().getCanonicalPath();
+ RrdDb rrd = new RrdDb(sourcePath);
+ ArcDef arcDef = rrd.getRrdDef().getArcDefs()[arcIndex];
+ rrd.close();
+ ArcDef newArcDef = new EditArchiveDialog(this, arcDef).getArcDef();
+ if(newArcDef != null) {
+ // action!
+ RrdToolkit toolkit = RrdToolkit.getInstance();
+ toolkit.setArcXff(sourcePath, newArcDef.getConsolFun(),
+ newArcDef.getSteps(), newArcDef.getXff());
+ inspectorModel.refresh();
+ tabbedPane.setSelectedIndex(0);
+ }
+ rrd.close();
+ } catch (IOException e) {
+ Util.error(this, e.toString());
+ } catch (RrdException e) {
+ Util.error(this, e.toString());
+ }
+ }
+
+ private void removeDatasource() {
+ if (!inspectorModel.isOk()) {
+ Util.error(this, "Open a valid RRD file first.");
+ return;
+ }
+ RrdNode rrdNode = getSelectedRrdNode();
+ int dsIndex = -1;
+ if(rrdNode == null || (dsIndex = rrdNode.getDsIndex()) < 0) {
+ Util.error(this, "Select datasource first");
+ return;
+ }
+ try {
+ String sourcePath = inspectorModel.getFile().getCanonicalPath();
+ RrdDb rrd = new RrdDb(sourcePath);
+ String dsName = rrd.getRrdDef().getDsDefs()[dsIndex].getDsName();
+ rrd.close();
+ RrdToolkit toolkit = RrdToolkit.getInstance();
+ toolkit.removeDatasource(sourcePath, dsName, SHOULD_CREATE_BACKUPS);
+ inspectorModel.refresh();
+ tabbedPane.setSelectedIndex(0);
+ } catch (IOException e) {
+ Util.error(this, e.toString());
+ } catch (RrdException e) {
+ Util.error(this, e.toString());
+ }
+ }
+
+ private void removeArchive() {
+ if (!inspectorModel.isOk()) {
+ Util.error(this, "Open a valid RRD file first.");
+ return;
+ }
+ RrdNode rrdNode = getSelectedRrdNode();
+ int arcIndex = -1;
+ if(rrdNode == null || (arcIndex = rrdNode.getArcIndex()) < 0) {
+ Util.error(this, "Select archive first");
+ return;
+ }
+ try {
+ String sourcePath = inspectorModel.getFile().getCanonicalPath();
+ RrdDb rrd = new RrdDb(sourcePath);
+ ArcDef arcDef = rrd.getRrdDef().getArcDefs()[arcIndex];
+ String consolFun = arcDef.getConsolFun();
+ int steps = arcDef.getSteps();
+ rrd.close();
+ RrdToolkit toolkit = RrdToolkit.getInstance();
+ toolkit.removeArchive(sourcePath, consolFun, steps, SHOULD_CREATE_BACKUPS);
+ inspectorModel.refresh();
+ tabbedPane.setSelectedIndex(0);
+ } catch (IOException e) {
+ Util.error(this, e.toString());
+ } catch (RrdException e) {
+ Util.error(this, e.toString());
}
}
|