From 2e17b9cded4b5dff6fc0a7c07708260c16334ebd Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 15 Jun 2005 00:24:33 +0000 Subject: [PATCH] simply counter management by removing it when we are done with it --- .../java/src/net/hyperic/sigar/win32/Pdh.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/bindings/java/src/net/hyperic/sigar/win32/Pdh.java b/bindings/java/src/net/hyperic/sigar/win32/Pdh.java index 4a51cdf0..6d714b55 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/Pdh.java +++ b/bindings/java/src/net/hyperic/sigar/win32/Pdh.java @@ -8,8 +8,6 @@ public class Pdh extends Win32Bindings { private long h_query; // Handle to the query private String hostname = null; - private long h_counter = -1l; // Handle to the counter - public Pdh() throws Win32Exception { h_query = pdhOpenQuery(); } @@ -28,11 +26,6 @@ public class Pdh extends Win32Bindings { } public synchronized void close() throws Win32Exception { - if (h_counter != -1l) { - pdhRemoveCounter(h_counter); - h_counter = -1l; - } - if (h_query != -1l) { pdhCloseQuery(h_query); h_query = -1l; @@ -62,14 +55,12 @@ public class Pdh extends Win32Bindings { pdhConnectMachine(this.hostname); } - if (h_counter != -1l) { - pdhRemoveCounter(h_counter); - h_counter = -1l; + long counter = pdhAddCounter(h_query, path); + try { + return pdhGetValue(h_query, counter, format); + } finally { + pdhRemoveCounter(counter); } - - h_counter = pdhAddCounter(h_query, path); - - return pdhGetValue(h_query, h_counter, format); } public static String[] getInstances(String path) throws Win32Exception {