KickJava   Java API By Example, From Geeks To Geeks.

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


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 HAStatefulSessionStoreStatsImpl
49     extends StatefulSessionStoreStatsImpl
50     implements com.sun.enterprise.admin.monitor.stats.HAStatefulSessionStoreStats
51 {
52
53     private MutableCountStatisticImpl checkpointCount;
54     private MutableCountStatisticImpl checkpointSuccessCount;
55     private MutableCountStatisticImpl checkpointErrorCount;
56     private MutableAverageRangeStatisticImpl checkpointSize;
57     private MutableAverageRangeStatisticImpl checkpointTime;
58
59     private Object JavaDoc checkpointCountLock = new Object JavaDoc();
60     private Object JavaDoc checkpointSizeLock = new Object JavaDoc();
61     private Object JavaDoc checkpointTimeLock = new Object JavaDoc();
62
63     private long checkpointCountVal;
64     private long checkpointSuccessCountVal;
65     private long checkpointErrorCountVal;
66
67     public HAStatefulSessionStoreStatsImpl(
68     MonitorableSFSBStoreManager provider)
69     {
70     super(provider, "com.sun.enterprise.admin.monitor.stats.HAStatefulSessionStoreStats");
71     initialize();
72     }
73
74     protected void initialize() {
75     super.initialize();
76
77     synchronized (checkpointCountLock) {
78         checkpointCount = new MutableCountStatisticImpl(
79         new CountStatisticImpl("CheckpointCount"));
80         checkpointSuccessCount = new MutableCountStatisticImpl(
81         new CountStatisticImpl("CheckpointSuccessCount"));
82         checkpointErrorCount = new MutableCountStatisticImpl(
83         new CountStatisticImpl("CheckpointErrorCount"));
84     }
85
86     long now = System.currentTimeMillis();
87     synchronized (checkpointTimeLock) {
88         checkpointTime = new MutableAverageRangeStatisticImpl(
89             new BoundedRangeStatisticImpl(0, 0, 0,
90                                      0, 0, "CheckpointTime",
91                                      "millis", "Time spent on checkpointing", 0, 0)
92         );
93     }
94
95     synchronized (checkpointSizeLock) {
96         checkpointSize = new MutableAverageRangeStatisticImpl(
97             new BoundedRangeStatisticImpl(0, 0, 0,
98                                      0, 0, "CheckpointSize",
99                                      "millis", "Number of bytes checkpointed", 0, 0)
100         );
101     }
102     }
103
104     /**
105      * Returns the total number of sessions checkpointed into the store
106      */

107     public CountStatistic JavaDoc getCheckpointCount() {
108     synchronized (checkpointCountLock) {
109         checkpointCount.setCount(checkpointCountVal);
110        return (CountStatistic JavaDoc) checkpointCount.unmodifiableView();
111     }
112     }
113
114     /**
115      * Returns the total number of sessions successfully Checkpointed into the store
116      */

117     public CountStatistic JavaDoc getCheckpointSuccessCount() {
118     synchronized (checkpointCountLock) {
119         checkpointSuccessCount.setCount(checkpointSuccessCountVal);
120         return (CountStatistic JavaDoc) checkpointSuccessCount.unmodifiableView();
121     }
122     }
123
124     /**
125      * Returns the total number of sessions that couldn't be Checkpointed into the store
126      */

127     public CountStatistic JavaDoc getCheckpointErrorCount() {
128     synchronized (checkpointCountLock) {
129         checkpointErrorCount.setCount(checkpointErrorCountVal);
130         return (CountStatistic JavaDoc) checkpointErrorCount.unmodifiableView();
131     }
132     }
133
134     /**
135      * Returns the number of bytes checkpointed
136      */

137     public AverageRangeStatistic getCheckpointedBeanSize() {
138     synchronized (checkpointTimeLock) {
139         return (AverageRangeStatistic) checkpointSize.unmodifiableView();
140     }
141     }
142
143     /**
144      * Returns the time spent on passivating beans to the store including total, min, max
145      */

146     public AverageRangeStatistic getCheckpointTime() {
147     synchronized (checkpointTimeLock) {
148         return (AverageRangeStatistic) checkpointTime.unmodifiableView();
149     }
150     }
151
152     public void incrementCheckpointCount(boolean success) {
153     synchronized (checkpointCountLock) {
154         checkpointCountVal++;
155         if (success) {
156         checkpointSuccessCountVal++;
157         } else {
158         checkpointErrorCountVal++;
159         }
160     }
161     }
162
163     public void setCheckpointSize(long val) {
164     synchronized (checkpointSizeLock) {
165         checkpointSize.setCount(val);
166     }
167     }
168
169     public void setCheckpointTime(long val) {
170     synchronized (checkpointTimeLock) {
171         checkpointTime.setCount(val);
172     }
173     }
174
175     protected void appendStats(StringBuffer JavaDoc sbuf) {
176     super.appendStats(sbuf);
177     sbuf.append("CheckpointCount: ").append(checkpointCountVal)
178         .append("; ")
179         .append("CheckpointSuccessCount: ").append(checkpointSuccessCountVal)
180         .append("; ")
181         .append("CheckpointErrorCount: ").append(checkpointErrorCountVal)
182         .append("; ");
183
184     appendTimeStatistic(sbuf, "CheckpointTime", checkpointTime);
185     }
186
187 }
188
Popular Tags