KickJava   Java API By Example, From Geeks To Geeks.

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


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.ClassLoadingMXBean 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.JVMClassLoadingStats;
33 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic;
34 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl;
35 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl;
36 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
37 import com.sun.enterprise.admin.monitor.stats.StatisticImpl;
38 import com.sun.enterprise.util.i18n.StringManager;
39
40
41 public class JVMClassLoadingStatsImpl implements JVMClassLoadingStats {
42     
43     private GenericStatsImpl baseStatsImpl;
44     private static final String JavaDoc STATS_INTERFACE_NAME =
45                         "com.sun.enterprise.admin.monitor.stats.JVMClassLoadingStats";
46     //private MBeanServer server;
47
private MutableCountStatistic loadedClassCount;
48     private MutableCountStatistic unloadedClassCount;
49     private MutableCountStatistic totalLoadedClassCount;
50     private ClassLoadingMXBean JavaDoc bean;
51     private static final StringManager localStrMgr =
52                 StringManager.getManager(JVMClassLoadingStatsImpl.class);
53
54     
55
56     /** Creates a new instance of JVMClassLoadingStatsImpl */
57     public JVMClassLoadingStatsImpl() {
58         
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.getClassLoadingMXBean();
67         
68         // initialize all the MutableStatistic Classes
69
initializeStatistics();
70
71     }
72     
73     public CountStatistic JavaDoc getTotalLoadedClassCount() {
74         long classCount = bean.getTotalLoadedClassCount();
75         totalLoadedClassCount.setCount (classCount);
76         return (CountStatistic JavaDoc)totalLoadedClassCount.unmodifiableView ();
77     }
78     
79     public CountStatistic JavaDoc getLoadedClassCount() {
80         long classCount = bean.getLoadedClassCount();
81         loadedClassCount.setCount (classCount);
82         return (CountStatistic JavaDoc)loadedClassCount.unmodifiableView ();
83     }
84
85     public CountStatistic JavaDoc getUnloadedClassCount() {
86         long classCount = bean.getUnloadedClassCount();
87         unloadedClassCount.setCount (classCount);
88         return (CountStatistic JavaDoc)unloadedClassCount.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 TotalLoadedClassCount
120
CountStatistic JavaDoc c = new CountStatisticImpl(
121             localStrMgr.getString("monitor.stats.total_classes_load"),
122             StatisticImpl.DEFAULT_UNIT,
123             localStrMgr.getString("monitor.stats.total_classes_load_desc"));
124         totalLoadedClassCount = new MutableCountStatisticImpl(c);
125
126        // Initialize the MutableCountStatistic for LoadedClassCount
127
c = new CountStatisticImpl(
128             localStrMgr.getString("monitor.stats.classes_loaded"),
129             StatisticImpl.DEFAULT_UNIT,
130             localStrMgr.getString("monitor.stats.classes_loaded_desc"));
131         loadedClassCount = new MutableCountStatisticImpl(c);
132
133        // Initialize the MutableCountStatistic for UnLoadedClassCount
134
c = new CountStatisticImpl(
135             localStrMgr.getString("monitor.stats.classes_unloaded"),
136             StatisticImpl.DEFAULT_UNIT,
137             localStrMgr.getString("monitor.stats.classes_unloaded_desc"));
138         unloadedClassCount = new MutableCountStatisticImpl(c);
139     }
140     
141 }
142
Popular Tags