示例#1
0
        /**
         * <p>Constructor used to create RRD files from external file sources with a backend type
         * different from default. Supported external file sources are:</p>
         * <p/>
         * <ul>
         * <li>RRDTool/Rrd4n XML file dumps (i.e files created with <code>rrdtool dump</code> command).
         * <li>RRDTool binary files.
         * </ul>
         * <p/>
         * <p>Rrd4n and RRDTool use the same format for XML dump and this constructor should be used to
         * (re)create Rrd4n RRD files from XML dumps. First, dump the content of a RRDTool
         * RRD file (use command line):</p>
         * <p/>
         * <pre>
         * rrdtool dump original.rrd > original.xml
         * </pre>
         * <p/>
         * <p>Than, use the file <code>original.xml</code> to create Rrd4n RRD file named
         * <code>copy.rrd</code>:</p>
         * <p/>
         * <pre>
         * RrdDb rrd = new RrdDb("copy.rrd", "original.xml");
         * </pre>
         * <p/>
         * <p>or:</p>
         * <p/>
         * <pre>
         * RrdDb rrd = new RrdDb("copy.rrd", "xml:/original.xml");
         * </pre>
         * <p/>
         * <p>See documentation for {@link #dumpXml(String) dumpXml()} method
         * to see how to convert Rrd4n files to RRDTool's format.</p>
         * <p/>
         * <p>To read RRDTool files directly, specify <code>rrdtool:/</code> prefix in the
         * <code>externalPath</code> argument. For example, to create Rrd4n compatible file named
         * <code>copy.rrd</code> from the file <code>original.rrd</code> created with RRDTool, use
         * the following code:</p>
         * <p/>
         * <pre>
         * RrdDb rrd = new RrdDb("copy.rrd", "rrdtool:/original.rrd");
         * </pre>
         * <p/>
         * <p>Note that the prefix <code>xml:/</code> or <code>rrdtool:/</code> is necessary to distinguish
         * between XML and RRDTool's binary sources. If no prefix is supplied, XML format is assumed</p>
         *
         * @param rrdPath      Path to RRD which will be created
         * @param externalPath Path to an external file which should be imported, with an optional
         *                     <code>xml:/</code> or <code>rrdtool:/</code> prefix.
         * @param factory      Backend factory which will be used to create storage (backend) for this RRD.
         * @Thrown in case of I/O error
         * @see RrdBackendFactory
         */
        public RrdDb(String rrdPath, String externalPath, RrdBackendFactory factory)
        {
            DataImporter reader;

            //    if (externalPath.startsWith(PREFIX_RRDTool)) {
            //        String rrdToolPath = externalPath.substring(PREFIX_RRDTool.Length);
            //        reader = new RrdToolReader(rrdToolPath);
            //    }
            //    else if (externalPath.startsWith(PREFIX_XML)) {
            //        externalPath = externalPath.substring(PREFIX_XML.Length);
            //        reader = new XmlReader(externalPath);
            //    }
            //    else {
            reader = new XmlImporter(externalPath);
            //    }
            backend = factory.open(rrdPath, false);
            try {
                backend.setLength(reader.getEstimatedSize());
                // create header
                header = new Header(this, reader);
                //        // create Datasources
                //        Datasources = new Datasource[reader.getDsCount()];
                //        for (int i = 0; i < Datasources.Length; i++) {
                //            Datasources[i] = new Datasource(this, reader, i);
                //        }
                //        // create archives
                //        archives = new Archive[reader.getArcCount()];
                //        for (int i = 0; i < archives.Length; i++) {
                //            archives[i] = new Archive(this, reader, i);
                //        }
                reader.release();
                // XMLReader is a rather huge DOM tree, release memory ASAP
                reader = null;
            }
            catch (IOException e)
            {
                backend.close();
                throw e;
            }
        }
示例#2
0
文件: RrdDb.cs 项目: mujing/rrd4net
 /**
  * <p>Constructor used to create RRD files from external file sources with a backend type
  * different from default. Supported external file sources are:</p>
  * <p/>
  * <ul>
  * <li>RRDTool/Rrd4n XML file dumps (i.e files created with <code>rrdtool dump</code> command).
  * <li>RRDTool binary files.
  * </ul>
  * <p/>
  * <p>Rrd4n and RRDTool use the same format for XML dump and this constructor should be used to
  * (re)create Rrd4n RRD files from XML dumps. First, dump the content of a RRDTool
  * RRD file (use command line):</p>
  * <p/>
  * <pre>
  * rrdtool dump original.rrd > original.xml
  * </pre>
  * <p/>
  * <p>Than, use the file <code>original.xml</code> to create Rrd4n RRD file named
  * <code>copy.rrd</code>:</p>
  * <p/>
  * <pre>
  * RrdDb rrd = new RrdDb("copy.rrd", "original.xml");
  * </pre>
  * <p/>
  * <p>or:</p>
  * <p/>
  * <pre>
  * RrdDb rrd = new RrdDb("copy.rrd", "xml:/original.xml");
  * </pre>
  * <p/>
  * <p>See documentation for {@link #dumpXml(String) dumpXml()} method
  * to see how to convert Rrd4n files to RRDTool's format.</p>
  * <p/>
  * <p>To read RRDTool files directly, specify <code>rrdtool:/</code> prefix in the
  * <code>externalPath</code> argument. For example, to create Rrd4n compatible file named
  * <code>copy.rrd</code> from the file <code>original.rrd</code> created with RRDTool, use
  * the following code:</p>
  * <p/>
  * <pre>
  * RrdDb rrd = new RrdDb("copy.rrd", "rrdtool:/original.rrd");
  * </pre>
  * <p/>
  * <p>Note that the prefix <code>xml:/</code> or <code>rrdtool:/</code> is necessary to distinguish
  * between XML and RRDTool's binary sources. If no prefix is supplied, XML format is assumed</p>
  *
  * @param rrdPath      Path to RRD which will be created
  * @param externalPath Path to an external file which should be imported, with an optional
  *                     <code>xml:/</code> or <code>rrdtool:/</code> prefix.
  * @param factory      Backend factory which will be used to create storage (backend) for this RRD.
  * @Thrown in case of I/O error
  * @see RrdBackendFactory
  */
 public RrdDb(String rrdPath, String externalPath, RrdBackendFactory factory) {
     DataImporter reader;
 //    if (externalPath.startsWith(PREFIX_RRDTool)) {
 //        String rrdToolPath = externalPath.substring(PREFIX_RRDTool.Length);
 //        reader = new RrdToolReader(rrdToolPath);
 //    }
 //    else if (externalPath.startsWith(PREFIX_XML)) {
 //        externalPath = externalPath.substring(PREFIX_XML.Length);
 //        reader = new XmlReader(externalPath);
 //    }
 //    else {
         reader = new XmlImporter(externalPath);
 //    }
     backend = factory.open(rrdPath, false);
     try {
         backend.setLength(reader.getEstimatedSize());
         // create header
         header = new Header(this, reader);
 //        // create Datasources
 //        Datasources = new Datasource[reader.getDsCount()];
 //        for (int i = 0; i < Datasources.Length; i++) {
 //            Datasources[i] = new Datasource(this, reader, i);
 //        }
 //        // create archives
 //        archives = new Archive[reader.getArcCount()];
 //        for (int i = 0; i < archives.Length; i++) {
 //            archives[i] = new Archive(this, reader, i);
 //        }
         reader.release();
         // XMLReader is a rather huge DOM tree, release memory ASAP
         reader = null;
     }
     catch (IOException e)
     {
        backend.close();
        throw e;
     }
 }