/** * 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); } } }
/** * 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; } }
passNext(ACTION.DROP, ref); throw new IllegalStateException("Could not release [" + rrdDb.getPath() + "], the file was never requested"); passNext(ACTION.DROP, ref); throw new IllegalStateException("Could not release [" + rrdDb.getPath() + "], pool corruption"); ref.rrdDb.internalClose(); } finally { passNext(ACTION.DROP, ref); passNext(ACTION.SWAP, ref);
} catch (InterruptedException | RuntimeException e) { passNext(ACTION.SWAP, ref); Thread.currentThread().interrupt(); throw e;
private RrdDb requestRrdDb(RrdDb.Builder builder, URI uri, RrdBackendFactory backend) throws IOException { RrdEntry ref = null; uri = backend.getCanonicalUri(uri); try { ref = requestEmpty(uri); ref.rrdDb = builder.setPath(uri).setBackendFactory(backend).setPool(this).build(); return ref.rrdDb; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("request interrupted for new rrd " + uri, e); } catch (RuntimeException e) { passNext(ACTION.DROP, ref); ref = null; throw e; } finally { if (ref != null) { passNext(ACTION.SWAP, ref); } } }
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; }
RrdDb requestRrdDb(RrdDef rrdDef, RrdBackendFactory backend) throws IOException { RrdEntry ref = null; try { URI uri = backend.getCanonicalUri(rrdDef.getUri()); ref = requestEmpty(uri); ref.rrdDb = RrdDb.getBuilder().setRrdDef(rrdDef).setBackendFactory(backend).setPool(this).build(); return ref.rrdDb; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("request interrupted for new rrdDef " + rrdDef.getPath(), e); } catch (RuntimeException e) { passNext(ACTION.DROP, ref); ref = null; throw e; } finally { if (ref != null) { passNext(ACTION.SWAP, ref); } } }