KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > jvm > ClassReporter


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ClassReporter.java
26  *
27  * Created on July 26, 2005, 1:16 AM
28  */

29
30 package com.sun.enterprise.admin.mbeans.jvm;
31
32 import com.sun.enterprise.util.i18n.StringManager;
33 import java.lang.management.ClassLoadingMXBean JavaDoc;
34 import java.lang.management.CompilationMXBean JavaDoc;
35 import java.lang.management.ManagementFactory JavaDoc;
36 import javax.management.MBeanServerConnection JavaDoc;
37
38 /**
39  */

40 class ClassReporter {
41
42     private final MBeanServerConnection JavaDoc mbsc;
43     private final StringManager sm = StringManager.getManager(ClassReporter.class);
44     public ClassReporter(final MBeanServerConnection JavaDoc mbsc) {
45         this.mbsc = mbsc;
46     }
47     public String JavaDoc getClassReport() throws RuntimeException JavaDoc {
48         try {
49             final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder JavaDoc());
50             final ClassLoadingMXBean JavaDoc clmb = ManagementFactory.newPlatformMXBeanProxy(mbsc,
51                     ManagementFactory.CLASS_LOADING_MXBEAN_NAME, ClassLoadingMXBean JavaDoc.class);
52             sb.append(sm.getString("classloading.info"));
53             sb.append(sm.getString("classes.loaded", clmb.getLoadedClassCount()));
54             sb.append(sm.getString("classes.total", clmb.getTotalLoadedClassCount()));
55             sb.append(sm.getString("classes.unloaded", clmb.getUnloadedClassCount()));
56             
57             final CompilationMXBean JavaDoc cmb = ManagementFactory.newPlatformMXBeanProxy(mbsc,
58                     ManagementFactory.COMPILATION_MXBEAN_NAME, CompilationMXBean JavaDoc.class);
59             sb.append(sm.getString("complilation.info"));
60             sb.append(sm.getString("compilation.monitor.status", cmb.isCompilationTimeMonitoringSupported()));
61             sb.append(sm.getString("jit.compilar.name", cmb.getName()));
62             sb.append(sm.getString("compilation.time", JVMInformationCollector.millis2HoursMinutesSeconds(cmb.getTotalCompilationTime())));
63             return ( sb.toString() );
64         } catch(final Exception JavaDoc e) {
65             throw new RuntimeException JavaDoc(e);
66         }
67     }
68 }
Popular Tags