KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > org > primrose > pool > jmx > Queue


1 /**
2 * Library name : Primrose - A Java Database Connection Pool.
3 * Published by Ben Keeping, http://primrose.org.uk .
4 * Copyright (C) 2004 Ben Keeping, primrose.org.uk
5 * Email: Use "Contact Us Form" on website
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */

21
22 package uk.org.primrose.pool.jmx;
23
24 import uk.org.primrose.pool.jmx.*;
25 import uk.org.primrose.pool.core.*;
26 import java.util.Vector JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28 import java.util.Properties JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.io.PrintWriter JavaDoc;
31 import java.io.FileOutputStream JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.Serializable JavaDoc;
34 import java.sql.Connection JavaDoc;
35
36 /**
37 * JMX wrapper for the core pool.<p>
38 * Each Queue has its own Pool, and controls how calling client code
39 * interacts with the core pool.<p>
40 */

41 public class Queue implements QueueMBean, Serializable JavaDoc {
42     private Pool pool;
43     private int waitingThreads;
44     // The time for which active/in use connections should be killed.
45
private String JavaDoc killActiveConnectionsOverAge = "-1";
46     private boolean queueConnectionRequests = true;
47     //private boolean poolHasBeenTerminated = false;
48
java.text.SimpleDateFormat JavaDoc sdf = new java.text.SimpleDateFormat JavaDoc("yyyy-MM-dd");
49     java.util.Date JavaDoc logDate = new java.util.Date JavaDoc();
50     String JavaDoc logDateString = "";
51     String JavaDoc logNameOrig = null;
52     String JavaDoc logName = null;
53     int inc = 0;
54     int dec = 0;
55     int threadCount = 0;
56     private boolean runPooledMode;
57     private ArrayList JavaDoc objectMonitors = null;
58
59     public Queue() {
60         logDateString = sdf.format(logDate);
61         objectMonitors = new ArrayList JavaDoc();
62     }
63
64
65     /**
66     * Kill active connections over a certain age, defined in seconds.
67     *
68     * @param int age - what age connections should be killed, defined in seconds.
69     * @param boolean daemon - whether or not a daemon thread is calling this
70     * or whether a user has called this from an exposed
71     * JMX method (used for logging).
72     */

73     private String JavaDoc killActiveConnectionsOverAge(int age, boolean daemon) {
74
75         String JavaDoc ret = "";
76
77         if (daemon) {
78             ret += "Killing connections by daemon :\n";
79         } else {
80             ret += "Killing connections by invocation from web management page :<br>";
81         }
82
83         Vector JavaDoc actCon = pool.getActiveConnections();
84         int actConSize = actCon.size();
85         boolean found = false;
86
87         for (int i = 0; i < actConSize; i++) {
88             try {
89             PoolConnection pc = (PoolConnection)actCon.elementAt(0);
90             // millis --> seconds
91
long timeInUse = pc.getTimeInUse()/1000;
92             if ((int)timeInUse > age) {
93                 found = true;
94                 ret += ("Killed connection " +pc +" : timeInUse(" +timeInUse +"), SQL(" + pc.getSql() +")<br>\n");
95                 if (daemon) pool.log("About to kill connection " +pc +" : timeInUse(" +timeInUse +"), SQL(" + pc.getSql() +")", true);
96
97                 pool.killActiveConnection(pc);
98
99                 // If we are running as the daemon, then log the kill
100
if (daemon) pool.log("Killed connection(complete) " +pc +" : timeInUse(" +timeInUse +"), SQL(" + pc.getSql() +")", true);
101             }
102
103             // Sometimes if the pool is loaded up, and connections
104
// are moving quickly, the actConSize may be > 0 at the time of asking
105
// but by the time it comes to extract elementAt(0), its gone -
106
// so ignore these Excpetions
107
} catch (Exception JavaDoc e) {}
108
109         }
110
111         if (!found) ret += "No connections found over age " +age +" seconds.";
112
113
114         return ret;
115
116     }
117
118
119
120
121     /**
122     * Kill active connections over a certain age, defined in seconds.<br>
123     * This method is exposed via JMX.
124     *
125     * @param int age - what age connections should be killed, defined in seconds.
126     */

127     public String JavaDoc killActiveConnectionsOverAge(int age) {
128         return killActiveConnectionsOverAge(age, false);
129     }
130
131
132     /** JMX Exposed Operations **/
133     // Stop and start the pool with the same parameters
134
public void reset() {
135         this.stopPool();
136         this.startPool();
137     }
138
139     public void addConnection(int num) {
140         pool.setBase(pool.getBase() +num);
141         pool.fill(num);
142     }
143
144     public void startPool() {
145         if (!getAvailable()) {
146             pool.fill(getBase());
147             if (getAvailableConnectionsSize() == getBase()) {
148                 setAvailable(true);
149             }
150         }
151         startObjectMonitors();
152     }
153
154     /**
155     * When the pool is stopped, all the connections are removed from the Pool
156     * object, and killed/closed at the physical connection source (ie the db).<br>
157     * If any connections are currently being used when the pool is closed,
158     * then once they return, the connections are dumped.
159     */

160     public void stopPool() {
161         pool.log("[Queue-" +this.getName() +"] SHUTTING DOWN POOL !", true);
162         stopObjectMonitors();
163         int availSize = getAvailableConnectionsSize();
164
165         if (availSize < getBase()) {
166             pool.getLog().println("WARNING !!! Pool elements are ACTIVE !!! " +availSize +" " +getBase());
167         }
168         for (int i = 0; i < availSize; i++) {
169             pool.log("[Queue-" +this.getName() +"] STOPPING POOL element : " +i +" (NON-ACTIVE)", false);
170             PoolConnection pc = (PoolConnection)pool.get();
171             pool.dump(pc);
172             pool.removeFromActiveConnections(pc);
173         }
174
175         int actSize = getActiveConnectionsSize();
176         Vector JavaDoc activeConnections = pool.getActiveConnections();
177         for (int i = 0; i < actSize; i++) {
178              PoolConnection pc = (PoolConnection)activeConnections.get(0);
179              pool.log("[Queue-" +this.getName() +"] STOPPING POOL element : " +i +" (ACTIVE)", false);
180              pool.dump(pc);
181              pool.removeFromActiveConnections(pc);
182
183         }
184         pool.log("[Queue-" +this.getName() +"] POOL STOPPED.", true);
185
186         setAvailable(false);
187         //setWaitingThreads(0);
188
//poolHasBeenTerminated = true;
189
pool.setOverflow(pool.getOverflow());
190
191     }
192
193     /** JMX Un-Exposed Operations **/
194
195
196     /**
197     * If the config file (poolConfig.properties) has this option set to any value
198     * higher than '-1' or "", then kill off any connections older than that specified
199     * time.
200     */

201     public int checkActiveConnectionTimes() {
202         String JavaDoc age = this.getKillActiveConnectionsOverAge();
203         if (age != null && age.length() != 0 && !(age.equals("-1"))) {
204             int a = (int)Long.parseLong(age) / 1000;
205             killActiveConnectionsOverAge(a, true);
206         }
207
208         return 0;
209     }
210
211     /**
212     * If the pool connections are too idle, then we may as well dump
213     * them as they may go stale, nad there is no point in keeping
214     * a network connection open if we don't need it.
215     */

216     public synchronized int checkIdleConnections() {
217         return pool.checkIdleConnections();
218     }
219
220     /**
221     * Create a new pool !
222     */

223     public void startNewPool(Properties JavaDoc props) {
224         pool = new Pool();
225         Object JavaDoc tmpProp = null;
226
227         // Set the pool / queue name
228
tmpProp = props.getProperty("poolName");
229         String JavaDoc poolName = (tmpProp == null ? "noPoolNameSet" : (String JavaDoc)tmpProp);
230
231         // Set the number of base connections
232
tmpProp = props.getProperty("base");
233         int base = (tmpProp == null ? 5 : Integer.parseInt((String JavaDoc)tmpProp));
234
235         // Set the number of overflow connections allowed
236
tmpProp = props.getProperty("overflow");
237         int overflow = (tmpProp == null ? 2 : Integer.parseInt((String JavaDoc)tmpProp));
238
239         // Set the log - this can be null !
240
tmpProp = props.getProperty("log");
241         String JavaDoc log = (tmpProp == null ? null : (String JavaDoc)tmpProp);
242
243         // Set the default idle time for connections
244
tmpProp = props.getProperty("idleTime");
245         int idleTime = (tmpProp == null ? 120000 : Integer.parseInt((String JavaDoc)tmpProp));
246
247         // Set whether pool messages should be logged
248
tmpProp = props.getProperty("messageLogging");
249         boolean messageLogging = (tmpProp == null ? true : new Boolean JavaDoc((String JavaDoc)tmpProp).booleanValue());
250
251         // Set whether pool sizes should be logged
252
tmpProp = props.getProperty("sizeLogging");
253         boolean sizeLogging = (tmpProp == null ? true : new Boolean JavaDoc((String JavaDoc)tmpProp).booleanValue());
254
255         // Set the driver class
256
tmpProp = props.getProperty("driverClass");
257         String JavaDoc driverClass = (tmpProp == null ? null : (String JavaDoc)tmpProp);
258
259         // Set the driver URL
260
tmpProp = props.getProperty("driverURL");
261         String JavaDoc driverURL = (tmpProp == null ? null : (String JavaDoc)tmpProp);
262
263         // Set the db user
264
tmpProp = props.getProperty("user");
265         String JavaDoc user = (tmpProp == null ? null : (String JavaDoc)tmpProp);
266
267         // Set the db password
268
tmpProp = props.getProperty("password");
269         String JavaDoc password = (tmpProp == null ? null : (String JavaDoc)tmpProp);
270
271         // Set the time connections have till they are timed out (killed)
272
tmpProp = props.getProperty("killActiveConnectionsOverAge");
273         String JavaDoc killActiveConnectionsOverAge = (tmpProp == null ? "-1" : (String JavaDoc)tmpProp);
274
275         // Set the number of max transactions a connection should make before being renewed
276
tmpProp = props.getProperty("cycleConnections");
277         int cycleConnections = (tmpProp == null ? -1 : Integer.parseInt((String JavaDoc)tmpProp));
278
279         // Set whether connection requests should be queued or not
280
tmpProp = props.getProperty("queueConnectionRequests");
281         boolean queueConnectionRequests = (tmpProp == null ? true : new Boolean JavaDoc((String JavaDoc)tmpProp).booleanValue());
282
283         // Set whether we should run with or without pooled connections vs dedicated connections
284
tmpProp = props.getProperty("runPooledMode");
285         boolean runPooledMode = (tmpProp == null ? true : new Boolean JavaDoc((String JavaDoc)tmpProp).booleanValue());
286
287         // Set whether auto commit should be on or off
288
tmpProp = props.getProperty("connectionAutoCommit");
289         boolean connectionAutoCommit = (tmpProp == null ? true : new Boolean JavaDoc((String JavaDoc)tmpProp).booleanValue());
290
291         // Set the transaction level - this can be null (will be defaulted if so in the Pool)!
292
tmpProp = props.getProperty("connectionTransactionIsolation");
293         String JavaDoc connectionTransactionIsolation = (tmpProp == null ? null : (String JavaDoc)tmpProp);
294
295         tmpProp = props.getProperty("checkSQL");
296         String JavaDoc checkSQL = (tmpProp == null ? null : (String JavaDoc)tmpProp);
297
298
299         // Now set all the appropriate properties in the pool
300
pool.setName(poolName);
301         pool.setBase(base);
302         pool.setOverflow(overflow);
303         this.logNameOrig = log;
304         this.setUpLog();
305         pool.setDriverClass(driverClass);
306         pool.setDriverURL(driverURL);
307         pool.setUser(user);
308         pool.setPassword(password);
309         this.setIdleTime(idleTime);
310         pool.setMessageLogging(messageLogging);
311         pool.setSizeLogging(sizeLogging);
312         this.setKillActiveConnectionsOverAge(killActiveConnectionsOverAge);
313         this.setQueueConnectionRequests(queueConnectionRequests);
314         pool.setCycleConnections(cycleConnections);
315         this.setRunPooledMode(runPooledMode);
316         this.setConnectionAutoCommit(connectionAutoCommit);
317         this.setConnectionTransactionIsolation(connectionTransactionIsolation);
318         pool.setCheckSQL(checkSQL);
319
320         pool.fill(base);
321
322         //if (getAvailableConnectionsSize() == base) {
323
//setAvailable(true);
324
//}
325
// set the pool as available ... even if we could not get a connection
326
// this may mean that the user wants a non-available db to be
327
// available as a pool at a later date (2.7.1 change) for a db that may
328
// come up as a failover ...
329
setAvailable(true);
330     }
331
332
333     public void startNewPool (String JavaDoc poolName, int base, int overflow, String JavaDoc log,
334                                 int idleTime, boolean messageLogging, boolean sizeLogging,
335                                 String JavaDoc driverClass, String JavaDoc driverURL, String JavaDoc user, String JavaDoc password,
336                                 String JavaDoc killActiveConnectionsOverAge, String JavaDoc cycleConnections, boolean queueConnectionRequests,
337                                 boolean runPooledMode, boolean connectionAutoCommit, String JavaDoc connectionTransactionIsolation, String JavaDoc checkSQL) {
338         pool = new Pool();
339         setPoolParameters(poolName, base, overflow, log, idleTime, messageLogging, sizeLogging,
340                             driverClass, driverURL, user, password, killActiveConnectionsOverAge,
341                             cycleConnections, queueConnectionRequests, runPooledMode, connectionAutoCommit, connectionTransactionIsolation, checkSQL);
342     }
343
344     /**
345     * When the pool is running, but you wish to reset the parameters ...
346     */

347     public void restartPool(String JavaDoc poolName, int base, int overflow, String JavaDoc log,
348                              Integer JavaDoc idleTime, Boolean JavaDoc messageLogging, Boolean JavaDoc sizeLogging,
349                              String JavaDoc driverClass, String JavaDoc driverURL, String JavaDoc user, String JavaDoc password,
350                              String JavaDoc killActiveConnectionsOverAge, String JavaDoc cycleConnections, boolean queueConnectionRequests,
351                              boolean runPooledMode, boolean connectionAutoCommit, String JavaDoc connectionTransactionIsolation, String JavaDoc checkSQL) {
352
353         setPoolParameters(poolName, base, overflow, log, idleTime.intValue(), messageLogging.booleanValue(),
354                             sizeLogging.booleanValue(), driverClass, driverURL, user, password,
355                             killActiveConnectionsOverAge, cycleConnections, queueConnectionRequests,
356                             runPooledMode, connectionAutoCommit, connectionTransactionIsolation, checkSQL);
357
358     }
359
360     /**
361     * private helper method for setting the pool parameters.
362     */

363     private void setPoolParameters(String JavaDoc poolName, int base, int overflow, String JavaDoc log,
364                              int idleTime, boolean messageLogging, boolean sizeLogging,
365                              String JavaDoc driverClass, String JavaDoc driverURL, String JavaDoc user, String JavaDoc password,
366                              String JavaDoc killActiveConnectionsOverAge, String JavaDoc cycleConnections, boolean queueConnectionRequests,
367                              boolean runPooledMode, boolean connectionAutoCommit, String JavaDoc connectionTransactionIsolation, String JavaDoc checkSQL) {
368         pool.setName(poolName);
369         pool.setBase(base);
370         pool.setOverflow(overflow);
371         this.logNameOrig = log;
372         this.setUpLog();
373         pool.setDriverClass(driverClass);
374         pool.setDriverURL(driverURL);
375         pool.setUser(user);
376         pool.setPassword(password);
377         this.setIdleTime(idleTime);
378         pool.setMessageLogging(messageLogging);
379         pool.setSizeLogging(sizeLogging);
380         this.setKillActiveConnectionsOverAge(killActiveConnectionsOverAge);
381         this.setRunPooledMode(runPooledMode);
382         this.setQueueConnectionRequests(queueConnectionRequests);
383         if (cycleConnections == null || cycleConnections.length() == 0) {
384             pool.setCycleConnections(-1);
385         } else {
386             pool.setCycleConnections(Integer.parseInt(cycleConnections));
387         }
388         pool.setCheckSQL(checkSQL);
389
390         pool.fill(base);
391
392         if (getAvailableConnectionsSize() == base) {
393             setAvailable(true);
394         }
395     }
396
397     private void parseLogName() {
398         if (logNameOrig == null || logNameOrig.indexOf("${") == -1) return;
399
400         String JavaDoc dateFormat = logNameOrig.substring(logNameOrig.indexOf("${") +2, logNameOrig.indexOf("}"));
401         String JavaDoc logPrefix = logNameOrig.substring(0, logNameOrig.indexOf("${"));
402         String JavaDoc logSuffix = logNameOrig.substring(logNameOrig.indexOf("}")+1, logNameOrig.length());
403         java.text.SimpleDateFormat JavaDoc sdf2 = new java.text.SimpleDateFormat JavaDoc(dateFormat);
404         java.util.Date JavaDoc tmp = new java.util.Date JavaDoc();
405         String JavaDoc formattedDate = sdf2.format(tmp);
406
407         this.logName = (logPrefix +formattedDate +logSuffix);
408     }
409
410     public String JavaDoc setUpLog() {
411         // If they have not set a log at all, just return
412
if (logNameOrig == null) return "0";
413
414         // If there is no date format to do, just set the log
415
// name as normal and return.
416
if (logNameOrig.indexOf("${") == -1) {
417             try {
418                 pool.setLog(new PrintWriter JavaDoc(new FileOutputStream JavaDoc(logNameOrig, true), true));
419             } catch (IOException JavaDoc ioe) {
420                 ioe.printStackTrace(System.err);
421             }
422
423             return "0";
424         }
425
426
427         // If this far, then there is a date format log to
428
// set up.
429
// So parse the date format and set up the log.
430
// Cycle the log day to day.
431
String JavaDoc tmpDateString = sdf.format(new java.util.Date JavaDoc());
432         PrintWriter JavaDoc log = pool.getLog();
433
434         if (log != null) {
435             if (!tmpDateString.equals(logDateString)) {
436                 this.logDateString = tmpDateString;
437                 pool.log("Cycling log at : " +(new java.util.Date JavaDoc()), false);
438                 log.flush();
439                 log.close();
440                 parseLogName();
441
442                 try {
443                     pool.setLog(new PrintWriter JavaDoc(new FileOutputStream JavaDoc(logName, true), true));
444                 } catch (IOException JavaDoc ioe) {
445                     ioe.printStackTrace(System.err);
446                 }
447             }
448         // First time through ...
449
} else {
450             parseLogName();
451             try {
452                 pool.setLog(new PrintWriter JavaDoc(new FileOutputStream JavaDoc(logName, true), true));
453             } catch (IOException JavaDoc ioe) {
454                 ioe.printStackTrace(System.err);
455             }
456         }
457         return "0";
458     }
459
460     /**
461     * Extract a connection from the pool.<br>
462     * If the connection returned from the pool is null, then all connections are busy.<br>
463     * If this happens, then go into a recursive call to getConnectionWait(),
464     * a private method that sleeps for a second, and then tries to get a connection
465     * again.<br>
466     * If this method is entered, then we add 1 to the waiting connections.<br>
467     * If the number of waiting connections is > 0, then we tell the pool that we
468     * have waiting threads, so it should not dump any overflow connections, but return
469     * them to the pool to ease congestion on the pool.<br>
470     * Once waiting threads have returned to 0, the pool may dump overflow connections
471     * to return the pool to its normal 'base' size.
472     *
473     */

474     public Connection JavaDoc getConnection() {
475         Connection JavaDoc pc = pool.get();
476
477         // Is our connection null (ie the pool full) ?
478
// If not, then return the connection, but if it is full,
479
// then set the number of waiting threads ++, and enter
480
// the recursive method call of getConnectionWait()
481
// System.err.println("waitingThreads " +waitingThreads);
482
if (pc != null) {
483             if (waitingThreads == 0) pool.setWaitingThreads(false);
484             return pc;
485         } else {
486             if (queueConnectionRequests == false || !pool.isAvailable()) {
487                 return null;
488             }
489             //setWaitingThreads(getWaitingThreads() +1);
490
waitingThreads++;
491             try { Thread.sleep(1000); } catch (InterruptedException JavaDoc ie) {}
492             return getConnectionWait();
493         }
494     }
495
496     private Connection JavaDoc getConnectionWait() {
497         // Send a hint to the pool to indicate whether we still have
498
// waiting threads or not.
499
if (waitingThreads > 0)
500             pool.setWaitingThreads(true);
501         else
502             pool.setWaitingThreads(false);
503
504         Connection JavaDoc pc = pool.get();
505         //System.err.println("waitingThreads " +waitingThreads);
506

507         // If the connection is not null, then return it, and set the
508
// waiting thread count --.
509
// Else, the pool must be full, so sleep, and recurse again.
510
//
511
// TODO : Need to think about blowing the stack with too
512
// many waiting threads ....
513
//
514
if (pc != null) {
515             //setWaitingThreads(getWaitingThreads() -1);
516
waitingThreads--;
517
518             return pc;
519         } else {
520             try { Thread.sleep(1000); } catch (InterruptedException JavaDoc ie) {}
521             return getConnectionWait();
522         }
523     }
524
525     /** RO Attributes **/
526
527     /**
528     * Gets the default level for connection's isolation transaction level.
529     */

530     public String JavaDoc getConnectionTransactionIsolation() {
531         return pool.getConnectionTransactionIsolation();
532     }
533
534
535     /**
536     * Gets whether the connections should have auto commit on or off by default.
537     */

538     public boolean getConnectionAutoCommit() {
539         return pool.getConnectionAutoCommit();
540     }
541
542
543     public boolean getRunPooledMode() {
544         return pool.getRunPooledMode();
545     }
546
547     /**
548     * Gets how often the pool should cycle connections.
549     * The param is the number of SQL transactions performed.
550     * If -1, then connections are not cycled.
551     */

552     public int getCycleConnections() {
553         return pool.getCycleConnections();
554     }
555
556     /**
557     * Gets the pool idle time.
558     */

559     public int getIdleTime() {
560         return pool.getIdleTime();
561     }
562
563     /**
564     * Returns the message logging state.
565     * @return boolean
566     */

567     public boolean getMessageLogging() {
568         return pool.getMessageLogging();
569     }
570
571     /**
572     * Returns the sizeLogging state.
573     * @return boolean
574     */

575     public boolean getSizeLogging() {
576         return pool.getSizeLogging();
577     }
578
579     /**
580     * Returns the threads waiting for a connection.
581     * @return int
582     */

583     public synchronized int getWaitingThreads() {
584         return waitingThreads;
585     }
586
587     private synchronized void setWaitingThreads(int waitingThreads) {
588         //if (waitingThreads < 0) {
589
//this.waitingThreads = 0;
590
//} else {
591
this.waitingThreads = waitingThreads;
592         //}
593
}
594
595
596     /**
597     * Returns the active connections size.
598     * @return boolean
599     */

600     public int getActiveConnectionsSize() {
601         return pool.getActiveConnections().size();
602     }
603
604     /**
605     * Returns the available connections size.
606     * @return boolean
607     */

608     public int getAvailableConnectionsSize() {
609         return pool.getAvailableConnections().length;
610     }
611
612     /**
613     * Returns the active.
614     * @return boolean
615     */

616     public boolean getAvailable() {
617         return pool.isAvailable();
618     }
619
620     /**
621     * Returns the SQL (if any) associated with a connection, and the time in use.
622     * @return String[]
623     */

624     public String JavaDoc[] getActiveConnectionData() {
625         return pool.getActiveConnectionsData();
626     }
627
628     public String JavaDoc[] getAvailableConnections() {
629         return pool.getAvailableConnections();
630     }
631
632     /**
633     * Returns the base.
634     * @return int
635     */

636     public int getBase() {
637         return pool.getBase();
638     }
639
640
641     /**
642     * Returns the name.
643     * @return String
644     */

645     public String JavaDoc getName() {
646         return pool.getName();
647     }
648
649     /**
650     * Returns the overflow.
651     * @return int
652     */

653     public int getOverflow() {
654         return pool.getOverflow();
655     }
656
657     /**
658     * Returns the driverURL.
659     * @return String
660     */

661     public String JavaDoc getDriverURL() {
662         return pool.getDriverURL();
663     }
664
665     /**
666     * Returns the user.
667     * @return String
668     */

669     public String JavaDoc getUser() {
670         return pool.getUser();
671     }
672
673     /**
674     * Returns the password.
675     * @return String
676     */

677     public String JavaDoc getPassword() {
678         return pool.getPassword();
679     }
680
681     /**
682     * Returns the driverClass.
683     * @return String
684     */

685     public String JavaDoc getDriverClass() {
686         return pool.getDriverClass();
687     }
688
689     /**
690     * Gets whether the pool should kill connections in use (active) over a certain age (in milliseconds).
691     */

692     public String JavaDoc getKillActiveConnectionsOverAge() {
693         return killActiveConnectionsOverAge;
694     }
695
696     /**
697     * Gets whether the pool queues Connection Requests.
698     */

699     public boolean getQueueConnectionRequests() {
700         return this.queueConnectionRequests;
701     }
702
703     /** WO attributes **/
704
705     /**
706     * Sets whether the connections should have auto commit on or off by default.
707     */

708     public void setConnectionAutoCommit(boolean connectionAutoCommit) {
709         pool.log("INFO : Connections default to auto commit : '" +connectionAutoCommit +"'", false);
710         pool.setConnectionAutoCommit(connectionAutoCommit);
711     }
712
713     /**
714     * Sets the default level for connection's isolation transaction level.
715     */

716     private void setConnectionTransactionIsolation(String JavaDoc connectionTransactionIsolation) {
717         pool.setConnectionTransactionIsolation(connectionTransactionIsolation);
718     }
719
720
721     public void setRunPooledMode(boolean runPooledMode) {
722             pool.log("INFO : Using pooling : '" +runPooledMode +"'", false);
723             this.runPooledMode = runPooledMode;
724             pool.setRunPooledMode(runPooledMode);
725     }
726
727     /**
728     * Sets the pool idle time.
729     */

730     public void setIdleTime(int idleTime) {
731         pool.setIdleTime(idleTime);
732     }
733
734     /**
735     * Sets whether the pool is available.
736     */

737     public void setAvailable(boolean a) {
738         pool.setAvailable(a);
739     }
740
741     /**
742     * Sets whether the pool logs messages/actions.
743     */

744     public void setMessageLogging(boolean messageLogging) {
745         pool.setMessageLogging(messageLogging);
746     }
747
748     /**
749     * Sets whether the pool logs the size of the pool.
750     */

751     public void setSizeLogging(boolean sizeLogging) {
752         pool.setSizeLogging(sizeLogging);
753     }
754
755     /**
756     * Gets how often the pool should cycle connections.
757     * The param is the number of SQL transactions performed.
758     * If -1, then connections are not cycled.
759     */

760     public void setCycleConnections(int cycleConnections) {
761         pool.setCycleConnections(cycleConnections);
762     }
763
764     /**
765     * Sets whether the pool should kill connections in use (active) over a certain age (in milliseconds).
766     */

767     public void setKillActiveConnectionsOverAge(String JavaDoc killActiveConnectionsOverAge) {
768         this.killActiveConnectionsOverAge = killActiveConnectionsOverAge;
769     }
770
771     /**
772     * Sets whether the pool queues Connection Requests.
773     */

774     public void setQueueConnectionRequests(boolean queueConnectionRequests) {
775         pool.log("INFO : Queueing Connection requests : '" +queueConnectionRequests +"'", false);
776         this.queueConnectionRequests = queueConnectionRequests;
777     }
778
779
780     public void startObjectMonitors() {
781         for (int i = 0; i < objectMonitors.size(); i++) {
782             ObjectMonitor om = (ObjectMonitor)objectMonitors.get(i);
783             om.start();
784         }
785     }
786
787
788     public void stopObjectMonitors() {
789         for (int i = 0; i < objectMonitors.size(); i++) {
790             ObjectMonitor om = (ObjectMonitor)objectMonitors.get(i);
791             om.stop();
792         }
793     }
794
795     public void registerNewObjectMonitor(ObjectMonitor om) {
796         objectMonitors.add(om);
797     }
798 }
799
Popular Tags