From: Arne V. <cob...@us...> - 2004-07-09 12:20:21
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17847/org/jrobin/core Modified Files: FetchData.java RrdDb.java Util.java Added Files: RrdDataSet.java Log Message: JRobin 1.4.0 - Major graph datapoint calculation rewrite - Added elaborate Export support with RRDtool like functionality - New classes: RrdExport, RrdExporter, RrdExportDef, ExportData - New interface: RrdDataSet - Value grid tweaking - Several minor tweaks Index: FetchData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchData.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FetchData.java 20 May 2004 10:29:32 -0000 1.5 --- FetchData.java 9 Jul 2004 12:20:10 -0000 1.6 *************** *** 53,57 **** * the values returned with {@link #getTimestamps() getTimestamps()} method.<p> */ ! public class FetchData { private FetchRequest request; private Archive matchingArchive; --- 53,57 ---- * the values returned with {@link #getTimestamps() getTimestamps()} method.<p> */ ! public class FetchData implements RrdDataSet { private FetchRequest request; private Archive matchingArchive; --- NEW FILE: RrdDataSet.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.core; import java.io.IOException; import java.io.OutputStream; /** * <p>Interface to represent a JRobin dataset. A dataset is nothing but a table of datasources, indexed * by equidistant timestamps. A dataset allows access to the internal datasources with aggregatoin methods.</p> * * @author Arne Vandamme (cob...@jr...) */ public interface RrdDataSet { /** * Returns the number of rows in this dataset. * * @return Number of rows (data samples). */ public int getRowCount(); /** * Returns the number of columns in this dataset. * * @return Number of columns (datasources). */ public int getColumnCount(); /** * Returns an array of timestamps covering the whole range specified in the * dataset object. * * @return Array of equidistant timestamps. */ public long[] getTimestamps(); /** * Returns all values for a single datasource, the returned values * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method. * * @param dsIndex Datasource index. * @return Array of single datasource values. */ public double[] getValues( int dsIndex ); /** * Returns all values for all datasources, the returned values * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method. * * @return Two-dimensional aray of all datasource values. */ public double[][] getValues(); /** * Returns all values for a single datasource, the returned values * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method. * * @param dsName Datasource name. * @return Array of single datasource values. * @throws RrdException Thrown if no matching datasource name is found. */ public double[] getValues( String dsName ) throws RrdException; /** * Returns the first timestamp in the dataset. * * @return The smallest timestamp. */ public long getFirstTimestamp(); /** * Returns the last timestamp in the dataset. * * @return The biggest timestamp. */ public long getLastTimestamp(); /** * Returns array of the names of all datasources in the set. * * @return Array of datasource names. */ public String[] getDsNames(); /** * Retrieve the table index number of a datasource by name. * Names are case sensitive. * * @param dsName Name of the datasource for which to find the index. * @return Index number of the datasource in the value table. * @throws RrdException Thrown if the given datasource name cannot be found in the dataset. */ public int getDsIndex( String dsName ) throws RrdException; /** * Returns aggregated value from the dataset for a single datasource. * * @param dsName Datasource name * @param consolFun Consolidation function to be applied to set datasource values datasource. * Valid consolidation functions are MIN, MAX, LAST and AVERAGE * @return MIN, MAX, LAST or AVERAGE value calculated from the dataset for the given datasource name * @throws RrdException Thrown if the given datasource name cannot be found in the dataset. */ public double getAggregate( String dsName, String consolFun ) throws RrdException; /** * Dumps fetch data to output stream in XML format. * * @param outputStream Output stream to dump dataset to * @throws RrdException Thrown in case of JRobin specific error. * @throws IOException Thrown in case of I/O error */ public void exportXml( OutputStream outputStream ) throws RrdException, IOException; /** * Dumps dataset to file in XML format. * * @param filepath Path to destination file * @throws RrdException Thrown in case of JRobin specific error. * @throws IOException Thrown in case of I/O error */ public void exportXml( String filepath ) throws RrdException, IOException; /** * Dumps the dataset to XML. * * @return XML string format of the dataset. * @throws RrdException Thrown in case of JRobin specific error. * @throws IOException Thrown in case of an I/O related error. */ public String exportXml() throws RrdException, IOException; } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Util.java 20 May 2004 10:29:33 -0000 1.16 --- Util.java 9 Jul 2004 12:20:11 -0000 1.17 *************** *** 76,80 **** } ! static long normalize(long timestamp, long step) { return timestamp - timestamp % step; } --- 76,80 ---- } ! public static long normalize(long timestamp, long step) { return timestamp - timestamp % step; } *************** *** 199,203 **** } ! static double parseDouble(String valueStr) { double value; try { --- 199,203 ---- } ! public static double parseDouble(String valueStr) { double value; try { *************** *** 210,214 **** } ! static boolean parseBoolean(String valueStr) { return valueStr.equalsIgnoreCase("true") || valueStr.equalsIgnoreCase("on") || --- 210,214 ---- } ! public static boolean parseBoolean(String valueStr) { return valueStr.equalsIgnoreCase("true") || valueStr.equalsIgnoreCase("on") || *************** *** 330,339 **** * Various DOM utility functions */ ! static class Xml { ! static Node[] getChildNodes(Node parentNode) { return getChildNodes(parentNode, null); } ! static Node[] getChildNodes(Node parentNode, String childName) { ArrayList nodes = new ArrayList(); NodeList nodeList = parentNode.getChildNodes(); --- 330,339 ---- * Various DOM utility functions */ ! public static class Xml { ! public static Node[] getChildNodes(Node parentNode) { return getChildNodes(parentNode, null); } ! public static Node[] getChildNodes(Node parentNode, String childName) { ArrayList nodes = new ArrayList(); NodeList nodeList = parentNode.getChildNodes(); *************** *** 347,351 **** } ! static Node getFirstChildNode(Node parentNode, String childName) throws RrdException { Node[] childs = getChildNodes(parentNode, childName); if (childs.length > 0) { --- 347,351 ---- } ! public static Node getFirstChildNode(Node parentNode, String childName) throws RrdException { Node[] childs = getChildNodes(parentNode, childName); if (childs.length > 0) { *************** *** 355,359 **** } ! static boolean hasChildNode(Node parentNode, String childName) { Node[] childs = getChildNodes(parentNode, childName); return childs.length > 0; --- 355,359 ---- } ! public static boolean hasChildNode(Node parentNode, String childName) { Node[] childs = getChildNodes(parentNode, childName); return childs.length > 0; *************** *** 361,369 **** // -- Wrapper around getChildValue with trim ! static String getChildValue( Node parentNode, String childName ) throws RrdException { return getChildValue( parentNode, childName, true ); } ! static String getChildValue( Node parentNode, String childName, boolean trim ) throws RrdException { NodeList children = parentNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { --- 361,369 ---- // -- Wrapper around getChildValue with trim ! public static String getChildValue( Node parentNode, String childName ) throws RrdException { return getChildValue( parentNode, childName, true ); } ! public static String getChildValue( Node parentNode, String childName, boolean trim ) throws RrdException { NodeList children = parentNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { *************** *** 377,385 **** // -- Wrapper around getValue with trim ! static String getValue(Node node) { return getValue( node, true ); } ! static String getValue(Node node, boolean trimValue ) { String value = null; Node child = node.getFirstChild(); --- 377,385 ---- // -- Wrapper around getValue with trim ! public static String getValue(Node node) { return getValue( node, true ); } ! public static String getValue(Node node, boolean trimValue ) { String value = null; Node child = node.getFirstChild(); *************** *** 393,437 **** } ! static int getChildValueAsInt(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Integer.parseInt(valueStr); } ! static int getValueAsInt(Node node) { String valueStr = getValue(node); return Integer.parseInt(valueStr); } ! static long getChildValueAsLong(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Long.parseLong(valueStr); } ! static long getValueAsLong(Node node) { String valueStr = getValue(node); return Long.parseLong(valueStr); } ! static double getChildValueAsDouble(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Util.parseDouble(valueStr); } ! static double getValueAsDouble(Node node) { String valueStr = getValue(node); return Util.parseDouble(valueStr); } ! static boolean getChildValueAsBoolean(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Util.parseBoolean(valueStr); } ! static boolean getValueAsBoolean(Node node) { String valueStr = getValue(node); return Util.parseBoolean(valueStr); } ! static Element getRootElement(InputSource inputSource) throws RrdException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); --- 393,437 ---- } ! public static int getChildValueAsInt(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Integer.parseInt(valueStr); } ! public static int getValueAsInt(Node node) { String valueStr = getValue(node); return Integer.parseInt(valueStr); } ! public static long getChildValueAsLong(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Long.parseLong(valueStr); } ! public static long getValueAsLong(Node node) { String valueStr = getValue(node); return Long.parseLong(valueStr); } ! public static double getChildValueAsDouble(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Util.parseDouble(valueStr); } ! public static double getValueAsDouble(Node node) { String valueStr = getValue(node); return Util.parseDouble(valueStr); } ! public static boolean getChildValueAsBoolean(Node parentNode, String childName) throws RrdException { String valueStr = getChildValue(parentNode, childName); return Util.parseBoolean(valueStr); } ! public static boolean getValueAsBoolean(Node node) { String valueStr = getValue(node); return Util.parseBoolean(valueStr); } ! public static Element getRootElement(InputSource inputSource) throws RrdException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); *************** *** 448,456 **** } ! 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 { --- 448,456 ---- } ! public static Element getRootElement(String xmlString) throws RrdException, IOException { return getRootElement(new InputSource(new StringReader(xmlString))); } ! public static Element getRootElement(File xmlFile) throws RrdException, IOException { Reader reader = null; try { *************** *** 480,484 **** return "[" + seconds + " sec]"; } ! } ! ! --- 480,483 ---- return "[" + seconds + " sec]"; } ! ! } \ No newline at end of file Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** RrdDb.java 29 Jun 2004 11:30:55 -0000 1.22 --- RrdDb.java 9 Jul 2004 12:20:10 -0000 1.23 *************** *** 503,507 **** } ! private Archive findMatchingArchive(FetchRequest request) throws RrdException, IOException { String consolFun = request.getConsolFun(); long fetchStart = request.getFetchStart(); --- 503,507 ---- } ! public Archive findMatchingArchive(FetchRequest request) throws RrdException, IOException { String consolFun = request.getConsolFun(); long fetchStart = request.getFetchStart(); *************** *** 560,564 **** * @throws IOException Thrown in case of I/O related error. */ ! public Archive findStartMatchArchive( String consolFun, long startTime, long resolution ) throws IOException { long arcStep, diff; int fallBackIndex = 0; --- 560,565 ---- * @throws IOException Thrown in case of I/O related error. */ ! public Archive findStartMatchArchive( String consolFun, long startTime, long resolution ) throws IOException ! { long arcStep, diff; int fallBackIndex = 0; |