KickJava   Java API By Example, From Geeks To Geeks.

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


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.web.stats;
25
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import javax.management.j2ee.statistics.Statistic JavaDoc;
29 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
30 import javax.management.j2ee.statistics.TimeStatistic JavaDoc;
31 import com.sun.logging.LogDomains;
32 import com.sun.enterprise.admin.monitor.stats.ServletStats;
33 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
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.web.monitor.PwcServletStats;
38
39
40 public class ServletStatsImpl implements ServletStats {
41     
42     private static Logger JavaDoc _logger = null;
43
44     private GenericStatsImpl baseStatsImpl;
45     private MutableCountStatistic maxTimeMillis;
46     private MutableCountStatistic processingTimeMillis;
47     private TimeStatistic JavaDoc serviceTimeMillis;
48     private MutableCountStatistic requestCount;
49     private MutableCountStatistic errorCount;
50     private PwcServletStats pwcServletStats;
51
52     
53     /**
54      * Constructor.
55      *
56      * @param pwcServletStats PwcServletStats instance to which to delegate
57      */

58     public ServletStatsImpl(PwcServletStats pwcServletStats) {
59
60         this.pwcServletStats = pwcServletStats;
61         
62         _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER);
63
64         baseStatsImpl = new GenericStatsImpl(
65             com.sun.enterprise.admin.monitor.stats.ServletStats.class, this);
66
67         // initialize all the MutableStatistic Classes
68
initializeStatistics();
69     }
70     
71     
72     /**
73      * The maximum processing time of a servlet request
74      * @return CountStatistic
75      */

76     public CountStatistic JavaDoc getMaxTime() {
77         maxTimeMillis.setCount(pwcServletStats.getMaxTimeMillis());
78         return (CountStatistic JavaDoc)maxTimeMillis.unmodifiableView();
79     }
80
81     
82     /**
83      * Gets the total execution time of the servlet's service method.
84      *
85      * @return Total execution time of the servlet's service method
86      */

87     public CountStatistic JavaDoc getProcessingTime() {
88         processingTimeMillis.setCount(pwcServletStats.getProcessingTimeMillis());
89         return (CountStatistic JavaDoc)processingTimeMillis.unmodifiableView();
90     }
91     
92
93     /**
94      * Gets the execution time of the servlet's service method as a
95      * TimeStatistic.
96      *
97      * @return Execution time of the servlet's service method
98      */

99     public TimeStatistic JavaDoc getServiceTime() {
100         return serviceTimeMillis;
101     }
102
103
104     /**
105      * Number of requests processed by this servlet.
106      * @return CountStatistic
107      */

108     public CountStatistic JavaDoc getRequestCount() {
109         requestCount.setCount(pwcServletStats.getRequestCount());
110         return (CountStatistic JavaDoc)requestCount.unmodifiableView();
111     }
112
113     
114     /**
115      * The errorCount represents the number of cases where the response
116      * code was >= 400
117      * @return CountStatistic
118      */

119     public CountStatistic JavaDoc getErrorCount() {
120         errorCount.setCount(pwcServletStats.getErrorCount());
121         return (CountStatistic JavaDoc)errorCount.unmodifiableView();
122     }
123
124     
125     /**
126      * This method can be used to retrieve all the Statistics, exposed
127      * by this implementation of Stats
128      * @return Statistic[]
129      */

130     public Statistic JavaDoc[] getStatistics() {
131         return baseStatsImpl.getStatistics();
132     }
133
134     
135     /**
136      * queries for a Statistic by name.
137      * @return Statistic
138      */

139     public Statistic JavaDoc getStatistic(String JavaDoc str) {
140         return baseStatsImpl.getStatistic(str);
141     }
142
143     
144     /**
145      * returns an array of names of all the Statistics, that can be
146      * retrieved from this implementation of Stats
147      * @return String[]
148      */

149     public String JavaDoc[] getStatisticNames() {
150         return baseStatsImpl.getStatisticNames();
151     }
152
153     
154     private void initializeStatistics() {
155         
156        // Initialize the MutableCountStatistic for ErrorCount
157
CountStatistic JavaDoc c = new CountStatisticImpl("ErrorCount");
158         errorCount = new MutableCountStatisticImpl(c);
159         
160         // Initialize the MutableCountStatistic for MaxTime
161
c = new CountStatisticImpl("MaxTime", "milliseconds");
162         maxTimeMillis = new MutableCountStatisticImpl(c);
163         
164         // Initialize the MutableCountStatistic for ProcessingTime
165
c = new CountStatisticImpl("ProcessingTime", "milliseconds");
166         processingTimeMillis = new MutableCountStatisticImpl(c);
167         
168         // Initialize the MutableCountStatistic for RequestCount
169
c = new CountStatisticImpl("RequestCount");
170         requestCount = new MutableCountStatisticImpl(c);
171
172         // Initialize the MutableTimeStatistic for ServiceTime
173
serviceTimeMillis = new ServletTimeStatisticImpl("ServiceTime",
174                                                          "milliseconds",
175                                                          pwcServletStats);
176     }
177     
178 }
179
Popular Tags