From: Arne V. <cob...@us...> - 2004-07-11 22:45:07
|
Update of /cvsroot/jrobin/src/org/jrobin/demo/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14605/org/jrobin/demo/graph Modified Files: GraphTemplate.java Added Files: ExportTemplate.java Log Message: JRobin 1.4.0 - Added ExportTemplate demo application Index: GraphTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/demo/graph/GraphTemplate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GraphTemplate.java 11 Jul 2004 22:06:45 -0000 1.1 --- GraphTemplate.java 11 Jul 2004 22:44:59 -0000 1.2 *************** *** 36,40 **** /** * <p>Simple command line application that allows you to generate a graph ! * from a RrdGraphDefTemplate. Pretty straightforward use.</p> * * @author Arne Vandamme (cob...@jr...) --- 36,40 ---- /** * <p>Simple command line application that allows you to generate a graph ! * from a RrdGraphDefTemplate. Pretty straightforward in use.</p> * * @author Arne Vandamme (cob...@jr...) *************** *** 112,115 **** --- 112,116 ---- RrdGraphDefTemplate template = new RrdGraphDefTemplate( new File(templateFile) ); + // -- Set the parameters (if there are any) System.out.println( ">>> Setting template variables" ); if ( template.hasVariables() ) *************** *** 126,129 **** --- 127,131 ---- long start = System.currentTimeMillis(); + // -- Generate the actual graph RrdGraph graph = new RrdGraph( template.getRrdGraphDef() ); --- NEW FILE: ExportTemplate.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.demo.graph; import org.jrobin.graph.RrdExport; import org.jrobin.graph.RrdExportDefTemplate; import org.jrobin.graph.ExportData; import org.jrobin.core.RrdException; import java.io.BufferedReader; import java.io.IOException; import java.io.File; import java.io.InputStreamReader; /** * <p>Simple command line application that allows you to export RRD data by means * of a RrdGraphDefTemplate. Pretty straightforward in use.</p> * * @author Arne Vandamme (cob...@jr...) */ public class ExportTemplate { private static int maxRows = 400; // Maximum number of rows private static String templateFile, dumpFile; private static void die( String msg ) { System.err.println( msg ); System.exit( -1 ); } private static void parseArguments( String[] args ) { int rpos = args.length - 1; // Last argument should be the templateFile templateFile = args[rpos]; // Remaining number of parameters should be even if ( rpos % 2 > 0 ) die( "Invalid number of arguments." ); for ( int i = 0; i < rpos; i += 2 ) { String arg = args[i]; String val = args[i + 1]; try { if ( arg.equalsIgnoreCase("-m") ) maxRows = Integer.parseInt(val); else if ( arg.equalsIgnoreCase("-f") ) dumpFile = val; } catch ( Exception e ) { die( "Error with option '" + arg + "': " + e.getMessage() ); } } } private static String readVariable( BufferedReader in, String name ) throws IOException { System.out.print( "Variable '" + name + "' = " ); return in.readLine(); } public static void main( String[] args ) { if ( args.length < 2 ) { System.out.println( "Usage: ExportTemplate [-m width] [-f <dump_file>] <template_file>" ); System.exit(0); } parseArguments( args ); try { // -- Read the RrdGraphDefTemplate (XML format) System.out.println( ">>> Reading XML template" ); RrdExportDefTemplate template = new RrdExportDefTemplate( new File(templateFile) ); // -- Set the parameters (if there are any) System.out.println( ">>> Setting template variables" ); if ( template.hasVariables() ) { BufferedReader in = new BufferedReader( new InputStreamReader(System.in) ); String[] variables = template.getVariables(); for ( int i = 0; i < variables.length; i++ ) template.setVariable( variables[i], readVariable( in, variables[i] ) ); } System.out.println( ">>> Exporting data..." ); long start = System.currentTimeMillis(); // -- Generate the actual graph RrdExport export = new RrdExport( template.getRrdExportDef() ); ExportData data = export.fetch( maxRows ); if ( dumpFile != null ) data.exportXml( dumpFile ); else data.exportXml( System.out ); long stop = System.currentTimeMillis(); System.out.println( ">>> Data exported in " + (stop - start) + " milliseconds" ); } catch ( RrdException rrde ) { die( "RrdException occurred: " + rrde.getMessage() ); } catch ( IOException ioe ) { die( "IOException occurred: " + ioe.getMessage() ); } } } |