KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > stats > spi > JVMRuntimeStatsImpl


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 package com.sun.enterprise.admin.monitor.stats.spi;
25 import java.util.ArrayList JavaDoc;
26 import java.lang.management.ManagementFactory JavaDoc;
27 import java.lang.management.RuntimeMXBean JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29 import javax.management.MBeanServerFactory JavaDoc;
30 import javax.management.MBeanServer JavaDoc;
31 import javax.management.j2ee.statistics.Statistic JavaDoc;
32 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
33 import com.sun.enterprise.admin.monitor.stats.StringStatistic;
34 import com.sun.enterprise.admin.monitor.stats.JVMRuntimeStats;
35 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic;
36 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl;
37 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl;
38 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
39 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl;
40 import com.sun.enterprise.util.i18n.StringManager;
41
42 public class JVMRuntimeStatsImpl implements JVMRuntimeStats {
43     
44     private GenericStatsImpl baseStatsImpl;
45     private static final String JavaDoc STATS_INTERFACE_NAME =
46                         "com.sun.enterprise.admin.monitor.stats.JVMRuntimeStats";
47     private MBeanServer JavaDoc server;
48     private MutableCountStatistic upTime;
49     private StringStatistic name;
50     private RuntimeMXBean JavaDoc bean;
51     final long initTime;
52     private static final StringManager localStrMgr =
53                 StringManager.getManager(JVMRuntimeStatsImpl.class);
54     
55
56     /** Creates a new instance of JVMRuntimeStatsImpl */
57     public JVMRuntimeStatsImpl () {
58         
59         initTime = System.currentTimeMillis ();
60         try {
61             baseStatsImpl = new GenericStatsImpl(STATS_INTERFACE_NAME, this);
62         } catch(Exception JavaDoc e) {
63             
64         }
65         // get an instance of the MBeanServer
66
// server = getPlatformMBeanServer();
67
bean = ManagementFactory.getRuntimeMXBean();
68         
69         // initialize all the MutableStatistic Classes
70
initializeStatistics();
71
72     }
73     
74     public StringStatistic getName() {
75         
76         String JavaDoc name = bean.getName();
77         
78         return new StringStatisticImpl(name,
79                    localStrMgr.getString("monitor.stats.name_string"),
80                    localStrMgr.getString("monitor.stats.string_units"),
81                    localStrMgr.getString("monitor.stats.name_of_vm"),
82                    initTime,
83                    System.currentTimeMillis());
84
85     }
86     
87     public StringStatistic getBootClasspath () {
88         
89         String JavaDoc bclasspath = bean.getBootClassPath();
90         
91         return new StringStatisticImpl(bclasspath,
92                localStrMgr.getString("monitor.stats.boot_class_path_string"),
93                localStrMgr.getString("monitor.stats.string_units"),
94                localStrMgr.getString("monitor.stats.name_of_boot_class_path"),
95                initTime,
96                System.currentTimeMillis());
97     }
98     
99     public StringStatistic getClassPath () {
100         
101         String JavaDoc cpath = bean.getClassPath();
102         
103         return new StringStatisticImpl(cpath,
104                localStrMgr.getString("monitor.stats.class_path_string"),
105                localStrMgr.getString("monitor.stats.string_units"),
106                localStrMgr.getString("monitor.stats.name_of_class_path"),
107                initTime,
108                System.currentTimeMillis());
109     }
110     
111     public StringStatistic getInputArguments () {
112         
113         ArrayList JavaDoc inputArgs = new ArrayList JavaDoc();
114         inputArgs.addAll(bean.getInputArguments());
115         
116         return new StringStatisticImpl(inputArgs.toString (),
117                localStrMgr.getString("monitor.stats.input_args_string"),
118                localStrMgr.getString("monitor.stats.string_units"),
119                localStrMgr.getString("monitor.stats.name_of_input_args"),
120                initTime,
121                System.currentTimeMillis());
122     }
123     
124     public StringStatistic getLibraryPath () {
125         
126         String JavaDoc libpath = bean.getLibraryPath();
127         
128         return new StringStatisticImpl(libpath,
129                localStrMgr.getString("monitor.stats.lib_path_string"),
130                localStrMgr.getString("monitor.stats.string_units"),
131                localStrMgr.getString("monitor.stats.name_of_lib_path"),
132                initTime,
133                System.currentTimeMillis());
134     }
135     
136     public StringStatistic getManagementSpecVersion () {
137         
138         String JavaDoc ver = bean.getManagementSpecVersion();
139         
140         return new StringStatisticImpl(ver,
141                localStrMgr.getString("monitor.stats.lib_mgmt_spec_ver"),
142                localStrMgr.getString("monitor.stats.string_units"),
143                localStrMgr.getString("monitor.stats.name_of_mgmt_spec_ver"),
144                initTime,
145                System.currentTimeMillis());
146     }
147     
148     public StringStatistic getSpecName () {
149         
150         String JavaDoc specname = bean.getSpecName();
151         
152         return new StringStatisticImpl(specname,
153                localStrMgr.getString("monitor.stats.spec_name"),
154                localStrMgr.getString("monitor.stats.string_units"),
155                localStrMgr.getString("monitor.stats.name_of_spec"),
156                initTime,
157                System.currentTimeMillis());
158     }
159     
160     public StringStatistic getSpecVendor () {
161         
162         String JavaDoc specvendor = bean.getSpecVendor();
163         
164         return new StringStatisticImpl(specvendor,
165                localStrMgr.getString("monitor.stats.spec_vendor"),
166                localStrMgr.getString("monitor.stats.string_units"),
167                localStrMgr.getString("monitor.stats.name_of_spec_vendor"),
168                initTime,
169                System.currentTimeMillis());
170     }
171     
172     public StringStatistic getSpecVersion () {
173         
174         String JavaDoc specver = bean.getSpecVersion();
175         
176         return new StringStatisticImpl(specver,
177                localStrMgr.getString("monitor.stats.jvm_spec_vers"),
178                localStrMgr.getString("monitor.stats.string_units"),
179                localStrMgr.getString("monitor.stats.name_of_jvm_spec_vers"),
180                initTime,
181                System.currentTimeMillis());
182     }
183     
184     public CountStatistic JavaDoc getUptime () {
185         long u = bean.getUptime();
186         upTime.setCount (u);
187         return (CountStatistic JavaDoc)upTime.unmodifiableView ();
188     }
189     
190     public StringStatistic getVmName () {
191         
192         String JavaDoc vmname = bean.getVmName();
193         
194         return new StringStatisticImpl(vmname,
195                localStrMgr.getString("monitor.stats.jvm_impl_name"),
196                localStrMgr.getString("monitor.stats.string_units"),
197                localStrMgr.getString("monitor.stats.name_of_jvm_impl"),
198                initTime,
199                System.currentTimeMillis());
200     }
201     
202     public StringStatistic getVmVendor () {
203         
204         String JavaDoc vmvendor = bean.getVmVendor();
205         
206         return new StringStatisticImpl(vmvendor,
207                localStrMgr.getString("monitor.stats.jvm_vendor"),
208                localStrMgr.getString("monitor.stats.string_units"),
209                localStrMgr.getString("monitor.stats.name_of_jvm_vendor"),
210                initTime,
211                System.currentTimeMillis());
212     }
213     
214     public StringStatistic getVmVersion () {
215         
216         String JavaDoc vmver = bean.getVmVersion();
217         
218         return new StringStatisticImpl(vmver,
219                localStrMgr.getString("monitor.stats.jvm_vers"),
220                localStrMgr.getString("monitor.stats.string_units"),
221                localStrMgr.getString("monitor.stats.name_of_jvm_vers"),
222                initTime,
223                System.currentTimeMillis());
224     }
225     
226     /**
227      * This method can be used to retrieve all the Statistics, exposed
228      * by this implementation of Stats
229      * @return Statistic[]
230      */

231     public Statistic JavaDoc[] getStatistics() {
232         return baseStatsImpl.getStatistics();
233     }
234     
235     /**
236      * queries for a Statistic by name.
237      * @return Statistic
238      */

239     public Statistic JavaDoc getStatistic(String JavaDoc str) {
240         return baseStatsImpl.getStatistic(str);
241     }
242     
243     /**
244      * returns an array of names of all the Statistics, that can be
245      * retrieved from this implementation of Stats
246      * @return String[]
247      */

248     public String JavaDoc[] getStatisticNames() {
249         return baseStatsImpl.getStatisticNames();
250     }
251     
252     private void initializeStatistics() {
253         
254        // Initialize the MutableCountStatistic for TotalCompilationTime
255
CountStatistic JavaDoc c = new CountStatisticImpl(
256             localStrMgr.getString("monitor.stats.total_compilation_time"),
257             localStrMgr.getString("monitor.stats.milli_sec_units"),
258             localStrMgr.getString("monitor.stats.milli_sec_units_desc"));
259         upTime = new MutableCountStatisticImpl(c);
260     }
261     
262 }
263
Popular Tags