Search in sources :

Example 36 with RrdException

use of org.jrobin.core.RrdException in project i2p.i2p by i2p.

the class RrdDbPool method requestRrdDb.

/**
 * Requests a RrdDb reference for the given RRD file path.<p>
 * <ul>
 * <li>If the file is already open, previously returned RrdDb reference will be returned. Its usage count
 * will be incremented by one.
 * <li>If the file is not already open and the number of already open RRD files is less than
 * {@link #INITIAL_CAPACITY}, the file will be open and a new 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 path Path to existing RRD file
 * @return reference for the give RRD file
 * @throws IOException  Thrown in case of I/O error
 * @throws RrdException Thrown in case of JRobin specific error
 */
public synchronized RrdDb requestRrdDb(String path) throws IOException, RrdException {
    String canonicalPath = Util.getCanonicalPath(path);
    while (!rrdMap.containsKey(canonicalPath) && rrdMap.size() >= capacity) {
        try {
            wait();
        } catch (InterruptedException e) {
            throw new RrdException(e);
        }
    }
    if (rrdMap.containsKey(canonicalPath)) {
        // already open, just increase usage count
        RrdEntry entry = rrdMap.get(canonicalPath);
        entry.count++;
        return entry.rrdDb;
    } else {
        // not open, open it now and add to the map
        RrdDb rrdDb = new RrdDb(canonicalPath);
        rrdMap.put(canonicalPath, new RrdEntry(rrdDb));
        return rrdDb;
    }
}
Also used : RrdException(org.jrobin.core.RrdException)

Example 37 with RrdException

use of org.jrobin.core.RrdException in project i2p.i2p by i2p.

the class RrdDbPool method requestRrdDb.

/**
 * 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
 * @throws IOException  Thrown in case of I/O error
 * @throws RrdException Thrown in case of JRobin specific error
 */
public synchronized RrdDb requestRrdDb(RrdDef rrdDef) throws IOException, RrdException {
    String canonicalPath = Util.getCanonicalPath(rrdDef.getPath());
    while (rrdMap.containsKey(canonicalPath) || rrdMap.size() >= capacity) {
        try {
            wait();
        } catch (InterruptedException e) {
            throw new RrdException(e);
        }
    }
    RrdDb rrdDb = new RrdDb(rrdDef);
    rrdMap.put(canonicalPath, new RrdEntry(rrdDb));
    return rrdDb;
}
Also used : RrdException(org.jrobin.core.RrdException)

Aggregations

RrdException (org.jrobin.core.RrdException)37 Node (org.w3c.dom.Node)13 IOException (java.io.IOException)10 Map (java.util.Map)4 Date (java.util.Date)3 FetchData (org.jrobin.core.FetchData)3 RrdDb (org.jrobin.core.RrdDb)3 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)3 Source (org.opennms.netmgt.measurements.model.Source)3 File (java.io.File)2 Calendar (java.util.Calendar)2 JAXBContext (javax.xml.bind.JAXBContext)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 SAXSource (javax.xml.transform.sax.SAXSource)2 TimeParser (org.jrobin.core.timespec.TimeParser)2 TimeSpec (org.jrobin.core.timespec.TimeSpec)2 Color (java.awt.Color)1 Font (java.awt.Font)1 Graphics (java.awt.Graphics)1 BufferedImage (java.awt.image.BufferedImage)1