KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > resource > JCAConnectionFactory


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JCAConnectionFactory.java,v 1.3 2005/04/26 16:19:06 ehardesty Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.resource;
27
28 // JOnAS imports
29
import java.util.Properties JavaDoc;
30
31 import org.objectweb.jonas.resource.pool.api.Pool;
32 import org.objectweb.jonas.resource.ConnectionManagerImpl;
33 import org.objectweb.jonas.management.ReconfiguredProp;
34 import org.objectweb.jonas.management.j2eemanagement.J2EEManagedObject;
35
36 /**
37  * MBean class for JCA Connection Factory Management
38  *
39  * @author Adriana Danes JSR 77 (J2EE Management Standard)
40  *
41  */

42 public class JCAConnectionFactory extends J2EEManagedObject {
43
44     // JSR 77
45
/**
46      * Associated ManagedConnectionFactory
47      */

48     private String JavaDoc managedConnectionFactory = null;
49
50     // JOnAS Specific
51
/**
52      * Description
53      */

54     private String JavaDoc description = null;
55     /**
56      * Jndi name
57      */

58     private String JavaDoc jndiname = null;
59     /**
60      * Properties associated with the ConnectionFactory
61      */

62     private Properties JavaDoc prop = null;
63
64     /**
65      * Associated connection manager
66      */

67     private ConnectionManagerImpl cm = null;
68
69     /**
70      * Pool associated to the connection manager
71      */

72     private Pool pool = null;
73
74     /**
75      * Value used as sequence number by reconfiguration notifications
76      */

77     private long sequenceNumber = 0;
78
79     /**
80      * Constructor
81      * @param objectName String of object name
82      * @param jndiname String of ConnectionFactory
83      * @param prop Properties of the ConnectionFactory
84      * @param description String of ConnectionFactory description
85      */

86     public JCAConnectionFactory(String JavaDoc objectName, String JavaDoc jndiname, Properties JavaDoc prop,
87                                 String JavaDoc description, ConnectionManagerImpl cm) {
88         super(objectName);
89         this.jndiname = jndiname;
90         this.prop = prop;
91         this.description = description;
92         this.cm = cm;
93         this.pool = cm.getPool();
94     }
95
96     /**
97      * return the description
98      * @return String description
99      */

100     public String JavaDoc getDescription() {
101         return description;
102     }
103
104     /**
105      * return the jndi name
106      * @return String jndi name
107      */

108     public String JavaDoc getJndiName() {
109         return jndiname;
110     }
111
112     /**
113      * Return the ManagedConnectionFactory object name
114      * @return String of ManagedConnectionFactory name
115      */

116     public String JavaDoc getManagedConnectionFactory() {
117         return managedConnectionFactory;
118     }
119
120     /**
121      * return the ConnectionFactory Properties
122      * @return Properties ConnectionFactory properties
123      */

124     public Properties JavaDoc getProperties() {
125         return prop;
126     }
127
128     /**
129      * Set the ManagedConnectionFactory object name
130      *
131      * @param managedConnectionFactoryObjectName String to set
132      */

133     public void setManagedConnectionFactory(String JavaDoc managedConnectionFactoryObjectName) {
134         managedConnectionFactory = managedConnectionFactoryObjectName;
135     }
136
137     // JDBC Connection Pool Configuration
138

139     /**
140      * @return JDBC connection checking level
141      */

142     public Integer JavaDoc getJdbcConnCheckLevel() {
143         return new Integer JavaDoc(cm.getCheckLevel());
144     }
145     /**
146      * Sets the JDBC connection checking level
147      * @param level connection level
148      */

149     public void setJdbcConnCheckLevel(Integer JavaDoc level) {
150         cm.setCheckLevel(level.intValue());
151     }
152
153     /**
154      * @return Connections maximum age
155      */

156     public Integer JavaDoc getConnMaxAge() {
157         return new Integer JavaDoc(pool.getMaxAge());
158     }
159     /**
160      * @param mn Connections maximum age
161      */

162     public void setConnMaxAge(Integer JavaDoc mn) {
163         pool.setMaxAge(mn.intValue());
164     }
165
166     /**
167      * @return max maximum size of connection pool
168      */

169     public Integer JavaDoc getMaxSize() {
170         return new Integer JavaDoc(pool.getMaxSize());
171     }
172     /**
173      * @param max maximum size of connection pool
174      */

175     public void setMaxSize(Integer JavaDoc max) {
176         try {
177           pool.setMaxSize(max.intValue());
178         } catch(Exception JavaDoc ex) { }
179     }
180
181     /**
182      * @return maximum opening time of connections
183      */

184     public Integer JavaDoc getMaxOpentime() {
185         return new Integer JavaDoc(pool.getMaxOpentime());
186     }
187     /**
188      * @param mn maximum opening time in minutes for connections
189      */

190     public void setMaxOpentime(Integer JavaDoc mn) {
191         pool.setMaxOpentime(mn.intValue());
192     }
193
194     /**
195      * @return maximum nb of waiters allowed
196      */

197     public Integer JavaDoc getMaxWaiters() {
198         return new Integer JavaDoc(pool.getMaxWaiters());
199     }
200     /**
201      * @param max maximum nb of waiters allowed
202      */

203     public void setMaxWaiters(Integer JavaDoc max) {
204         pool.setMaxWaiters(max.intValue());
205     }
206
207     /**
208      * @return maximum time to wait for a connection, in seconds
209      */

210     public Integer JavaDoc getMaxWaitTime() {
211         return new Integer JavaDoc(pool.getMaxWaitTime());
212     }
213
214     /**
215      * @param max maximum time to wait for a connection, in seconds
216      */

217     public void setMaxWaitTime(Integer JavaDoc max) {
218         pool.setMaxWaitTime(max.intValue());
219     }
220
221     /**
222      * @return minimum size of connection pool
223      */

224     public Integer JavaDoc getMinSize() {
225         return new Integer JavaDoc(pool.getMinSize());
226     }
227     /**
228      * MBean method allowing to set the minimum size of connection pool
229      * @param min minimum size of connection pool
230      */

231     public void setMinSize(Integer JavaDoc min) {
232         try {
233             pool.setMinSize(min.intValue());
234         } catch (Exception JavaDoc ex) { }
235     }
236
237     /**
238      * @return sampling period for refresching pool statistics
239      */

240     public Integer JavaDoc getSamplingPeriod() {
241         return new Integer JavaDoc(pool.getSamplingPeriod());
242     }
243
244     /**
245      * @param i sampling period for refresching pool statistics
246      */

247     public void setSamplingPeriod(Integer JavaDoc i) {
248         pool.setSamplingPeriod(i.intValue());
249     }
250
251     /**
252      * @return SQL query for JDBC connections test
253      */

254     public String JavaDoc getJdbcTestStatement() {
255         return cm.getTestStatement();
256     }
257     /**
258      * @param test SQL query for JDBC connections test
259      */

260     public void setJdbcTestStatement(String JavaDoc test) {
261         cm.setTestStatement(test);
262     }
263
264     // JDBC Connection Pool Statistics
265

266     /**
267      * @return number of connection failures
268      */

269     public Integer JavaDoc getConnectionFailures() {
270         return new Integer JavaDoc(pool.getConnectionFailures());
271     }
272     /**
273      * @return number of connection leaks
274      */

275     public Integer JavaDoc getConnectionLeaks() {
276         return new Integer JavaDoc(pool.getConnectionLeaks());
277     }
278     /**
279      * @return number of busy connections
280      */

281     public Integer JavaDoc getCurrentBusy() {
282         return new Integer JavaDoc(pool.getCurrentBusy());
283     }
284     /**
285      * @return number of busy connections
286      */

287     public Integer JavaDoc getBusyMax() {
288         return new Integer JavaDoc(pool.getBusyMaxRecent());
289     }
290     /**
291      * @return number of busy connections
292      */

293     public Integer JavaDoc getBusyMin() {
294         return new Integer JavaDoc(pool.getBusyMinRecent());
295     }
296     /**
297      * @return number of connections used in transactions
298      */

299     public Integer JavaDoc getCurrentInTx() {
300         return new Integer JavaDoc(cm.getCurrentInTx());
301     }
302     /**
303      * @return number of opened connections
304      */

305     public Integer JavaDoc getCurrentOpened() {
306         return new Integer JavaDoc(pool.getCurrentOpened());
307     }
308     /**
309      * @return current number of connection waiters
310      */

311     public Integer JavaDoc getCurrentWaiters() {
312         return new Integer JavaDoc(pool.getCurrentWaiters());
313     }
314     /**
315      * @return number of opened physical JDBC connections
316      */

317     public Integer JavaDoc getOpenedCount() {
318         return new Integer JavaDoc(pool.getOpenedCount());
319     }
320     /**
321      * @return number of open calls that were rejected because too many waiters
322      */

323     public Integer JavaDoc getRejectedFull() {
324         return new Integer JavaDoc(pool.getRejectedFull());
325     }
326     /**
327      * @return total number of open calls that were rejected
328      */

329     public Integer JavaDoc getRejectedOpen() {
330         return new Integer JavaDoc(pool.getRejectedOpen());
331     }
332     /**
333      * @return number of open calls that were rejected by an unknown reason
334      */

335     public Integer JavaDoc getRejectedOther() {
336         return new Integer JavaDoc(pool.getRejectedOther());
337     }
338     /**
339      * @return number of open calls that were rejected by timeout
340      */

341     public Integer JavaDoc getRejectedTimeout() {
342         return new Integer JavaDoc(pool.getRejectedTimeout());
343     }
344     /**
345      * @return number of xa connection served
346      */

347     public Integer JavaDoc getServedOpen() {
348         return new Integer JavaDoc(pool.getServedOpen());
349     }
350     /**
351      * @return total number of waiters since datasource creation.
352      */

353     public Integer JavaDoc getWaiterCount() {
354         return new Integer JavaDoc(pool.getWaiterCount());
355     }
356     /**
357      * @return Maximum number of waiters since datasource creation.
358      */

359     public Integer JavaDoc getWaitersHigh() {
360         return new Integer JavaDoc(pool.getWaitersHigh());
361     }
362     /**
363      * @return Maximum nb of waiters in last sampling period
364      */

365     public Integer JavaDoc getWaitersHighRecent() {
366         return new Integer JavaDoc(pool.getWaitersHighRecent());
367     }
368     /**
369      * @return Maximum waiting time (millisec) since datasource creation.
370      */

371     public Long JavaDoc getWaitingHigh() {
372         return new Long JavaDoc(pool.getWaitingHigh());
373     }
374     /**
375      * @return Maximum waiting time (millisec) in last sampling period
376      */

377     public Long JavaDoc getWaitingHighRecent() {
378         return new Long JavaDoc(pool.getWaitingHighRecent());
379     }
380     /**
381      * @return Total waiting time (millisec) since datasource creation.
382      */

383     public Long JavaDoc getWaitingTime() {
384         return new Long JavaDoc(pool.getWaitingTime());
385     }
386
387     /**
388      * Gets the sequence number for reconfiguration opeartions
389      * @return the sequence number for reconfiguration operations
390      */

391     protected long getSequenceNumber() {
392         return ++sequenceNumber;
393     }
394
395 }
396
Popular Tags