From: Sasa M. <sa...@us...> - 2004-07-22 09:34:19
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9612/org/jrobin/core Modified Files: Archive.java DataImporter.java Datasource.java Header.java RrdDb.java Added Files: RrdToolReader.java Log Message: Added support for direct RRDTool file format reading Index: Datasource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Datasource.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Datasource.java 20 May 2004 10:29:32 -0000 1.6 --- Datasource.java 22 Jul 2004 09:34:10 -0000 1.7 *************** *** 75,79 **** } ! Datasource(RrdDb parentDb, XmlReader reader, int dsIndex) throws IOException, RrdException { this(parentDb, null); dsName.set(reader.getDsName(dsIndex)); --- 75,79 ---- } ! Datasource(RrdDb parentDb, DataImporter reader, int dsIndex) throws IOException, RrdException { this(parentDb, null); dsName.set(reader.getDsName(dsIndex)); Index: DataImporter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/DataImporter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DataImporter.java 22 Jul 2004 07:23:46 -0000 1.1 --- DataImporter.java 22 Jul 2004 09:34:10 -0000 1.2 *************** *** 70,72 **** --- 70,76 ---- } + void release() throws RrdException, IOException { + // NOP + } + } \ No newline at end of file Index: Header.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Header.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Header.java 20 May 2004 10:29:32 -0000 1.6 --- Header.java 22 Jul 2004 09:34:10 -0000 1.7 *************** *** 66,70 **** } ! Header(RrdDb parentDb, XmlReader reader) throws IOException, RrdException { this(parentDb, (RrdDef) null); String version = reader.getVersion(); --- 66,70 ---- } ! Header(RrdDb parentDb, DataImporter reader) throws IOException, RrdException { this(parentDb, (RrdDef) null); String version = reader.getVersion(); --- NEW FILE: RrdToolReader.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.jrobin.core.jrrd.RRDatabase; import java.io.IOException; class RrdToolReader extends DataImporter { private RRDatabase rrd; RrdToolReader(String rrdPath) throws IOException { rrd = new RRDatabase(rrdPath); } String getVersion() { return rrd.getHeader().getVersion(); } long getLastUpdateTime() { return Util.getTimestamp(rrd.getLastUpdate()); } long getStep() { return rrd.getHeader().getPDPStep(); } int getDsCount() { return rrd.getHeader().getDSCount(); } int getArcCount() throws RrdException, IOException { return rrd.getNumArchives(); } String getDsName(int dsIndex) { return rrd.getDataSource(dsIndex).getName(); } String getDsType(int dsIndex) { return rrd.getDataSource(dsIndex).getType().toString(); } long getHeartbeat(int dsIndex) { return rrd.getDataSource(dsIndex).getMinimumHeartbeat(); } double getMinValue(int dsIndex) { return rrd.getDataSource(dsIndex).getMinimum(); } double getMaxValue(int dsIndex) { return rrd.getDataSource(dsIndex).getMaximum(); } double getLastValue(int dsIndex) { String valueStr = rrd.getDataSource(dsIndex).getPDPStatusBlock().getLastReading(); return Util.parseDouble(valueStr); } double getAccumValue(int dsIndex) { return rrd.getDataSource(dsIndex).getPDPStatusBlock().getValue(); } long getNanSeconds(int dsIndex) { return rrd.getDataSource(dsIndex).getPDPStatusBlock().getUnknownSeconds(); } String getConsolFun(int arcIndex) { return rrd.getArchive(arcIndex).getType().toString(); } double getXff(int arcIndex) { return rrd.getArchive(arcIndex).getXff(); } int getSteps(int arcIndex) { return rrd.getArchive(arcIndex).getPdpCount(); } int getRows(int arcIndex) throws RrdException, IOException { return rrd.getArchive(arcIndex).getRowCount(); } double getStateAccumValue(int arcIndex, int dsIndex) throws RrdException, IOException { return rrd.getArchive(arcIndex).getCDPStatusBlock(dsIndex).getValue(); } int getStateNanSteps(int arcIndex, int dsIndex) throws RrdException, IOException { return rrd.getArchive(arcIndex).getCDPStatusBlock(dsIndex).getUnknownDatapoints(); } double[] getValues(int arcIndex, int dsIndex) throws RrdException, IOException { return rrd.getArchive(arcIndex).getValues()[dsIndex]; } void release() throws IOException { if(rrd != null) { rrd.close(); rrd = null; } } protected void finalize() throws Throwable { release(); } } Index: Archive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Archive.java 20 May 2004 10:29:32 -0000 1.15 --- Archive.java 22 Jul 2004 09:34:10 -0000 1.16 *************** *** 72,76 **** // read from XML ! Archive(RrdDb parentDb, XmlReader reader, int arcIndex) throws IOException, RrdException { this(parentDb, new ArcDef( reader.getConsolFun(arcIndex), reader.getXff(arcIndex), --- 72,76 ---- // read from XML ! Archive(RrdDb parentDb, DataImporter reader, int arcIndex) throws IOException, RrdException { this(parentDb, new ArcDef( reader.getConsolFun(arcIndex), reader.getXff(arcIndex), Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** RrdDb.java 21 Jul 2004 08:27:40 -0000 1.25 --- RrdDb.java 22 Jul 2004 09:34:10 -0000 1.26 *************** *** 306,310 **** throws IOException, RrdException { backend = factory.open(rrdPath, false, lockMode); ! XmlReader reader = new XmlReader(xmlPath); backend.setLength(reader.getEstimatedSize()); // create header --- 306,321 ---- throws IOException, RrdException { backend = factory.open(rrdPath, false, lockMode); ! DataImporter reader; ! if(xmlPath.startsWith("rrdtool:/")) { ! String rrdToolPath = xmlPath.substring("rrdtool:/".length()); ! reader = new RrdToolReader(rrdToolPath); ! } ! else if(xmlPath.startsWith("xml:/")) { ! xmlPath = xmlPath.substring("xml:/".length()); ! reader = new XmlReader(xmlPath); ! } ! else { ! reader = new XmlReader(xmlPath); ! } backend.setLength(reader.getEstimatedSize()); // create header *************** *** 320,323 **** --- 331,335 ---- archives[i] = new Archive(this, reader, i); } + reader.release(); // XMLReader is a rather huge DOM tree, release memory ASAP reader = null; |