Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9371/org/jrobin/core Modified Files: ArcDef.java ArcState.java Archive.java Datasource.java DsDef.java FetchData.java FetchPoint.java FetchRequest.java Header.java Robin.java RpnCalculator.java RrdDb.java RrdDbPool.java RrdDef.java RrdDefTemplate.java RrdDouble.java RrdDoubleArray.java RrdException.java RrdInt.java RrdLong.java RrdPrimitive.java RrdString.java RrdToolkit.java RrdUpdater.java Sample.java Util.java XmlReader.java XmlTemplate.java Log Message: Major core package redesign Index: FetchData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchData.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FetchData.java 1 Mar 2004 08:50:24 -0000 1.4 --- FetchData.java 20 May 2004 10:29:32 -0000 1.5 *************** *** 32,41 **** /** ! * Class used to represent data fetched from the RRD file. * Object of this class is created when the method * {@link org.jrobin.core.FetchRequest#fetchData() fetchData()} is * called on a {@link org.jrobin.core.FetchRequest FetchRequest} object.<p> * ! * Data returned from the RRD file is, simply, just one big table filled with * timestamps and corresponding datasource values. * Use {@link #getRowCount() getRowCount()} method to count the number --- 32,41 ---- /** ! * Class used to represent data fetched from the RRD. * Object of this class is created when the method * {@link org.jrobin.core.FetchRequest#fetchData() fetchData()} is * called on a {@link org.jrobin.core.FetchRequest FetchRequest} object.<p> * ! * Data returned from the RRD is, simply, just one big table filled with * timestamps and corresponding datasource values. * Use {@link #getRowCount() getRowCount()} method to count the number *************** *** 78,82 **** /** ! * Returns the number of rows fetched from the underlying RRD file. * Each row represents datasource values for the specific timestamp. * @return Number of rows. --- 78,82 ---- /** ! * Returns the number of rows fetched from the corresponding RRD. * Each row represents datasource values for the specific timestamp. * @return Number of rows. *************** *** 87,93 **** /** ! * Returns the number of columns fetched from the underlying RRD file. * This number is always equal to the number of datasources defined ! * in the RRD file. Each column represents values of a single datasource. * @return Number of columns (datasources). */ --- 87,93 ---- /** ! * Returns the number of columns fetched from the corresponding RRD. * This number is always equal to the number of datasources defined ! * in the RRD. Each column represents values of a single datasource. * @return Number of columns (datasources). */ *************** *** 97,101 **** /** ! * Returns the number of rows fetched from the underlying RRD file. * Each row represents datasource values for the specific timestamp. * @param rowIndex Row index. --- 97,101 ---- /** ! * Returns the number of rows fetched from the corresponding RRD. * Each row represents datasource values for the specific timestamp. * @param rowIndex Row index. *************** *** 194,198 **** /** ! * Returns array of datasource names found in the underlying RRD file. If the request * was filtered (data was fetched only for selected datasources), only datasources selected * for fetching are returned. --- 194,198 ---- /** ! * Returns array of datasource names found in the corresponding RRD. If the request * was filtered (data was fetched only for selected datasources), only datasources selected * for fetching are returned. *************** *** 208,212 **** * @return Index number of the datasources in the value table. */ ! public int getDsIndex( String dsName ) { // Let's assume the table of dsNames is always small, so it is not necessary to use a hashmap for lookups for (int i = 0; i < dsNames.length; i++) --- 208,212 ---- * @return Index number of the datasources in the value table. */ ! public int getDsIndex(String dsName) { // Let's assume the table of dsNames is always small, so it is not necessary to use a hashmap for lookups for (int i = 0; i < dsNames.length; i++) *************** *** 246,250 **** * <code>getAggregate("foots", "MAX", "value,0.3048,*");</code> * Note that 'value' in the RPN expression is a reserved word and stands for the ! * original value (value fetched from RRD file)</p> * @param dsName Datasource name * @param consolFun Consolidation function to be applied to fetched datasource values. --- 246,250 ---- * <code>getAggregate("foots", "MAX", "value,0.3048,*");</code> * Note that 'value' in the RPN expression is a reserved word and stands for the ! * original value (value fetched from RRD)</p> * @param dsName Datasource name * @param consolFun Consolidation function to be applied to fetched datasource values. *************** *** 354,358 **** 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()); --- 354,358 ---- writer.startTag("fetch_data"); writer.startTag("request"); ! writer.writeTag("file", request.getParentDb().getPath()); writer.writeComment(Util.getDate(request.getFetchStart())); writer.writeTag("start", request.getFetchStart()); Index: FetchRequest.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchRequest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FetchRequest.java 15 Mar 2004 10:40:50 -0000 1.4 --- FetchRequest.java 20 May 2004 10:29:32 -0000 1.5 *************** *** 61,65 **** * the specified array of datasources (datasource names). * If not set (or set to null), fetched data will ! * containt values of all datasources defined in the underlying RRD file. * To fetch data only from selected * datasources, specify an array of datasource names as method argument. --- 61,65 ---- * the specified array of datasources (datasource names). * If not set (or set to null), fetched data will ! * containt values of all datasources defined in the corresponding RRD. * To fetch data only from selected * datasources, specify an array of datasource names as method argument. *************** *** 74,78 **** * a single datasource (datasource name). * If not set (or set to null), fetched data will ! * containt values of all datasources defined in the underlying RRD file. * To fetch data for a single datasource only, * specify an array of datasource names as method argument. --- 74,78 ---- * a single datasource (datasource name). * If not set (or set to null), fetched data will ! * containt values of all datasources defined in the corresponding RRD. * To fetch data for a single datasource only, * specify an array of datasource names as method argument. *************** *** 148,152 **** */ public String dump() { ! return RrdDb.RRDTOOL + " fetch " + parentDb.getRrdFile().getFilePath() + " " + consolFun + " --start " + fetchStart + " --end " + fetchEnd + (resolution > 1? " --resolution " + resolution: ""); --- 148,152 ---- */ public String dump() { ! return RrdDb.RRDTOOL + " fetch " + parentDb.getRrdBackend().getPath() + " " + consolFun + " --start " + fetchStart + " --end " + fetchEnd + (resolution > 1? " --resolution " + resolution: ""); *************** *** 158,162 **** /** ! * Returns data from the underlying RRD file as an array of * {@link org.jrobin.core.FetchPoint FetchPoint} objects. Each fetch point object represents * RRD datasource values for the specific timestamp. Timestamp difference between --- 158,162 ---- /** ! * Returns data from the underlying RRD as an array of * {@link org.jrobin.core.FetchPoint FetchPoint} objects. Each fetch point object represents * RRD datasource values for the specific timestamp. Timestamp difference between *************** *** 174,178 **** /** ! * Returns data from the underlying RRD file and puts it in a single * {@link org.jrobin.core.FetchData FetchData} object. Use this method instead of * deprecated {@link #fetch() fetch()} method. --- 174,178 ---- /** ! * Returns data from the underlying RRD and puts it in a single * {@link org.jrobin.core.FetchData FetchData} object. Use this method instead of * deprecated {@link #fetch() fetch()} method. Index: RrdToolkit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RrdToolkit.java 23 Feb 2004 15:48:41 -0000 1.8 --- RrdToolkit.java 20 May 2004 10:29:33 -0000 1.9 *************** *** 23,26 **** --- 23,27 ---- * Boston, MA 02111-1307, USA. */ + package org.jrobin.core; Index: Header.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Header.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Header.java 2 Dec 2003 10:18:17 -0000 1.5 --- Header.java 20 May 2004 10:29:32 -0000 1.6 *************** *** 29,35 **** /** ! * Class to represent RRD file header. Header information is mainly static (once set, it * cannot be changed), with the exception of last update time (this value is changed whenever ! * RRD file gets updated).<p> * * Normally, you don't need to manipulate the Header object directly - JRobin framework --- 29,35 ---- /** ! * Class to represent RRD header. Header information is mainly static (once set, it * cannot be changed), with the exception of last update time (this value is changed whenever ! * RRD gets updated).<p> * * Normally, you don't need to manipulate the Header object directly - JRobin framework *************** *** 49,130 **** private RrdLong lastUpdateTime; ! Header(RrdDb parentDb) throws IOException, RrdException { this.parentDb = parentDb; signature = new RrdString(this); - if(!signature.get().equals(SIGNATURE)) { - throw new RrdException("Not a JRobin RRD file"); - } step = new RrdLong(this); dsCount = new RrdInt(this); arcCount = new RrdInt(this); lastUpdateTime = new RrdLong(this); ! } ! ! Header(RrdDb parentDb, RrdDef rrdDef) throws IOException, RrdException { ! this.parentDb = parentDb; ! signature = new RrdString(SIGNATURE, this); ! step = new RrdLong(rrdDef.getStep(), this); ! dsCount = new RrdInt(rrdDef.getDsCount(), this); ! arcCount = new RrdInt(rrdDef.getArcCount(), this); ! lastUpdateTime = new RrdLong(rrdDef.getStartTime(), this); } Header(RrdDb parentDb, XmlReader reader) throws IOException, RrdException { ! this.parentDb = parentDb; String version = reader.getVersion(); if(!version.equals(RRDTOOL_VERSION)) { throw new RrdException("Could not unserilalize xml version " + version); } ! signature = new RrdString(SIGNATURE, this); ! step = new RrdLong(reader.getStep(), this); ! dsCount = new RrdInt(reader.getDsCount(), this); ! arcCount = new RrdInt(reader.getArcCount(), this); ! lastUpdateTime = new RrdLong(reader.getLastUpdateTime(), this); } /** ! * Returns RRD file signature. The returned string will be always ! * of the form <b><i>JRobin, version x.x</i></b>. Note: RRD file format did not * change since Jrobin 1.0.0 release (and probably never will). * ! * @return RRD file signature */ ! public String getSignature() { return signature.get(); } /** ! * Returns the last update time of the RRD file. * * @return Timestamp (Unix epoch, no milliseconds) corresponding to the last update time. */ ! public long getLastUpdateTime() { return lastUpdateTime.get(); } /** ! * Returns primary RRD file time step. * * @return Primary time step in seconds */ ! public long getStep() { return step.get(); } /** ! * Returns the number of datasources defined in the RRD file. * * @return Number of datasources defined */ ! public int getDsCount() { return dsCount.get(); } /** ! * Returns the number of archives defined in the RRD file. * * @return Number of archives defined */ ! public int getArcCount() { return arcCount.get(); } --- 49,131 ---- private RrdLong lastUpdateTime; ! Header(RrdDb parentDb, RrdDef rrdDef) throws IOException { ! boolean shouldInitialize = rrdDef != null; this.parentDb = parentDb; signature = new RrdString(this); step = new RrdLong(this); dsCount = new RrdInt(this); arcCount = new RrdInt(this); lastUpdateTime = new RrdLong(this); ! if(shouldInitialize) { ! signature.set(SIGNATURE); ! step.set(rrdDef.getStep()); ! dsCount.set(rrdDef.getDsCount()); ! arcCount.set(rrdDef.getArcCount()); ! lastUpdateTime.set(rrdDef.getStartTime()); ! } } Header(RrdDb parentDb, XmlReader reader) throws IOException, RrdException { ! this(parentDb, (RrdDef) null); String version = reader.getVersion(); if(!version.equals(RRDTOOL_VERSION)) { throw new RrdException("Could not unserilalize xml version " + version); } ! signature.set(SIGNATURE); ! step.set(reader.getStep()); ! dsCount.set(reader.getDsCount()); ! arcCount.set(reader.getArcCount()); ! lastUpdateTime.set(reader.getLastUpdateTime()); } /** ! * Returns RRD signature. The returned string will be always ! * of the form <b><i>JRobin, version x.x</i></b>. Note: RRD format did not * change since Jrobin 1.0.0 release (and probably never will). * ! * @return RRD signature ! * @throws IOException Thrown in case of I/O error */ ! public String getSignature() throws IOException { return signature.get(); } /** ! * Returns the last update time of the RRD. * * @return Timestamp (Unix epoch, no milliseconds) corresponding to the last update time. + * @throws IOException Thrown in case of I/O error */ ! public long getLastUpdateTime() throws IOException { return lastUpdateTime.get(); } /** ! * Returns primary RRD time step. * * @return Primary time step in seconds + * @throws IOException Thrown in case of I/O error */ ! public long getStep() throws IOException { return step.get(); } /** ! * Returns the number of datasources defined in the RRD. * * @return Number of datasources defined + * @throws IOException Thrown in case of I/O error */ ! public int getDsCount() throws IOException { return dsCount.get(); } /** ! * Returns the number of archives defined in the RRD. * * @return Number of archives defined + * @throws IOException Thrown in case of I/O error */ ! public int getArcCount() throws IOException { return arcCount.get(); } *************** *** 134,138 **** } ! String dump() { return "== HEADER ==\n" + "signature:" + getSignature() + --- 135,139 ---- } ! String dump() throws IOException { return "== HEADER ==\n" + "signature:" + getSignature() + *************** *** 143,155 **** } - /** - * Returns the underlying RrdFile object. - * - * @return Underlying RrdFile object. - */ - public RrdFile getRrdFile() { - return parentDb.getRrdFile(); - } - void appendXml(XmlWriter writer) throws IOException { writer.writeTag("version", RRDTOOL_VERSION); --- 144,147 ---- *************** *** 174,176 **** --- 166,195 ---- header.lastUpdateTime.set(lastUpdateTime.get()); } + + /** + * Returns the underlying storage (backend) object which actually performs all + * I/O operations. + * @return I/O backend object + */ + public RrdBackend getRrdBackend() { + return parentDb.getRrdBackend(); + } + + boolean isJRobinHeader() throws IOException { + return signature.get().equals(SIGNATURE); + } + + void validateHeader() throws IOException, RrdException { + if(!isJRobinHeader()) { + throw new RrdException("Not a JRobin RRD!"); + } + } + + /** + * Required to implement RrdUpdater interface. You should never call this method directly. + * @return Allocator object + */ + public RrdAllocator getRrdAllocator() { + return parentDb.getRrdAllocator(); + } } Index: XmlTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlTemplate.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** XmlTemplate.java 26 Apr 2004 22:28:33 -0000 1.7 --- XmlTemplate.java 20 May 2004 10:29:33 -0000 1.8 *************** *** 23,26 **** --- 23,27 ---- * Boston, MA 02111-1307, USA. */ + package org.jrobin.core; Index: Robin.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Robin.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Robin.java 20 Apr 2004 08:20:29 -0000 1.11 --- Robin.java 20 May 2004 10:29:32 -0000 1.12 *************** *** 31,40 **** * 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> --- 31,40 ---- * 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, archived * value for the specific timestamp. When the underlying array of double values gets completely ! * filled, new values will replace the oldest ones.<p> * * Robin object does not hold values in memory - such object could be quite large. ! * Instead of it, Robin reads them from the backend I/O only when necessary. * * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> *************** *** 46,67 **** private int rows; ! Robin(Archive parentArc, int rows) throws IOException { this.parentArc = parentArc; this.rows = rows; ! if(getRrdFile().getRrdMode() == 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 { --- 46,65 ---- private int rows; ! Robin(Archive parentArc, int rows, boolean shouldInitialize) throws IOException { this.parentArc = parentArc; + this.pointer = new RrdInt(this); + this.values = new RrdDoubleArray(this, rows); this.rows = rows; ! if(shouldInitialize) { ! pointer.set(0); ! values.set(0, Double.NaN, rows); } } /** ! * Fetches all archived values. * * @return Array of double archive values, starting from the oldest one. ! * @throws IOException Thrown in case of I/O specific error. */ public double[] getValues() throws IOException { *************** *** 93,102 **** } ! /** ! * Returns the underlying RrdFile object. ! * @return Underlying RrdFile object ! */ ! public RrdFile getRrdFile() { ! return parentArc.getRrdFile(); } --- 91,100 ---- } ! // updates Robin values in bulk ! void update(double[] newValues) throws IOException { ! assert rows == newValues.length: "Invalid number of values supplied: " + newValues.length + ! " rows=" + rows; ! pointer.set(0); ! values.writeDouble(0, newValues); } *************** *** 115,118 **** --- 113,117 ---- * @param index Value index * @return Value stored in the i-th position (the oldest value has zero index) + * @throws IOException Thrown in case of I/O specific error. */ public double getValue(int index) throws IOException { *************** *** 154,158 **** /** ! * Returns the size of the underlying array of archive values. * * @return Number of stored values --- 153,157 ---- /** ! * Returns the size of the underlying array of archived values. * * @return Number of stored values *************** *** 200,202 **** --- 199,218 ---- } } + + /** + * Returns the underlying storage (backend) object which actually performs all + * I/O operations. + * @return I/O backend object + */ + public RrdBackend getRrdBackend() { + return parentArc.getRrdBackend(); + } + + /** + * Required to implement RrdUpdater interface. You should never call this method directly. + * @return Allocator object + */ + public RrdAllocator getRrdAllocator() { + return parentArc.getRrdAllocator(); + } } Index: RrdDouble.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDouble.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdDouble.java 21 Apr 2004 10:56:44 -0000 1.7 --- RrdDouble.java 20 May 2004 10:29:33 -0000 1.8 *************** *** 29,66 **** class RrdDouble extends RrdPrimitive { ! static final int SIZE = 8; ! ! private double cache; RrdDouble(RrdUpdater updater) throws IOException { ! super(updater, SIZE); ! loadCache(); ! } ! ! void loadCache() throws IOException { ! if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { ! restorePosition(); ! cache = rrdFile.readDouble(); ! cached = true; ! } ! } ! ! RrdDouble(double initValue, RrdUpdater updater) throws IOException { ! super(updater, SIZE); ! set(initValue); } void set(double value) throws IOException { ! if(!cached || cache != value) { ! restorePosition(); ! rrdFile.writeDouble(value); ! cache = value; ! cached = true; } } ! double get() { ! assert cached: "Not cached!"; ! return cache; } } --- 29,49 ---- class RrdDouble extends RrdPrimitive { ! private RrdCacher cache = new RrdCacher(); RrdDouble(RrdUpdater updater) throws IOException { ! super(updater, RrdDouble.RRD_DOUBLE); } void set(double value) throws IOException { ! if(cache.setDouble(value)) { ! writeDouble(value); } } ! double get() throws IOException { ! if(cache.isEmpty()) { ! cache.setDouble(readDouble()); ! } ! return cache.getDouble(); } } Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** RrdDb.java 21 Apr 2004 10:56:37 -0000 1.15 --- RrdDb.java 20 May 2004 10:29:32 -0000 1.16 *************** *** 26,48 **** package org.jrobin.core; ! import java.io.*; /** ! * <p>Main class used for RRD files manipulation. Use this class to perform ! * update and fetch operations on exisiting ! * RRD files. This class is also used to create new RRD file from * the definition (object of class {@link org.jrobin.core.RrdDef RrdDef}) or * from XML file (dumped content of RRDTool's or JRobin's RRD file).</p> * ! * <p> ! * Note that JRobin uses binary format different from RRDTool's format. You cannot * use this class to manipulate RRD files created with RRDTool. <b>However, if you perform * the same sequence of create, update and fetch operations, you will get exactly the same ! * results from JRobin and RRDTool.</b> ! * </p> * * <p> * You will not be able to use JRobin API if you are not familiar with ! * basic RRDTool concepts. Good place to start is * <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/tutorial/rrdtutorial.html">official RRD tutorial</a> * and relevant RRDTool man pages: <a href="../../../../man/rrdcreate.html" target="man">rrdcreate</a>, --- 26,56 ---- package org.jrobin.core; ! import java.io.ByteArrayOutputStream; ! import java.io.FileOutputStream; ! import java.io.IOException; ! import java.io.OutputStream; /** ! * <p>Main class used to create and manipulate round robin databases (RRDs). Use this class to perform ! * update and fetch operations on exisiting RRDs, to create new RRD from * the definition (object of class {@link org.jrobin.core.RrdDef RrdDef}) or * from XML file (dumped content of RRDTool's or JRobin's RRD file).</p> * ! * <p>Each RRD is backed with some kind of storage. For example, RRDTool supports only one kind of ! * storage (disk file). On the contrary, JRobin gives you freedom to use other storage (backend) types ! * even to create your own backend types for some special purposes. JRobin by default stores ! * RRD data in files (as RRDTool), but you might choose to store RRD data in memory (this is ! * supported in JRobin), to use java.nio.* instead of java.io.* package for file manipulation ! * (also supported) or to store whole RRDs in the SQL database ! * (you'll have to extend some classes to do this).</p> ! * ! * <p>Note that JRobin uses binary format different from RRDTool's format. You cannot * use this class to manipulate RRD files created with RRDTool. <b>However, if you perform * the same sequence of create, update and fetch operations, you will get exactly the same ! * results from JRobin and RRDTool.</b><p> * * <p> * You will not be able to use JRobin API if you are not familiar with ! * basic RRDTool concepts. Good place to start is the * <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/tutorial/rrdtutorial.html">official RRD tutorial</a> * and relevant RRDTool man pages: <a href="../../../../man/rrdcreate.html" target="man">rrdcreate</a>, *************** *** 55,59 **** * </p> * ! * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> */ public class RrdDb implements RrdUpdater { --- 63,68 ---- * </p> * ! * @see RrdBackend ! * @see RrdBackendFactory */ public class RrdDb implements RrdUpdater { *************** *** 66,74 **** static final String RRDTOOL = "rrdtool"; - static boolean DEBUG = false; static final int XML_INITIAL_BUFFER_CAPACITY = 100000; // bytes - private String canonicalPath; - private RrdFile file; private Header header; private Datasource[] datasources; --- 75,84 ---- static final String RRDTOOL = "rrdtool"; static final int XML_INITIAL_BUFFER_CAPACITY = 100000; // bytes + private static int lockMode = NO_LOCKS; + + private RrdBackend backend; + private RrdAllocator allocator = new RrdAllocator(); private Header header; private Datasource[] datasources; *************** *** 78,85 **** /** ! * <p>Constructor used to create new RRD file from the definition. New RRD file structure is specified by object of class ! * {@link org.jrobin.core.RrdDef <b>RrdDef</b>}. RRD file is created on ! * the disk as soon as this constructor returns. Once created, the structure and size ! * of the newly created RRD file cannot be modified.</p> * * <p>Typical scenario:</p> --- 88,99 ---- /** ! * <p>Constructor used to create new RRD object from the definition. This RRD object will be backed ! * with a storage (backend) of the default type. Initially, storage type defaults to "FILE" ! * (RRD bytes will be put in a file on the disk). Default storage type can be changed with a static ! * {@link RrdBackendFactory#setDefaultFactory(String)} method call.</p> ! * ! * <p>New RRD file structure is specified with an object of class ! * {@link org.jrobin.core.RrdDef <b>RrdDef</b>}. The underlying RRD storage is created as soon ! * as the constructor returns.</p> * * <p>Typical scenario:</p> *************** *** 99,106 **** * def.addArchive("MAX", 0.5, 288, 775); * ! * // RRD file definition is now completed, create the database! * RrdDb rrd = new RrdDb(def); * // new RRD file has been created on your disk ! * </code> * * @param rrdDef Object describing the structure of the new RRD file. --- 113,120 ---- * def.addArchive("MAX", 0.5, 288, 775); * ! * // RRD definition is now completed, create the database! * RrdDb rrd = new RrdDb(def); * // new RRD file has been created on your disk ! * </pre> * * @param rrdDef Object describing the structure of the new RRD file. *************** *** 108,114 **** * @throws RrdException Thrown if invalid RrdDef object is supplied. */ ! public RrdDb(RrdDef rrdDef) throws IOException, RrdException { rrdDef.validate(); ! initializeSetup(rrdDef.getPath(), RrdFile.MODE_CREATE, false); // create header header = new Header(this, rrdDef); --- 122,167 ---- * @throws RrdException Thrown if invalid RrdDef object is supplied. */ ! public RrdDb(RrdDef rrdDef) throws RrdException, IOException { ! this(rrdDef, RrdFileBackendFactory.getDefaultFactory()); ! } ! ! /** ! * <p>Constructor used to create new RRD object from the definition object but with a storage ! * (backend) different from default.</p> ! * ! * <p>JRobin uses <i>factories</i> to create RRD backend objecs. There are three different ! * backend factories supplied with JRobin, and each factory has its unique name:</p> ! * ! * <ul> ! * <li><b>FILE</b>: backends created from this factory will store RRD data to files by using ! * java.io.* classes and methods ! * <li><b>NIO</b>: backends created from this factory will store RRD data to files by using ! * java.nio.* classes and methods ! * <li><b>MEMORY</b>: backends created from this factory will store RRD data in memory. This might ! * be useful in runtime environments which prohibit disk utilization, or for storing temporary, ! * non-critical data (it gets lost as soon as JVM exits). ! * </ul> ! * ! * <p>For example, to create RRD in memory, use the following code</p> ! * <pre> ! * RrdBackendFactory factory = RrdBackendFactory.getFactory("MEMORY"); ! * RrdDb rrdDb = new RrdDb(rrdDef, factory); ! * rrdDb.close(); ! * </pre> ! * ! * <p>New RRD file structure is specified with an object of class ! * {@link org.jrobin.core.RrdDef <b>RrdDef</b>}. The underlying RRD storage is created as soon ! * as the constructor returns.</p> ! * @param rrdDef RRD definition object ! * @param factory The factory which will be used to create storage for this RRD ! * @throws RrdException Thrown if invalid factory or definition is supplied ! * @throws IOException Thrown in case of I/O error ! * @see RrdBackendFactory ! */ ! public RrdDb(RrdDef rrdDef, RrdBackendFactory factory) throws RrdException, IOException { rrdDef.validate(); ! String path = rrdDef.getPath(); ! backend = factory.open(path, false, lockMode); ! backend.setLength(rrdDef.getEstimatedSize()); // create header header = new Header(this, rrdDef); *************** *** 125,140 **** archives[i] = new Archive(this, arcDefs[i]); } - // finalize - finalizeSetup(); - Util.debug(rrdDef.getRrdToolCommand()); } /** ! * <p>Constructor used to open already existing RRD file. ! * Obtains read or read/write access to RRD file.</p> * ! * @param path Path to existing RRD file. * @param readOnly Should be set to <code>false</code> if you want to update ! * the underlying RRD file. If you want just to fetch data from the RRD file * (read-only access), specify <code>true</code>. If you try to update RRD file * open in read-only mode (<code>readOnly</code> set to <code>true</code>), --- 178,191 ---- archives[i] = new Archive(this, arcDefs[i]); } } /** ! * <p>Constructor used to open already existing RRD. This RRD object will be backed ! * with a storage (backend) of the default type (file on the disk). Constructor ! * obtains read or read/write access to this RRD.</p> * ! * @param path Path to existing RRD. * @param readOnly Should be set to <code>false</code> if you want to update ! * the underlying RRD. If you want just to fetch data from the RRD file * (read-only access), specify <code>true</code>. If you try to update RRD file * open in read-only mode (<code>readOnly</code> set to <code>true</code>), *************** *** 143,181 **** * @throws RrdException Thrown in case of JRobin specific error. */ ! public RrdDb(String path, boolean readOnly) throws IOException, RrdException { // opens existing RRD file - throw exception if the file does not exist... ! File rrdFile = new File(path); ! if(!rrdFile.exists()) { ! throw new IOException("Could not open file " + path + " [non existent]"); } ! try { ! initializeSetup(path, RrdFile.MODE_RESTORE, readOnly); ! // restore header ! header = new Header(this); ! // restore datasources ! int dsCount = header.getDsCount(); ! datasources = new Datasource[dsCount]; ! for(int i = 0; i < dsCount; i++) { ! datasources[i] = new Datasource(this); ! } ! // restore archives ! int arcCount = header.getArcCount(); ! archives = new Archive[arcCount]; ! for(int i = 0; i < arcCount; i++) { ! archives[i] = new Archive(this); ! } ! finalizeSetup(); } ! catch(RuntimeException e) { ! throw new RrdException(e); } } /** ! * <p>Constructor used to open already existing RRD file. ! * Obtains <b>full</b> (read/write) access to the underlying RRD file ! * so that future RRD updates are possible.</p> * ! * @param path Path to existing RRD file. * @throws IOException Thrown in case of I/O error. * @throws RrdException Thrown in case of JRobin specific error. --- 194,246 ---- * @throws RrdException Thrown in case of JRobin specific error. */ ! public RrdDb(String path, boolean readOnly) throws IOException, RrdException { ! this(path, readOnly, RrdBackendFactory.getDefaultFactory()); ! } ! ! /** ! * <p>Constructor used to open already existing RRD backed ! * with a storage (backend) different from default. Constructor ! * obtains read or read/write access to this RRD.</p> ! * ! * @param path Path to existing RRD. ! * @param readOnly Should be set to <code>false</code> if you want to update ! * the underlying RRD. If you want just to fetch data from the RRD file ! * (read-only access), specify <code>true</code>. If you try to update RRD file ! * open in read-only mode (<code>readOnly</code> set to <code>true</code>), ! * <code>IOException</code> will be thrown. ! * @param factory Backend factory which will be used for this RRD. ! * @throws IOException Thrown in case of I/O error. ! * @throws RrdException Thrown in case of JRobin specific error. ! * @see RrdBackendFactory ! */ ! public RrdDb(String path, boolean readOnly, RrdBackendFactory factory) ! throws IOException, RrdException { // opens existing RRD file - throw exception if the file does not exist... ! if(!factory.exists(path)) { ! throw new IOException("Could not open " + path + " [non existent]"); } ! backend = factory.open(path, readOnly, lockMode); ! // restore header ! header = new Header(this, (RrdDef) null); ! header.validateHeader(); ! // restore datasources ! int dsCount = header.getDsCount(); ! datasources = new Datasource[dsCount]; ! for(int i = 0; i < dsCount; i++) { ! datasources[i] = new Datasource(this, null); } ! // restore archives ! int arcCount = header.getArcCount(); ! archives = new Archive[arcCount]; ! for(int i = 0; i < arcCount; i++) { ! archives[i] = new Archive(this, null); } } /** ! * <p>Constructor used to open already existing RRD in R/W mode, with a default storage ! * (backend) type (file on the disk). * ! * @param path Path to existing RRD. * @throws IOException Thrown in case of I/O error. * @throws RrdException Thrown in case of JRobin specific error. *************** *** 186,192 **** /** ! * <p>Constructor used to create new RRD file from XML dump. JRobin and RRDTool * use the same format for XML dump and this constructor should be used to ! * (re)create JRobin RRD file from XML. In other words, it is possible to convert * RRDTool RRD files to JRobin RRD files: first, dump the content of RRDTool * RRD file (use command line):</p> --- 251,272 ---- /** ! * <p>Constructor used to open already existing RRD in R/W mode with a storage (backend) type ! * different from default.</p> ! * ! * @param path Path to existing RRD. ! * @param factory Backend factory used to create this RRD. ! * @throws IOException Thrown in case of I/O error. ! * @throws RrdException Thrown in case of JRobin specific error. ! * @see RrdBackendFactory ! */ ! public RrdDb(String path, RrdBackendFactory factory) throws IOException, RrdException { ! this(path, false, factory); ! } ! ! /** ! * <p>Constructor used to create new RRD from XML dump. Newly created RRD will be backed ! * with a default storage (backend) type (file on the disk). JRobin and RRDTool * use the same format for XML dump and this constructor should be used to ! * (re)create JRobin RRD from XML. In other words, it is possible to convert * RRDTool RRD files to JRobin RRD files: first, dump the content of RRDTool * RRD file (use command line):</p> *************** *** 202,206 **** * how to convert JRobin files to RRDTool format.</p> * ! * @param rrdPath Path to RRD file which will be created on the disk * @param xmlPath Path to file containing XML dump of RRDTool's or JRobin's RRD file * @throws IOException Thrown in case of I/O error --- 282,286 ---- * how to convert JRobin files to RRDTool format.</p> * ! * @param rrdPath Path to RRD file which will be created * @param xmlPath Path to file containing XML dump of RRDTool's or JRobin's RRD file * @throws IOException Thrown in case of I/O error *************** *** 208,213 **** */ public RrdDb(String rrdPath, String xmlPath) throws IOException, RrdException { ! initializeSetup(rrdPath, RrdFile.MODE_CREATE, false); XmlReader reader = new XmlReader(xmlPath); // create header header = new Header(this, reader); --- 288,310 ---- */ public RrdDb(String rrdPath, String xmlPath) throws IOException, RrdException { ! this(rrdPath, xmlPath, RrdBackendFactory.getDefaultFactory()); ! } ! ! /** ! * <p>Constructor used to create new RRD from XML dump but with a storage (backend) type ! * different from default.</p> ! * ! * @param rrdPath Path to RRD which will be created ! * @param xmlPath Path to file containing XML dump of RRDTool's or JRobin's RRD file ! * @param factory Backend factory which will be used to create storage (backend) for this RRD. ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown in case of JRobin specific error ! * @see RrdBackendFactory ! */ ! public RrdDb(String rrdPath, String xmlPath, RrdBackendFactory factory) ! throws IOException, RrdException { ! backend = factory.open(rrdPath, false, lockMode); XmlReader reader = new XmlReader(xmlPath); + backend.setLength(reader.getEstimatedSize()); // create header header = new Header(this, reader); *************** *** 224,252 **** // XMLReader is a rather huge DOM tree, release memory ASAP reader = null; - // finalize - finalizeSetup(); - } - - - private void initializeSetup(String path, int mode, boolean readOnly) throws IOException { - file = new RrdFile(path, mode, readOnly); - } - - private void finalizeSetup() throws IOException { - int mode = file.getRrdMode(); - if(mode == RrdFile.MODE_CREATE) { - file.truncateFile(); - } - else if(mode == RrdFile.MODE_RESTORE) { - if(!file.isEndReached()) { - throw new IOException("Extra bytes found in RRD file. Not a RRD file at all?"); - } - } - file.setRrdMode(RrdFile.MODE_NORMAL); - canonicalPath = file.getCanonicalFilePath(); } /** ! * Closes RRD file. No further operations are allowed on this RrdDb object. * * @throws IOException Thrown in case of I/O related error. --- 321,328 ---- // XMLReader is a rather huge DOM tree, release memory ASAP reader = null; } /** ! * Closes RRD. No further operations are allowed on this RrdDb object. * * @throws IOException Thrown in case of I/O related error. *************** *** 254,258 **** public synchronized void close() throws IOException { if(!closed) { ! file.close(); closed = true; } --- 330,334 ---- public synchronized void close() throws IOException { if(!closed) { ! backend.close(); closed = true; } *************** *** 260,264 **** /** ! * Returns true if the underlying RRD file is closed. * @return true if closed, false otherwise */ --- 336,340 ---- /** ! * Returns true if the RRD is closed. * @return true if closed, false otherwise */ *************** *** 268,283 **** /** ! * <p>Returns underlying <code>RrdFile</code> object. <code>RrdFile</code> is a light ! * wrapper around <code>RandomAccessFile</code> class. ! * It is used for all I/O operations on RRD files.</p> ! * ! * @return Underlying RrdFile object ! */ ! public RrdFile getRrdFile() { ! return file; ! } ! ! /** ! * Returns RRD file header. * @return Header object */ --- 344,348 ---- /** ! * Returns RRD header. * @return Header object */ *************** *** 305,313 **** /** ! * <p>Returns an array of datasource names defined in RRD file.</p> * * @return Array of datasource names. */ ! public String[] getDsNames() { int n = datasources.length; String[] dsNames = new String[n]; --- 370,379 ---- /** ! * <p>Returns an array of datasource names defined in RRD.</p> * * @return Array of datasource names. + * @throws IOException Thrown in case of I/O error. */ ! public String[] getDsNames() throws IOException { int n = datasources.length; String[] dsNames = new String[n]; *************** *** 319,323 **** /** ! * <p>Creates new sample with the given timestamp and all data source values set to * 'unknown'. Use returned <code>Sample</code> object to specify * datasource values for the given timestamp. See documentation for --- 385,389 ---- /** ! * <p>Creates new sample with the given timestamp and all datasource values set to * 'unknown'. Use returned <code>Sample</code> object to specify * datasource values for the given timestamp. See documentation for *************** *** 326,334 **** * <p>Once populated with data source values, call Sample's * {@link org.jrobin.core.Sample#update() update()} method to actually ! * store sample in the RRD file associated with it.</p> * @param time Sample timestamp rounded to the nearest second (without milliseconds). * @return Fresh sample with the given timestamp and all data source values set to 'unknown'. */ ! public Sample createSample(long time) { return new Sample(this, time); } --- 392,401 ---- * <p>Once populated with data source values, call Sample's * {@link org.jrobin.core.Sample#update() update()} method to actually ! * store sample in the RRD associated with it.</p> * @param time Sample timestamp rounded to the nearest second (without milliseconds). * @return Fresh sample with the given timestamp and all data source values set to 'unknown'. + * @throws IOException Thrown in case of I/O error. */ ! public Sample createSample(long time) throws IOException { return new Sample(this, time); } *************** *** 342,355 **** * <p>Once populated with data source values, call Sample's * {@link org.jrobin.core.Sample#update() update()} method to actually ! * store sample in the RRD file associated with it.</p> * @return Fresh sample with the current timestamp and all * data source values set to 'unknown'. */ ! public Sample createSample() { return createSample(Util.getTime()); } /** ! * <p>Prepares fetch request to be executed on the underlying RRD file. Use returned * <code>FetchRequest</code> object and its {@link org.jrobin.core.FetchRequest#fetch() fetch()} * method to actually fetch data from the RRD file.</p> --- 409,423 ---- * <p>Once populated with data source values, call Sample's * {@link org.jrobin.core.Sample#update() update()} method to actually ! * store sample in the RRD associated with it.</p> * @return Fresh sample with the current timestamp and all * data source values set to 'unknown'. + * @throws IOException Thrown in case of I/O error. */ ! public Sample createSample() throws IOException { return createSample(Util.getTime()); } /** ! * <p>Prepares fetch request to be executed on this RRD. Use returned * <code>FetchRequest</code> object and its {@link org.jrobin.core.FetchRequest#fetch() fetch()} * method to actually fetch data from the RRD file.</p> *************** *** 361,365 **** * <a href="../../../../man/rrdfetch.html" target="man">rrdfetch man page</a> for an * explanation of this parameter. ! * @return Request object that should be used to actually fetch data from RRD file. * @throws RrdException In case of JRobin related error (invalid consolidation function or * invalid time span). --- 429,433 ---- * <a href="../../../../man/rrdfetch.html" target="man">rrdfetch man page</a> for an * explanation of this parameter. ! * @return Request object that should be used to actually fetch data from RRD. * @throws RrdException In case of JRobin related error (invalid consolidation function or * invalid time span). *************** *** 371,377 **** /** ! * <p>Prepares fetch request to be executed on the underlying RRD file. Use returned * <code>FetchRequest</code> object and its {@link org.jrobin.core.FetchRequest#fetch() fetch()} ! * method to actually fetch data from the RRD file. Data will be fetched with the smallest * possible resolution (see RRDTool's * <a href="../../../../man/rrdfetch.html" target="man">rrdfetch man page</a> --- 439,445 ---- /** ! * <p>Prepares fetch request to be executed on this RRD. Use returned * <code>FetchRequest</code> object and its {@link org.jrobin.core.FetchRequest#fetch() fetch()} ! * method to actually fetch data from this RRD. Data will be fetched with the smallest * possible resolution (see RRDTool's * <a href="../../../../man/rrdfetch.html" target="man">rrdfetch man page</a> *************** *** 382,387 **** * @param fetchStart Starting timestamp for fetch request. * @param fetchEnd Ending timestamp for fetch request. ! * explanation of this parameter. ! * @return Request object that should be used to actually fetch data from RRD file. * @throws RrdException In case of JRobin related error (invalid consolidation function or * invalid time span). --- 450,454 ---- * @param fetchStart Starting timestamp for fetch request. * @param fetchEnd Ending timestamp for fetch request. ! * @return Request object that should be used to actually fetch data from RRD. * @throws RrdException In case of JRobin related error (invalid consolidation function or * invalid time span). *************** *** 393,396 **** --- 460,466 ---- void store(Sample sample) throws IOException, RrdException { + if(closed) { + throw new RrdException("RRD already closed, cannot store this sample"); + } long newTime = sample.getTime(); long lastTime = header.getLastUpdateTime(); *************** *** 405,426 **** } header.setLastUpdateTime(newTime); - Util.debug(sample.getRrdToolCommand()); } FetchPoint[] fetch(FetchRequest request) throws IOException, RrdException { Archive archive = findMatchingArchive(request); FetchPoint[] points = archive.fetch(request); - Util.debug(request.getRrdToolCommand()); return points; } FetchData fetchData(FetchRequest request) throws IOException, RrdException { Archive archive = findMatchingArchive(request); FetchData fetchData = archive.fetchData(request); - Util.debug(request.getRrdToolCommand()); return fetchData; } ! private Archive findMatchingArchive(FetchRequest request) throws RrdException { String consolFun = request.getConsolFun(); long fetchStart = request.getFetchStart(); --- 475,499 ---- } header.setLastUpdateTime(newTime); } FetchPoint[] fetch(FetchRequest request) throws IOException, RrdException { + if(closed) { + throw new RrdException("RRD already closed, cannot fetch data"); + } Archive archive = findMatchingArchive(request); FetchPoint[] points = archive.fetch(request); return points; } FetchData fetchData(FetchRequest request) throws IOException, RrdException { + if(closed) { + throw new RrdException("RRD already closed, cannot fetch data"); + } Archive archive = findMatchingArchive(request); FetchData fetchData = archive.fetchData(request); return fetchData; } ! private Archive findMatchingArchive(FetchRequest request) throws RrdException, IOException { String consolFun = request.getConsolFun(); long fetchStart = request.getFetchStart(); *************** *** 471,477 **** /** ! * <p>Returns string representing complete internal state of RRD file. The returned * string can be printed to <code>stdout</code> and/or used for debugging purposes.</p> ! * @return String representing internal state of RRD file. * @throws IOException Thrown in case of I/O related error. */ --- 544,550 ---- /** ! * <p>Returns string representing complete internal RRD state. The returned * string can be printed to <code>stdout</code> and/or used for debugging purposes.</p> ! * @return String representing internal RRD state. * @throws IOException Thrown in case of I/O related error. */ *************** *** 500,508 **** * used by jrobin.graph package and has no value outside of it.</p> * @param dsName Data source name. ! * @return Internal index of the given data source name in RRD file. * @throws RrdException Thrown in case of JRobin related error (invalid data source name, * for example) */ ! public int getDsIndex(String dsName) throws RrdException { for(int i = 0; i < datasources.length; i++) { if(datasources[i].getDsName().equals(dsName)) { --- 573,582 ---- * used by jrobin.graph package and has no value outside of it.</p> * @param dsName Data source name. ! * @return Internal index of the given data source name in this RRD. * @throws RrdException Thrown in case of JRobin related error (invalid data source name, * for example) + * @throws IOException Thrown in case of I/O error. */ ! public int getDsIndex(String dsName) throws RrdException, IOException { for(int i = 0; i < datasources.length; i++) { if(datasources[i].getDsName().equals(dsName)) { *************** *** 522,526 **** /** ! * <p>Writes the content of RRD file to OutputStream using XML format. This format * is fully compatible with RRDTool's XML dump format and can be used for conversion * purposes or debugging.</p> --- 596,600 ---- /** ! * <p>Writes the RRD content to OutputStream using XML format. This format * is fully compatible with RRDTool's XML dump format and can be used for conversion * purposes or debugging.</p> *************** *** 554,561 **** /** ! * <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 * purposes or debugging.</p> ! * @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 --- 628,635 ---- /** ! * <p>Returns string representing internal RRD state in XML format. This format * is fully compatible with RRDTool's XML dump format and can be used for conversion * purposes or debugging.</p> ! * @return Internal RRD state in XML format. * @throws IOException Thrown in case of I/O related error * @throws RrdException Thrown in case of JRobin specific error *************** *** 569,573 **** /** * 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 --- 643,647 ---- /** * This method is just an alias for {@link #getXml() getXml} method. ! * @return Internal RRD state in XML format. * @throws IOException Thrown in case of I/O related error * @throws RrdException Thrown in case of JRobin specific error *************** *** 578,583 **** /** ! * <p>Dumps internal state of RRD file to XML file. ! * Use this XML file to convert your JRobin RRD file to RRDTool format.</p> * * <p>Suppose that you have a JRobin RRD file <code>original.rrd</code> and you want --- 652,657 ---- /** ! * <p>Dumps internal RRD state to XML file. ! * Use this XML file to convert your JRobin RRD to RRDTool format.</p> * * <p>Suppose that you have a JRobin RRD file <code>original.rrd</code> and you want *************** *** 622,631 **** * @return Last update time (in seconds). */ ! public long getLastUpdateTime() { return header.getLastUpdateTime(); } /** ! * <p>Returns RRD definition object which can be used to create new RRD file * with the same creation parameters but with no data in it.</p> * --- 696,705 ---- * @return Last update time (in seconds). */ ! public long getLastUpdateTime() throws IOException { return header.getLastUpdateTime(); } /** ! * <p>Returns RRD definition object which can be used to create new RRD * with the same creation parameters but with no data in it.</p> * *************** *** 640,651 **** * RrdDb rrd2 = new RrdDb(def); * </pre> ! * @return RRD file definition. * @throws RrdException Thrown in case of JRobin specific error. */ ! public RrdDef getRrdDef() throws RrdException { // set header long startTime = header.getLastUpdateTime(); long step = header.getStep(); ! String path = getRrdFile().getFilePath(); RrdDef rrdDef = new RrdDef(path, startTime, step); // add datasources --- 714,725 ---- * RrdDb rrd2 = new RrdDb(def); * </pre> ! * @return RRD definition. * @throws RrdException Thrown in case of JRobin specific error. */ ! public RrdDef getRrdDef() throws RrdException, IOException { // set header long startTime = header.getLastUpdateTime(); long step = header.getStep(); ! String path = backend.getPath(); RrdDef rrdDef = new RrdDef(path, startTime, step); // add datasources *************** *** 688,692 **** */ public static int getLockMode() { ! return RrdFile.getLockMode(); } --- 762,766 ---- */ public static int getLockMode() { ! return RrdDb.lockMode; } *************** *** 698,702 **** */ public static void setLockMode(int lockMode) { ! RrdFile.setLockMode(lockMode); } --- 772,776 ---- */ public static void setLockMode(int lockMode) { ! RrdDb.lockMode = lockMode; } *************** *** 785,793 **** /** ! * Returns canonical path to the underlying RRD file. * @return Canonical path to RRD file; */ ! public String getCanonicalPath() { ! return canonicalPath; } } --- 859,904 ---- /** ! * Returns canonical path to the underlying RRD file. Note that this method makes sense just for ! * ordinary RRD files created on the disk - an exception will be thrown for RRD objects created in ! * memory or with custom backends. * @return Canonical path to RRD file; + * @throws IOException Thrown in case of I/O error. */ ! public String getCanonicalPath() throws IOException { ! return ((RrdFileBackend) backend).getCanonicalPath(); ! } ! ! /** ! * Returns path to this RRD. ! * @return Path to this RRD. ! */ ! public String getPath() { ! return backend.getPath(); ! } ! ! /** ! * Returns backend object for this RRD which performs actual I/O operations. ! * @return RRD backend for this RRD. ! */ ! public RrdBackend getRrdBackend() { ! return backend; } + + /** + * Required to implement RrdUpdater interface. You should never call this method directly. + * @return Allocator object + */ + public RrdAllocator getRrdAllocator() { + return allocator; + } + + /** + * Returns an array of bytes representing the whole RRD. + * @return All RRD bytes + * @throws IOException Thrown in case of I/O related error. + */ + public byte[] getBytes() throws IOException { + return backend.readAll(); + } + } Index: FetchPoint.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchPoint.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FetchPoint.java 17 Nov 2003 08:09:42 -0000 1.4 --- FetchPoint.java 20 May 2004 10:29:32 -0000 1.5 *************** *** 32,35 **** --- 32,39 ---- * * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> + * @deprecated This class is deprecated since 1.2.0 and might be removed from future releases + * of JRobin. You don't need this class if you fetch RRD data with the + * {@link org.jrobin.core.FetchRequest#fetchData() fetchData()} method from the + * {@link org.jrobin.core.FetchRequest FetchRequest} class */ public class FetchPoint { *************** *** 65,69 **** /** ! * Returns number of data source values (same as number od data sources defined in RRD file). * @return Number of data source values. */ --- 69,73 ---- /** ! * Returns number of data source values (same as number od data sources defined in RRD). * @return Number of data source values. */ Index: RrdUpdater.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdUpdater.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdUpdater.java 27 Nov 2003 14:15:11 -0000 1.3 --- RrdUpdater.java 20 May 2004 10:29:33 -0000 1.4 *************** *** 28,50 **** import java.io.IOException; - /** - * Interface that has to be implemented for all classes which read from or write to - * a RRD file. - * - * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> - */ interface RrdUpdater { ! /** ! * Returns associated RrdFile object. ! * @return RrdFile object. ! */ ! public RrdFile getRrdFile(); ! ! /** ! * Copies the internal object state to another object of the same type. ! * @param updater Object to copy the internal state to ! * @throws IOException Thrown in case of I/O error ! * @throws RrdException Thrown if supplied argument is not an object of a compatible class ! */ public void copyStateTo(RrdUpdater updater) throws IOException, RrdException; } --- 28,34 ---- import java.io.IOException; interface RrdUpdater { ! public RrdBackend getRrdBackend(); public void copyStateTo(RrdUpdater updater) throws IOException, RrdException; + public RrdAllocator getRrdAllocator(); } Inde... [truncated message content] |