KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > ConnectorConnectionPool


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.connectors;
25
26 import com.sun.enterprise.util.Utility;
27 import com.sun.enterprise.repository.J2EEResourceBase;
28 import com.sun.enterprise.repository.J2EEResource;
29 import java.io.Serializable JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import com.sun.enterprise.deployment.EnvironmentProperty;
32 import com.sun.enterprise.connectors.authentication.ConnectorSecurityMap;
33
34 /**
35  * This class abstracts a connection connection pool. It contains
36  * two parts
37  * 1) Connector Connection Pool properties.
38  * 2) ConnectorDescriptorInfo which contains some of the values of ra.xml
39  * pertaining to managed connection factory class
40  *
41  * @author Srikanth Padakandla
42  */

43
44 public class ConnectorConnectionPool extends J2EEResourceBase
45                                       implements Serializable JavaDoc {
46     
47     protected ConnectorDescriptorInfo connectorDescriptorInfo_ ;
48
49     protected String JavaDoc steadyPoolSize_;
50     protected String JavaDoc maxPoolSize_;
51     protected String JavaDoc maxWaitTimeInMillis_;
52     protected String JavaDoc poolResizeQuantity_;
53     protected String JavaDoc idleTimeoutInSeconds_;
54     protected boolean failAllConnections_;
55     //This property will *always* initially be set to:
56
// true - by ConnectorConnectionPoolDeployer
57
// false - by JdbcConnectionPoolDeployer
58
protected boolean matchConnections_ = false;
59
60     protected int transactionSupport_;
61     protected boolean isConnectionValidationRequired_ = false;
62
63     private boolean lazyConnectionAssoc_ = false;
64     private boolean lazyConnectionEnlist_ = false;
65     private boolean associateWithThread_ = false;
66     private boolean nonTransactional_ = false;
67     private boolean nonComponent_ = false;
68     private boolean connectionLeakTracing_ = false;
69     private ConnectorSecurityMap[] securityMaps = null;
70     private boolean isAuthCredentialsDefinedInPool_ = false;
71
72     //To validate a Sun RA Pool Connection if it hasnot been validated in the past x sec. (x=idle-timeout)
73
//The property will be set from system property - com.sun.enterprise.connectors.ValidateAtmostEveryIdleSecs=true
74
private boolean validateAtmostEveryIdleSecs = false;
75     
76
77     /** Constructor
78      * @param name Name of the connector connection pool
79      */

80
81     public ConnectorConnectionPool(String JavaDoc name) {
82         super(name);
83     }
84     
85     /** Clone method.
86      */

87
88     protected J2EEResource doClone(String JavaDoc name) {
89
90         ConnectorConnectionPool clone = new ConnectorConnectionPool(name);
91         ConnectorDescriptorInfo cdi = connectorDescriptorInfo_.doClone();
92         clone.setSecurityMaps(this.securityMaps);
93         clone.setSteadyPoolSize(getSteadyPoolSize());
94         clone.setMaxPoolSize(getMaxPoolSize());
95         clone.setMaxWaitTimeInMillis(getMaxWaitTimeInMillis());
96         clone.setPoolResizeQuantity(getPoolResizeQuantity());
97         clone.setIdleTimeoutInSeconds(getIdleTimeoutInSeconds());
98         clone.setFailAllConnections(isFailAllConnections());
99         clone.setMatchConnections(matchConnections());
100     clone.setTransactionSupport( getTransactionSupport());
101         clone.setConnectorDescriptorInfo(cdi);
102     clone.setConnectionValidationRequired( isConnectionValidationRequired_ );
103     clone.setLazyConnectionAssoc( isLazyConnectionAssoc() );
104     clone.setAssociateWithThread( isAssociateWithThread() );
105     clone.setNonComponent( isNonComponent() );
106     clone.setNonTransactional( isNonTransactional() );
107     clone.setConnectionLeakTracing( isConnectionLeakTracing() );
108
109         return clone;
110     }
111
112     public void setAuthCredentialsDefinedInPool(boolean authCred) {
113         this.isAuthCredentialsDefinedInPool_ = authCred;
114     }
115
116     public boolean getAuthCredentialsDefinedInPool() {
117         return this.isAuthCredentialsDefinedInPool_;
118     }
119
120     /**
121      * Getter method of ConnectorDescriptorInfo which contains some the ra.xml
122      * values pertainining to managed connection factory
123      * @return ConnectorDescriptorInfo which contains ra.xml values
124      * pertaining to managed connection factory
125      */

126
127     public ConnectorDescriptorInfo getConnectorDescriptorInfo() {
128         return connectorDescriptorInfo_;
129     }
130    
131     /**
132      * Setter method of ConnectorDescriptorInfo which contains some the ra.xml
133      * values pertainining to managed connection factory
134      * @param ConnectorDescriptorInfo which contains ra.xml values
135      * pertaining to managed connection factory
136      */

137     
138     public void setConnectorDescriptorInfo(
139                    ConnectorDescriptorInfo connectorDescriptorInfo)
140     {
141         connectorDescriptorInfo_ = connectorDescriptorInfo;
142     }
143
144     /**
145      * Getter method of the Resource Type.
146      * @return Resource type
147      */

148
149     public int getType() {
150         return J2EEResource.JDBC_CONNECTION_POOL;
151     }
152    
153     /**
154      * Getter method of SteadyPoolSize property
155      * @return Steady Pool Size value
156      */

157
158     public String JavaDoc getSteadyPoolSize() {
159         return steadyPoolSize_;
160     }
161     
162     /**
163      * Setter method of SteadyPoolSize property
164      * @param steadyPoolSize Steady pool size value
165      */

166
167     public void setSteadyPoolSize(String JavaDoc steadyPoolSize) {
168         steadyPoolSize_ = steadyPoolSize;
169     }
170
171     /**
172      * Getter method of MaxPoolSize property
173      * @return maximum Pool Size value
174      */

175
176     public String JavaDoc getMaxPoolSize() {
177         return maxPoolSize_;
178     }
179
180     /**
181      * Setter method of MaxPoolSize property
182      * @param maxPoolSize maximum pool size value
183      */

184
185     public void setMaxPoolSize(String JavaDoc maxPoolSize) {
186         maxPoolSize_ = maxPoolSize;
187     }
188
189     /**
190      * Getter method of MaxWaitTimeInMillis property
191      * @return maximum wait time in milli value
192      */

193
194     public String JavaDoc getMaxWaitTimeInMillis() {
195         return maxWaitTimeInMillis_;
196     }
197     
198     /**
199      * Setter method of MaxWaitTimeInMillis property
200      * @param maxWaitTimeInMillis maximum wait time in millis value
201      */

202
203     public void setMaxWaitTimeInMillis(String JavaDoc maxWaitTimeInMillis) {
204         maxWaitTimeInMillis_ = maxWaitTimeInMillis;
205     }
206
207     /**
208      * Getter method of PoolResizeQuantity property
209      * @return pool resize quantity value
210      */

211
212     public String JavaDoc getPoolResizeQuantity() {
213         return poolResizeQuantity_;
214     }
215     
216     /**
217      * Setter method of PoolResizeQuantity property
218      * @param poolResizeQuantity pool resize quantity value
219      */

220
221     public void setPoolResizeQuantity(String JavaDoc poolResizeQuantity) {
222         poolResizeQuantity_ = poolResizeQuantity;
223     }
224
225     /**
226      * Getter method of IdleTimeoutInSeconds property
227      * @return idle Timeout in seconds value
228      */

229
230     public String JavaDoc getIdleTimeoutInSeconds() {
231         return idleTimeoutInSeconds_;
232     }
233     
234     /**
235      * Setter method of IdleTimeoutInSeconds property
236      * @param idleTimeoutInSeconds Idle timeout in seconds value
237      */

238
239     public void setIdleTimeoutInSeconds(String JavaDoc idleTimeoutInSeconds) {
240         idleTimeoutInSeconds_ = idleTimeoutInSeconds;
241     }
242     
243     /**
244      * Getter method of FailAllConnections property
245      * @return whether to fail all connections or not
246      */

247
248     public boolean isFailAllConnections() {
249         return failAllConnections_;
250     }
251     
252     /**
253      * Setter method of FailAllConnections property
254      * @param failAllConnections fail all connections value
255      *
256      */

257
258     public void setFailAllConnections(boolean failAllConnections) {
259         failAllConnections_ = failAllConnections;
260     }
261     
262     /**
263      * Getter method of matchConnections property
264      * @return whether to match connections always with resource adapter
265      * or not
266      */

267
268     public boolean matchConnections() {
269         return matchConnections_;
270     }
271     
272     /**
273      * Setter method of matchConnections property
274      * @param matchConnections fail all connections value
275      *
276      */

277
278     public void setMatchConnections(boolean matchConnections) {
279         matchConnections_ = matchConnections;
280     }
281
282     /**
283      * Returns the transaction support level for this pool
284      * The valid values are<br>
285      * <ul>
286      * <li>ConnectorConstants.NO_TRANSACTION</li>
287      * <li>ConnectorConstants.LOCAL_TRANSACTION</li>
288      * <li>ConnectorConstants.XA_TRANSACTION</li>
289      * </ul>
290      * @return the transaction support level for this pool
291      */

292     public int getTransactionSupport() {
293         return transactionSupport_;
294     }
295     
296     /**
297      * Sets the transaction support level for this pool
298      * The valid values are<br>
299      * <ul>
300      * <li>ConnectorConstants.NO_TRANSACTION</li>
301      * <li>ConnectorConstants.LOCAL_TRANSACTION</li>
302      * <li>ConnectorConstants.XA_TRANSACTION</li>
303      * </ul>
304      *
305      */

306     public void setTransactionSupport( int transactionSupport ) {
307         transactionSupport_ = transactionSupport;
308     }
309     
310     /**
311      * Sets the is-connection-validation-required pool attribute
312      */

313     public void setConnectionValidationRequired( boolean validation ) {
314         isConnectionValidationRequired_ = validation;
315     }
316     
317     /**
318      * Queries the is-connection-validation-required pool attribute
319      */

320     public boolean isIsConnectionValidationRequired() {
321         return isConnectionValidationRequired_;
322     }
323    
324     public boolean isLazyConnectionAssoc() {
325         return lazyConnectionAssoc_;
326     }
327
328     public void setLazyConnectionAssoc( boolean match ) {
329         lazyConnectionAssoc_ = match;
330     }
331
332     public boolean isLazyConnectionEnlist() {
333         return lazyConnectionEnlist_;
334     }
335
336     public void setLazyConnectionEnlist( boolean flag ) {
337         lazyConnectionEnlist_ = flag;
338     }
339    
340     public boolean isAssociateWithThread() {
341         return associateWithThread_;
342     }
343
344     public void setAssociateWithThread( boolean match ) {
345         associateWithThread_ = match;
346     }
347     
348     public boolean isNonTransactional() {
349         return nonTransactional_;
350     }
351
352     public void setNonTransactional( boolean match ) {
353         nonTransactional_ = match;
354     }
355
356     public boolean isNonComponent() {
357         return nonComponent_;
358     }
359
360     public void setNonComponent( boolean match ) {
361         nonComponent_ = match;
362     }
363     public boolean isConnectionLeakTracing() {
364         return connectionLeakTracing_;
365     }
366
367     public void setConnectionLeakTracing( boolean match ) {
368         connectionLeakTracing_ = match;
369     }
370
371
372     /** Setter method for Security Maps
373      * @param securityMapArray SecurityMap[]
374      */

375
376     public void setSecurityMaps(ConnectorSecurityMap[] securityMapArray){
377         this.securityMaps = securityMapArray;
378     }
379     
380     /** Getter method for Security Maps
381      * @return SecurityMap[]
382      */

383
384     public ConnectorSecurityMap[] getSecurityMaps(){
385         return this.securityMaps;
386     }
387
388     /**
389      * return the String representation of the pool.
390      * @return String representation of pool
391      */

392     public String JavaDoc toString() {
393         String JavaDoc returnVal = null;
394         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("ConnectorConnectionPool :: ");
395         try {
396             sb.append(getName());
397             sb.append("\nsteady size: ");
398             sb.append(getSteadyPoolSize());
399             sb.append("\nmax pool size: ");
400             sb.append(getMaxPoolSize());
401             sb.append("\nmax wait time: ");
402             sb.append(getMaxWaitTimeInMillis());
403             sb.append("\npool resize qty: ");
404             sb.append(getPoolResizeQuantity());
405             sb.append("\nIdle timeout: ");
406             sb.append(getIdleTimeoutInSeconds());
407             sb.append("\nfailAllConnections: ");
408             sb.append(isFailAllConnections());
409         sb.append("\nTransaction Support Level: ");
410         sb.append(transactionSupport_);
411         sb.append("\nmatchConnections_ ");
412         sb.append(matchConnections_);
413         sb.append("\nisConnectionValidationRequired_ ");
414         sb.append(isConnectionValidationRequired_);
415         sb.append("\nassociateWithThread_ ");
416         sb.append(associateWithThread_);
417             sb.append("\nlazyConnectionAssoc_ ");
418         sb.append(lazyConnectionAssoc_);
419         sb.append("\nnonTransactional_ ");
420         sb.append(nonTransactional_);
421         sb.append("\nnonComponent_ ");
422         sb.append(nonComponent_);
423         sb.append("\nconnectionLeakTracing_ ");
424         sb.append(connectionLeakTracing_);
425             sb.append("\nConnectorDescriptorInfo -> ");
426             sb.append("\nrarName: ");
427             sb.append(connectorDescriptorInfo_.getRarName());
428             sb.append("\nresource adapter class: ");
429             sb.append(connectorDescriptorInfo_.getResourceAdapterClassName());
430             sb.append("\nconnection def name: ");
431             sb.append(connectorDescriptorInfo_.getConnectionDefinitionName());
432             sb.append("\nMCF Config properties-> ");
433             Iterator JavaDoc iter =
434                 connectorDescriptorInfo_.getMCFConfigProperties().iterator();
435             while( iter.hasNext() ) {
436                 EnvironmentProperty ep = (EnvironmentProperty)iter.next();
437                 sb.append(ep.getName());
438                 sb.append(":");
439                 sb.append( ("password".equalsIgnoreCase(ep.getName()) ? "****" : ep.getValue() ));
440                 sb.append("\n");
441             }
442             if ( securityMaps != null ) {
443                 sb.append("SecurityMaps -> {");
444                 for (int i=0; i<securityMaps.length; i++) {
445                     if ( securityMaps[i] != null &&
446                             securityMaps[i].getName() != null ) {
447                         sb.append(securityMaps[i].getName()+" ");
448                     }
449                 }
450                 sb.append("}");
451             }
452             returnVal = sb.toString();
453         } catch( Exception JavaDoc e) {
454             e.printStackTrace();
455         }
456         return returnVal;
457     }
458
459      public boolean isValidateAtmostEveryIdleSecs() {
460          return validateAtmostEveryIdleSecs;
461      }
462      public void setValidateAtmostEveryIdleSecs(boolean validateAtmostEveryIdleSecs) {
463          this.validateAtmostEveryIdleSecs = validateAtmostEveryIdleSecs;
464      }
465
466 }
467
Popular Tags