Author: rjung
Date: Sat May 11 10:48:33 2013
New Revision: 1481288
URL: http://svn.apache.org/r1481288
Log:
Make remaining MXBean methods that trigger
an action or change data available in
Diagnostics API.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java?rev=1481288&r1=1481287&r2=1481288&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java Sat May 11
10:48:33 2013
@@ -19,13 +19,18 @@
// XXX TODO: More JavaDoc
// XXX Optional: Add support for com.sun.management specific mbean
//
(http://docs.oracle.com/javase/7/docs/jre/api/management/extension/index.html)
-// XXX Optional: Wire setters to the manager:
-// log level setter, verbose class loading setter,
-// setVerbose() and gc() in MemoryMXBean,
-// resetPeakUsage(), setUsageThreshold() and
-// setCollectionUsageThreshold() in MemoryPoolMXBean,
-// and threadMXBean setters, probably even for
-// com.sun.management like HotSpotDiagnosticMXBean.
+// XXX Optional: Wire additional public static methods implemented here
+// to the manager (think about manager access roles!)
+// setLoggerLevel(),
+// setVerboseClassLoading(),
+// setThreadContentionMonitoringEnabled(),
+// setThreadCpuTimeEnabled(),
+// resetPeakThreadCount(),
+// setVerboseGarbageCollection()
+// gc(),
+// resetPeakUsage(),
+// setUsageThreshold(),
+// setCollectionUsageThreshold()
package org.apache.tomcat.util;
@@ -184,6 +189,84 @@ public class Diagnostics {
}
/**
+ * Set verbose garbage collection logging
+ *
+ * @param verbose whether to enable verbose gc logging
+ */
+ public static void setVerboseGarbageCollection(boolean verbose) {
+ memoryMXBean.setVerbose(verbose);
+ boolean checkValue = memoryMXBean.isVerbose();
+ if (verbose != checkValue) {
+ log.error("Could not set verbose garbage collection logging to " +
verbose +
+ ", got " + checkValue + " instead");
+ }
+ }
+
+ /**
+ * Initiate garbage collection via MX Bean
+ */
+ public static void gc() {
+ memoryMXBean.gc();
+ }
+
+ /**
+ * Reset peak memory usage data in MemoryPoolMXBean
+ *
+ * @param name name of the MemoryPoolMXBean or "all"
+ */
+ public static void resetPeakUsage(String name) {
+ for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
+ if (name.equals("all") || name.equals(mbean.getName())) {
+ mbean.resetPeakUsage();
+ }
+ }
+ }
+
+ /**
+ * Reset peak memory usage data in MemoryPoolMXBean
+ *
+ * @param name name of the MemoryPoolMXBean
+ */
+ public static boolean setUsageThreshold(String name, long threshold) {
+ for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
+ if (name.equals(mbean.getName())) {
+ try {
+ mbean.setUsageThreshold(threshold);
+ return true;
+ } catch (IllegalArgumentException ex) {
+ // IGNORE
+ } catch (UnsupportedOperationException ex) {
+ // IGNORE
+ }
+ return false;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Reset peak memory collection usage data in MemoryPoolMXBean
+ *
+ * @param name name of the MemoryPoolMXBean
+ */
+ public static boolean setCollectionUsageThreshold(String name, long
threshold) {
+ for (MemoryPoolMXBean mbean: memoryPoolMXBeans) {
+ if (name.equals(mbean.getName())) {
+ try {
+ mbean.setCollectionUsageThreshold(threshold);
+ return true;
+ } catch (IllegalArgumentException ex) {
+ // IGNORE
+ } catch (UnsupportedOperationException ex) {
+ // IGNORE
+ }
+ return false;
+ }
+ }
+ return false;
+ }
+
+ /**
* Formats the thread dump header for one thread.
*
* @param ti the ThreadInfo describing the thread
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]