/** * 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 Util.getCanonicalPath(path); }
String getCanonicalPath() throws IOException { return Util.getCanonicalPath(path); }
String getCanonicalPath() throws IOException { return Util.getCanonicalPath(path); }
@Override public int getOpenCount(String path) throws IOException { String canonicalPath = Util.getCanonicalPath(path); RrdEntry ref = rrdMap.get(canonicalPath); if(ref == null) return 0; return ref.count; }
@Override public int getOpenCount(String path) throws IOException { String canonicalPath = Util.getCanonicalPath(path); RrdEntry ref = pool.get(canonicalPath); if(ref == null) return 0; return ref.count.get(); } }
public synchronized RrdDb requestRrdDb(String path, String sourcePath) throws IOException { String canonicalPath = Util.getCanonicalPath(path); while (rrdMap.containsKey(canonicalPath) || rrdMap.size() >= capacity) { try { wait(); } catch (InterruptedException e) { throw new RuntimeException(e); } } RrdDb rrdDb = new RrdDb(canonicalPath, sourcePath); rrdMap.put(canonicalPath, new RrdEntry(rrdDb)); return rrdDb; }
private RrdEntry getEntry(String path) throws IOException { String canonicalPath = Util.getCanonicalPath(path); RrdEntry ref; boolean poollocked = false; try { poolLock.acquire(); poollocked = true; ref = pool.get(canonicalPath); if(ref == null) { ref = new RrdEntry(); pool.put(canonicalPath, ref); } ref.rlock.acquire(); } catch (InterruptedException e) { throw new RuntimeException(e); } finally { if(poollocked) poolLock.release(); } return ref; }
public synchronized void release(RrdDb rrdDb) throws IOException { // null pointer should not kill the thread, just ignore it if (rrdDb == null) { return; } String canonicalPath = Util.getCanonicalPath(rrdDb.getPath()); if (!rrdMap.containsKey(canonicalPath)) { throw new IllegalStateException("Could not release [" + canonicalPath + "], the file was never requested"); } RrdEntry entry = rrdMap.get(canonicalPath); if (--entry.count <= 0) { // no longer used rrdMap.remove(canonicalPath); notifyAll(); entry.rrdDb.close(); } }
public synchronized RrdDb requestRrdDb(RrdDef rrdDef) throws IOException { String canonicalPath = Util.getCanonicalPath(rrdDef.getPath()); while (rrdMap.containsKey(canonicalPath) || rrdMap.size() >= capacity) { try { wait(); } catch (InterruptedException e) { throw new RuntimeException(e); } } RrdDb rrdDb = new RrdDb(rrdDef); rrdMap.put(canonicalPath, new RrdEntry(rrdDb)); return rrdDb; }
public synchronized RrdDb requestRrdDb(String path) throws IOException { String canonicalPath = Util.getCanonicalPath(path); while (!rrdMap.containsKey(canonicalPath) && rrdMap.size() >= capacity) { try { wait(); } catch (InterruptedException e) { throw new RuntimeException(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; } }
private RrdEntry getUnusedEntry(String path) throws IOException { String canonicalPath = Util.getCanonicalPath(path); RrdEntry ref = getEntry(canonicalPath); ref.rlock.release(); //wait until the entry is unused while(true) { try { ref.ulock.acquire(); } catch (InterruptedException e) { throw new RuntimeException("RrdDb acquire interrupted", e); } ref = getEntry(canonicalPath); //Check if ref is still unreferenced if(ref.count.get() == 0) { try { capacity.acquire(); } catch (InterruptedException e) { ref.rlock.release(); ref.ulock.release(); throw new RuntimeException("RrdDb acquire interrupted", e); } return ref; } } }