KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SummaryReporter.java
26  *
27  * Created on July 26, 2005, 2:28 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.ManagementFactory JavaDoc;
34 import java.lang.management.OperatingSystemMXBean JavaDoc;
35 import java.lang.management.RuntimeMXBean JavaDoc;
36 import java.util.Map JavaDoc;
37 import java.util.TreeMap JavaDoc;
38 import javax.management.MBeanServerConnection JavaDoc;
39
40 /**
41  */

42 class SummaryReporter {
43     
44     private final MBeanServerConnection JavaDoc mbsc;
45     private final StringManager sm = StringManager.getManager(SummaryReporter.class);
46     private final static String JavaDoc secretProperty = "module.core.status";
47     
48     public SummaryReporter(final MBeanServerConnection JavaDoc mbsc) {
49         this.mbsc = mbsc;
50     }
51     public String JavaDoc getSummaryReport() throws RuntimeException JavaDoc {
52         try {
53             final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder JavaDoc());
54             final OperatingSystemMXBean JavaDoc os = ManagementFactory.newPlatformMXBeanProxy(mbsc,
55                     ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean JavaDoc.class);
56             sb.append(getOSInfo(os));
57             final RuntimeMXBean JavaDoc rt = ManagementFactory.newPlatformMXBeanProxy(mbsc,
58                     ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean JavaDoc.class);
59             sb.append(getVMInfo(rt));
60             return ( sb.toString(secretProperty) );
61         } catch(final Exception JavaDoc e) {
62             throw new RuntimeException JavaDoc(e);
63         }
64     }
65     
66     private String JavaDoc getOSInfo(final OperatingSystemMXBean JavaDoc os) {
67         final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder JavaDoc());
68         sb.append(sm.getString("os.info"));
69         sb.append(sm.getString("os.name", os.getName()));
70         sb.append(sm.getString("os.arch", os.getArch(), os.getVersion()));
71         sb.append(sm.getString("os.nproc", os.getAvailableProcessors()));
72         return ( sb.toString() );
73     }
74     private String JavaDoc getVMInfo(final RuntimeMXBean JavaDoc rt) {
75         final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder JavaDoc());
76         sb.append(sm.getString("rt.info", rt.getName()));
77         sb.append(sm.getString("rt.bcp", rt.getBootClassPath()));
78         sb.append(sm.getString("rt.cp", rt.getClassPath()));
79         sb.append(sm.getString("rt.libpath", rt.getLibraryPath()));
80         sb.append(sm.getString("rt.nvv", rt.getVmName(), rt.getVmVendor(), rt.getVmVersion()));
81         sb.append(getProperties(rt));
82         return ( sb.toString() );
83     }
84     private String JavaDoc getProperties(final RuntimeMXBean JavaDoc rt) {
85         final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder JavaDoc());
86         final Map JavaDoc<String JavaDoc, String JavaDoc> unsorted = rt.getSystemProperties();
87         // I decided to sort this for better readability -- 27 Feb 2006
88
final TreeMap JavaDoc<String JavaDoc, String JavaDoc> props = new TreeMap JavaDoc<String JavaDoc, String JavaDoc>(unsorted);
89         sb.append(sm.getString("rt.sysprops"));
90         for (final String JavaDoc n : props.keySet()) {
91             sb.append(n + " = " + props.get(n));
92         }
93         return ( sb.toString() );
94     }
95 }
96
Popular Tags