📄 rrddbpool.java
字号:
// proveActive();
// if (rrdDb == null) {
// // we don't want NullPointerException
// return;
// }
// if (rrdDb.isClosed()) {
// throw new RrdException("File " + rrdDb.getPath() + " already closed");
// }
// String canonicalPath = getCanonicalPath(rrdDb.getPath());
// if (rrdMap.containsKey(canonicalPath)) {
// RrdEntry rrdEntry = rrdMap.get(canonicalPath);
// reportRelease(canonicalPath, rrdEntry);
//// debug("RELEASED: " + rrdEntry.dump());
// } else {
// throw new RrdException("RRD file " + rrdDb.getPath() + " not in the pool");
// }
// // notify waiting threads
// notifyAll();
// }
//
// /**
// * This method runs garbage collector in a separate thread. If the number of
// * open RRD files kept in the pool is too big (greater than number
// * returned from {@link #getCapacity getCapacity()}), garbage collector will try
// * to close and remove RRD files with a reference count equal to zero.
// * Never call this method directly.
// */
// public void run() {
//// debug("GC: started");
// while (active) {
// synchronized (this) {
// if (rrdMap.size() >= capacity && rrdIdleMap.size() > 0) {
// try {
// String canonicalPath = rrdIdleMap.keySet().iterator().next();
// RrdEntry rrdEntry = rrdIdleMap.get(canonicalPath);
//// debug("GC: closing " + rrdEntry.dump());
// removeRrdEntry(canonicalPath, rrdEntry);
// } catch (IOException e) {
// e.printStackTrace();
// }
// notifyAll();
// }
// else {
// try {
//// debug("GC: waiting");
// wait();
//// debug("GC: running");
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// }
// }
// }
//
// protected void finalize() throws IOException {
// close();
// }
//
// /**
// * Clears the internal state of the pool entirely. All open RRD files are closed.
// *
// * @throws IOException Thrown in case of I/O related error.
// */
// public synchronized void reset() throws IOException {
// Iterator<RrdEntry> it = rrdMap.values().iterator();
// while (it.hasNext()) {
// RrdEntry rrdEntry = it.next();
// rrdEntry.closeRrdDb();
// }
// rrdMap.clear();
// rrdIdleMap.clear();
//// debug("Pool cleared");
// }
//
// /**
// * Closes the pool and all RRD files currently held in the pool.
// * No further operations on the pool are allowed.
// * @throws IOException Thrown in case of I/O error.
// */
// public synchronized void close() throws IOException {
// if(active) {
// active = false;
// reset();
//// debug("The pool is closed.");
// }
// else {
//// debug("The pool is already closed!");
// }
// }
//
// private static String getCanonicalPath(String path) throws IOException {
// return Util.getCanonicalPath(path);
// }
//
// static void debug(String msg) {
// if (DEBUG) {
// System.out.println("POOL: " + msg);
// }
// }
//
// /**
// * Returns the internal state of the pool. Useful for debugging purposes.
// *
// * @param dumpFiles <code>true</code>, if dumped information should contain paths to open files
// * currently held in the pool, <code>false</code> otherwise
// * @return Internal pool state (with an optional list of open RRD files and
// * the current number of usages for each one).
// * @throws IOException Thrown in case of I/O error.
// */
// public synchronized String dump(boolean dumpFiles) throws IOException {
// StringBuffer buff = new StringBuffer();
// buff.append("==== POOL DUMP ===========================\n");
// buff.append("open=" + rrdMap.size() + ", idle=" + rrdIdleMap.size() + "\n");
// buff.append("capacity=" + capacity + ", " + "maxUsedCapacity=" + maxUsedCapacity + "\n");
// buff.append("hits=" + poolHitsCount + ", " + "requests=" + poolRequestsCount + "\n");
// buff.append("efficiency=" + getPoolEfficiency() + "\n");
// if(dumpFiles) {
// buff.append("---- CACHED FILES ------------------------\n");
// Iterator<RrdEntry> it = rrdMap.values().iterator();
// while (it.hasNext()) {
// RrdEntry rrdEntry = it.next();
// buff.append(rrdEntry.dump() + "\n");
// }
// }
// return buff.toString();
// }
//
// /**
// * Returns the complete internal state of the pool. Useful for debugging purposes.
// *
// * @return Internal pool state (with a list of open RRD files and the current number of
// * usages for each one).
// * @throws IOException Thrown in case of I/O error.
// */
// public synchronized String dump() throws IOException {
// return dump(true);
// }
//
// /**
// * Returns paths to all open files currently held in the pool.
// * @return An array containing open file paths.
// */
// public synchronized String[] getCachedFilePaths() {
// Set<String> keySet = rrdMap.keySet();
// int n = keySet.size(), i = 0;
// String[] files = new String[n];
// Iterator<String> it = keySet.iterator();
// while(it.hasNext()) {
// files[i++] = it.next();
// }
// return files;
// }
//
// /**
// * Returns maximum number of internally open RRD files
// * which still does not force garbage collector to run.
// *
// * @return Desired nuber of open files held in the pool.
// */
// public synchronized int getCapacity() {
// return capacity;
// }
//
// /**
// * Sets maximum number of internally open RRD files
// * which still does not force garbage collector to run.
// *
// * @param capacity Desired number of open files to hold in the pool
// */
// public synchronized void setCapacity(int capacity) {
// this.capacity = capacity;
//// debug("Capacity set to: " + capacity);
// }
//
// private RrdBackendFactory getFactory() throws RrdException {
// if (factory == null) {
// factory = RrdBackendFactory.getDefaultFactory();
// if (!(factory instanceof RrdFileBackendFactory)) {
// factory = null;
// throw new RrdException(
// "RrdDbPool cannot work with factories not derived from RrdFileBackendFactory");
// }
// }
// return factory;
// }
//
// private class RrdEntry {
// private RrdDb rrdDb;
// private int usageCount = 1;
//
// public RrdEntry(RrdDb rrdDb) {
// this.rrdDb = rrdDb;
// }
//
// RrdDb getRrdDb() {
// return rrdDb;
// }
//
// int reportUsage() {
// assert usageCount >= 0: "Unexpected reportUsage count: " + usageCount;
// return ++usageCount;
// }
//
// int reportRelease() {
// assert usageCount > 0: "Unexpected reportRelease count: " + usageCount;
// return --usageCount;
// }
//
// boolean isInUse() {
// return usageCount > 0;
// }
//
// void closeRrdDb() throws IOException {
// rrdDb.close();
// }
//
// String dump() throws IOException {
// String canonicalPath = getCanonicalPath(rrdDb.getPath());
// return canonicalPath + " [" + usageCount + "]";
// }
// }
//
// /**
// * Calculates pool's efficency ratio. The ratio is obtained by dividing the number of
// * RrdDb requests served from the internal pool of open RRD files
// * with the number of total RrdDb requests.
// *
// * @return Pool's efficiency ratio as a double between 1 (best) and 0 (worst).
// * If no RrdDb reference was ever requested, 1 would be returned.
// */
// public synchronized double getPoolEfficiency() {
// if (poolRequestsCount == 0) {
// return 1.0;
// }
// double ratio = (double) poolHitsCount / (double) poolRequestsCount;
// // round to 3 decimal digits
// return Math.round(ratio * 1000.0) / 1000.0;
// }
//
// /**
// * Returns the number of RRD requests served from the internal pool of open RRD files
// *
// * @return The number of pool "hits".
// */
// public synchronized int getPoolHitsCount() {
// return poolHitsCount;
// }
//
// /**
// * Returns the total number of RRD requests successfully served by this pool.
// *
// * @return Total number of RRD requests
// */
// public synchronized int getPoolRequestsCount() {
// return poolRequestsCount;
// }
//
// /**
// * Returns the maximum number of open RRD files over the lifetime
// * of the pool.
// * @return maximum number of open RRD files.
// */
// public synchronized int getMaxUsedCapacity() {
// return maxUsedCapacity;
// }
//
// /**
// * Checks the internal behaviour of the pool. See {@link #setLimitedCapacity(boolean)} for
// * more information.
// *
// * @return <code>true</code> if the pool is 'flexible' (by not imposing the strict
// * limit on the number of simultaneously open files), <code>false</code> otherwise.
// */
// public synchronized boolean isLimitedCapacity() {
// return limitedCapacity;
// }
//
// /**
// * Sets the behaviour of the pool. If <code>true</code> is passed as argument, the pool will never
// * open more than {@link #getCapacity()} files at any time. If set to <code>false</code>,
// * the pool might keep more open files, but only for a short period of time. This method might be
// * useful if you want avoid OS limits when it comes to the number of simultaneously open files.<p>
// *
// * By default, the pool behaviour is 'flexible' (<code>limitedCapacity</code> property defaults
// * to false<p>
// *
// * @param limitedCapacity <code>true</code> if the pool should be 'flexible' (not imposing the strict
// * limit on the number of simultaneously open files), <code>false</code> otherwise.
// */
// public synchronized void setLimitedCapacity(boolean limitedCapacity) {
// this.limitedCapacity = limitedCapacity;
// }
//
// private void proveActive() throws IOException {
// if(!active) {
// throw new IOException("RrdDbPool is already closed");
// }
// }
//
// /**
// * Checks if the pool is active. You can request RrdDb references only from the active pool. The
// * pool is deactived when the {@link #close()} method is called.
// * @return <code>true</code> if active, <code>false</code> otherwise.
// */
// public synchronized boolean isActive() {
// return active;
// }
//}
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -