diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2007-11-28 20:38:58 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2007-11-28 20:38:58 +0000 |
commit | de5073829367a0573cf11a2985069f7007834b48 (patch) | |
tree | 0caa7d389dfd472c4e45a4223af60bd0eaac06b8 | |
parent | 01332a3a7f7095b703bc492b9d47baf5e02cd292 (diff) | |
download | classpath-de5073829367a0573cf11a2985069f7007834b48.tar.gz |
2007-11-28 Andrew John Hughes <gnu_andrew@member.fsf.org>
* examples/gnu/classpath/examples/management/TestBeans.java:
Simplify so that it uses the management server.
* examples/gnu/classpath/examples/management/TestClassLoading.java:
Test via the server and the proxy as well.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | examples/gnu/classpath/examples/management/TestBeans.java | 29 | ||||
-rw-r--r-- | examples/gnu/classpath/examples/management/TestClassLoading.java | 36 |
3 files changed, 50 insertions, 22 deletions
@@ -1,3 +1,10 @@ +2007-11-28 Andrew John Hughes <gnu_andrew@member.fsf.org> + + * examples/gnu/classpath/examples/management/TestBeans.java: + Simplify so that it uses the management server. + * examples/gnu/classpath/examples/management/TestClassLoading.java: + Test via the server and the proxy as well. + 2007-11-27 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java, diff --git a/examples/gnu/classpath/examples/management/TestBeans.java b/examples/gnu/classpath/examples/management/TestBeans.java index ad8234555..381dca448 100644 --- a/examples/gnu/classpath/examples/management/TestBeans.java +++ b/examples/gnu/classpath/examples/management/TestBeans.java @@ -22,34 +22,19 @@ package gnu.classpath.examples.management; import java.lang.management.ManagementFactory; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.util.Set; -import javax.management.DynamicMBean; +import javax.management.MBeanServer; +import javax.management.ObjectName; public class TestBeans { public static void main(String[] args) throws Exception { - List beans = new ArrayList(); - /* FIXME: When there's a server, this will be easier... :) */ - beans.add(ManagementFactory.getOperatingSystemMXBean()); - beans.add(ManagementFactory.getRuntimeMXBean()); - beans.add(ManagementFactory.getThreadMXBean()); - beans.add(ManagementFactory.getCompilationMXBean()); - beans.add(ManagementFactory.getClassLoadingMXBean()); - beans.add(ManagementFactory.getMemoryMXBean()); - beans.addAll(ManagementFactory.getMemoryPoolMXBeans()); - beans.addAll(ManagementFactory.getMemoryManagerMXBeans()); - beans.addAll(ManagementFactory.getGarbageCollectorMXBeans()); - Iterator it = beans.iterator(); - while (it.hasNext()) - { - DynamicMBean bean = (DynamicMBean) it.next(); - if (bean != null) - System.out.println(bean.getMBeanInfo()); - } + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + Set<ObjectName> names = server.queryNames(null, null); + for (ObjectName name : names) + System.out.println(server.getMBeanInfo(name)); } } diff --git a/examples/gnu/classpath/examples/management/TestClassLoading.java b/examples/gnu/classpath/examples/management/TestClassLoading.java index 113a4f258..b4e8d9826 100644 --- a/examples/gnu/classpath/examples/management/TestClassLoading.java +++ b/examples/gnu/classpath/examples/management/TestClassLoading.java @@ -23,10 +23,18 @@ package gnu.classpath.examples.management; import java.lang.management.ClassLoadingMXBean; import java.lang.management.ManagementFactory; +import static java.lang.management.ManagementFactory.CLASS_LOADING_MXBEAN_NAME; + +import javax.management.Attribute; +import javax.management.MBeanServer; +import javax.management.ObjectName; + public class TestClassLoading { public static void main(String[] args) + throws Exception { + System.out.println("Testing locally..."); ClassLoadingMXBean bean = ManagementFactory.getClassLoadingMXBean(); System.out.println("Bean: " + bean); System.out.println("Loaded classes: " + bean.getLoadedClassCount()); @@ -37,5 +45,33 @@ public class TestClassLoading System.out.println("Changing verbose setting..."); bean.setVerbose(!verbosity); System.out.println("Verbose class output: " + (bean.isVerbose() ? "yes" : "no")); + System.out.println("Testing via the server..."); + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + ObjectName classBean = new ObjectName(CLASS_LOADING_MXBEAN_NAME); + System.out.println("Bean: " + classBean); + System.out.println("Loaded classes: " + server.getAttribute(classBean, "LoadedClassCount")); + System.out.println("Unloaded classes: " + server.getAttribute(classBean, + "UnloadedClassCount")); + System.out.println("Total loaded classes: " + server.getAttribute(classBean, + "TotalLoadedClassCount")); + verbosity = (Boolean) server.getAttribute(classBean, "Verbose"); + System.out.println("Verbose class output: " + (verbosity ? "yes" : "no")); + System.out.println("Changing verbose setting..."); + server.setAttribute(classBean, new Attribute("Verbose", !verbosity)); + System.out.println("Verbose class output: " + ((Boolean) + server.getAttribute(classBean, "Verbose") ? + "yes" : "no")); + System.out.println("Testing via the proxy..."); + bean = ManagementFactory.newPlatformMXBeanProxy(server, CLASS_LOADING_MXBEAN_NAME, + ClassLoadingMXBean.class); + System.out.println("Bean: " + bean); + System.out.println("Loaded classes: " + bean.getLoadedClassCount()); + System.out.println("Unloaded classes: " + bean.getUnloadedClassCount()); + System.out.println("Total loaded classes: " + bean.getTotalLoadedClassCount()); + verbosity = bean.isVerbose(); + System.out.println("Verbose class output: " + (verbosity ? "yes" : "no")); + System.out.println("Changing verbose setting..."); + bean.setVerbose(!verbosity); + System.out.println("Verbose class output: " + (bean.isVerbose() ? "yes" : "no")); } } |