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: Sasa M. <sa...@us...> - 2004-05-25 07:49:39
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5269/org/jrobin/mrtg/client Modified Files: GraphFrame.java Log Message: Minor changes Index: GraphFrame.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/GraphFrame.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GraphFrame.java 1 Mar 2004 13:11:26 -0000 1.3 --- GraphFrame.java 25 May 2004 07:49:28 -0000 1.4 *************** *** 331,334 **** --- 331,340 ---- graphBytes = client.getPngGraph(routerInfo, linkInfo, start, end); ImageIcon icon = new ImageIcon(graphBytes, "PNG graph"); + if(icon.getIconWidth() != GRAPH_SIZE.getWidth() || + icon.getIconHeight() != GRAPH_SIZE.getHeight()) { + GRAPH_SIZE = new Dimension(icon.getIconWidth(), icon.getIconHeight()); + graphLabel.setPreferredSize(GRAPH_SIZE); + pack(); + } graphLabel.setIcon(icon); if(start.getTime() <= now.getTime() && now.getTime() < end.getTime()) { |
From: Sasa M. <sa...@us...> - 2004-05-25 07:49:39
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5269/org/jrobin/mrtg Modified Files: MrtgConstants.java Log Message: Minor changes Index: MrtgConstants.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/MrtgConstants.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MrtgConstants.java 28 Apr 2004 12:05:02 -0000 1.7 --- MrtgConstants.java 25 May 2004 07:49:26 -0000 1.8 *************** *** 183,187 **** " <datasource>out8</datasource> \n" + " <color>#00FF00</color> \n" + ! " <legend>output traffic@l</legend> \n" + " </area> \n" + " <line> \n" + --- 183,187 ---- " <datasource>out8</datasource> \n" + " <color>#00FF00</color> \n" + ! " <legend>output traffic</legend> \n" + " </area> \n" + " <line> \n" + |
From: Sasa M. <sa...@us...> - 2004-05-24 15:03:11
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1905/org/jrobin/core Modified Files: RrdBackendFactory.java Log Message: Minor changes Index: RrdBackendFactory.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdBackendFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdBackendFactory.java 21 May 2004 12:30:00 -0000 1.3 --- RrdBackendFactory.java 24 May 2004 15:02:29 -0000 1.4 *************** *** 73,79 **** // Here is the default backend factory ! //defaultFactory = fileFactory; ! defaultFactory = nioFactory; ! //defaultFactory = memoryFactory; } catch (RrdException e) { --- 73,77 ---- // Here is the default backend factory ! defaultFactory = fileFactory; } catch (RrdException e) { |
From: Sasa M. <sa...@us...> - 2004-05-24 15:03:11
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1905 Modified Files: StressTest.java Log Message: Minor changes Index: StressTest.java =================================================================== RCS file: /cvsroot/jrobin/src/StressTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** StressTest.java 20 May 2004 10:29:31 -0000 1.3 --- StressTest.java 24 May 2004 15:02:28 -0000 1.4 *************** *** 35,42 **** class StressTest { public static final String RRD_PATH = Util.getJRobinDemoPath("stress.rrd"); public static final long RRD_START = 946710000L; public static final long RRD_STEP = 30; - public static final String BACKEND_NAME = "MEMORY"; public static final String RRD_DATASOURCE_NAME = "T"; --- 35,43 ---- class StressTest { + public static final String RRD_BACKEND_FACTORY = "NIO"; + public static final String RRD_PATH = Util.getJRobinDemoPath("stress.rrd"); public static final long RRD_START = 946710000L; public static final long RRD_STEP = 30; public static final String RRD_DATASOURCE_NAME = "T"; *************** *** 73,78 **** System.out.println("* computer with 256MB of RAM. *"); System.out.println("********************************************************************"); - printLapTime("Starting demo at " + new Date()); // create RRD database printLapTime("Creating RRD definition"); --- 74,80 ---- System.out.println("* computer with 256MB of RAM. *"); System.out.println("********************************************************************"); printLapTime("Starting demo at " + new Date()); + RrdBackendFactory.setDefaultFactory(RRD_BACKEND_FACTORY); + printLapTime("Backend factory set to " + RRD_BACKEND_FACTORY); // create RRD database printLapTime("Creating RRD definition"); |
From: Sasa M. <sa...@us...> - 2004-05-24 15:02:54
|
Update of /cvsroot/jrobin/src/org/jrobin/inspector In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1905/org/jrobin/inspector Modified Files: RrdInspector.java Log Message: Minor changes Index: RrdInspector.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/RrdInspector.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdInspector.java 8 Dec 2003 13:47:41 -0000 1.4 --- RrdInspector.java 24 May 2004 15:02:29 -0000 1.5 *************** *** 63,67 **** constructUI(); showCentered(); ! selectFile(); } --- 63,67 ---- constructUI(); showCentered(); ! //selectFile(); } *************** *** 259,267 **** File file = chooser.getSelectedFile(); lastDirectory = file.getParent(); ! inspectorModel.setFile(file); ! tabbedPane.setSelectedIndex(0); } } private void addDatasource() { if (!inspectorModel.isOk()) { --- 259,274 ---- File file = chooser.getSelectedFile(); lastDirectory = file.getParent(); ! //inspectorModel.setFile(file); ! //tabbedPane.setSelectedIndex(0); ! loadFile(file); } } + private void loadFile(File file) { + inspectorModel.setFile(file); + tabbedPane.setSelectedIndex(0); + } + + private void addDatasource() { if (!inspectorModel.isOk()) { *************** *** 436,442 **** } public static void main(String[] args) { new RrdInspector(); } - } --- 443,465 ---- } + private static void printUsage() { + System.err.println("usage: " + RrdInspector.class.getName() + " [<filename>]"); + System.exit(1); + } + public static void main(String[] args) { new RrdInspector(); + File file = null; + if (args.length > 1) { + printUsage(); + } else if (args.length == 1) { + file = new File(args[0]); + } + RrdInspector inspector = new RrdInspector(); + if (file == null) { + inspector.selectFile(); + } else { + inspector.loadFile(file); + } } } |
From: Sasa M. <sa...@us...> - 2004-05-21 12:30:10
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6801/org/jrobin/core Modified Files: RrdBackend.java RrdBackendFactory.java Log Message: Method provided to replace the default backend but before any RRD gets created. Index: RrdBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdBackend.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdBackend.java 20 May 2004 10:34:00 -0000 1.1 --- RrdBackend.java 21 May 2004 12:30:00 -0000 1.2 *************** *** 69,72 **** --- 69,73 ---- public abstract class RrdBackend { private String path; + private static long count = 0; /** *************** *** 78,81 **** --- 79,83 ---- protected RrdBackend(String path) { this.path = path; + count++; } *************** *** 302,304 **** --- 304,310 ---- return Double.longBitsToDouble(getLong(b)); } + + static long getCount() { + return count; + } } Index: RrdBackendFactory.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdBackendFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdBackendFactory.java 20 May 2004 14:49:29 -0000 1.2 --- RrdBackendFactory.java 21 May 2004 12:30:00 -0000 1.3 *************** *** 73,77 **** // Here is the default backend factory ! defaultFactory = fileFactory; } catch (RrdException e) { --- 73,79 ---- // Here is the default backend factory ! //defaultFactory = fileFactory; ! defaultFactory = nioFactory; ! //defaultFactory = memoryFactory; } catch (RrdException e) { *************** *** 133,136 **** --- 135,158 ---- /** + * Replaces the default backend factory with a new one. This method must be called before + * the first RRD gets created. <p> + * @param factoryName Name of the default factory. Out of the box, JRobin supports three + * different RRD backends: "FILE" (java.io.* based), "NIO" (java.nio.* based) and "MEMORY" + * (byte[] based). + * @throws RrdException Thrown if invalid factory name is supplied or not called before + * the first RRD is created. + */ + public static void setDefaultFactory(String factoryName) throws RrdException { + // We will allow this only if no RRDs are created + if(RrdBackend.getCount() == 0) { + defaultFactory = getFactory(factoryName); + } + else { + throw new RrdException("Could not change the default backend factory. " + + "This method must be called before the first RRD gets created"); + } + } + + /** * Creates RrdBackend object for the given storage path. * @param path Storage path |
From: Sasa M. <sa...@us...> - 2004-05-21 10:41:02
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19251/org/jrobin/core Modified Files: RrdFileBackend.java RrdMemoryBackend.java RrdPrimitive.java Log Message: minor changes Index: RrdMemoryBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdMemoryBackend.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdMemoryBackend.java 20 May 2004 10:34:00 -0000 1.1 --- RrdMemoryBackend.java 21 May 2004 10:40:50 -0000 1.2 *************** *** 78,82 **** /** ! * This method is required by the base class definition, but has no effect at all. */ public void close() { --- 78,83 ---- /** ! * This method is required by the base class definition, but it does not ! * releases any memory resources at all. */ public void close() { Index: RrdPrimitive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdPrimitive.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdPrimitive.java 20 May 2004 10:29:33 -0000 1.6 --- RrdPrimitive.java 21 May 2004 10:40:50 -0000 1.7 *************** *** 109,112 **** backend.writeString(pointer, value); } - } --- 109,111 ---- Index: RrdFileBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFileBackend.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdFileBackend.java 20 May 2004 10:34:00 -0000 1.1 --- RrdFileBackend.java 21 May 2004 10:40:50 -0000 1.2 *************** *** 46,50 **** super(path); file = new RandomAccessFile(path, readOnly? "r": "rw"); ! lockFile(lockMode); } --- 46,54 ---- super(path); file = new RandomAccessFile(path, readOnly? "r": "rw"); ! // We'll try to lock the file only in "rw" mode ! // locks are meaningless for read-only access ! if(!readOnly) { ! lockFile(lockMode); ! } } |
From: Sasa M. <sa...@us...> - 2004-05-21 07:14:34
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16942/org/jrobin/core Removed Files: RrdFile.java Log Message: RrdFile is now obsolete - removed from CVS --- RrdFile.java DELETED --- |
From: Sasa M. <sa...@us...> - 2004-05-20 14:49:54
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25847/org/jrobin/core Modified Files: RrdBackendFactory.java RrdFileBackendFactory.java RrdMemoryBackendFactory.java Log Message: Minor fine-tunnig of the new core package. Index: RrdFileBackendFactory.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFileBackendFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdFileBackendFactory.java 20 May 2004 10:34:00 -0000 1.1 --- RrdFileBackendFactory.java 20 May 2004 14:49:29 -0000 1.2 *************** *** 61,73 **** /** - * Removes the file from the disk. - * @param path File path - * @return True, if the file is deleted, false otherwise. - */ - protected boolean delete(String path) { - return new File(path).delete(); - } - - /** * Returns the name of this factory. * @return Factory name (equals to string "FILE") --- 61,64 ---- Index: RrdMemoryBackendFactory.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdMemoryBackendFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdMemoryBackendFactory.java 20 May 2004 10:34:00 -0000 1.1 --- RrdMemoryBackendFactory.java 20 May 2004 14:49:29 -0000 1.2 *************** *** 30,34 **** /** ! * Factory class which creates actual {@link RrdMemoryBackend} objects. */ public class RrdMemoryBackendFactory extends RrdBackendFactory { --- 30,41 ---- /** ! * Factory class which creates actual {@link RrdMemoryBackend} objects. JRobin's support ! * for in-memory RRDs is still experimental. You should know that all active RrdMemoryBackend ! * objects are held in memory, each backend object stores RRD data in one big byte array. This ! * implementation is therefore quite basic and memory hungry but runs very fast.<p> ! * ! * Calling {@link RrdDb#close() close()} on RrdDb objects does not release any memory at all ! * (RRD data must be available for the next <code>new RrdDb(path)</code> call. To release allocated ! * memory, you'll have to call {@link #delete(java.lang.String) delete(path)} method of this class.<p> */ public class RrdMemoryBackendFactory extends RrdBackendFactory { *************** *** 73,77 **** * @return True, if the storage with the given ID is deleted, false otherwise. */ ! protected boolean delete(String id) { if(backends.containsKey(id)) { backends.remove(id); --- 80,84 ---- * @return True, if the storage with the given ID is deleted, false otherwise. */ ! public boolean delete(String id) { if(backends.containsKey(id)) { backends.remove(id); Index: RrdBackendFactory.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdBackendFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdBackendFactory.java 20 May 2004 10:34:00 -0000 1.1 --- RrdBackendFactory.java 20 May 2004 14:49:29 -0000 1.2 *************** *** 142,146 **** * @throws IOException Thrown in case of I/O error. */ ! protected abstract RrdBackend open(String path, boolean readOnly, int lockMode) throws IOException; /** --- 142,147 ---- * @throws IOException Thrown in case of I/O error. */ ! protected abstract RrdBackend open(String path, boolean readOnly, int lockMode) ! throws IOException; /** *************** *** 149,162 **** * @return True, if such storage exists, false otherwise. */ ! protected abstract boolean exists(String path); ! ! /** ! * Releases all system resources associated with the storage with the given path. ! * If the storage represents a file on the disk, the file will be removed. ! * If the storage represents a section in memory, the memory will be released. ! * @param path Storage path ! * @return true, if all resources are released without a problem, false otherwise. ! */ ! protected abstract boolean delete(String path); /** --- 150,154 ---- * @return True, if such storage exists, false otherwise. */ ! protected abstract boolean exists(String path) throws IOException; /** |
From: Sasa M. <sa...@us...> - 2004-05-20 10:34:09
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10576/org/jrobin/core Added Files: RrdAllocator.java RrdBackend.java RrdBackendFactory.java RrdCacher.java RrdFileBackend.java RrdFileBackendFactory.java RrdMemoryBackend.java RrdMemoryBackendFactory.java RrdNioBackend.java RrdNioBackendFactory.java Log Message: Major core package redesign --- NEW FILE: RrdCacher.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; class RrdCacher { private Object cache = null; boolean setInt(int value) { if(isCached(value)) { return false; } else { cache = new Integer(value); return true; } } boolean setLong(long value) { if(isCached(value)) { return false; } else { cache = new Long(value); return true; } } boolean setDouble(double value) { if(isCached(value)) { return false; } else { cache = new Double(value); return true; } } boolean setString(String value) { if(isCached(value)) { return false; } else { cache = value; return true; } } boolean isEmpty() { return cache == null; } int getInt() { return ((Integer) cache).intValue(); } long getLong() { return ((Long) cache).longValue(); } double getDouble() { return ((Double) cache).doubleValue(); } String getString() { return (String) cache; } private boolean isCached(int value) { return cache != null && getInt() == value; } private boolean isCached(long value) { return cache != null && getLong() == value; } private boolean isCached(double value) { return cache != null && getDouble() == value; } private boolean isCached(String value) { return cache != null && getString().equals(value); } } --- NEW FILE: RrdBackend.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 java.io.IOException; /** * Base implementation class for all backend classes. Each Round Robin Database object * ({@link RrdDb} object) is backed with a single RrdBackend object which performs * actual I/O operations on the underlying storage. JRobin supports * three different bakcends out of the box:</p> * <ul> * <li>{@link RrdFileBackend}: objects of this class are created from the * {@link RrdFileBackendFactory} class. This is the default backend used in all * JRobin releases. It uses java.io.* package and RandomAccessFile class to store * RRD data in files on the disk. * * <li>{@link RrdNioBackend}: objects of this class are created from the * {@link RrdNioBackendFactory} class. The backend uses java.io.* and java.nio.* * classes (mapped ByteBuffer) to store RRD data in files on the disk. * * <li>{@link RrdMemoryBackend}: objects of this class are created from the * {@link RrdMemoryBackendFactory} class. This backend stores all data in memory. Once * JVM exits, all data gets lost. The backend is extremely fast and memory hungry. * </ul> * * To create your own backend in order to provide some custom type of RRD storage, * you should do the following:</p> * * <ul> * <li>Create your custom RrdBackend class (RrdCustomBackend, for example) * by extending RrdBackend class. You have to implement all abstract methods defined * in the base class. * * <li>Create your custom RrdBackendFactory class (RrdCustomBackendFactory, * for example) by extending RrdBackendFactory class. You have to implement all * abstract methods defined in the base class. Your custom factory class will actually * create custom backend objects when necessary. * * <li>Create instance of your custom RrdBackendFactory and register it as a regular * factory available to JRobin framework. See javadoc for {@link RrdBackendFactory} to * find out how to do this * </ul> * */ public abstract class RrdBackend { private String path; /** * Creates backend for a RRD storage with the given path. * @param path String identifying RRD storage. For files on the disk, this * argument should represent file path. Other storage types might interpret * this argument differently. */ protected RrdBackend(String path) { this.path = path; } /** * Returns path to the storage. * @return Storage path */ public String getPath() { return path; } /** * Writes an array of bytes to the underlying storage starting from the given * storage offset. * @param offset Storage offset. * @param b Array of bytes that should be copied to the underlying storage * @throws IOException Thrown in case of I/O error */ protected abstract void write(long offset, byte[] b) throws IOException; /** * Reads an array of bytes from the underlying storage starting from the given * storage offset. * @param offset Storage offset. * @param b Array which receives bytes from the underlying storage * @throws IOException Thrown in case of I/O error */ protected abstract void read(long offset, byte[] b) throws IOException; /** * Reads all RRD bytes from the underlying storage * @return RRD bytes * @throws IOException Thrown in case of I/O error */ public final byte[] readAll() throws IOException { byte[] b = new byte[(int) getLength()]; read(0, b); return b; } /** * Returns the number of RRD bytes in the underlying storage. * @return Number of RRD bytes in the storage. * @throws IOException Thrown in case of I/O error. */ public abstract long getLength() throws IOException; /** * Sets the number of bytes in the underlying RRD storage. * This method is called only once, immediately after a new RRD storage gets created. * @param length Length of the underlying RRD storage in bytes. * @throws IOException Thrown in case of I/O error. */ protected abstract void setLength(long length) throws IOException; /** * Closes the storage. * @throws IOException Thrown in case of I/O error */ public abstract void close() throws IOException; final void writeInt(long offset, int value) throws IOException { write(offset, getIntBytes(value)); } final void writeLong(long offset, long value) throws IOException { write(offset, getLongBytes(value)); } final void writeDouble(long offset, double value) throws IOException { write(offset, getDoubleBytes(value)); } final void writeDouble(long offset, double value, int count) throws IOException { byte[] b = getDoubleBytes(value); byte[] image = new byte[8 * count]; for(int i = 0, k = 0; i < count; i++) { image[k++] = b[0]; image[k++] = b[1]; image[k++] = b[2]; image[k++] = b[3]; image[k++] = b[4]; image[k++] = b[5]; image[k++] = b[6]; image[k++] = b[7]; } write(offset, image); image = null; } final void writeDouble(long offset, double[] values) throws IOException { int count = values.length; byte[] image = new byte[8 * count]; for(int i = 0, k = 0; i < count; i++) { byte[] b = getDoubleBytes(values[i]); image[k++] = b[0]; image[k++] = b[1]; image[k++] = b[2]; image[k++] = b[3]; image[k++] = b[4]; image[k++] = b[5]; image[k++] = b[6]; image[k++] = b[7]; } write(offset, image); image = null; } final void writeString(long offset, String value) throws IOException { value = value.trim(); byte[] b = new byte[RrdPrimitive.STRING_LENGTH * 2]; for(int i = 0, k = 0; i < RrdPrimitive.STRING_LENGTH; i++) { char c = (i < value.length())? value.charAt(i): ' '; byte[] cb = getCharBytes(c); b[k++] = cb[0]; b[k++] = cb[1]; } write(offset, b); } final int readInt(long offset) throws IOException { byte[] b = new byte[4]; read(offset, b); return getInt(b); } final long readLong(long offset) throws IOException { byte[] b = new byte[8]; read(offset, b); return getLong(b); } final double readDouble(long offset) throws IOException { byte[] b = new byte[8]; read(offset, b); return getDouble(b); } final double[] readDouble(long offset, int count) throws IOException { int byteCount = 8 * count; byte[] image = new byte[byteCount]; read(offset, image); double[] values = new double[count]; for(int i = 0, k = -1; i < count; i++) { byte[] b = new byte[] { image[++k], image[++k], image[++k], image[++k], image[++k], image[++k], image[++k], image[++k] }; values[i] = getDouble(b); } image = null; return values; } final String readString(long offset) throws IOException { byte[] b = new byte[RrdPrimitive.STRING_LENGTH * 2]; char[] c = new char[RrdPrimitive.STRING_LENGTH]; read(offset, b); for(int i = 0, k = -1; i < RrdPrimitive.STRING_LENGTH; i++) { byte[] cb = new byte[] { b[++k], b[++k] }; c[i] = getChar(cb); } return new String(c).trim(); } // static helper methods private final static byte[] getIntBytes(int value) { byte[] b = new byte[4]; b[0] = (byte)((value >>> 24) & 0xFF); b[1] = (byte)((value >>> 16) & 0xFF); b[2] = (byte)((value >>> 8) & 0xFF); b[3] = (byte)((value >>> 0) & 0xFF); return b; } private final static byte[] getLongBytes(long value) { byte[] b = new byte[8]; b[0] = (byte)((int)(value >>> 56) & 0xFF); b[1] = (byte)((int)(value >>> 48) & 0xFF); b[2] = (byte)((int)(value >>> 40) & 0xFF); b[3] = (byte)((int)(value >>> 32) & 0xFF); b[4] = (byte)((int)(value >>> 24) & 0xFF); b[5] = (byte)((int)(value >>> 16) & 0xFF); b[6] = (byte)((int)(value >>> 8) & 0xFF); b[7] = (byte)((int)(value >>> 0) & 0xFF); return b; } private final static byte[] getCharBytes(char value) { byte[] b = new byte[2]; b[0] = (byte)((value >>> 8) & 0xFF); b[1] = (byte)((value >>> 0) & 0xFF); return b; } private final static byte[] getDoubleBytes(double value) { byte[] bytes = getLongBytes(Double.doubleToLongBits(value)); return bytes; } private final static int getInt(byte[] b) { assert b.length == 4: "Invalid number of bytes for integer conversion"; return ((b[0] << 24) & 0xFF000000) + ((b[1] << 16) & 0x00FF0000) + ((b[2] << 8) & 0x0000FF00) + ((b[3] << 0) & 0x000000FF); } private final static long getLong(byte[] b) { assert b.length == 8: "Invalid number of bytes for long conversion"; int high = getInt(new byte[] { b[0], b[1], b[2], b[3] }); int low = getInt(new byte[] { b[4], b[5], b[6], b[7] }); long value = ((long)(high) << 32) + (low & 0xFFFFFFFFL); return value; } private final static char getChar(byte[] b) { assert b.length == 2: "Invalid number of bytes for char conversion"; return (char)(((b[0] << 8) & 0x0000FF00) + ((b[1] << 0) & 0x000000FF)); } private final static double getDouble(byte[] b) { assert b.length == 8: "Invalid number of bytes for double conversion"; return Double.longBitsToDouble(getLong(b)); } } --- NEW FILE: RrdNioBackend.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 java.io.IOException; import java.nio.channels.FileChannel; import java.nio.MappedByteBuffer; /** * JRobin backend which is used to store RRD data to ordinary files on the disk * by using java.nio.* package. */ public class RrdNioBackend extends RrdFileBackend { FileChannel.MapMode mapMode; MappedByteBuffer byteBuffer; RrdNioBackend(String path, boolean readOnly, int lockMode) throws IOException { super(path, readOnly, lockMode); mapMode = readOnly? FileChannel.MapMode.READ_ONLY: FileChannel.MapMode.READ_WRITE; byteBuffer = file.getChannel().map(mapMode, 0, getLength()); } /** * Sets length of the underlying RRD file. This method is called only once, immediately * after a new RRD file gets created. * @param length Length of the RRD file * @throws IOException Thrown in case of I/O error. */ protected void setLength(long length) throws IOException { super.setLength(length); byteBuffer = file.getChannel().map(mapMode, 0, length); } /** * Writes bytes to the underlying RRD file on the disk * @param offset Starting file offset * @param b Bytes to be written. * @throws IOException Thrown in case of I/O error */ protected void write(long offset, byte[] b) throws IOException { byteBuffer.position((int)offset); byteBuffer.put(b); } /** * Reads a number of bytes from the RRD file on the disk * @param offset Starting file offset * @param b Buffer which receives bytes read from the file. * @throws IOException Thrown in case of I/O error. */ protected void read(long offset, byte[] b) throws IOException { byteBuffer.position((int)offset); byteBuffer.get(b); } /** * Closes the underlying RRD file. * @throws IOException Thrown in case of I/O error */ public void close() throws IOException { byteBuffer.force(); super.close(); } } --- NEW FILE: RrdMemoryBackendFactory.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 java.io.IOException; import java.util.HashMap; /** * Factory class which creates actual {@link RrdMemoryBackend} objects. */ public class RrdMemoryBackendFactory extends RrdBackendFactory { /** factory name, "MEMORY" */ public static final String NAME = "MEMORY"; private HashMap backends = new HashMap(); /** * Creates RrdMemoryBackend object. * @param id Since this backend holds all data in memory, this argument is interpreted * as an ID for this memory-based storage. * @param readOnly This parameter is ignored * @param lockMode This parameter is ignored * @return RrdMemoryBackend object which handles all I/O operations * @throws IOException Thrown in case of I/O error. */ protected synchronized RrdBackend open(String id, boolean readOnly, int lockMode) throws IOException { RrdMemoryBackend backend; if(backends.containsKey(id)) { backend = (RrdMemoryBackend) backends.get(id); } else { backend = new RrdMemoryBackend(id); backends.put(id, backend); } return backend; } /** * Method to determine if a memory storage with the given ID already exists. * @param id Memory storage ID. * @return True, if such storage exists, false otherwise. */ protected synchronized boolean exists(String id) { return backends.containsKey(id); } /** * Removes the storage with the given ID from the memory. * @param id Storage ID * @return True, if the storage with the given ID is deleted, false otherwise. */ protected boolean delete(String id) { if(backends.containsKey(id)) { backends.remove(id); return true; } else { return false; } } /** * Returns the name of this factory. * @return Factory name (equals to "MEMORY"). */ protected String getFactoryName() { return NAME; } } --- NEW FILE: RrdBackendFactory.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 java.util.HashMap; import java.io.IOException; /** * Base (abstract) backend factory class which holds references to all concrete * backend factories and defines abstract methods which must be implemented in * all concrete factory implementations.<p> * * Factory classes are used to create concrete {@link RrdBackend} implementations. * Each factory creates unlimited number of specific backend objects. * * JRobin supports three different backend types (backend factories) out of the box:<p> * <ul> * <li>{@link RrdFileBackend}: objects of this class are created from the * {@link RrdFileBackendFactory} class. This is the default backend used in all * JRobin releases. It uses java.io.* package and RandomAccessFile class to store * RRD data in files on the disk. * * <li>{@link RrdNioBackend}: objects of this class are created from the * {@link RrdNioBackendFactory} class. The backend uses java.io.* and java.nio.* * classes (mapped ByteBuffer) to store RRD data in files on the disk. * * <li>{@link RrdMemoryBackend}: objects of this class are created from the * {@link RrdMemoryBackendFactory} class. This backend stores all data in memory. Once * JVM exits, all data gets lost. The backend is extremely fast and memory hungry. * </ul> * * Each backend factory is identifed by its {@link #getFactoryName() name}. Constructors * are provided in the {@link RrdDb} class to create RrdDb objects (RRD databases) * backed with a specific backend.<p> * * See javadoc for {@link RrdBackend} to find out how to create your custom backends. */ public abstract class RrdBackendFactory { private static final HashMap factories = new HashMap(); private static RrdBackendFactory defaultFactory; static { try { RrdFileBackendFactory fileFactory = new RrdFileBackendFactory(); registerFactory(fileFactory); RrdMemoryBackendFactory memoryFactory = new RrdMemoryBackendFactory(); registerFactory(memoryFactory); RrdNioBackendFactory nioFactory = new RrdNioBackendFactory(); registerFactory(nioFactory); // Here is the default backend factory defaultFactory = fileFactory; } catch (RrdException e) { throw new RuntimeException("FATAL: Cannot register RRD backend factories: " + e); } } /** * Returns backend factory for the given backend factory name. * @param name Backend factory name. Initially supported names are:<p> * <ul> * <li><b>FILE</b>: Default factory which creates backends based on the * java.io.* package. RRD data is stored in files on the disk * <li><b>NIO</b>: Factory which creates backends based on the * java.nio.* package. RRD data is stored in files on the disk * <li><b>MEMORY</b>: Factory which creates memory-oriented backends. * RRD data is stored in memory, it gets lost as soon as JVM exits. * </ul> * @return Backend factory for the given factory name * @throws RrdException Thrown if no factory with the given name * is available. */ public static synchronized RrdBackendFactory getFactory(String name) throws RrdException { RrdBackendFactory factory = (RrdBackendFactory) factories.get(name); if(factory != null) { return factory; } else { throw new RrdException("No backend factory found with the name specified [" + name + "]"); } } /** * Registers new (custom) backend factory within the JRobin framework. * @param factory Factory to be registered * @throws RrdException Thrown if the name of the specified factory is already * used. */ public static synchronized void registerFactory(RrdBackendFactory factory) throws RrdException { String name = factory.getFactoryName(); if(!factories.containsKey(name)) { factories.put(name, factory); } else { throw new RrdException("Backend factory of this name2 (" + name + ") already exists and cannot be registered"); } } /** * Returns the defaul backend factory. This factory is used to construct * {@link RrdDb} objects if no factory is specified in the RrdDb constructor. * @return Default backend factory. */ public static RrdBackendFactory getDefaultFactory() { return defaultFactory; } /** * Creates RrdBackend object for the given storage path. * @param path Storage path * @param readOnly True, if the storage should be accessed in read/only mode. * False otherwise. * @param lockMode One of the following constants: {@link RrdDb.NO_LOCKS}, * {@link RrdDb.EXCEPTION_IF_LOCKED} or {@link RrdDb.WAIT_IF_LOCKED}. * @return Backend object which handles all I/O operations for the given storage path * @throws IOException Thrown in case of I/O error. */ protected abstract RrdBackend open(String path, boolean readOnly, int lockMode) throws IOException; /** * Method to determine if a storage with the given path already exists. * @param path Storage path * @return True, if such storage exists, false otherwise. */ protected abstract boolean exists(String path); /** * Releases all system resources associated with the storage with the given path. * If the storage represents a file on the disk, the file will be removed. * If the storage represents a section in memory, the memory will be released. * @param path Storage path * @return true, if all resources are released without a problem, false otherwise. */ protected abstract boolean delete(String path); /** * Returns the name (primary ID) for the factory. * @return Name of the factory. */ protected abstract String getFactoryName(); } --- NEW FILE: RrdFileBackend.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 java.io.IOException; import java.io.RandomAccessFile; import java.io.File; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; /** * Default JRobin backend which is used to store RRD data to ordinary files on the disk.<p> * * This backend is based on the RandomAccessFile class (java.io.* package). */ public class RrdFileBackend extends RrdBackend { static final long LOCK_DELAY = 100; // 0.1sec protected RandomAccessFile file; protected FileLock fileLock; RrdFileBackend(String path, boolean readOnly, int lockMode) throws IOException { super(path); file = new RandomAccessFile(path, readOnly? "r": "rw"); lockFile(lockMode); } private void lockFile(int lockMode) throws IOException { if(lockMode == RrdDb.WAIT_IF_LOCKED || lockMode == RrdDb.EXCEPTION_IF_LOCKED) { FileChannel fileChannel = file.getChannel(); do { fileLock = fileChannel.tryLock(); if(fileLock == null) { // could not obtain lock if(lockMode == RrdDb.WAIT_IF_LOCKED) { // wait a little, than try again try { Thread.sleep(LOCK_DELAY); } catch (InterruptedException e) { // NOP } } else { throw new IOException("Access denied. " + "File [" + getPath() + "] already locked"); } } } while(fileLock == null); } } /** * Closes the underlying RRD file. * @throws IOException Thrown in case of I/O error */ public void close() throws IOException { unlockFile(); file.close(); } private void unlockFile() throws IOException { if(fileLock != null) { fileLock.release(); fileLock = null; } } /** * Closes the underlying RRD file if not already closed * @throws IOException Thrown in case of I/O error */ protected void finalize() throws IOException { close(); } /** * Returns canonical path to the file on the disk. * @param path File path * @return Canonical file path * @throws IOException Thrown in case of I/O error */ public static String getCanonicalPath(String path) throws IOException { return new File(path).getCanonicalPath(); } /** * Returns canonical path to the file on the disk. * @return Canonical file path * @throws IOException Thrown in case of I/O error */ public String getCanonicalPath() throws IOException { return RrdFileBackend.getCanonicalPath(getPath()); } /** * Writes bytes to the underlying RRD file on the disk * @param offset Starting file offset * @param b Bytes to be written. * @throws IOException Thrown in case of I/O error */ protected void write(long offset, byte[] b) throws IOException { file.seek(offset); file.write(b); } /** * Reads a number of bytes from the RRD file on the disk * @param offset Starting file offset * @param b Buffer which receives bytes read from the file. * @throws IOException Thrown in case of I/O error. */ protected void read(long offset, byte[] b) throws IOException { file.seek(offset); if(file.read(b) != b.length) { throw new IOException("Not enough bytes available in file " + getPath()); } } /** * Returns RRD file length. * @return File length. * @throws IOException Thrown in case of I/O error. */ public long getLength() throws IOException { return file.length(); } /** * Sets length of the underlying RRD file. This method is called only once, immediately * after a new RRD file gets created. * @param length Length of the RRD file * @throws IOException Thrown in case of I/O error. */ protected void setLength(long length) throws IOException { file.setLength(length); } } --- NEW FILE: RrdFileBackendFactory.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 java.io.IOException; import java.io.File; /** * Factory class which creates actual {@link RrdFileBackend} objects. This is the default * backend factory in JRobin. */ public class RrdFileBackendFactory extends RrdBackendFactory { /** factory name, "FILE" */ public static final String NAME = "FILE"; /** * Creates RrdFileBackend object for the given file path. * @param path File path * @param readOnly True, if the file should be accessed in read/only mode. * False otherwise. * @param lockMode One of the following constants: {@link RrdDb.NO_LOCKS}, * {@link RrdDb.EXCEPTION_IF_LOCKED} or {@link RrdDb.WAIT_IF_LOCKED}. * @return RrdFileBackend object which handles all I/O operations for the given file path * @throws IOException Thrown in case of I/O error. */ protected RrdBackend open(String path, boolean readOnly, int lockMode) throws IOException { return new RrdFileBackend(path, readOnly, lockMode); } /** * Method to determine if a file with the given path already exists. * @param path File path * @return True, if such file exists, false otherwise. */ protected boolean exists(String path) { return new File(path).exists(); } /** * Removes the file from the disk. * @param path File path * @return True, if the file is deleted, false otherwise. */ protected boolean delete(String path) { return new File(path).delete(); } /** * Returns the name of this factory. * @return Factory name (equals to string "FILE") */ protected String getFactoryName() { return NAME; } } --- NEW FILE: RrdAllocator.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 java.io.IOException; class RrdAllocator { private long allocationPointer = 0L; long allocate(long byteCount) throws IOException { long pointer = allocationPointer; allocationPointer += byteCount; return pointer; } } --- NEW FILE: RrdNioBackendFactory.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 java.io.IOException; /** * Factory class which creates actual {@link RrdNioBackend} objects. */ public class RrdNioBackendFactory extends RrdFileBackendFactory{ /** factory name, "NIO" */ public static final String NAME = "NIO"; /** * Creates RrdNioBackend object for the given file path. * @param path File path * @param readOnly True, if the file should be accessed in read/only mode. * False otherwise. * @param lockMode One of the following constants: {@link RrdDb.NO_LOCKS}, * {@link RrdDb.EXCEPTION_IF_LOCKED} or {@link RrdDb.WAIT_IF_LOCKED}. * @return RrdNioBackend object which handles all I/O operations for the given file path * @throws IOException Thrown in case of I/O error. */ protected RrdBackend open(String path, boolean readOnly, int lockMode) throws IOException { return new RrdNioBackend(path, readOnly, lockMode); } /** * Returns the name of this factory. * @return Factory name (equals to string "NIO") */ protected String getFactoryName() { return NAME; } } --- NEW FILE: RrdMemoryBackend.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 java.io.IOException; /** * Backend which is used to store all RRD bytes in memory.<p> */ public class RrdMemoryBackend extends RrdBackend { private byte[] buffer = new byte[0]; RrdMemoryBackend(String path) { super(path); } protected void write(long offset, byte[] b) throws IOException { int pos = (int) offset; for(int i = 0; i < b.length; i++) { buffer[pos++] = b[i]; } } protected void read(long offset, byte[] b) throws IOException { int pos = (int) offset; if(pos + b.length <= buffer.length) { for(int i = 0; i < b.length; i++) { b[i] = buffer[pos++]; } } else { throw new IOException("Not enough bytes available in memory " + getPath()); } } /** * Returns the number of RRD bytes held in memory. * @return Number of all RRD bytes. */ public long getLength() { return buffer.length; } /** * Reserves a memory section as a RRD storage. * @param newLength Number of bytes held in memory. * @throws IOException Thrown in case of I/O error. */ protected void setLength(long newLength) throws IOException { if(newLength > Integer.MAX_VALUE) { throw new IOException("Cannot create this big memory backed RRD"); } buffer = new byte[(int) newLength]; } /** * This method is required by the base class definition, but has no effect at all. */ public void close() { // NOP } } |
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] |
From: Sasa M. <sa...@us...> - 2004-05-20 10:29:43
|
Update of /cvsroot/jrobin/src/org/jrobin/inspector In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9371/org/jrobin/inspector Modified Files: HeaderTableModel.java RrdNode.java Log Message: Major core package redesign Index: RrdNode.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/RrdNode.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdNode.java 10 Nov 2003 08:52:28 -0000 1.2 --- RrdNode.java 20 May 2004 10:29:33 -0000 1.3 *************** *** 37,41 **** RrdNode(RrdDb rrd) { // header node ! String path = rrd.getRrdFile().getFilePath(); label = new File(path).getName(); } --- 37,41 ---- RrdNode(RrdDb rrd) { // header node ! String path = rrd.getRrdBackend().getPath(); label = new File(path).getName(); } Index: HeaderTableModel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/inspector/HeaderTableModel.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** HeaderTableModel.java 4 Dec 2003 13:21:03 -0000 1.5 --- HeaderTableModel.java 20 May 2004 10:29:33 -0000 1.6 *************** *** 81,85 **** String datasources = "" + header.getDsCount(); String archives = "" + header.getArcCount(); ! String size = rrd.getRrdFile().getFileSize() + " bytes"; rrd.close(); values = new Object[]{ --- 81,85 ---- String datasources = "" + header.getDsCount(); String archives = "" + header.getArcCount(); ! String size = rrd.getRrdBackend().getLength() + " bytes"; rrd.close(); values = new Object[]{ |
From: Sasa M. <sa...@us...> - 2004-05-20 10:29:41
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9371 Modified Files: Demo.java StressTest.java Log Message: Major core package redesign Index: Demo.java =================================================================== RCS file: /cvsroot/jrobin/src/Demo.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Demo.java 11 May 2004 10:05:48 -0000 1.16 --- Demo.java 20 May 2004 10:29:31 -0000 1.17 *************** *** 40,43 **** --- 40,44 ---- static final Random RANDOM = new Random(SEED); static final String FILE = "demo"; + static final String FACTORY_NAME = "FILE"; static final long START = Util.getTimestamp(2003, 4, 1); *************** *** 50,54 **** println("== Starting demo"); RrdDb.setLockMode(RrdDb.NO_LOCKS); - long startMillis = System.currentTimeMillis(); long start = START; --- 51,54 ---- Index: StressTest.java =================================================================== RCS file: /cvsroot/jrobin/src/StressTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StressTest.java 29 Mar 2004 14:38:27 -0000 1.2 --- StressTest.java 20 May 2004 10:29:31 -0000 1.3 *************** *** 38,41 **** --- 38,42 ---- public static final long RRD_START = 946710000L; public static final long RRD_STEP = 30; + public static final String BACKEND_NAME = "MEMORY"; public static final String RRD_DATASOURCE_NAME = "T"; *************** *** 94,101 **** def.addArchive("MIN", 0.5, 1440, 50000); def.addArchive("MAX", 0.5, 1440, 50000); - //printLapTime(def.dump()); printLapTime("Definition created, creating RRD file"); ! RrdDbPool pool = RrdDbPool.getInstance(); ! RrdDb rrd = pool.requestRrdDb(def); printLapTime("RRD file created: " + RRD_PATH); BufferedReader r = new BufferedReader(new FileReader(args[0])); --- 95,100 ---- def.addArchive("MIN", 0.5, 1440, 50000); def.addArchive("MAX", 0.5, 1440, 50000); printLapTime("Definition created, creating RRD file"); ! RrdDb rrd = new RrdDb(def); printLapTime("RRD file created: " + RRD_PATH); BufferedReader r = new BufferedReader(new FileReader(args[0])); *************** *** 117,121 **** } } ! pool.release(rrd); printLapTime("FINISHED: " + count + " samples stored"); // GRAPH --- 116,120 ---- } } ! rrd.close(); printLapTime("FINISHED: " + count + " samples stored"); // GRAPH *************** *** 139,143 **** gdef.comment("\nOriginal data provided by diy-zoning.sf.net@c"); printLapTime("Graph definition created"); ! RrdGraph g = new RrdGraph(gdef, true); g.saveAsPNG(PNG_PATH, PNG_WIDTH, PNG_HEIGHT); printLapTime("Graph saved: " + PNG_PATH); --- 138,142 ---- gdef.comment("\nOriginal data provided by diy-zoning.sf.net@c"); printLapTime("Graph definition created"); ! RrdGraph g = new RrdGraph(gdef); g.saveAsPNG(PNG_PATH, PNG_WIDTH, PNG_HEIGHT); printLapTime("Graph saved: " + PNG_PATH); |
From: Sasa M. <sa...@us...> - 2004-05-11 10:06:02
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16824 Modified Files: Demo.java Log Message: getEstimatedSize() method introduced to RrdDef class Index: Demo.java =================================================================== RCS file: /cvsroot/jrobin/src/Demo.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Demo.java 11 May 2004 09:01:59 -0000 1.15 --- Demo.java 11 May 2004 10:05:48 -0000 1.16 *************** *** 80,83 **** --- 80,84 ---- println(rrdDef.dump()); log.println(rrdDef.dump()); + println("Estimated file size: " + rrdDef.getEstimatedSize()); RrdDb rrdDb = new RrdDb(rrdDef); println("== RRD file created."); |
From: Sasa M. <sa...@us...> - 2004-05-11 10:06:02
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16824/org/jrobin/core Modified Files: RrdDef.java Log Message: getEstimatedSize() method introduced to RrdDef class Index: RrdDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** RrdDef.java 28 Apr 2004 11:11:47 -0000 1.10 --- RrdDef.java 11 May 2004 10:05:49 -0000 1.11 *************** *** 528,530 **** --- 528,547 ---- out.close(); } + + /** + * Returns the number of bytes required on the disk to create RRD file from this + * RrdDef object. + * @return Estimated length of the new RRD file. + */ + public long getEstimatedSize() { + int dsCount = dsDefs.size(); + int arcCount = arcDefs.size(); + int rowsCount = 0; + for(int i = 0; i < arcDefs.size(); i++) { + ArcDef arcDef = (ArcDef) arcDefs.get(i); + rowsCount += arcDef.getRows(); + } + return 64L + 128L * dsCount + 56L * arcCount + + 20L * dsCount * arcCount + 8L * dsCount * rowsCount; + } } |
From: Sasa M. <sa...@us...> - 2004-05-11 09:02:12
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2655/org/jrobin/mrtg/client Modified Files: AboutDialog.java Client.java HelpDialog.java SplashWindow.java TreeRenderer.java Log Message: Folders reorganized. In other to run MRTG-CLIENT properly, move the files from jrobin/mrtg-res folder to jrobin/res/mrtg folder. Then remove mrtg-res folder. Index: TreeRenderer.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/TreeRenderer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TreeRenderer.java 10 Nov 2003 08:52:29 -0000 1.2 --- TreeRenderer.java 11 May 2004 09:02:01 -0000 1.3 *************** *** 41,49 **** static { try { ! MRTG_ICON = Resources.getImageIcon("mrtg-res/mrtg.png"); ! ROUTER_ICON = Resources.getImageIcon("mrtg-res/router.png"); ! LINK_ICON = Resources.getImageIcon("mrtg-res/link.png"); ! INACTIVE_ROUTER_ICON = Resources.getImageIcon("mrtg-res/router_inactive.png"); ! INACTIVE_LINK_ICON = Resources.getImageIcon("mrtg-res/link_inactive.png"); } catch (MrtgException e) { e.printStackTrace(); --- 41,49 ---- static { try { ! MRTG_ICON = Resources.getImageIcon(Client.RESOURCE_PATH + "mrtg.png"); ! ROUTER_ICON = Resources.getImageIcon(Client.RESOURCE_PATH + "router.png"); ! LINK_ICON = Resources.getImageIcon(Client.RESOURCE_PATH + "link.png"); ! INACTIVE_ROUTER_ICON = Resources.getImageIcon(Client.RESOURCE_PATH + "router_inactive.png"); ! INACTIVE_LINK_ICON = Resources.getImageIcon(Client.RESOURCE_PATH + "link_inactive.png"); } catch (MrtgException e) { e.printStackTrace(); Index: SplashWindow.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/SplashWindow.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SplashWindow.java 10 Nov 2003 08:52:29 -0000 1.2 --- SplashWindow.java 11 May 2004 09:02:01 -0000 1.3 *************** *** 41,45 **** JLabel imageLabel = new JLabel(); try { ! imageLabel.setIcon(Resources.getImageIcon("mrtg-res/logo.png")); } catch (MrtgException e) { // NOP --- 41,45 ---- JLabel imageLabel = new JLabel(); try { ! imageLabel.setIcon(Resources.getImageIcon(Client.RESOURCE_PATH + "logo.png")); } catch (MrtgException e) { // NOP Index: Client.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/Client.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Client.java 9 Apr 2004 14:07:24 -0000 1.7 --- Client.java 11 May 2004 09:02:01 -0000 1.8 *************** *** 38,45 **** class Client extends JFrame { static final String TITLE = "JRobin-MRTG client"; static final String SUBTITLE = "http://www.jrobin.org"; static final String COPYRIGHT = "Copyright \u00A9 2004 Sasa Markovic"; ! static final String ICON = "mrtg-res/icon.png"; static Dimension MAIN_TREE_SIZE = new Dimension(320, 400); --- 38,46 ---- class Client extends JFrame { + static final String RESOURCE_PATH = "res/mrtg/"; static final String TITLE = "JRobin-MRTG client"; static final String SUBTITLE = "http://www.jrobin.org"; static final String COPYRIGHT = "Copyright \u00A9 2004 Sasa Markovic"; ! static final String ICON = RESOURCE_PATH + "icon.png"; static Dimension MAIN_TREE_SIZE = new Dimension(320, 400); Index: HelpDialog.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/HelpDialog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HelpDialog.java 10 Nov 2003 08:52:29 -0000 1.2 --- HelpDialog.java 11 May 2004 09:02:01 -0000 1.3 *************** *** 35,39 **** class HelpDialog extends JDialog { static final String TITLE = "Help"; ! static final String HTML = "mrtg-res/help.html"; static final Dimension SIZE = new Dimension(600, 300); --- 35,39 ---- class HelpDialog extends JDialog { static final String TITLE = "Help"; ! static final String HTML = Client.RESOURCE_PATH + "help.html"; static final Dimension SIZE = new Dimension(600, 300); Index: AboutDialog.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/client/AboutDialog.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AboutDialog.java 4 Dec 2003 13:21:03 -0000 1.3 --- AboutDialog.java 11 May 2004 09:02:00 -0000 1.4 *************** *** 36,40 **** static final String TITLE = "About JRobin"; static final String EMAIL = "sa...@eu..."; ! static final String LOGO = "mrtg-res/logo.png"; private static final int GAP = 3; --- 36,40 ---- static final String TITLE = "About JRobin"; static final String EMAIL = "sa...@eu..."; ! static final String LOGO = Client.RESOURCE_PATH + "logo.png"; private static final int GAP = 3; |
From: Sasa M. <sa...@us...> - 2004-05-11 09:02:10
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2655/org/jrobin/core Modified Files: Util.java Log Message: Folders reorganized. In other to run MRTG-CLIENT properly, move the files from jrobin/mrtg-res folder to jrobin/res/mrtg folder. Then remove mrtg-res folder. Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Util.java 26 Apr 2004 22:28:33 -0000 1.14 --- Util.java 11 May 2004 09:02:00 -0000 1.15 *************** *** 47,56 **** /** ! * Class defines various utility functions used in JRobin. * * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> */ public class Util { ! // pattern RRDTool uses to format doubles in XML files static final String PATTERN = "0.0000000000E00"; --- 47,56 ---- /** ! * Class defines various utility functions used in JRobin. * * @author <a href="mailto:sa...@jr...">Sasa Markovic</a> */ public class Util { ! // pattern RRDTool uses to format doubles in XML files static final String PATTERN = "0.0000000000E00"; *************** *** 224,233 **** } private static final File homeDirFile; private static final String homeDirPath; static { ! String delim = System.getProperty("file.separator"); ! homeDirPath = System.getProperty("user.home") + delim + JROBIN_DIR + delim; homeDirFile = new File(homeDirPath); } --- 224,248 ---- } + /** + * Returns file system separator string. + * @return File system separator ("/" on Unix, "\" on Windows) + */ + public static String getFileSeparator() { + return System.getProperty("file.separator"); + } + + /** + * Returns path to user's home directory. + * @return Path to users home directory, with file separator appended. + */ + public static String getUserHomeDirectory() { + return System.getProperty("user.home") + getFileSeparator(); + } + private static final File homeDirFile; private static final String homeDirPath; static { ! homeDirPath = getUserHomeDirectory() + JROBIN_DIR + getFileSeparator(); homeDirFile = new File(homeDirPath); } *************** *** 355,359 **** return getChildValue( parentNode, childName, true ); } ! static String getChildValue( Node parentNode, String childName, boolean trim ) throws RrdException { NodeList children = parentNode.getChildNodes(); --- 370,374 ---- return getChildValue( parentNode, childName, true ); } ! static String getChildValue( Node parentNode, String childName, boolean trim ) throws RrdException { NodeList children = parentNode.getChildNodes(); *************** *** 371,375 **** return getValue( node, true ); } ! static String getValue(Node node, boolean trimValue ) { String value = null; --- 386,390 ---- return getValue( node, true ); } ! static String getValue(Node node, boolean trimValue ) { String value = null; |
From: Sasa M. <sa...@us...> - 2004-05-11 09:02:10
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2655 Modified Files: Demo.java Log Message: Folders reorganized. In other to run MRTG-CLIENT properly, move the files from jrobin/mrtg-res folder to jrobin/res/mrtg folder. Then remove mrtg-res folder. Index: Demo.java =================================================================== RCS file: /cvsroot/jrobin/src/Demo.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Demo.java 20 Apr 2004 10:22:03 -0000 1.14 --- Demo.java 11 May 2004 09:01:59 -0000 1.15 *************** *** 94,97 **** --- 94,99 ---- Sample sample = rrdDb.createSample(); while(t <= end + 86400L) { + //rrdDb = new RrdDb(rrdPath); + //Sample sample = rrdDb.createSample(); sample.setTime(t); sample.setValue("sun", sunSource.getValue()); *************** *** 103,106 **** --- 105,109 ---- System.out.print("*"); }; + //rrdDb.close(); } println(""); |
From: Sasa M. <sa...@us...> - 2004-04-29 10:17:32
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24539/org/jrobin/graph Modified Files: RrdGraphDef.java Log Message: Fixed javadoc for GPRINT (added TOTAL) Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** RrdGraphDef.java 26 Apr 2004 22:28:33 -0000 1.10 --- RrdGraphDef.java 29 Apr 2004 10:17:21 -0000 1.11 *************** *** 907,911 **** * @param sourceName Graph source name * @param consolFun Consolidation function to be used for calculation ("AVERAGE", ! * "MIN", "MAX" or "LAST") * @param format Format string. For example: "speed is @5.2 @sbits/sec@c", * "temperature = @0 degrees" --- 907,911 ---- * @param sourceName Graph source name * @param consolFun Consolidation function to be used for calculation ("AVERAGE", ! * "MIN", "MAX", "LAST" or "TOTAL" (since 1.3.1) * @param format Format string. For example: "speed is @5.2 @sbits/sec@c", * "temperature = @0 degrees" *************** *** 925,929 **** * * @param sourceName Graph source name ! * @param consolFun Consolidation function to be used for calculation ("AVERAGE", "MIN", "MAX" or "LAST") * @param format Format string. For example: "speed is @5.2 @sbits/sec@c", "temperature = @0 degrees" * @param base Base value for the formatting, defaults to the graphing base value --- 925,930 ---- * * @param sourceName Graph source name ! * @param consolFun Consolidation function to be used for calculation ("AVERAGE", "MIN", "MAX", "LAST" ! * or "TOTAL" (since 1.3.1) * @param format Format string. For example: "speed is @5.2 @sbits/sec@c", "temperature = @0 degrees" * @param base Base value for the formatting, defaults to the graphing base value |
From: Sasa M. <sa...@us...> - 2004-04-28 12:05:18
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29705/org/jrobin/mrtg Modified Files: MrtgConstants.java Log Message: Added support for gprint/TOTAL in MRTG server app Index: MrtgConstants.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/MrtgConstants.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MrtgConstants.java 8 Apr 2004 12:00:00 -0000 1.6 --- MrtgConstants.java 28 Apr 2004 12:05:02 -0000 1.7 *************** *** 198,202 **** " <datasource>out8</datasource> \n" + " <cf>MAX</cf> \n" + ! " <format>Maximum output:@7.2 @Sbits/s@l</format> \n" + " </gprint> \n" + " <gprint> \n" + --- 198,208 ---- " <datasource>out8</datasource> \n" + " <cf>MAX</cf> \n" + ! " <format>Maximum output:@7.2 @Sbits/s</format> \n" + ! " </gprint> \n" + ! " <gprint> \n" + ! " <datasource>out</datasource> \n" + ! " <cf>TOTAL</cf> \n" + ! " <format>Total output:@7.2 @sbytes@l</format> \n" + ! " <base>1024</base> \n" + " </gprint> \n" + " <gprint> \n" + *************** *** 208,212 **** " <datasource>in8</datasource> \n" + " <cf>MAX</cf> \n" + ! " <format>Maximum input: @7.2 @Sbits/s@l</format> \n" + " </gprint> \n" + " <comment>@l</comment> \n" + --- 214,224 ---- " <datasource>in8</datasource> \n" + " <cf>MAX</cf> \n" + ! " <format>Maximum input: @7.2 @Sbits/s</format> \n" + ! " </gprint> \n" + ! " <gprint> \n" + ! " <datasource>in</datasource> \n" + ! " <cf>TOTAL</cf> \n" + ! " <format>Total input :@7.2 @sbytes@l</format> \n" + ! " <base>1024</base> \n" + " </gprint> \n" + " <comment>@l</comment> \n" + |
From: Sasa M. <sa...@us...> - 2004-04-28 12:05:17
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29705/org/jrobin/graph Modified Files: RrdGraphDefTemplate.java Log Message: Added support for gprint/TOTAL in MRTG server app Index: RrdGraphDefTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDefTemplate.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdGraphDefTemplate.java 26 Apr 2004 22:28:33 -0000 1.5 --- RrdGraphDefTemplate.java 28 Apr 2004 12:05:01 -0000 1.6 *************** *** 187,192 **** * <gprint> * <datasource>output</datasource> ! * <cf>MAX</cf> ! * <format>Average output: @2@r</format> * </gprint> * <hrule> --- 187,194 ---- * <gprint> * <datasource>output</datasource> ! * <cf>TOTAL</cf> ! * <format>total output: @2@r</format> ! * <-- optional base value --> ! * <base>1024</base> * </gprint> * <hrule> |
From: Sasa M. <sa...@us...> - 2004-04-28 11:12:02
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21117/org/jrobin/core Modified Files: RrdDef.java Log Message: added methods to add datasource and archive definition using RRDTool's syntax (DS:... RRA:...) Index: RrdDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RrdDef.java 1 Mar 2004 08:50:24 -0000 1.9 --- RrdDef.java 28 Apr 2004 11:11:47 -0000 1.10 *************** *** 29,32 **** --- 29,33 ---- import java.util.Date; import java.util.GregorianCalendar; + import java.util.StringTokenizer; import java.io.*; *************** *** 209,212 **** --- 210,273 ---- /** + * Adds single datasource to RRD definition from a RRDTool-like + * datasource definition string. The string must have six elements separated with colons + * (:) in the following order:<p> + * <pre> + * DS:name:type:heartbeat:minValue:maxValue + * </pre> + * For example:</p> + * <pre> + * DS:input:COUNTER:600:0:U + * </pre> + * For more information on datasource definition parameters see <code>rrdcreate</code> + * man page.<p> + * @param rrdToolDsDef Datasource definition string with the syntax borrowed from RRDTool. + * @throws RrdException Thrown if invalid string is supplied. + */ + public void addDatasource(String rrdToolDsDef) throws RrdException { + RrdException rrdException = new RrdException( + "Wrong rrdtool-like datasource definition: " + rrdToolDsDef); + StringTokenizer tokenizer = new StringTokenizer(rrdToolDsDef, ":"); + if (tokenizer.countTokens() != 6) { + throw rrdException; + } + String[] tokens = new String[6]; + for (int curTok = 0; tokenizer.hasMoreTokens(); curTok++) { + tokens[curTok] = tokenizer.nextToken(); + } + if (!tokens[0].equalsIgnoreCase("DS")) { + throw rrdException; + } + String dsName = tokens[1]; + String dsType = tokens[2]; + long dsHeartbeat; + try { + dsHeartbeat = Long.parseLong(tokens[3]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + double minValue = Double.NaN; + if(!tokens[4].equalsIgnoreCase("U")) { + try { + minValue = Double.parseDouble(tokens[4]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + } + double maxValue = Double.NaN; + if(!tokens[5].equalsIgnoreCase("U")) { + try { + maxValue = Double.parseDouble(tokens[5]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + } + addDatasource(new DsDef(dsName, dsType, dsHeartbeat, minValue, maxValue)); + } + + /** * Adds data source definitions to RRD definition in bulk. * @param dsDefs Array of data source definition objects. *************** *** 262,265 **** --- 323,381 ---- } + /** + * Adds single archive to RRD definition from a RRDTool-like + * archive definition string. The string must have five elements separated with colons + * (:) in the following order:<p> + * <pre> + * RRA:consolidationFunction:XFilesFactor:steps:rows + * </pre> + * For example:</p> + * <pre> + * RRA:AVERAGE:0.5:10:1000 + * </pre> + * For more information on archive definition parameters see <code>rrdcreate</code> + * man page.<p> + * @param rrdToolArcDef Archive definition string with the syntax borrowed from RRDTool. + * @throws RrdException Thrown if invalid string is supplied. + */ + public void addArchive(String rrdToolArcDef) throws RrdException { + RrdException rrdException = new RrdException( + "Wrong rrdtool-like archive definition: " + rrdToolArcDef); + StringTokenizer tokenizer = new StringTokenizer(rrdToolArcDef, ":"); + if (tokenizer.countTokens() != 5) { + throw rrdException; + } + String[] tokens = new String[5]; + for (int curTok = 0; tokenizer.hasMoreTokens(); curTok++) { + tokens[curTok] = tokenizer.nextToken(); + } + if (!tokens[0].equalsIgnoreCase("RRA")) { + throw rrdException; + } + String consolFun = tokens[1]; + double xff; + try { + xff = Double.parseDouble(tokens[2]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + int steps; + try { + steps = Integer.parseInt(tokens[3]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + int rows; + try { + rows = Integer.parseInt(tokens[4]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + addArchive(new ArcDef(consolFun, xff, steps, rows)); + } + void validate() throws RrdException { if(dsDefs.size() == 0) { |
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv964/src/org/jrobin/graph Modified Files: Gprint.java RrdGraphDefTemplate.java RrdGraphDef.java TimeAxisUnit.java ValueGrid.java ValueFormatter.java Source.java Log Message: JRobin 1.3.1 - Improved Value Grid calculation - Updated RrdGraph for read-only opening of RRD files - Added STEP and SAMPLES rpn values - Added first_day_of_week XML option for time_axis node - Added gprint overload with specific base value - Added TOTAL aggregate for datasources - Improved graph XML parsing (legend and comments do not get trimmed any longer) Index: ValueFormatter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueFormatter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ValueFormatter.java 7 Nov 2003 14:42:02 -0000 1.2 --- ValueFormatter.java 26 Apr 2004 22:28:33 -0000 1.3 *************** *** 207,211 **** * @param scaleIndex Forced index of the SI unit in the <code>PREFIXES</code> table. <code>NO_SCALE</code> if not forced. */ ! private void scaleValue( int scaleIndex) { double absValue = Math.abs(value); --- 207,211 ---- * @param scaleIndex Forced index of the SI unit in the <code>PREFIXES</code> table. <code>NO_SCALE</code> if not forced. */ ! private void scaleValue( int scaleIndex ) { double absValue = Math.abs(value); Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ValueGrid.java 21 Apr 2004 09:49:01 -0000 1.6 --- ValueGrid.java 26 Apr 2004 22:28:33 -0000 1.7 *************** *** 147,151 **** // Keep the rest of division - double left = shifted % scaleValues[scaleIndex + 1]; shifted = shifted / scaleValues[++scaleIndex]; --- 147,150 ---- *************** *** 161,173 **** } - left = left / scaleValues[scaleIndex]; - - - if ( left == 0.00 ) { - scaleIndex--; - mod = 1.0; - } - - // Create nice grid based on 'fixed' ranges if ( shifted <= 1.5 ) --- 160,163 ---- Index: RrdGraphDefTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDefTemplate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdGraphDefTemplate.java 8 Mar 2004 13:14:39 -0000 1.4 --- RrdGraphDefTemplate.java 26 Apr 2004 22:28:33 -0000 1.5 *************** *** 96,99 **** --- 96,101 ---- * <date_format>HH:mm</date_format> * <center_labels>true</center_labels> + * <!-- ALLOWED DAYS OF WEEK: MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY --> + * <first_day_of_week>MONDAY</first_day_of_week> * </time_axis> * <time_axis_label>time</time_axis_label> *************** *** 357,373 **** String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend"); rrdGraphDef.stack(datasource, color, legend); } else if(nodeName.equals("comment")) { ! String comment = getValue(childs[i]); rrdGraphDef.comment(comment); } else if(nodeName.equals("gprint")) { ! validateTagsOnlyOnce(childs[i], new String[] { "datasource", "cf", "format" }); ! String datasource = getChildValue(childs[i], "datasource"); ! String consolFun = getChildValue(childs[i], "cf"); ! String format = getChildValue(childs[i], "format"); ! rrdGraphDef.gprint(datasource, consolFun, format); } else if(nodeName.equals("hrule")) { --- 359,379 ---- String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend", false); rrdGraphDef.stack(datasource, color, legend); } else if(nodeName.equals("comment")) { ! String comment = getValue(childs[i], false); rrdGraphDef.comment(comment); } else if(nodeName.equals("gprint")) { ! validateTagsOnlyOnce(childs[i], new String[] { "datasource", "cf", "format", "base" }); ! String datasource = getChildValue(childs[i], "datasource"); ! String consolFun = getChildValue(childs[i], "cf"); ! String format = getChildValue(childs[i], "format", false ); ! ! if ( !hasChildNode(childs[i], "base") ) ! rrdGraphDef.gprint( datasource, consolFun, format ); ! else ! rrdGraphDef.gprint( datasource, consolFun, format, getChildValueAsDouble(childs[i], "base") ); } else if(nodeName.equals("hrule")) { *************** *** 376,380 **** String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend"); int width = 1; try { --- 382,386 ---- String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend", false); int width = 1; try { *************** *** 389,393 **** String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend"); int width = 1; try { --- 395,399 ---- String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend", false); int width = 1; try { *************** *** 406,410 **** String colorStr = getChildValue(lineNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(lineNode, "legend"); // line width is not mandatory int width = 1; --- 412,416 ---- String colorStr = getChildValue(lineNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(lineNode, "legend", false); // line width is not mandatory int width = 1; *************** *** 427,431 **** String colorStr = getChildValue(lineNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(lineNode, "legend"); int width = 1; try { --- 433,437 ---- String colorStr = getChildValue(lineNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(lineNode, "legend", false); int width = 1; try { *************** *** 446,450 **** String colorStr = getChildValue(areaNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(areaNode, "legend"); rrdGraphDef.area(datasource, color, legend); } --- 452,456 ---- String colorStr = getChildValue(areaNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(areaNode, "legend", false); rrdGraphDef.area(datasource, color, legend); } *************** *** 462,466 **** String colorStr = getChildValue(areaNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(areaNode, "legend"); rrdGraphDef.area(gc1, v1, gc2, v2, color, legend); } --- 468,472 ---- String colorStr = getChildValue(areaNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(areaNode, "legend", false); rrdGraphDef.area(gc1, v1, gc2, v2, color, legend); } *************** *** 645,657 **** validateTagsOnlyOnce(optionNode, new String[] { "min_grid_time_unit", "min_grid_unit_steps", "maj_grid_time_unit", ! "maj_grid_unit_steps", "date_format", "center_labels" }); ! int unit1 = resolveUnit(getChildValue(optionNode, "min_grid_time_unit")); ! int step1 = getChildValueAsInt(optionNode, "min_grid_unit_steps"); ! int unit2 = resolveUnit(getChildValue(optionNode, "maj_grid_time_unit")); ! int step2 = getChildValueAsInt(optionNode, "maj_grid_unit_steps"); ! String format = getChildValue(optionNode, "date_format"); ! boolean center = getChildValueAsBoolean(optionNode, "center_labels"); ! rrdGraphDef.setTimeAxis(unit1, step1, unit2, step2, format, center); } // TIME AXIS LABEL --- 651,674 ---- validateTagsOnlyOnce(optionNode, new String[] { "min_grid_time_unit", "min_grid_unit_steps", "maj_grid_time_unit", ! "maj_grid_unit_steps", "date_format", "center_labels", "first_day_of_week" }); ! ! if ( hasChildNode( optionNode, "min_grid_time_unit" ) ) ! { ! int unit1 = resolveUnit(getChildValue(optionNode, "min_grid_time_unit")); ! int step1 = getChildValueAsInt(optionNode, "min_grid_unit_steps"); ! int unit2 = resolveUnit(getChildValue(optionNode, "maj_grid_time_unit")); ! int step2 = getChildValueAsInt(optionNode, "maj_grid_unit_steps"); ! String format = getChildValue(optionNode, "date_format"); ! boolean center = getChildValueAsBoolean(optionNode, "center_labels"); ! rrdGraphDef.setTimeAxis(unit1, step1, unit2, step2, format, center); ! } ! ! // Determine first day of the week ! if ( hasChildNode( optionNode, "first_day_of_week" ) ) ! { ! int dow = resolveDayUnit( getChildValue(optionNode, "first_day_of_week") ); ! rrdGraphDef.setFirstDayOfWeek( dow ); ! } } // TIME AXIS LABEL *************** *** 721,724 **** --- 738,769 ---- } } + + private int resolveDayUnit( String unit ) { + if ( unit.equalsIgnoreCase("monday") ) { + return TimeAxisUnit.MONDAY; + } + else if ( unit.equalsIgnoreCase("tuesday") ) { + return TimeAxisUnit.TUESDAY; + } + else if ( unit.equalsIgnoreCase("wednesday") ) { + return TimeAxisUnit.WEDNESDAY; + } + else if ( unit.equalsIgnoreCase("thursday") ) { + return TimeAxisUnit.THURSDAY; + } + else if ( unit.equalsIgnoreCase("friday") ) { + return TimeAxisUnit.FRIDAY; + } + else if ( unit.equalsIgnoreCase("saturday") ) { + return TimeAxisUnit.SATURDAY; + } + else if ( unit.equalsIgnoreCase("sunday") ) { + return TimeAxisUnit.SUNDAY; + } + else { + throw new IllegalArgumentException( "Invalid day unit specified: " + unit ); + } + + } private void resolveSpan(Node spanNode) throws RrdException { Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Source.java 19 Apr 2004 22:35:00 -0000 1.6 --- Source.java 26 Apr 2004 22:28:33 -0000 1.7 *************** *** 55,59 **** private long lastTime = 0; private long totalTime = 0; - double testval = 0; // ================================================================ --- 55,58 ---- *************** *** 129,133 **** case AGG_TOTAL: ! return testval; } --- 128,132 ---- case AGG_TOTAL: ! return totalValue; } *************** *** 164,168 **** { long timeDelta = time - lastTime; ! testval += value; totalValue += timeDelta * ( value + lastValue ) / 2.0; totalTime += timeDelta; --- 163,167 ---- { long timeDelta = time - lastTime; ! totalValue += timeDelta * ( value + lastValue ) / 2.0; totalTime += timeDelta; Index: TimeAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeAxisUnit.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TimeAxisUnit.java 21 Apr 2004 09:49:01 -0000 1.6 --- TimeAxisUnit.java 26 Apr 2004 22:28:33 -0000 1.7 *************** *** 69,72 **** --- 69,76 ---- "SECOND", "MINUTE", "HOUR", "DAY", "WEEK", "MONTH", "YEAR" }; + + private static final String[] DAY_NAMES = { + "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" + }; private int minGridTimeUnit = HOUR; // minor grid *************** *** 282,285 **** --- 286,293 ---- return UNIT_NAMES[unit]; } + + static String getDayName( int dayIndex ) { + return DAY_NAMES[dayIndex]; + } void exportXmlTemplate(XmlWriter xml) { *************** *** 291,294 **** --- 299,306 ---- xml.writeTag("date_format", getDateFormat().toPattern()); xml.writeTag("center_labels", getCenterLabels()); + + if ( firstDayOfWeek != MONDAY ) + xml.writeTag( "first_day_of_week", getDayName(firstDayOfWeek) ); + xml.closeTag(); // time_axis } Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RrdGraphDef.java 21 Apr 2004 09:48:58 -0000 1.9 --- RrdGraphDef.java 26 Apr 2004 22:28:33 -0000 1.10 *************** *** 916,919 **** --- 916,937 ---- addComment( new Gprint(sourceName, consolFun, format) ); } + + /** + * <p>See the {@link #gprint(java.lang.String, java.lang.String, java.lang.String) gprint()} method for more details. + * This gprint implementation allows a specific base value to be specified for this particular gprint only, the specified + * base value can be different than the global base value used through the entire graph for the drawing. The resulting value of the gprint + * will be formatted according to the specified base value. + * </p> + * + * @param sourceName Graph source name + * @param consolFun Consolidation function to be used for calculation ("AVERAGE", "MIN", "MAX" or "LAST") + * @param format Format string. For example: "speed is @5.2 @sbits/sec@c", "temperature = @0 degrees" + * @param base Base value for the formatting, defaults to the graphing base value + * @throws RrdException Thrown in case of JRobin specific error + */ + public void gprint( String sourceName, String consolFun, String format, double base ) throws RrdException + { + addComment( new Gprint(sourceName, consolFun, format, base) ); + } /** Index: Gprint.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Gprint.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Gprint.java 19 Apr 2004 22:35:00 -0000 1.4 --- Gprint.java 26 Apr 2004 22:28:33 -0000 1.5 *************** *** 52,55 **** --- 52,56 ---- private int numDec = 3; // Show 3 decimal values by default private int strLen = -1; + private double baseValue = -1; // Default: use global base value private boolean normalScale = false; private boolean uniformScale = false; *************** *** 62,67 **** * Constructs a Gprint object based on a string of text (with a specific placement * marker in), a source from which to retrieve a value, and a consolidation function that ! * specifies which value to retrieve. Possible consolidation functions are <code>AVERAGE, MAX, MIN, FIRST</code> ! * and <code>LAST</code>. * @param sourceName Name of the datasource from which to retrieve the consolidated value. * @param consolFunc Consolidation function to use. --- 63,68 ---- * Constructs a Gprint object based on a string of text (with a specific placement * marker in), a source from which to retrieve a value, and a consolidation function that ! * specifies which value to retrieve. Possible consolidation functions are <code>AVERAGE, MAX, MIN, FIRST, LAST</code> ! * and <code>TOTAL</code>. * @param sourceName Name of the datasource from which to retrieve the consolidated value. * @param consolFunc Consolidation function to use. *************** *** 94,97 **** --- 95,116 ---- } + /** + * Constructs a Gprint object based on a string of text (with a specific placement + * marker in), a source from which to retrieve a value, and a consolidation function that + * specifies which value to retrieve. Possible consolidation functions are <code>AVERAGE, MAX, MIN, FIRST</code> + * and <code>LAST</code>. + * @param sourceName Name of the datasource from which to retrieve the consolidated value. + * @param consolFunc Consolidation function to use. + * @param text String of text with a placement marker for the resulting value. + * @param base Base value to use for formatting the value that needs to be printed. + * @throws RrdException Thrown in case of a JRobin specific error. + */ + Gprint( String sourceName, String consolFunc, String text, double base ) throws RrdException + { + this( sourceName, consolFunc, text ); + + baseValue = base; + } + // ================================================================ *************** *** 114,117 **** --- 133,141 ---- double value = sources[ ((Integer) sourceIndex.get(sourceName)).intValue() ].getAggregate( aggregate ); + // See if we need to use a specific value for the formatting + double oldBase = vFormat.getBase(); + if ( baseValue != -1 ) + vFormat.setBase( baseValue ); + vFormat.setFormat( value, numDec, strLen ); vFormat.setScaling( normalScale, uniformScale ); *************** *** 131,134 **** --- 155,162 ---- oList.set( i, str ); } + + // Reset the base value of the formatter + if ( baseValue != -1 ) + vFormat.setBase( oldBase ); } catch (Exception e) { *************** *** 183,186 **** --- 211,216 ---- xml.writeTag("cf", Source.aggregates[aggregate]); xml.writeTag("format", text); + if ( baseValue != -1 ) + xml.writeTag( "base", baseValue ); xml.closeTag(); // gprint } |
From: Arne V. <cob...@us...> - 2004-04-26 22:28:42
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv964/src/org/jrobin/core Modified Files: Util.java XmlTemplate.java Log Message: JRobin 1.3.1 - Improved Value Grid calculation - Updated RrdGraph for read-only opening of RRD files - Added STEP and SAMPLES rpn values - Added first_day_of_week XML option for time_axis node - Added gprint overload with specific base value - Added TOTAL aggregate for datasources - Improved graph XML parsing (legend and comments do not get trimmed any longer) Index: XmlTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/XmlTemplate.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** XmlTemplate.java 15 Mar 2004 10:40:50 -0000 1.6 --- XmlTemplate.java 26 Apr 2004 22:28:33 -0000 1.7 *************** *** 178,188 **** } ! protected String getChildValue(Node parentNode, String childName) throws RrdException { ! String value = Util.Xml.getChildValue(parentNode, childName); return resolveMappings(value); } ! protected String getValue(Node parentNode) { ! String value = Util.Xml.getValue(parentNode); return resolveMappings(value); } --- 178,196 ---- } ! protected String getChildValue( Node parentNode, String childName ) throws RrdException { ! return getChildValue( parentNode, childName, true ); ! } ! ! protected String getChildValue(Node parentNode, String childName, boolean trim) throws RrdException { ! String value = Util.Xml.getChildValue(parentNode, childName, trim); return resolveMappings(value); } ! protected String getValue( Node parentNode ) { ! return getValue( parentNode, true ); ! } ! ! protected String getValue(Node parentNode, boolean trim ) { ! String value = Util.Xml.getValue(parentNode, trim); return resolveMappings(value); } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Util.java 22 Mar 2004 09:20:12 -0000 1.13 --- Util.java 26 Apr 2004 22:28:33 -0000 1.14 *************** *** 351,360 **** } ! 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 getValue(child); } } --- 351,365 ---- } ! // -- 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++) { Node child = children.item(i); if (child.getNodeName().equals(childName)) { ! return getValue(child, trim); } } *************** *** 362,371 **** } static String getValue(Node node) { String value = null; Node child = node.getFirstChild(); if(child != null) { value = child.getNodeValue(); ! if(value != null) { value = value.trim(); } --- 367,381 ---- } + // -- 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(); if(child != null) { value = child.getNodeValue(); ! if( value != null && trimValue ) { value = value.trim(); } |
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31473/org/jrobin/core Modified Files: RrdDb.java RrdDouble.java RrdDoubleArray.java RrdFile.java RrdInt.java RrdLong.java RrdPrimitive.java RrdString.java Log Message: Slightly faster openning of RRD files Index: RrdString.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdString.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdString.java 20 Apr 2004 08:20:29 -0000 1.6 --- RrdString.java 21 Apr 2004 10:56:55 -0000 1.7 *************** *** 39,45 **** void loadCache() throws IOException { - RrdFile rrdFile = getRrdFile(); if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { ! rrdFile.seek(getPointer()); char[] c = new char[SIZE]; for(int i = 0; i < SIZE; i++) { --- 39,44 ---- void loadCache() throws IOException { if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { ! restorePosition(); char[] c = new char[SIZE]; for(int i = 0; i < SIZE; i++) { *************** *** 59,64 **** value = value.trim(); if(!cached || !cache.equals(value)) { ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); for(int i = 0; i < SIZE; i++) { if(i < value.length()) { --- 58,62 ---- value = value.trim(); if(!cached || !cache.equals(value)) { ! restorePosition(); for(int i = 0; i < SIZE; i++) { if(i < value.length()) { Index: RrdLong.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdLong.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdLong.java 20 Apr 2004 08:20:29 -0000 1.6 --- RrdLong.java 21 Apr 2004 10:56:55 -0000 1.7 *************** *** 39,45 **** void loadCache() throws IOException { - RrdFile rrdFile = getRrdFile(); if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { ! rrdFile.seek(getPointer()); cache = rrdFile.readLong(); cached = true; --- 39,44 ---- void loadCache() throws IOException { if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { ! restorePosition(); cache = rrdFile.readLong(); cached = true; *************** *** 54,59 **** void set(long value) throws IOException { if(!cached || cache != value) { ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); rrdFile.writeLong(value); cache = value; --- 53,57 ---- void set(long value) throws IOException { if(!cached || cache != value) { ! restorePosition(); rrdFile.writeLong(value); cache = value; Index: RrdPrimitive.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdPrimitive.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdPrimitive.java 29 Mar 2004 14:38:28 -0000 1.4 --- RrdPrimitive.java 21 Apr 2004 10:56:55 -0000 1.5 *************** *** 28,42 **** abstract class RrdPrimitive { ! ! private RrdUpdater parent; private long pointer; private int byteCount; ! protected boolean cached = false; RrdPrimitive(RrdUpdater parent, int byteCount) throws IOException { ! this.parent = parent; // this will set pointer and byteCount ! parent.getRrdFile().allocate(this, byteCount); } --- 28,42 ---- abstract class RrdPrimitive { ! private long pointer; private int byteCount; ! RrdFile rrdFile; ! boolean cached = false; RrdPrimitive(RrdUpdater parent, int byteCount) throws IOException { ! rrdFile = parent.getRrdFile(); // this will set pointer and byteCount ! rrdFile.allocate(this, byteCount); } *************** *** 57,89 **** } - RrdUpdater getParent() { - return parent; - } - - RrdFile getRrdFile() { - return parent.getRrdFile(); - } - byte[] readBytes() throws IOException { byte[] b = new byte[byteCount]; ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(pointer); int bytesRead = rrdFile.read(b); ! if(bytesRead != byteCount) { ! throw new IOException("Could not read enough bytes (" + byteCount + ! " bytes requested, " + bytesRead + " bytes obtained"); ! } return b; } void writeBytes(byte[] b) throws IOException { ! if(b.length != byteCount) { ! throw new IOException("Invalid number of bytes supplied (" + b.length + ! "), exactly " + byteCount + " needed"); ! } ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(pointer); rrdFile.write(b); } } --- 57,82 ---- } byte[] readBytes() throws IOException { byte[] b = new byte[byteCount]; ! restorePosition(); int bytesRead = rrdFile.read(b); ! assert bytesRead == byteCount: "Could not read enough bytes (" + byteCount + ! " bytes requested, " + bytesRead + " bytes obtained"; return b; } void writeBytes(byte[] b) throws IOException { ! assert b.length == byteCount: "Invalid number of bytes supplied (" + b.length + ! "), exactly " + byteCount + " needed"; ! restorePosition(); rrdFile.write(b); } + final void restorePosition() throws IOException { + rrdFile.seek(pointer); + } + + final void restorePosition(int unitIndex, int unitSize) throws IOException { + rrdFile.seek(pointer + unitIndex * unitSize); + } } Index: RrdInt.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdInt.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdInt.java 20 Apr 2004 08:20:29 -0000 1.6 --- RrdInt.java 21 Apr 2004 10:56:54 -0000 1.7 *************** *** 39,45 **** void loadCache() throws IOException { - RrdFile rrdFile = getRrdFile(); if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { ! rrdFile.seek(getPointer()); cache = rrdFile.readInt(); cached = true; --- 39,44 ---- void loadCache() throws IOException { if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { ! restorePosition(); cache = rrdFile.readInt(); cached = true; *************** *** 54,59 **** void set(int value) throws IOException { if(!cached || cache != value) { ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); rrdFile.writeInt(value); cache = value; --- 53,57 ---- void set(int value) throws IOException { if(!cached || cache != value) { ! restorePosition(); rrdFile.writeInt(value); cache = value; Index: RrdDoubleArray.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDoubleArray.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdDoubleArray.java 26 Mar 2004 08:47:05 -0000 1.4 --- RrdDoubleArray.java 21 Apr 2004 10:56:54 -0000 1.5 *************** *** 50,55 **** assert index + count <= length: "Invalid robin index supplied: index=" + index + ", count=" + count + ", length=" + length; ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer() + index * RrdDouble.SIZE); rrdFile.writeDouble(value, count); } --- 50,54 ---- assert index + count <= length: "Invalid robin index supplied: index=" + index + ", count=" + count + ", length=" + length; ! restorePosition(index, RrdDouble.SIZE); rrdFile.writeDouble(value, count); } *************** *** 57,62 **** double get(int index) throws IOException { assert index < length: "Invalid index supplied: " + index + ", length=" + length; ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer() + index * RrdDouble.SIZE); return rrdFile.readDouble(); } --- 56,60 ---- double get(int index) throws IOException { assert index < length: "Invalid index supplied: " + index + ", length=" + length; ! restorePosition(index, RrdDouble.SIZE); return rrdFile.readDouble(); } *************** *** 65,70 **** assert index + count <= length: "Invalid index/count supplied: " + index + "/" + count + " (length=" + length + ")"; ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer() + index * RrdDouble.SIZE); return rrdFile.readDouble(count); } --- 63,67 ---- assert index + count <= length: "Invalid index/count supplied: " + index + "/" + count + " (length=" + length + ")"; ! restorePosition(index, RrdDouble.SIZE); return rrdFile.readDouble(count); } Index: RrdFile.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFile.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdFile.java 20 Apr 2004 08:20:29 -0000 1.7 --- RrdFile.java 21 Apr 2004 10:56:54 -0000 1.8 *************** *** 31,36 **** import java.nio.channels.FileChannel; import java.nio.channels.FileLock; - import java.util.LinkedList; - import java.util.List; /** --- 31,34 ---- *************** *** 56,61 **** private String filePath; private FileLock fileLock; ! private List primitives = new LinkedList(); private int rrdMode; RrdFile(String filePath, int rrdMode, boolean readOnly) throws IOException { --- 54,60 ---- private String filePath; private FileLock fileLock; ! private int rrdMode; + private long nextPointer = 0L; RrdFile(String filePath, int rrdMode, boolean readOnly) throws IOException { *************** *** 110,140 **** } - RrdPrimitive getPrimitive(int index) { - return (RrdPrimitive) primitives.get(index); - } - void allocate(RrdPrimitive primitive, int byteCount) throws IOException { ! long pointer = getNextPointer(); ! primitive.setPointer(pointer); primitive.setByteCount(byteCount); ! primitives.add(primitive); } - private long getNextPointer() { - long pointer = 0; - int count = primitives.size(); - if(count > 0) { - RrdPrimitive lastPrimitive = getPrimitive(count - 1); - pointer = lastPrimitive.getPointer() + lastPrimitive.getByteCount(); - } - return pointer; - } - void truncateFile() throws IOException { ! setLength(getNextPointer()); } boolean isEndReached() throws IOException { ! return getNextPointer() == length(); } --- 109,124 ---- } void allocate(RrdPrimitive primitive, int byteCount) throws IOException { ! primitive.setPointer(nextPointer); primitive.setByteCount(byteCount); ! nextPointer += byteCount; } void truncateFile() throws IOException { ! setLength(nextPointer); } boolean isEndReached() throws IOException { ! return nextPointer == length(); } Index: RrdDouble.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDouble.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdDouble.java 20 Apr 2004 08:20:29 -0000 1.6 --- RrdDouble.java 21 Apr 2004 10:56:44 -0000 1.7 *************** *** 39,45 **** void loadCache() throws IOException { - RrdFile rrdFile = getRrdFile(); if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { ! rrdFile.seek(getPointer()); cache = rrdFile.readDouble(); cached = true; --- 39,44 ---- void loadCache() throws IOException { if(rrdFile.getRrdMode() == RrdFile.MODE_RESTORE) { ! restorePosition(); cache = rrdFile.readDouble(); cached = true; *************** *** 54,59 **** void set(double value) throws IOException { if(!cached || cache != value) { ! RrdFile rrdFile = getRrdFile(); ! rrdFile.seek(getPointer()); rrdFile.writeDouble(value); cache = value; --- 53,57 ---- void set(double value) throws IOException { if(!cached || cache != value) { ! restorePosition(); rrdFile.writeDouble(value); cache = value; Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** RrdDb.java 20 Apr 2004 08:20:29 -0000 1.14 --- RrdDb.java 21 Apr 2004 10:56:37 -0000 1.15 *************** *** 75,78 **** --- 75,80 ---- private Archive[] archives; + private boolean closed = false; + /** * <p>Constructor used to create new RRD file from the definition. New RRD file structure is specified by object of class *************** *** 251,257 **** */ public synchronized void close() throws IOException { ! if(file != null) { file.close(); ! file = null; } } --- 253,259 ---- */ public synchronized void close() throws IOException { ! if(!closed) { file.close(); ! closed = true; } } *************** *** 262,266 **** */ public boolean isClosed() { ! return file == null; } --- 264,268 ---- */ public boolean isClosed() { ! return closed; } |