KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.management.ManagementFactory JavaDoc;
26 import java.lang.management.CompilationMXBean JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import javax.management.MBeanServerFactory JavaDoc;
29 import javax.management.MBeanServer JavaDoc;
30 import javax.management.j2ee.statistics.Statistic JavaDoc;
31 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
32 import com.sun.enterprise.admin.monitor.stats.StringStatistic;
33 import com.sun.enterprise.admin.monitor.stats.JVMCompilationStats;
34 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic;
35 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl;
36 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl;
37 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
38 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl;
39 import com.sun.enterprise.util.i18n.StringManager;
40
41 public class JVMCompilationStatsImpl implements JVMCompilationStats {
42     
43     private GenericStatsImpl baseStatsImpl;
44     private static final String JavaDoc STATS_INTERFACE_NAME =
45                         "com.sun.enterprise.admin.monitor.stats.JVMCompilationStats";
46     private MBeanServer JavaDoc server;
47     private MutableCountStatistic compileTime;
48     private StringStatistic name;
49     private CompilationMXBean JavaDoc bean;
50     final long initTime;
51     private static final StringManager localStrMgr =
52                 StringManager.getManager(JVMCompilationStatsImpl.class);
53     
54
55     /** Creates a new instance of JVMCompilationStatsImpl */
56     public JVMCompilationStatsImpl() {
57         
58         initTime = System.currentTimeMillis ();
59         try {
60             baseStatsImpl = new GenericStatsImpl(STATS_INTERFACE_NAME, this);
61         } catch(Exception JavaDoc e) {
62             
63         }
64         // get an instance of the MBeanServer
65
// server = getPlatformMBeanServer();
66
bean = ManagementFactory.getCompilationMXBean();
67         
68         // initialize all the MutableStatistic Classes
69
initializeStatistics();
70
71     }
72     
73     public StringStatistic getName() {
74         
75         String JavaDoc name = bean.getName();
76         
77         return new StringStatisticImpl(name,
78                    localStrMgr.getString("monitor.stats.name_string"),
79                    localStrMgr.getString("monitor.stats.string_units"),
80                    localStrMgr.getString("monitor.stats.name_of_jit_compiler"),
81                    initTime,
82                    System.currentTimeMillis());
83     }
84     
85     public CountStatistic JavaDoc getTotalCompilationTime() {
86         long cTime = bean.getTotalCompilationTime();
87         compileTime.setCount (cTime);
88         return (CountStatistic JavaDoc)compileTime.unmodifiableView ();
89     }
90     
91     /**
92      * This method can be used to retrieve all the Statistics, exposed
93      * by this implementation of Stats
94      * @return Statistic[]
95      */

96     public Statistic JavaDoc[] getStatistics() {
97         return baseStatsImpl.getStatistics();
98     }
99     
100     /**
101      * queries for a Statistic by name.
102      * @return Statistic
103      */

104     public Statistic JavaDoc getStatistic(String JavaDoc str) {
105         return baseStatsImpl.getStatistic(str);
106     }
107     
108     /**
109      * returns an array of names of all the Statistics, that can be
110      * retrieved from this implementation of Stats
111      * @return String[]
112      */

113     public String JavaDoc[] getStatisticNames() {
114         return baseStatsImpl.getStatisticNames();
115     }
116     
117     private void initializeStatistics() {
118         
119        // Initialize the MutableCountStatistic for TotalCompilationTime
120
CountStatistic JavaDoc c = new CountStatisticImpl(
121             localStrMgr.getString("monitor.stats.total_compilation_time"),
122             localStrMgr.getString("monitor.stats.milli_sec_units"),
123             localStrMgr.getString("monitor.stats.total_compilation_time_desc"));
124         compileTime = new MutableCountStatisticImpl(c);
125     }
126     
127 }
128
Popular Tags