KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > base > stats > StatefulSessionStoreStatsImpl


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.ejb.base.stats;
25
26 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
27 import javax.management.j2ee.statistics.RangeStatistic JavaDoc;
28 import javax.management.j2ee.statistics.TimeStatistic JavaDoc;
29
30 import com.sun.ejb.spi.stats.MonitorableSFSBStoreManager;
31
32 import com.sun.enterprise.admin.monitor.stats.AverageRangeStatistic;
33 import com.sun.enterprise.admin.monitor.stats.BoundedRangeStatisticImpl;
34 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
35 import com.sun.enterprise.admin.monitor.stats.MutableAverageRangeStatisticImpl;
36 import com.sun.enterprise.admin.monitor.stats.MutableBoundedRangeStatisticImpl;
37 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl;
38 import com.sun.enterprise.admin.monitor.stats.MutableTimeStatisticImpl;
39 import com.sun.enterprise.admin.monitor.stats.TimeStatisticImpl;
40
41 /**
42  * Implementation of StatefulSessionStoreStats
43  * There is once instance of this class per StatefulEJBContainer
44  *
45  * @author Mahesh Kannan
46  */

47
48 public class StatefulSessionStoreStatsImpl
49     extends StatsImpl
50     implements com.sun.enterprise.admin.monitor.stats.StatefulSessionStoreStats
51 {
52
53     private MonitorableSFSBStoreManager provider;
54
55     private MutableBoundedRangeStatisticImpl currentSize;
56
57     private MutableCountStatisticImpl activationCount;
58     private MutableCountStatisticImpl activationSuccessCount;
59     private MutableCountStatisticImpl activationErrorCount;
60
61     private MutableCountStatisticImpl passivationCount;
62     private MutableCountStatisticImpl passivationSuccessCount;
63     private MutableCountStatisticImpl passivationErrorCount;
64
65     private MutableCountStatisticImpl expiredSessionCount;
66
67     private MutableAverageRangeStatisticImpl activationSize;
68     private MutableAverageRangeStatisticImpl activationTime;
69
70     private MutableAverageRangeStatisticImpl passivationSize;
71     private MutableAverageRangeStatisticImpl passivationTime;
72
73     private Object JavaDoc currentSizeLock = new Object JavaDoc();
74
75     private Object JavaDoc activationCountLock = new Object JavaDoc();
76     private Object JavaDoc activationSizeLock = new Object JavaDoc();
77     private Object JavaDoc activationTimeLock = new Object JavaDoc();
78
79     private Object JavaDoc passivationCountLock = new Object JavaDoc();
80     private Object JavaDoc passivationSizeLock = new Object JavaDoc();
81     private Object JavaDoc passivationTimeLock = new Object JavaDoc();
82
83     private Object JavaDoc expiredSessionCountLock = new Object JavaDoc();
84
85     private long activationCountVal;
86     private long activationSuccessCountVal;
87     private long activationErrorCountVal;
88
89     private long passivationCountVal;
90     private long passivationSuccessCountVal;
91     private long passivationErrorCountVal;
92
93     private long expiredSessionCountVal;
94
95     public StatefulSessionStoreStatsImpl(
96     MonitorableSFSBStoreManager provider)
97     {
98     this.provider = provider;
99     super.initialize("com.sun.enterprise.admin.monitor.stats.StatefulSessionStoreStats");
100
101     initialize();
102     }
103
104     protected StatefulSessionStoreStatsImpl(
105     MonitorableSFSBStoreManager provider, String JavaDoc intfName)
106     {
107     this.provider = provider;
108     super.initialize(intfName);
109     }
110
111     protected void initialize() {
112
113     long now = System.currentTimeMillis();
114
115     synchronized (currentSizeLock) {
116         currentSize = new MutableBoundedRangeStatisticImpl(
117             new BoundedRangeStatisticImpl(0, 0, Long.MAX_VALUE,
118             Long.MAX_VALUE, 0, "CurrentSize",
119             "bytes", "Number of sessions in store", now, now)
120         );
121     }
122
123     synchronized (activationCountLock) {
124         activationCount = new MutableCountStatisticImpl(
125         new CountStatisticImpl("ActivationCount"));
126         activationSuccessCount = new MutableCountStatisticImpl(
127         new CountStatisticImpl("ActivationSuccessCount"));
128         activationErrorCount = new MutableCountStatisticImpl(
129         new CountStatisticImpl("ActivationErrorCount"));
130     }
131
132     synchronized (activationSizeLock) {
133         activationSize = new MutableAverageRangeStatisticImpl(
134             new BoundedRangeStatisticImpl(0, 0, Long.MAX_VALUE,
135             Long.MAX_VALUE, 0, "ActivationSize",
136             "bytes", "Number of bytes activated", now, now)
137         );
138     }
139
140     synchronized (passivationSizeLock) {
141         passivationSize = new MutableAverageRangeStatisticImpl(
142             new BoundedRangeStatisticImpl(0, 0, Long.MAX_VALUE,
143             Long.MAX_VALUE, 0, "PassivationSize",
144             "bytes", "Number of bytes passivated", now, now)
145         );
146     }
147
148     synchronized (passivationCountLock) {
149         passivationCount = new MutableCountStatisticImpl(
150         new CountStatisticImpl("PassivationCount"));
151         passivationSuccessCount = new MutableCountStatisticImpl(
152         new CountStatisticImpl("PassivationSuccessCount"));
153         passivationErrorCount = new MutableCountStatisticImpl(
154         new CountStatisticImpl("PassivationErrorCount"));
155     }
156
157     synchronized (expiredSessionCountLock) {
158         expiredSessionCount = new MutableCountStatisticImpl(
159         new CountStatisticImpl("ExpiredSessionCount"));
160     }
161
162     synchronized (activationTimeLock) {
163         activationTime = new MutableAverageRangeStatisticImpl(
164             new BoundedRangeStatisticImpl(0, 0, Long.MAX_VALUE,
165             Long.MAX_VALUE, 0, "ActivationTime",
166             "millis", "Time spent on activation", now, now)
167         );
168     }
169
170     synchronized (passivationTimeLock) {
171         passivationTime = new MutableAverageRangeStatisticImpl(
172             new BoundedRangeStatisticImpl(0, 0, Long.MAX_VALUE,
173             Long.MAX_VALUE, 0, "PassivationTime",
174             "millis", "Time spent on passivation", now, now)
175         );
176     }
177     }
178
179     /**
180      * Returns the number of passivated / checkpointed sessions in the store
181      */

182     public RangeStatistic JavaDoc getCurrentSize() {
183     synchronized (currentSizeLock) {
184         currentSize.setCount(provider.getCurrentStoreSize());
185         return (RangeStatistic JavaDoc) currentSize.unmodifiableView();
186     }
187     }
188
189     /**
190      * Returns the total number of sessions activated from the store
191      */

192     public CountStatistic JavaDoc getActivationCount() {
193     synchronized (activationCountLock) {
194         activationCount.setCount(activationCountVal);
195        return (CountStatistic JavaDoc) activationCount.unmodifiableView();
196     }
197     }
198
199     /**
200      * Returns the total number of sessions successfully Activated from the store
201      */

202     public CountStatistic JavaDoc getActivationSuccessCount() {
203     synchronized (activationCountLock) {
204         activationSuccessCount.setCount(activationSuccessCountVal);
205         return (CountStatistic JavaDoc) activationSuccessCount.unmodifiableView();
206     }
207     }
208
209     /**
210      * Returns the total number of sessions that couldn't be Activated from the store
211      */

212     public CountStatistic JavaDoc getActivationErrorCount() {
213     synchronized (activationCountLock) {
214         activationErrorCount.setCount(activationErrorCountVal);
215         return (CountStatistic JavaDoc) activationErrorCount.unmodifiableView();
216     }
217     }
218
219     /**
220      * Returns the total number of sessions passivated using this store
221      */

222     public CountStatistic JavaDoc getPassivationCount() {
223     synchronized (passivationCountLock) {
224         passivationCount.setCount(passivationCountVal);
225         return (CountStatistic JavaDoc) passivationSuccessCount.unmodifiableView();
226     }
227     }
228
229     /**
230      * Returns the total number of sessions successfully Passivated using the store
231      */

232     public CountStatistic JavaDoc getPassivationSuccessCount() {
233     synchronized (passivationCountLock) {
234         passivationSuccessCount.setCount(passivationSuccessCountVal);
235         return (CountStatistic JavaDoc) passivationSuccessCount.unmodifiableView();
236     }
237     }
238
239     /**
240      * Returns the total number of sessions that couldn't be Passivated using the store
241      */

242     public CountStatistic JavaDoc getPassivationErrorCount() {
243     synchronized (passivationCountLock) {
244         passivationErrorCount.setCount(passivationErrorCountVal);
245         return (CountStatistic JavaDoc) passivationSuccessCount.unmodifiableView();
246     }
247     }
248
249     /**
250      * Returns the total number of expired sessions that were removed by this store
251      */

252     public CountStatistic JavaDoc getExpiredSessionCount() {
253     synchronized (expiredSessionCountLock) {
254         expiredSessionCount.setCount(expiredSessionCountVal);
255         return (CountStatistic JavaDoc) expiredSessionCount.unmodifiableView();
256
257     }
258     }
259
260     /**
261      * Returns the total number of bytes activated by this store including total, min, maximum
262      */

263     public AverageRangeStatistic getActivatedBeanSize() {
264     synchronized (activationSizeLock) {
265         return (AverageRangeStatistic) activationSize.unmodifiableView();
266     }
267     }
268
269     /**
270      * Returns the time spent on activating beans from the store including total, min, max
271      */

272     public AverageRangeStatistic getActivationTime() {
273     synchronized (activationTimeLock) {
274         return (AverageRangeStatistic) activationTime.unmodifiableView();
275     }
276     }
277     
278     /**
279      * Returns the total number of bytes passivated by this store including total, min, maximum
280      */

281     public AverageRangeStatistic getPassivatedBeanSize() {
282     synchronized (passivationSizeLock) {
283         return (AverageRangeStatistic) passivationSize.unmodifiableView();
284     }
285     }
286
287     /**
288      * Returns the time spent on passivating beans to the store including total, min, max
289      */

290     public AverageRangeStatistic getPassivationTime() {
291     synchronized (passivationTimeLock) {
292         return (AverageRangeStatistic) passivationTime.unmodifiableView();
293     }
294     }
295     
296     //The following methods are called from StatefulSessionStoreMonitor
297
//
298
void incrementActivationCount(boolean success) {
299     synchronized (activationCountLock) {
300         activationCountVal++;
301         if (success) {
302         activationSuccessCountVal++;
303         } else {
304         activationErrorCountVal++;
305         }
306     }
307     }
308
309     void incrementPassivationCount(boolean success) {
310     synchronized (passivationCountLock) {
311         passivationCountVal++;
312         if (success) {
313         passivationSuccessCountVal++;
314         } else {
315         passivationErrorCountVal++;
316         }
317     }
318     }
319
320     void setActivationSize(long val) {
321     synchronized (activationSizeLock) {
322         activationSize.setCount(val);
323     }
324     }
325
326     void setActivationTime(long val) {
327     synchronized (activationTimeLock) {
328         activationTime.setCount(val);
329     }
330     }
331
332     void setPassivationSize(long val) {
333     synchronized (passivationSizeLock) {
334         passivationSize.setCount(val);
335     }
336     }
337
338     void setPassivationTime(long val) {
339     synchronized (passivationTimeLock) {
340         passivationTime.setCount(val);
341     }
342     }
343
344     void incrementExpiredSessionCountVal(long val) {
345     synchronized (expiredSessionCountLock) {
346         expiredSessionCountVal += val;
347     }
348     }
349
350     protected void appendStats(StringBuffer JavaDoc sbuf) {
351     sbuf.append("currentSize=").append(provider.getCurrentStoreSize())
352         .append("; ")
353         .append("ActivationCount=").append(activationCountVal)
354         .append("; ")
355         .append("ActivationSuccessCount=").append(activationSuccessCountVal)
356         .append("; ")
357         .append("ActivationErrorCount=").append(activationErrorCountVal)
358         .append("; ")
359         .append("PassivationCount=").append(passivationCountVal)
360         .append("; ")
361         .append("PassivationSuccessCount=").append(passivationSuccessCountVal)
362         .append("; ")
363         .append("PassivationErrorCount=").append(passivationErrorCountVal)
364         .append("; ")
365         .append("ExpiredSessionsRemoved=").append(expiredSessionCountVal)
366         .append("; ");
367
368     appendTimeStatistic(sbuf, "ActivationSize", activationSize);
369     appendTimeStatistic(sbuf, "ActivationTime", activationTime);
370     appendTimeStatistic(sbuf, "PassivationSize", passivationSize);
371     appendTimeStatistic(sbuf, "PassivationTime", passivationTime);
372
373     //Do not call provider.appendStats(). It is called from
374
// MonitoringRegistryMediator so that all undocumented
375
// features are grouped together
376
}
377
378     protected static void appendTimeStatistic(StringBuffer JavaDoc sbuf, String JavaDoc name,
379         MutableAverageRangeStatisticImpl stat)
380     {
381     sbuf.append(name).append("(")
382         .append("min=").append(stat.getLowWaterMark()).append(", ")
383         .append("max=").append(stat.getHighWaterMark()).append(", ")
384         .append("avg=").append(stat.getAverage())
385         .append("); ");
386     }
387
388
389     //Some of the store attributes are (unfortunately) exposed through
390
// the LruSessionCache too
391
//Called from LruCache -> StatefulSessionStoreMonitor
392
int getNumExpiredSessionCount() {
393     synchronized (expiredSessionCountLock) {
394         return (int) expiredSessionCountVal;
395     }
396     }
397
398     int getNumPassivationCount() {
399     synchronized (passivationCountLock) {
400         return (int) passivationCountVal;
401     }
402     }
403
404     int getNumPassivationSuccessCount() {
405     synchronized (passivationCountLock) {
406         return (int) passivationSuccessCountVal;
407     }
408     }
409
410     int getNumPassivationErrorCount() {
411     synchronized (passivationCountLock) {
412         return (int) passivationErrorCountVal;
413     }
414     }
415
416
417 }
418
Popular Tags