Merge with trank @ 137446
[official-gcc.git] / libjava / classpath / examples / gnu / classpath / examples / management / TestClassLoading.java
blobb4e8d98268cee6149161a1d4e90e9eac1b0f86fd
1 /* TestClassLoading.java -- Tests the class loading bean.
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath examples.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA. */
21 package gnu.classpath.examples.management;
23 import java.lang.management.ClassLoadingMXBean;
24 import java.lang.management.ManagementFactory;
26 import static java.lang.management.ManagementFactory.CLASS_LOADING_MXBEAN_NAME;
28 import javax.management.Attribute;
29 import javax.management.MBeanServer;
30 import javax.management.ObjectName;
32 public class TestClassLoading
34 public static void main(String[] args)
35 throws Exception
37 System.out.println("Testing locally...");
38 ClassLoadingMXBean bean = ManagementFactory.getClassLoadingMXBean();
39 System.out.println("Bean: " + bean);
40 System.out.println("Loaded classes: " + bean.getLoadedClassCount());
41 System.out.println("Unloaded classes: " + bean.getUnloadedClassCount());
42 System.out.println("Total loaded classes: " + bean.getTotalLoadedClassCount());
43 boolean verbosity = bean.isVerbose();
44 System.out.println("Verbose class output: " + (verbosity ? "yes" : "no"));
45 System.out.println("Changing verbose setting...");
46 bean.setVerbose(!verbosity);
47 System.out.println("Verbose class output: " + (bean.isVerbose() ? "yes" : "no"));
48 System.out.println("Testing via the server...");
49 MBeanServer server = ManagementFactory.getPlatformMBeanServer();
50 ObjectName classBean = new ObjectName(CLASS_LOADING_MXBEAN_NAME);
51 System.out.println("Bean: " + classBean);
52 System.out.println("Loaded classes: " + server.getAttribute(classBean, "LoadedClassCount"));
53 System.out.println("Unloaded classes: " + server.getAttribute(classBean,
54 "UnloadedClassCount"));
55 System.out.println("Total loaded classes: " + server.getAttribute(classBean,
56 "TotalLoadedClassCount"));
57 verbosity = (Boolean) server.getAttribute(classBean, "Verbose");
58 System.out.println("Verbose class output: " + (verbosity ? "yes" : "no"));
59 System.out.println("Changing verbose setting...");
60 server.setAttribute(classBean, new Attribute("Verbose", !verbosity));
61 System.out.println("Verbose class output: " + ((Boolean)
62 server.getAttribute(classBean, "Verbose") ?
63 "yes" : "no"));
64 System.out.println("Testing via the proxy...");
65 bean = ManagementFactory.newPlatformMXBeanProxy(server, CLASS_LOADING_MXBEAN_NAME,
66 ClassLoadingMXBean.class);
67 System.out.println("Bean: " + bean);
68 System.out.println("Loaded classes: " + bean.getLoadedClassCount());
69 System.out.println("Unloaded classes: " + bean.getUnloadedClassCount());
70 System.out.println("Total loaded classes: " + bean.getTotalLoadedClassCount());
71 verbosity = bean.isVerbose();
72 System.out.println("Verbose class output: " + (verbosity ? "yes" : "no"));
73 System.out.println("Changing verbose setting...");
74 bean.setVerbose(!verbosity);
75 System.out.println("Verbose class output: " + (bean.isVerbose() ? "yes" : "no"));