/** * Wait for a empty reference with no usage * @param uri * @return an reference with no usage * @throws IOException * @throws InterruptedException */ private RrdEntry waitEmpty(URI uri) throws IOException, InterruptedException { RrdEntry ref = getEntry(uri, true); try { while (ref.count != 0) { //Not empty, give it back, but wait for signal passNext(ACTION.SWAP, ref); ref.waitempty.await(); ref = getEntry(uri, true); } return ref; } catch (InterruptedException e) { passNext(ACTION.SWAP, ref); Thread.currentThread().interrupt(); throw e; } }
/** * Returns the number of usage for a RRD. * * @param uri RRD's uri for which informations is needed. * @return the number of request for this file * @throws java.io.IOException if any. */ public int getOpenCount(URI uri) throws IOException { RrdEntry ref = null; try { ref = getEntry(uri, false); if (ref == null) return 0; else { return ref.count; } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("getOpenCount interrupted", e); } finally { if (ref != null) { passNext(ACTION.SWAP, ref); } } }
RrdEntry ref = null; try { ref = getEntry(dburi, false); } catch (InterruptedException e) { Thread.currentThread().interrupt();
RrdDb requestRrdDb(URI uri, RrdBackendFactory factory) throws IOException { uri = factory.getCanonicalUri(uri); RrdEntry ref = null; try { ref = getEntry(uri, true); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("request interrupted for " + uri, e); } //Someone might have already open it, rechecks if (ref.count == 0) { try { ref.rrdDb = RrdDb.getBuilder().setPath(factory.getPath(uri)).setBackendFactory(factory).setPool(this).build(); } catch (IOException | RuntimeException e) { passNext(ACTION.DROP, ref); throw e; } } ref.count++; passNext(ACTION.SWAP, ref); return ref.rrdDb; }