/** * Requests a RrdDb reference for the given RRD file definition object.<p> * <ul> * <li>If the file with the path specified in the RrdDef object is already open, * the method blocks until the file is closed. * <li>If the file is not already open and the number of already open RRD files is less than * {@link #INITIAL_CAPACITY}, a new RRD file will be created and a its RrdDb reference will be returned. * If the file is not already open and the number of already open RRD files is equal to * {@link #INITIAL_CAPACITY}, the method blocks until some RRD file is closed. * </ul> * * @param rrdDef Definition of the RRD file to be created * @return Reference to the newly created RRD file * @ Thrown in case of I/O error */ public RrdDb requestRrdDb(RrdDef rrdDef) { lock (sync) { String canonicalPath = Util.getCanonicalPath(rrdDef.getPath()); while (rrdMap.ContainsKey(canonicalPath) || rrdMap.Count >= capacity) { Thread.Sleep(10); } RrdDb rrdDb = new RrdDb(rrdDef); rrdMap.Add(canonicalPath, new RrdEntry(rrdDb)); return(rrdDb); } }
/** * Constructor used to create new RRD object from the definition object but with a storage * (backend) different from default. * * <p>Rrd4n uses <i>factories</i> to create RRD backend objecs. There are three different * backend factories supplied with Rrd4n, and each factory has its unique name:</p> * <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/> * <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/> * <p>New RRD file structure is specified with an object of class * {@link 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 * @Thrown in case of I/O error * @see RrdBackendFactory */ public RrdDb(RrdDef rrdDef, RrdBackendFactory factory) { if (!rrdDef.hasDatasources()) { throw new ArgumentException("No RRD Datasource specified. At least one is needed."); } if (!rrdDef.hasArchives()) { throw new ArgumentException("No RRD archive specified. At least one is needed."); } String path = rrdDef.getPath(); backend = factory.open(path, false); try { backend.setLength(rrdDef.getEstimatedSize()); // create header header = new Header(this, rrdDef); // create Datasources DsDef[] dsDefs = rrdDef.getDsDefs(); Datasources = new Datasource[dsDefs.Length]; for (int i = 0; i < dsDefs.Length; i++) { Datasources[i] = new Datasource(this, dsDefs[i]); } // create archives ArcDef[] arcDefs = rrdDef.getArcDefs(); archives = new Archive[arcDefs.Length]; for (int i = 0; i < arcDefs.Length; i++) { archives[i] = new Archive(this, arcDefs[i]); } } catch (IOException e) { backend.close(); throw; } }
/** * Requests a RrdDb reference for the given RRD file definition object.<p> * <ul> * <li>If the file with the path specified in the RrdDef object is already open, * the method blocks until the file is closed. * <li>If the file is not already open and the number of already open RRD files is less than * {@link #INITIAL_CAPACITY}, a new RRD file will be created and a its RrdDb reference will be returned. * If the file is not already open and the number of already open RRD files is equal to * {@link #INITIAL_CAPACITY}, the method blocks until some RRD file is closed. * </ul> * * @param rrdDef Definition of the RRD file to be created * @return Reference to the newly created RRD file * @ Thrown in case of I/O error */ public RrdDb requestRrdDb(RrdDef rrdDef) { lock (sync) { String canonicalPath = Util.getCanonicalPath(rrdDef.getPath()); while (rrdMap.ContainsKey(canonicalPath) || rrdMap.Count >= capacity) { Thread.Sleep(10); } RrdDb rrdDb = new RrdDb(rrdDef); rrdMap.Add(canonicalPath, new RrdEntry(rrdDb)); return rrdDb; } }