KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > smartlib > pool > core > PoolConfig


1 /*
2  * @(#) PoolConfig 1.0 02/08/01
3  */

4
5 package org.smartlib.pool.core;
6
7 /**
8  * This class encapsulates the configuration of the pool
9  *
10  * @author Sachin Shekar Shetty
11  * @version 1.0, 02/08/01
12  */

13
14
15 public class PoolConfig implements ConfigMonitor {
16
17
18     //Default values when not specified
19
public static final boolean DEFAULT_POOL_VALUE = false;
20     public static final boolean AUTO_CLOSE = false;
21     public static final boolean ALLOW_ANONYMOUS_CONNECTIONS = false;
22     public static final String JavaDoc VALIDATION_QUERY = null;
23     public static final int INCREMENT_BY = 1;
24     public static final int MAX_FREE_CONNECTIONS_FOR_RELEASE = -1;
25     public static final int CONNECTION_WAIT_TIME_OUT = 10000;
26     public static final int MAX_CONNECTION_IDLE_TIME = -1;
27     public static final int POLL_THREAD_TIME = 5000;
28     public static final int LEAK_TIME_OUT = -1;
29     public static final boolean DETECT_LEAKS = false;
30
31
32
33     private String JavaDoc poolName;
34     private int maxConnections;
35     private int minConnections;
36     private int increment = INCREMENT_BY;
37     private String JavaDoc userName;
38     private String JavaDoc password;
39     private ConnectionString connectionString[];
40     private String JavaDoc driver;
41     private boolean isDefaultPool = DEFAULT_POOL_VALUE;
42     private boolean detectLeaks = DETECT_LEAKS;
43
44     //Leaktime out in milliseconds
45
private long leakTimeOut = LEAK_TIME_OUT;
46     private String JavaDoc defaultListener;
47
48     // Sleep time in Milliseconds
49
private long pollThreadTime = POLL_THREAD_TIME;
50     private boolean autoClose = AUTO_CLOSE;
51     private int maxConnectionsForRelease = MAX_FREE_CONNECTIONS_FOR_RELEASE;
52     private boolean allowAnonymousConnections = ALLOW_ANONYMOUS_CONNECTIONS;
53     private boolean externalPooling;
54     private ConnectionLoaderClass connectionLoaderClass[] = null;
55
56     // Wait time for connections in milliseconds
57
private long connectionWaitTimeOut = CONNECTION_WAIT_TIME_OUT;
58     private String JavaDoc validatorQuery = VALIDATION_QUERY;
59
60
61     // Connection Idle time in milliseconds
62
private long maxConnectionIdleTime = MAX_CONNECTION_IDLE_TIME;
63     private boolean threadStickiness;
64
65
66     PoolConfig() {
67     }
68
69     /**
70      * parameter list is too long to document, SELF HELP IS THE BEST HELP.
71      */

72     PoolConfig(String JavaDoc poolName, int maxConnections,
73                         int minConnections, String JavaDoc userName,
74                         String JavaDoc password, ConnectionString connectionString[],
75                         int increment, String JavaDoc driver
76                         ) {
77                                 
78         this.poolName = poolName;
79         this.maxConnections = maxConnections;
80         this.minConnections = minConnections;
81         this.increment = increment;
82         this.userName = userName;
83         this.password = password;
84         this.connectionString = connectionString;
85         this.driver = driver;
86
87     }
88
89     
90     /**
91      * This method returns the name of the pool.
92      * @return name of the pool.
93      */

94     public String JavaDoc getMultiPoolName() {
95
96         return poolName;
97
98     }
99
100     
101     void setMultiPoolName(String JavaDoc poolName) {
102
103         this.poolName = poolName;
104
105     }
106
107     public boolean isThreadStickiness() {
108         return threadStickiness;
109     }
110
111     public void setThreadStickiness(boolean threadStickiness) {
112         this.threadStickiness = threadStickiness;
113     }
114
115     /**
116      * @return Max connections allowed in the pool.
117      */

118     public int getMaxConnections() {
119
120         return maxConnections;
121
122     }
123
124     
125     void setMaxConnections(int maxConnections) {
126
127         this.maxConnections = maxConnections;
128
129     }
130
131     
132     /**
133      * @return minimun connections in the pool.
134      */

135     public int getMinConnections() {
136
137         return minConnections;
138
139     }
140
141     void setMinConnections(int minConnections) {
142
143         this.minConnections = minConnections;
144
145     }
146
147     /**
148      * @return size of blocks of connections withdrawn at a time when no free
149      * connections are available.
150      */

151     public int getIncrement() {
152
153         return increment;
154
155     }
156
157     
158     void setIncrement(int increment) {
159
160         this.increment = increment;
161
162     }
163
164     /**
165      * @return username to connect to the database.
166      */

167     public String JavaDoc getUserName() {
168
169         return userName;
170     
171     }
172
173     void setUserName(String JavaDoc userName) {
174
175         this.userName = userName;
176         
177     }
178
179     /**
180      * This method returns the password to connect to the database.
181      * @return password to connect to the database.
182      */

183     public String JavaDoc getPassword() {
184
185         return password;
186     
187     }
188
189     void setPassword(String JavaDoc password) {
190
191         this.password = password;
192         
193     }
194
195     /**
196      * @return connection string to connect to the database.
197      */

198     public ConnectionString[] getConnectionString() {
199
200         return connectionString;
201     
202     }
203
204     void setConnectionString(ConnectionString connectionString[]) {
205
206         this.connectionString = connectionString;
207         
208     }
209
210     /**
211      * @return driver name used to connect to database.
212      */

213     public String JavaDoc getDriver() {
214
215         return driver;
216
217     }
218
219     void setDriver(String JavaDoc driver) {
220
221         this.driver = driver;
222
223     }
224
225     /**
226      * @return true if this pool is the default pool.
227      */

228     public boolean isDefaultPool() {
229
230         return isDefaultPool;
231
232     }
233
234     void setDefaultPool(boolean b) {
235
236         isDefaultPool = b;
237
238     }
239
240     /**
241      * @return true if connection leak monitoring is enabled.
242      */

243     public boolean isDetectLeaks() {
244
245         return detectLeaks;
246
247     }
248
249     void setDetectLeaks(boolean b) {
250
251         detectLeaks = b;
252
253     }
254
255     /**
256      * @return time out for detecting leaks.
257      */

258     public long getLeakTimeOut() {
259
260         return leakTimeOut;
261
262     }
263
264     void setLeakTimeOut(long leakTimeOut) {
265
266         this.leakTimeOut = leakTimeOut;
267
268     }
269
270     /**
271      * @return default listener class for connection leak.
272      */

273     public String JavaDoc getDefaultListener() {
274
275         return defaultListener;
276
277     }
278
279     void setDefaultListener(String JavaDoc defaultListener) {
280
281         this.defaultListener= defaultListener ;
282
283     }
284     /**
285      * @return true if automotic closing of Statement ,PreparedStatement ,
286      * CallableStatement is enabled once the connection is closed is
287      * enabled.
288      */

289     public long getPollThreadTime() {
290
291         return pollThreadTime;
292
293     }
294
295     void setPollThreadTime(long pollThreadTime) {
296
297         this.pollThreadTime = pollThreadTime;
298
299     }
300
301     /**
302      * @return true if automatic closing of Statement ,PreparedStatement ,
303      * CallableStatement is enabled once the connection is closed is
304      * enabled.
305      */

306     public boolean isAutoClose() {
307
308         return autoClose;
309
310     }
311
312     void setAutoClose(boolean autoClose) {
313
314         this.autoClose = autoClose;
315     
316     }
317
318     /**
319      * This method returns the name of the pool.
320      * @return maximum number of free connections allowed after which
321      * excessive connections are released .
322      */

323     public int getMaxConnectionsForRelease() {
324
325         return maxConnectionsForRelease;
326
327     }
328
329     void setMaxConnectionsForRelease(int maxConnectionsForRelease) {
330
331         this.maxConnectionsForRelease = maxConnectionsForRelease;
332
333     }
334
335     void setAllowAnonymousConnections(
336             boolean allowAnonymousConnections) {
337             
338         this.allowAnonymousConnections = allowAnonymousConnections;
339
340     }
341
342     /**
343      * This method returns the name of the pool.
344      * @return true if anonymous connections are allowed , i.e
345      * without specifying the owner .
346      */

347     public boolean isAllowAnonymousConnections() {
348             
349         return (allowAnonymousConnections);
350
351     }
352
353
354     /**
355      * This method sets the fully qualified name of the Connection Loader class.
356      * @param connectionLoaderClass the fully qualified name of the Connection Loader class
357      */

358     
359     void setConnectionLoaderClass(ConnectionLoaderClass connectionLoaderClass[]) {
360
361         if (connectionLoaderClass != null)
362             externalPooling = true;
363         this.connectionLoaderClass = connectionLoaderClass;
364         
365     }
366
367     /**
368      * This method returns the fully qualified name of the Connection Loader class.
369      * @return Fully qualified name of the class
370      */

371     
372     public ConnectionLoaderClass[] getConnectionLoaderClass() {
373         
374         return (connectionLoaderClass);
375
376     }
377
378     /**
379      * This method returs a boolean.
380      *
381      * @return true- If Smart pool is wrapped to another pool
382      *
383      */

384     public boolean isExternalPooling() {
385     
386         return externalPooling;
387
388     }
389
390
391     /**
392      * This method sets the isExternalPooling value.
393      *
394      * @param externalPooling true- If Smart pool is wrapped to another pool.
395      *
396      */

397     void setExternalPooling(boolean externalPooling) {
398
399         this.externalPooling = externalPooling;
400
401     }
402
403     /**
404      * This method returns the connectionWaitTimeOut value.
405      */

406     public long getConnectionWaitTimeOut() {
407
408         return connectionWaitTimeOut;
409         
410     }
411     
412     /**
413      * This method sets the connectionWaitTimeOut value.
414      *
415      * @param connectionWaitTimeOut
416      *
417      */

418     void setConnectionWaitTimeOut(long connectionWaitTimeOut) {
419
420         this.connectionWaitTimeOut = connectionWaitTimeOut;
421         
422     }
423
424     /**
425      * This method returns the max-connection-idle-time value.
426      */

427     public long getMaxConnectionIdleTime() {
428
429         return maxConnectionIdleTime;
430         
431     }
432     
433     /**
434      * This method sets the max-connection-idle-time value.
435      *
436      * @param maxConnectionIdleTime
437      *
438      */

439     void setMaxConnectionIdleTime(long maxConnectionIdleTime) {
440
441         this.maxConnectionIdleTime = maxConnectionIdleTime;
442         
443     }
444
445     /**
446      * This method sets the Validator-Query.
447      *
448      * @param validatorQuery
449      */

450
451     void setValidatorQuery(String JavaDoc validatorQuery) {
452
453         this.validatorQuery = validatorQuery;
454         
455     }
456
457     /**
458      * This method returns the validatorQuery.
459      *
460      * @return validatorQuery
461      */

462     public String JavaDoc getValidatorQuery() {
463
464         return validatorQuery;
465
466     }
467
468     /**
469      * This metod returns the ConnectionString object with the name <code>name</code>
470      */

471     public ConnectionString getConnectionStringByName(String JavaDoc name) {
472         for (int i=0; i<connectionString.length; i++) {
473             if (connectionString[i].getName().equals(name)) {
474                 return connectionString[i];
475             }
476         }
477         return null;
478     }
479
480     /**
481      * This metod returns the ConnectionLoaderClass object with the name <code>name</code>
482      */

483     public ConnectionLoaderClass getConnectionLoaderClassByName(String JavaDoc name) {
484         for (int i=0; i<connectionLoaderClass.length; i++) {
485             if (connectionLoaderClass[i].getName().equals(name)) {
486                 return connectionLoaderClass[i];
487             }
488         }
489         return null;
490     }
491
492
493     /**
494      * You know what this does.
495      */

496     public String JavaDoc toString() {
497
498         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
499         sb.append("\n\nConnection Pool Configuration ======>");
500         sb.append("\n\tPoolName: " + poolName);
501         sb.append("\n\tMax Connections: " + maxConnections);
502         sb.append("\n\tMin Connections: " + minConnections);
503         sb.append("\n\tIncrement-Connections by: " + increment);
504         sb.append("\n\tUser Name: " + userName);
505         sb.append("\n\tPassword: " + password);
506         sb.append("\n\tConnection String: " + connectionString);
507         if (connectionString != null) {
508             for (int i=0; i<connectionString.length; i++) {
509                 sb.append("\n\t " + connectionString[i]);
510             }
511         }
512         sb.append("\n\tThread Skickiness: " + threadStickiness);
513         sb.append("\n\tDriver: " + driver);
514         sb.append("\n\tVakidator Query: " + validatorQuery);
515         sb.append("\n\tDefault Pool: " + isDefaultPool);
516         sb.append("\n\tDetect Leaks: " + detectLeaks);
517         sb.append("\n\tLeak Timeout: " + leakTimeOut + " Milli Seconds");
518         sb.append("\n\tDefault Listener: " + defaultListener);
519         sb.append("\n\tPool Thread Time: " + pollThreadTime + " Milli Seconds");
520         sb.append("\n\tAuto Close: " + autoClose);
521         sb.append("\n\tMax connection for release: " + maxConnectionsForRelease);
522         sb.append("\n\tConnection Loader Class: " + connectionLoaderClass);
523         if (connectionLoaderClass != null) {
524             for (int i=0; i<connectionLoaderClass.length; i++) {
525                 sb.append("\n\t " + connectionLoaderClass[i]);
526             }
527         }
528         sb.append("\n\tConnection Wait Time Out: " + connectionWaitTimeOut + " Milli Seconds");
529         sb.append("\n\tMaximum Connection Idle Time: " + maxConnectionIdleTime + " Milli Seconds");
530         return sb.toString();
531
532     }
533
534     public static class ConnectionString {
535
536         private String JavaDoc name;
537         private String JavaDoc connectString;
538
539         public String JavaDoc getName() {
540             return name;
541         }
542
543         public void setName(String JavaDoc name) {
544             this.name = name;
545         }
546
547         public String JavaDoc getConnectString() {
548             return connectString;
549         }
550
551         public void setConnectString(String JavaDoc connectString) {
552             this.connectString = connectString;
553         }
554
555         public String JavaDoc toString() {
556             return "ConnectionString{" + name + "," + connectString +"}";
557         }
558
559     }
560
561     public static class ConnectionLoaderClass {
562
563         private String JavaDoc name;
564         private String JavaDoc connectionLoaderClass;
565
566         public String JavaDoc getName() {
567             return name;
568         }
569
570         public void setName(String JavaDoc name) {
571             this.name = name;
572         }
573
574         public String JavaDoc getConnectionLoaderClass() {
575             return connectionLoaderClass;
576         }
577
578         public void setConnectionLoaderClass(String JavaDoc connectionLoaderClass) {
579             this.connectionLoaderClass = connectionLoaderClass;
580         }
581
582         public String JavaDoc toString() {
583             return "ConnectionLoaderClass{" + name + "," + connectionLoaderClass +"}";
584         }
585
586     }
587  
588 }
589
Popular Tags