KickJava   Java API By Example, From Geeks To Geeks.

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


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.GarbageCollectorMXBean JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27 import javax.management.MBeanServerFactory JavaDoc;
28 import javax.management.MBeanServer JavaDoc;
29 import javax.management.j2ee.statistics.Statistic JavaDoc;
30 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
31 import com.sun.enterprise.admin.monitor.stats.JVMGarbageCollectorStats;
32 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic;
33 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl;
34 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl;
35 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
36 import com.sun.enterprise.admin.monitor.stats.StatisticImpl;
37 import com.sun.enterprise.util.i18n.StringManager;
38
39 public class JVMGarbageCollectorStatsImpl implements JVMGarbageCollectorStats {
40     
41     private GenericStatsImpl baseStatsImpl;
42     private static final String JavaDoc STATS_INTERFACE_NAME =
43                         "com.sun.enterprise.admin.monitor.stats.JVMGarbageCollectorStats";
44     //private MBeanServer server;
45
private MutableCountStatistic collectionCount;
46     private MutableCountStatistic collectionTime;
47     private GarbageCollectorMXBean JavaDoc bean;
48     private static final StringManager localStrMgr =
49                 StringManager.getManager(JVMMemoryStatsImpl.class);
50     
51
52     /** Creates a new instance of JVMGarbageCollectorStatsImpl */
53     public JVMGarbageCollectorStatsImpl(GarbageCollectorMXBean JavaDoc gcMXBean) {
54         
55         try {
56             baseStatsImpl = new GenericStatsImpl(STATS_INTERFACE_NAME, this);
57         } catch(Exception JavaDoc e) {
58             
59         }
60         // get an instance of the MBeanServer
61
// server = getPlatformMBeanServer();
62
bean = gcMXBean;
63         
64         // initialize all the MutableStatistic Classes
65
initializeStatistics();
66     }
67     
68     public CountStatistic JavaDoc getCollectionTime() {
69         long collTime = bean.getCollectionTime();
70         collectionTime.setCount (collTime);
71         return (CountStatistic JavaDoc)collectionTime.unmodifiableView ();
72     }
73     
74     public CountStatistic JavaDoc getCollectionCount() {
75         long collCount = bean.getCollectionCount();
76         collectionCount.setCount (collCount);
77         return (CountStatistic JavaDoc)collectionCount.unmodifiableView ();
78     }
79     
80     /**
81      * This method can be used to retrieve all the Statistics, exposed
82      * by this implementation of Stats
83      * @return Statistic[]
84      */

85     public Statistic JavaDoc[] getStatistics() {
86         return baseStatsImpl.getStatistics();
87     }
88     
89     /**
90      * queries for a Statistic by name.
91      * @return Statistic
92      */

93     public Statistic JavaDoc getStatistic(String JavaDoc str) {
94         return baseStatsImpl.getStatistic(str);
95     }
96     
97     /**
98      * returns an array of names of all the Statistics, that can be
99      * retrieved from this implementation of Stats
100      * @return String[]
101      */

102     public String JavaDoc[] getStatisticNames() {
103         return baseStatsImpl.getStatisticNames();
104     }
105     
106     private void initializeStatistics() {
107         
108        // Initialize the MutableCountStatistic for CollectionCount
109
CountStatistic JavaDoc c = new CountStatisticImpl(
110             localStrMgr.getString("monitor.stats.collection_cnt"),
111             StatisticImpl.DEFAULT_UNIT,
112             localStrMgr.getString("monitor.stats.collection_cnt_desc"));
113         collectionCount = new MutableCountStatisticImpl(c);
114
115        // Initialize the MutableCountStatistic for CollectionTime
116
c = new CountStatisticImpl(
117             localStrMgr.getString("monitor.stats.collection_time"),
118             localStrMgr.getString("monitor.stats.milli_sec_units"),
119             localStrMgr.getString("monitor.stats.collection_time_desc"));
120         collectionTime = new MutableCountStatisticImpl(c);
121     }
122 }
123
Popular Tags