KickJava   Java API By Example, From Geeks To Geeks.

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


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.OperatingSystemMXBean 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.JVMOperatingSystemStats;
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.admin.monitor.stats.StatisticImpl;
40 import com.sun.enterprise.util.i18n.StringManager;
41
42 public class JVMOperatingSystemStatsImpl implements JVMOperatingSystemStats {
43     
44     private GenericStatsImpl baseStatsImpl;
45     private static final String JavaDoc STATS_INTERFACE_NAME =
46                         "com.sun.enterprise.admin.monitor.stats.JVMOperatingSystemStats";
47     private MBeanServer JavaDoc server;
48     private MutableCountStatistic availProcs;
49     private StringStatistic name;
50     private OperatingSystemMXBean JavaDoc bean;
51     final long initTime;
52     private static final StringManager localStrMgr =
53                 StringManager.getManager(JVMOperatingSystemStatsImpl.class);
54     
55
56     /** Creates a new instance of JVMOperatingSystemStatsImpl */
57     public JVMOperatingSystemStatsImpl () {
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.getOperatingSystemMXBean();
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_os"),
82                    initTime,
83                    System.currentTimeMillis());
84     }
85     
86     public StringStatistic getArch () {
87         
88         String JavaDoc arch = bean.getArch();
89         
90         return new StringStatisticImpl(arch,
91                    localStrMgr.getString("monitor.stats.arch_string"),
92                    localStrMgr.getString("monitor.stats.string_units"),
93                    localStrMgr.getString("monitor.stats.arch_of_os"),
94                    initTime,
95                    System.currentTimeMillis());
96     }
97     
98     public CountStatistic JavaDoc getAvailableProcessors () {
99         long procs = bean.getAvailableProcessors();
100         availProcs.setCount (procs);
101         return (CountStatistic JavaDoc)availProcs.unmodifiableView ();
102     }
103     
104     public StringStatistic getVersion () {
105         
106         String JavaDoc version = bean.getVersion();
107         
108         return new StringStatisticImpl(version,
109                    localStrMgr.getString("monitor.stats.vers_string"),
110                    localStrMgr.getString("monitor.stats.string_units"),
111                    localStrMgr.getString("monitor.stats.vers_of_os"),
112                    initTime,
113                    System.currentTimeMillis());
114     }
115     
116     
117     /**
118      * This method can be used to retrieve all the Statistics, exposed
119      * by this implementation of Stats
120      * @return Statistic[]
121      */

122     public Statistic JavaDoc[] getStatistics() {
123         return baseStatsImpl.getStatistics();
124     }
125     
126     /**
127      * queries for a Statistic by name.
128      * @return Statistic
129      */

130     public Statistic JavaDoc getStatistic(String JavaDoc str) {
131         return baseStatsImpl.getStatistic(str);
132     }
133     
134     /**
135      * returns an array of names of all the Statistics, that can be
136      * retrieved from this implementation of Stats
137      * @return String[]
138      */

139     public String JavaDoc[] getStatisticNames() {
140         return baseStatsImpl.getStatisticNames();
141     }
142     
143     private void initializeStatistics() {
144         
145        // Initialize the MutableCountStatistic for AvailableProcessors
146
CountStatistic JavaDoc c = new CountStatisticImpl(
147             localStrMgr.getString("monitor.stats.avail_procs"),
148             StatisticImpl.DEFAULT_UNIT,
149             localStrMgr.getString("monitor.stats.avail_procs_desc"));
150         availProcs = new MutableCountStatisticImpl(c);
151     }
152 }
153
Popular Tags