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;
}
}
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;
}
Aggregations