KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > stats > PWCKeepAliveStatsImpl


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 package com.sun.enterprise.web.stats;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.text.MessageFormat JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.management.MBeanServerFactory JavaDoc;
31 import javax.management.MBeanServer JavaDoc;
32 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
33 import javax.management.j2ee.statistics.Statistic JavaDoc;
34 import com.sun.logging.LogDomains;
35 import com.sun.enterprise.admin.monitor.stats.PWCKeepAliveStats;
36 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic;
37 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl;
38 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl;
39 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
40
41 /**
42  * @author Jan Luehe
43  */

44 public class PWCKeepAliveStatsImpl implements PWCKeepAliveStats {
45
46     private static Logger JavaDoc _logger
47         = LogDomains.getLogger(LogDomains.WEB_LOGGER);
48
49     private GenericStatsImpl baseStatsImpl;
50
51     private MBeanServer JavaDoc server;
52     private ObjectName JavaDoc keepAliveName;
53
54     private MutableCountStatistic countConnections;
55     private MutableCountStatistic maxConnections;
56     private MutableCountStatistic countHits;
57     private MutableCountStatistic countFlushes;
58     private MutableCountStatistic countRefusals;
59     private MutableCountStatistic countTimeouts;
60     private MutableCountStatistic secondsTimeouts;
61     
62
63     public PWCKeepAliveStatsImpl(String JavaDoc domain) {
64        
65         baseStatsImpl = new GenericStatsImpl(
66             com.sun.enterprise.admin.monitor.stats.PWCKeepAliveStats.class,
67             this);
68         
69         // get an instance of the MBeanServer
70
ArrayList JavaDoc servers = MBeanServerFactory.findMBeanServer(null);
71         if(!servers.isEmpty())
72             server = (MBeanServer JavaDoc)servers.get(0);
73         else
74             server = MBeanServerFactory.createMBeanServer();
75         
76         String JavaDoc objNameStr = domain + ":type=PWCKeepAlive,*";
77         try {
78             keepAliveName = new ObjectName JavaDoc(objNameStr);
79         } catch (Throwable JavaDoc t) {
80             String JavaDoc msg = _logger.getResourceBundle().getString(
81                                     "webcontainer.objectNameCreationError");
82             msg = MessageFormat.format(msg, new Object JavaDoc[] { objNameStr });
83             _logger.log(Level.SEVERE, msg, t);
84         }
85
86         // initialize all the MutableStatistic Classes
87
initializeStatistics();
88     }
89
90
91     /**
92      * Gets the number of connections in keep-alive mode.
93      *
94      * @return Number of connections in keep-alive mode
95      */

96     public CountStatistic JavaDoc getCountConnections() {
97         countConnections.setCount(
98             StatsUtil.getAggregateStatistic(server, keepAliveName,
99                                             "countConnections"));
100         return (CountStatistic JavaDoc)countConnections.unmodifiableView();
101     }
102     
103
104     /**
105      * Gets the maximum number of concurrent connections in keep-alive mode.
106      *
107      * @return Maximum number of concurrent connections in keep-alive mode
108      */

109     public CountStatistic JavaDoc getMaxConnections() {
110         maxConnections.setCount(
111             StatsUtil.getConstant(server, keepAliveName, "maxConnections"));
112         return (CountStatistic JavaDoc)maxConnections.unmodifiableView();
113     }
114
115     
116     /**
117      * Gets the number of requests received by connections in keep-alive mode.
118      *
119      * @return Number of requests received by connections in keep-alive mode.
120      */

121     public CountStatistic JavaDoc getCountHits() {
122         countHits.setCount(
123             StatsUtil.getAggregateStatistic(server, keepAliveName,
124                                             "countHits"));
125         return (CountStatistic JavaDoc)countHits.unmodifiableView();
126     }
127
128     
129     /**
130      * Gets the number of keep-alive connections that were closed
131      *
132      * @return Number of keep-alive connections that were closed
133      */

134     public CountStatistic JavaDoc getCountFlushes() {
135         countFlushes.setCount(
136             StatsUtil.getAggregateStatistic(server, keepAliveName,
137                                             "countFlushes"));
138         return (CountStatistic JavaDoc)countFlushes.unmodifiableView();
139     }
140
141     
142     /**
143      * Gets the number of keep-alive connections that were rejected.
144      *
145      * @return Number of keep-alive connections that were rejected.
146      */

147     public CountStatistic JavaDoc getCountRefusals() {
148         countRefusals.setCount(
149             StatsUtil.getAggregateStatistic(server, keepAliveName,
150                                             "countRefusals"));
151         return (CountStatistic JavaDoc)countRefusals.unmodifiableView();
152     }
153
154     
155     /**
156      * Gets the number of keep-alive connections that timed out.
157      *
158      * @return Number of keep-alive connections that timed out.
159      */

160     public CountStatistic JavaDoc getCountTimeouts() {
161         countTimeouts.setCount(
162             StatsUtil.getAggregateStatistic(server, keepAliveName,
163                                             "countTimeouts"));
164         return (CountStatistic JavaDoc)countTimeouts.unmodifiableView();
165     }
166
167     
168     /**
169      * Gets the number of seconds before a keep-alive connection that has
170      * been idle times out and is closed.
171      *
172      * @return Keep-alive timeout in number of seconds
173      */

174     public CountStatistic JavaDoc getSecondsTimeouts() {
175         secondsTimeouts.setCount(
176             StatsUtil.getConstant(server, keepAliveName, "secondsTimeouts"));
177         return (CountStatistic JavaDoc)secondsTimeouts.unmodifiableView();
178     }
179     
180     
181     /**
182      * This method can be used to retrieve all the Statistics, exposed
183      * by this implementation of Stats
184      * @return Statistic[]
185      */

186     public Statistic JavaDoc[] getStatistics() {
187         return baseStatsImpl.getStatistics();
188     }
189     
190
191     /**
192      * Queries for a statistic with the given name.
193      *
194      * @name Name of the statistic to query for
195      *
196      * @return Statistic for the given name
197      */

198     public Statistic JavaDoc getStatistic(String JavaDoc name) {
199         return baseStatsImpl.getStatistic(name);
200     }
201
202     
203     /**
204      * Gets array of all statistic names exposed by this implementation of
205      * <codeStats</code>
206      *
207      * @return Array of statistic names
208      */

209     public String JavaDoc[] getStatisticNames() {
210         return baseStatsImpl.getStatisticNames();
211     }
212
213     
214     private void initializeStatistics() {
215         
216         CountStatistic JavaDoc c = null;
217
218         c = new CountStatisticImpl("CountConnections");
219         countConnections = new MutableCountStatisticImpl(c);
220
221         c = new CountStatisticImpl("MaxConnections");
222         maxConnections = new MutableCountStatisticImpl(c);
223
224         c = new CountStatisticImpl("CountHits");
225         countHits = new MutableCountStatisticImpl(c);
226
227         c = new CountStatisticImpl("CountFlushes");
228         countFlushes = new MutableCountStatisticImpl(c);
229
230         c = new CountStatisticImpl("CountRefusals");
231         countRefusals = new MutableCountStatisticImpl(c);
232
233         c = new CountStatisticImpl("CountTimeouts");
234         countTimeouts = new MutableCountStatisticImpl(c);
235
236         c = new CountStatisticImpl("SecondsTimeouts");
237         secondsTimeouts = new MutableCountStatisticImpl(c);
238     }
239
240 }
241
Popular Tags