KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > stats > impl > WebServiceEndpointStatsProviderImpl


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.admin.wsmgmt.stats.impl;
24
25 import com.sun.enterprise.admin.wsmgmt.stats.spi.WebServiceEndpointStatsProvider;
26
27 /**
28  * A Class for providing stats for Web Service Endpoint.
29  *
30  * @author Satish Viswanatham
31  */

32 public class WebServiceEndpointStatsProviderImpl
33     implements WebServiceEndpointStatsProvider
34 {
35
36     public WebServiceEndpointStatsProviderImpl() {
37         faultActor = faultString = faultCode = clientHost = clientUser = null;
38         responseSize = requestSize = totalFaults =
39         totalSuccess = totalAuthFailures = totalAuthSuccess = 0;
40         responseTime = avgResponseTime =
41                 totalResponseTime = maxResponseTime = (long)0;
42         resetTime = System.currentTimeMillis();
43         minResponseTime = -1;
44         throughput = 0.0;
45
46     }
47
48     // Setters -- that change the state
49

50     public void setRequestTimeStamp(long t , String JavaDoc host, String JavaDoc user,
51         int rSize) {
52
53         enterTime = t;
54         reqSize = rSize;
55         cHost = host;
56         cUser = user;
57     }
58
59     public void setSuccess(int resSize, long exitTime, long respTime) {
60         
61         precheck();
62
63         responseTime = respTime;
64         calculateResponseTimes (responseTime);
65         clientHost = cHost;
66         clientUser = cUser;
67         requestSize = reqSize;
68         responseSize = resSize;
69         totalSuccess++;
70         totalAuthSuccess++;
71     
72         // since this is success reset the fault related values
73
faultCode = faultString = faultActor = null;
74
75         cleanup();
76     }
77
78     void calculateResponseTimes (long curRespTime) {
79         if ( curRespTime > maxResponseTime) {
80             maxResponseTime = curRespTime;
81         }
82
83         if (minResponseTime < 0 ) {
84             minResponseTime = curRespTime;
85         } else if ( curRespTime < minResponseTime) {
86             minResponseTime = curRespTime;
87         }
88         totalResponseTime += curRespTime;
89     }
90
91     public void setFault(int resSize, long exitTime, long rTime, String JavaDoc fCode, String JavaDoc fString,
92     String JavaDoc fActor) {
93         precheck();
94
95         responseTime = rTime;
96         calculateResponseTimes (responseTime);
97         clientHost = cHost;
98         clientUser = cUser;
99         requestSize = reqSize;
100         responseSize = resSize;
101         totalFaults++;
102         totalAuthSuccess++;
103     
104         // since this is success reset the fault related values
105
faultCode = fCode;
106         faultString = fString;
107         faultActor = fActor;
108
109         cleanup();
110
111     }
112
113     public void setAuthFailure (long t) {
114
115         // precheck(); -- precheck may not be called for auth failures
116

117         clientHost = cHost;
118         clientUser = cUser;
119         requestSize = reqSize;
120         totalFaults++;
121         totalAuthFailures++;
122     
123         // since this is success reset the fault related values
124
faultCode = faultString = faultActor = null;
125
126         cleanup();
127
128     }
129
130     public void precheck() {
131         if ( enterTime == 0 ) {
132             throw new RuntimeException JavaDoc(
133             "Request method should also update the request stats");
134         }
135
136         // XXX store this stat into message store if history size is > 0
137

138     }
139
140     public void cleanup() {
141         enterTime = 0;
142         cHost = cUser = null;
143     }
144
145     public void reset() {
146         faultActor = faultString = faultCode = clientHost = clientUser = null;
147         responseSize = requestSize = totalFaults =
148         totalSuccess = totalAuthFailures = totalAuthSuccess = 0;
149         responseTime = totalResponseTime = maxResponseTime =
150         avgResponseTime = (long) 0;
151         resetTime = System.currentTimeMillis();
152         throughput = 0.0;
153         minResponseTime = -1;
154     }
155
156     // Getters -- used by the monioring MBeans
157
public long getLastResetTime() {
158         return resetTime;
159     }
160
161     public long getAverageResponseTime() {
162         int totalInv = totalSuccess + totalFaults;
163         if (totalInv == 0 ) {
164             return (long)0;
165         } else {
166             return totalResponseTime/ (totalInv);
167         }
168     }
169
170     public long getMinResponseTime() {
171         if (minResponseTime < 0 ) {
172             return 0;
173         } else {
174             return minResponseTime;
175         }
176     }
177
178     public long getMaxResponseTime() {
179         return maxResponseTime;
180     }
181
182     public long getResponseTime() {
183         return responseTime;
184     }
185
186     public int getTotalFailures() {
187         return totalFaults;
188     }
189
190     public int getTotalSuccesses() {
191         return totalSuccess;
192     }
193
194     public int getTotalAuthFailures() {
195         return totalAuthFailures;
196     }
197
198     public int getTotalAuthSuccesses() {
199         return totalAuthSuccess;
200     }
201
202     public double getThroughput() {
203         long avgRespTime = getAverageResponseTime();
204         double dValue = avgRespTime;
205         if ( avgRespTime == 0 ) {
206             return 0;
207         } else {
208             return 1000/dValue;
209         }
210     }
211
212     public int getRequestSize() {
213         return requestSize;
214     }
215
216     public int getResponseSize() {
217         return responseSize;
218     }
219
220     public String JavaDoc getClientHost() {
221         return clientHost;
222     }
223
224     public String JavaDoc getClientUser() {
225         return clientUser;
226     }
227
228     public String JavaDoc getFaultCode() {
229         return faultCode;
230     }
231
232     public String JavaDoc getFaultString() {
233         return faultString;
234     }
235
236     public String JavaDoc getFaultActor() {
237         return faultActor;
238     }
239
240     // PRIVATE VARS
241

242     String JavaDoc faultActor, faultString, faultCode, clientHost, clientUser;
243
244     int responseSize, requestSize, totalFaults, totalSuccess,
245         totalAuthFailures, totalAuthSuccess;
246     long responseTime, totalResponseTime, avgResponseTime, minResponseTime,
247         maxResponseTime;
248     double throughput;
249
250     // Temp data to hold between request and reponse stage, before this
251
// Statistic is posted
252

253     long enterTime =0;
254     long resetTime =0;
255     int reqSize = 0;
256     String JavaDoc cHost = null, cUser = null;
257 }
258
Popular Tags