KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > resource > monitor > ConnectionPoolStatsImpl


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.resource.monitor;
25
26 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
27
28 import com.sun.enterprise.admin.monitor.stats.ConnectorConnectionPoolStats;
29 import com.sun.enterprise.admin.monitor.stats.JDBCConnectionPoolStats;
30 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic;
31 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl;
32 import com.sun.enterprise.admin.monitor.stats.RangeStatisticImpl;
33 import com.sun.logging.LogDomains;
34
35 import java.util.logging.Level JavaDoc;
36 import java.util.logging.Logger JavaDoc;
37
38 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
39 import javax.management.j2ee.statistics.RangeStatistic JavaDoc;
40 import com.sun.enterprise.util.i18n.StringManager;
41
42 import com.sun.enterprise.resource.MonitorableResourcePool;
43
44 /**
45  * An abstract class that provides an implementation of the ConnectionPoolStats
46  * interface. This common implementation is used by the JDBCConnectionPoolStats
47  * and ConnectorConnectionPoolStats implementations.
48  * @author Sivakumar Thyagarajan
49  */

50 public abstract class ConnectionPoolStatsImpl extends AbstractStatsImpl
51                                     implements ConnectorConnectionPoolStats, JDBCConnectionPoolStats {
52     
53     protected MonitorableResourcePool pool_;
54     
55     private static StringManager localStrings =
56         StringManager.getManager(ConnectionPoolStatsImpl.class);
57     
58     private String JavaDoc poolName_;
59
60     private MutableCountStatistic numConnFailedValidation_;
61     private MutableCountStatistic numConnTimedOut_;
62     private RangeStatistic JavaDoc numConnUsed_;
63     
64     //Since 8.1
65
private RangeStatistic JavaDoc numConnFree_;
66     private RangeStatistic JavaDoc numConnRequestWaitTime_;
67     private MutableCountStatistic averageConnWaitTime;
68     private MutableCountStatistic waitQueueLength;
69     private MutableCountStatistic numConnCreated;
70     private MutableCountStatistic numConnDestroyed;
71     private MutableCountStatistic numConnAcquired;
72     private MutableCountStatistic numConnReleased;
73     
74     //Since 9.0
75
private MutableCountStatistic numConnMatched;
76     private MutableCountStatistic numConnNotMatched;
77
78     protected static Logger JavaDoc _logger = LogDomains.getLogger( LogDomains.RSR_LOGGER );
79     
80     public CountStatistic getNumConnFailedValidation() {
81         numConnFailedValidation_.setCount(
82             pool_.getNumConnFailedValidation() );
83         return (CountStatistic)numConnFailedValidation_.unmodifiableView();
84     }
85
86     public CountStatistic getNumConnTimedOut() {
87         numConnTimedOut_.setCount(
88             pool_.getNumConnTimedOut() );
89         return (CountStatistic) numConnTimedOut_.unmodifiableView();
90     }
91     
92     public RangeStatistic JavaDoc getNumConnUsed() {
93         numConnUsed_ = getUpdatedRangeStatistic(numConnUsed_,
94                         pool_.getNumConnInUse(), pool_.getMaxNumConnUsed(),
95                         pool_.getMinNumConnUsed());
96         return numConnUsed_;
97     }
98
99     /*
100      * Initialize the Statistic objects for all collected
101      * statistics.
102      */

103     protected void initializeStatistics() {
104
105         long time = System.currentTimeMillis();
106         CountStatistic cs = null;
107     
108         cs = new CountStatisticImpl(0,
109             getLocalizedStringFor("num.conn.failed.validation",
110                             "NumConnFailedValidation"),
111             getLocalizedStringFor("stat.count", "Count"),
112             getLocalizedStringFor("num.conn.failed.validation.desc",
113                             "Number Of Connections that failed validation"),
114             time, time);
115         numConnFailedValidation_ = new MutableCountStatisticImpl( cs );
116
117         cs = new CountStatisticImpl(0,
118             getLocalizedStringFor("num.conn.timedout", "NumConnTimedOut"),
119             getLocalizedStringFor("stat.count", "Count"),
120             getLocalizedStringFor("num.conn.timedout.desc",
121                             "Number of Connection requests that timed out waiting"),
122             time, time);
123         numConnTimedOut_ = new MutableCountStatisticImpl( cs );
124
125         cs = new CountStatisticImpl(0,
126                         getLocalizedStringFor("num.conn.created","NumConnCreated"),
127                         getLocalizedStringFor("stat.count", "Count"),
128                         getLocalizedStringFor("num.conn.created.desc",
129                                         "Number of Connection that have been created"),
130                         time, time);
131         numConnCreated = new MutableCountStatisticImpl( cs );
132         
133         cs = new CountStatisticImpl(0,
134                         getLocalizedStringFor("num.conn.destroyed",
135                                         "NumConnDestroyed"),
136                         getLocalizedStringFor("stat.count", "Count"),
137                         getLocalizedStringFor("num.conn.destroyed.desc",
138                                         "Number of Connection that have been destroyed") ,
139                         time, time);
140         numConnDestroyed = new MutableCountStatisticImpl( cs );
141         
142         cs = new CountStatisticImpl(0,
143                         getLocalizedStringFor("num.conn.opened", "NumConnOpened"),
144                         getLocalizedStringFor("stat.count", "Count"),
145                         getLocalizedStringFor("num.conn.opened.desc",
146                                         "Number of Connection that have been acquired"),
147                     time, time);
148         numConnAcquired = new MutableCountStatisticImpl( cs );
149         
150         cs = new CountStatisticImpl(0,
151                         getLocalizedStringFor("num.conn.closed", "NumConnClosed"),
152                         getLocalizedStringFor("stat.count", "Count"),
153                         getLocalizedStringFor("num.conn.closed.desc",
154                                         "Number of Connection that have been released"),
155                     time, time);
156         numConnReleased = new MutableCountStatisticImpl( cs );
157         
158         
159         cs = new CountStatisticImpl(0,
160                         getLocalizedStringFor("avg.conn.wait.time",
161                                         "AvgConnWaitTime"),
162                         getLocalizedStringFor("stat.milliseconds", "milliseconds"),
163                         getLocalizedStringFor("avg.conn.wait.time.desc",
164                                         "Average wait time-duration per successful connection request"),
165                         time, time);
166         averageConnWaitTime = new MutableCountStatisticImpl( cs );
167         
168         cs = new CountStatisticImpl(0,
169                         getLocalizedStringFor("wait.queue.length",
170                                         "WaitQueueLength"),
171                         getLocalizedStringFor("stat.count", "Count"),
172                         getLocalizedStringFor("wait.queue.length.desc",
173                                         "Connection request Wait Queue length"),
174                         time, time);
175         waitQueueLength = new MutableCountStatisticImpl( cs );
176         
177         //the low water mark is set with a seed value of 1 to
178
//ensure that the comparison with currentVal returns
179
//the correct low water mark the first time around
180
//the least number of connections that we can use is always 1
181
numConnUsed_ = new RangeStatisticImpl(0, 0, 1,
182                         getLocalizedStringFor("num.conn.used", "NumConnUsed"),
183                         getLocalizedStringFor("stat.count", "Count"),
184                         getLocalizedStringFor("num.conn.used.desc",
185                                         "Number Of Connections used"),
186                         time, time);
187         
188         numConnFree_ = new RangeStatisticImpl(0, 0, 1,
189                         getLocalizedStringFor("num.conn.free", "NumConnFree"),
190                         getLocalizedStringFor("stat.count", "Count"),
191                         getLocalizedStringFor("num.conn.free.desc",
192                                         "Number Of Free Connections"),
193                         time, time);
194         numConnRequestWaitTime_ = new RangeStatisticImpl(0, 0, 1,
195                         getLocalizedStringFor("conn.request.wait.time",
196                                         "ConnRequestWaitTime"),
197                         getLocalizedStringFor("stat.milliseconds", "milliseconds"),
198                         getLocalizedStringFor("conn.request.wait.time.desc",
199                                         "Max and min connection request wait times"),
200                          time, time);
201         
202         cs = new CountStatisticImpl(0,
203                 getLocalizedStringFor("num.conn.matched", "NumConnMatched"),
204                 getLocalizedStringFor("stat.count", "Count"),
205                 getLocalizedStringFor("num.conn.matched.desc",
206                                 "Number of Connection that were successfully matched by the MCF. "),
207             time, time);
208         numConnMatched = new MutableCountStatisticImpl( cs );
209
210         cs = new CountStatisticImpl(0,
211                 getLocalizedStringFor("num.conn.not.matched", "NumConnNotMatched"),
212                 getLocalizedStringFor("stat.count", "Count"),
213                 getLocalizedStringFor("num.conn.not.matched.desc",
214                                 "Number of Connection that were rejected by the MCF. "),
215             time, time);
216         numConnNotMatched = new MutableCountStatisticImpl( cs );
217
218     }
219
220    
221    // Begin - New Statistics for 8.1
222
public RangeStatistic JavaDoc getNumConnFree(){
223        numConnFree_ = getUpdatedRangeStatistic(numConnFree_,
224                        pool_.getNumConnFree(), pool_.getMaxNumConnFree(),
225                        pool_.getMinNumConnFree());
226        return numConnFree_;
227    }
228    
229    public CountStatistic getAverageConnWaitTime() {
230        //Time taken by all connection requests divided by total number of
231
//connections acquired in the sampling period.
232
long averageWaitTime = 0;
233        if (getNumConnAcquired().getCount() != 0) {
234            averageWaitTime = pool_.getTotalConnectionRequestWaitTime() /
235                                  (getNumConnAcquired().getCount());
236        } else {
237            averageWaitTime = 0;
238        }
239
240        averageConnWaitTime.setCount(averageWaitTime);
241        return (CountStatistic)averageConnWaitTime.unmodifiableView();
242    }
243
244    public RangeStatistic JavaDoc getConnRequestWaitTime() {
245        numConnRequestWaitTime_ = getUpdatedRangeStatistic(
246                numConnRequestWaitTime_ , pool_.getCurrentConnRequestWaitTime() ,
247                pool_.getMaxConnRequestWaitTime(),
248                pool_.getMinConnRequestWaitTime());
249        return numConnRequestWaitTime_;
250    }
251    
252    public CountStatistic getNumConnCreated() {
253        numConnCreated.setCount((long)pool_.getNumConnCreated());
254        return (CountStatistic)numConnCreated.unmodifiableView();
255    }
256    
257    public CountStatistic getNumConnDestroyed() {
258        numConnDestroyed.setCount((long)pool_.getNumConnDestroyed());
259        return (CountStatistic)numConnDestroyed.unmodifiableView();
260    }
261    
262    public CountStatistic getNumConnAcquired(){
263        numConnAcquired.setCount((long)pool_.getNumConnAcquired());
264        return (CountStatistic)numConnAcquired.unmodifiableView();
265    }
266    
267    public CountStatistic getNumConnReleased(){
268        numConnReleased.setCount((long)pool_.getNumConnReleased());
269        return (CountStatistic)numConnReleased.unmodifiableView();
270    }
271    
272    
273    public CountStatistic getWaitQueueLength() {
274        waitQueueLength.setCount((long)pool_.getNumThreadWaiting());
275        return (CountStatistic)waitQueueLength.unmodifiableView();
276    }
277    //END - New Statistics for 8.1
278

279    //START - New Statistics for 9.0
280
public CountStatistic getNumConnSuccessfullyMatched() {
281        numConnMatched.setCount((long)pool_.getNumConnSuccessfullyMatched());
282        return (CountStatistic)numConnMatched.unmodifiableView();
283    }
284    
285    public CountStatistic getNumConnNotSuccessfullyMatched() {
286        numConnNotMatched.setCount((long)pool_.getNumConnNotSuccessfullyMatched());
287        return (CountStatistic)numConnNotMatched.unmodifiableView();
288    }
289    
290    private String JavaDoc getLocalizedStringFor(String JavaDoc key, String JavaDoc defaultValue){
291        return localStrings.getString(key , defaultValue);
292    }
293 }
294
Popular Tags