001: /*
002: * @(#) PoolConfig 1.0 02/08/01
003: */
004:
005: package org.smartlib.pool.core;
006:
007: /**
008: * This class encapsulates the configuration of the pool
009: *
010: * @author Sachin Shekar Shetty
011: * @version 1.0, 02/08/01
012: */
013:
014: public class PoolConfig implements ConfigMonitor {
015:
016: //Default values when not specified
017: public static final boolean DEFAULT_POOL_VALUE = false;
018: public static final boolean AUTO_CLOSE = false;
019: public static final boolean ALLOW_ANONYMOUS_CONNECTIONS = false;
020: public static final String VALIDATION_QUERY = null;
021: public static final int INCREMENT_BY = 1;
022: public static final int MAX_FREE_CONNECTIONS_FOR_RELEASE = -1;
023: public static final int CONNECTION_WAIT_TIME_OUT = 10000;
024: public static final int MAX_CONNECTION_IDLE_TIME = -1;
025: public static final int POLL_THREAD_TIME = 5000;
026: public static final int LEAK_TIME_OUT = -1;
027: public static final boolean DETECT_LEAKS = false;
028:
029: private String poolName;
030: private int maxConnections;
031: private int minConnections;
032: private int increment = INCREMENT_BY;
033: private String userName;
034: private String password;
035: private ConnectionString connectionString[];
036: private String driver;
037: private boolean isDefaultPool = DEFAULT_POOL_VALUE;
038: private boolean detectLeaks = DETECT_LEAKS;
039:
040: //Leaktime out in milliseconds
041: private long leakTimeOut = LEAK_TIME_OUT;
042: private String defaultListener;
043:
044: // Sleep time in Milliseconds
045: private long pollThreadTime = POLL_THREAD_TIME;
046: private boolean autoClose = AUTO_CLOSE;
047: private int maxConnectionsForRelease = MAX_FREE_CONNECTIONS_FOR_RELEASE;
048: private boolean allowAnonymousConnections = ALLOW_ANONYMOUS_CONNECTIONS;
049: private boolean externalPooling;
050: private ConnectionLoaderClass connectionLoaderClass[] = null;
051:
052: // Wait time for connections in milliseconds
053: private long connectionWaitTimeOut = CONNECTION_WAIT_TIME_OUT;
054: private String validatorQuery = VALIDATION_QUERY;
055:
056: // Connection Idle time in milliseconds
057: private long maxConnectionIdleTime = MAX_CONNECTION_IDLE_TIME;
058: private boolean threadStickiness;
059:
060: PoolConfig() {
061: }
062:
063: /**
064: * parameter list is too long to document, SELF HELP IS THE BEST HELP.
065: */
066: PoolConfig(String poolName, int maxConnections, int minConnections,
067: String userName, String password,
068: ConnectionString connectionString[], int increment,
069: String driver) {
070:
071: this .poolName = poolName;
072: this .maxConnections = maxConnections;
073: this .minConnections = minConnections;
074: this .increment = increment;
075: this .userName = userName;
076: this .password = password;
077: this .connectionString = connectionString;
078: this .driver = driver;
079:
080: }
081:
082: /**
083: * This method returns the name of the pool.
084: * @return name of the pool.
085: */
086: public String getMultiPoolName() {
087:
088: return poolName;
089:
090: }
091:
092: void setMultiPoolName(String poolName) {
093:
094: this .poolName = poolName;
095:
096: }
097:
098: public boolean isThreadStickiness() {
099: return threadStickiness;
100: }
101:
102: public void setThreadStickiness(boolean threadStickiness) {
103: this .threadStickiness = threadStickiness;
104: }
105:
106: /**
107: * @return Max connections allowed in the pool.
108: */
109: public int getMaxConnections() {
110:
111: return maxConnections;
112:
113: }
114:
115: void setMaxConnections(int maxConnections) {
116:
117: this .maxConnections = maxConnections;
118:
119: }
120:
121: /**
122: * @return minimun connections in the pool.
123: */
124: public int getMinConnections() {
125:
126: return minConnections;
127:
128: }
129:
130: void setMinConnections(int minConnections) {
131:
132: this .minConnections = minConnections;
133:
134: }
135:
136: /**
137: * @return size of blocks of connections withdrawn at a time when no free
138: * connections are available.
139: */
140: public int getIncrement() {
141:
142: return increment;
143:
144: }
145:
146: void setIncrement(int increment) {
147:
148: this .increment = increment;
149:
150: }
151:
152: /**
153: * @return username to connect to the database.
154: */
155: public String getUserName() {
156:
157: return userName;
158:
159: }
160:
161: void setUserName(String userName) {
162:
163: this .userName = userName;
164:
165: }
166:
167: /**
168: * This method returns the password to connect to the database.
169: * @return password to connect to the database.
170: */
171: public String getPassword() {
172:
173: return password;
174:
175: }
176:
177: void setPassword(String password) {
178:
179: this .password = password;
180:
181: }
182:
183: /**
184: * @return connection string to connect to the database.
185: */
186: public ConnectionString[] getConnectionString() {
187:
188: return connectionString;
189:
190: }
191:
192: void setConnectionString(ConnectionString connectionString[]) {
193:
194: this .connectionString = connectionString;
195:
196: }
197:
198: /**
199: * @return driver name used to connect to database.
200: */
201: public String getDriver() {
202:
203: return driver;
204:
205: }
206:
207: void setDriver(String driver) {
208:
209: this .driver = driver;
210:
211: }
212:
213: /**
214: * @return true if this pool is the default pool.
215: */
216: public boolean isDefaultPool() {
217:
218: return isDefaultPool;
219:
220: }
221:
222: void setDefaultPool(boolean b) {
223:
224: isDefaultPool = b;
225:
226: }
227:
228: /**
229: * @return true if connection leak monitoring is enabled.
230: */
231: public boolean isDetectLeaks() {
232:
233: return detectLeaks;
234:
235: }
236:
237: void setDetectLeaks(boolean b) {
238:
239: detectLeaks = b;
240:
241: }
242:
243: /**
244: * @return time out for detecting leaks.
245: */
246: public long getLeakTimeOut() {
247:
248: return leakTimeOut;
249:
250: }
251:
252: void setLeakTimeOut(long leakTimeOut) {
253:
254: this .leakTimeOut = leakTimeOut;
255:
256: }
257:
258: /**
259: * @return default listener class for connection leak.
260: */
261: public String getDefaultListener() {
262:
263: return defaultListener;
264:
265: }
266:
267: void setDefaultListener(String defaultListener) {
268:
269: this .defaultListener = defaultListener;
270:
271: }
272:
273: /**
274: * @return true if automotic closing of Statement ,PreparedStatement ,
275: * CallableStatement is enabled once the connection is closed is
276: * enabled.
277: */
278: public long getPollThreadTime() {
279:
280: return pollThreadTime;
281:
282: }
283:
284: void setPollThreadTime(long pollThreadTime) {
285:
286: this .pollThreadTime = pollThreadTime;
287:
288: }
289:
290: /**
291: * @return true if automatic closing of Statement ,PreparedStatement ,
292: * CallableStatement is enabled once the connection is closed is
293: * enabled.
294: */
295: public boolean isAutoClose() {
296:
297: return autoClose;
298:
299: }
300:
301: void setAutoClose(boolean autoClose) {
302:
303: this .autoClose = autoClose;
304:
305: }
306:
307: /**
308: * This method returns the name of the pool.
309: * @return maximum number of free connections allowed after which
310: * excessive connections are released .
311: */
312: public int getMaxConnectionsForRelease() {
313:
314: return maxConnectionsForRelease;
315:
316: }
317:
318: void setMaxConnectionsForRelease(int maxConnectionsForRelease) {
319:
320: this .maxConnectionsForRelease = maxConnectionsForRelease;
321:
322: }
323:
324: void setAllowAnonymousConnections(boolean allowAnonymousConnections) {
325:
326: this .allowAnonymousConnections = allowAnonymousConnections;
327:
328: }
329:
330: /**
331: * This method returns the name of the pool.
332: * @return true if anonymous connections are allowed , i.e
333: * without specifying the owner .
334: */
335: public boolean isAllowAnonymousConnections() {
336:
337: return (allowAnonymousConnections);
338:
339: }
340:
341: /**
342: * This method sets the fully qualified name of the Connection Loader class.
343: * @param connectionLoaderClass the fully qualified name of the Connection Loader class
344: */
345:
346: void setConnectionLoaderClass(
347: ConnectionLoaderClass connectionLoaderClass[]) {
348:
349: if (connectionLoaderClass != null)
350: externalPooling = true;
351: this .connectionLoaderClass = connectionLoaderClass;
352:
353: }
354:
355: /**
356: * This method returns the fully qualified name of the Connection Loader class.
357: * @return Fully qualified name of the class
358: */
359:
360: public ConnectionLoaderClass[] getConnectionLoaderClass() {
361:
362: return (connectionLoaderClass);
363:
364: }
365:
366: /**
367: * This method returs a boolean.
368: *
369: * @return true- If Smart pool is wrapped to another pool
370: *
371: */
372: public boolean isExternalPooling() {
373:
374: return externalPooling;
375:
376: }
377:
378: /**
379: * This method sets the isExternalPooling value.
380: *
381: * @param externalPooling true- If Smart pool is wrapped to another pool.
382: *
383: */
384: void setExternalPooling(boolean externalPooling) {
385:
386: this .externalPooling = externalPooling;
387:
388: }
389:
390: /**
391: * This method returns the connectionWaitTimeOut value.
392: */
393: public long getConnectionWaitTimeOut() {
394:
395: return connectionWaitTimeOut;
396:
397: }
398:
399: /**
400: * This method sets the connectionWaitTimeOut value.
401: *
402: * @param connectionWaitTimeOut
403: *
404: */
405: void setConnectionWaitTimeOut(long connectionWaitTimeOut) {
406:
407: this .connectionWaitTimeOut = connectionWaitTimeOut;
408:
409: }
410:
411: /**
412: * This method returns the max-connection-idle-time value.
413: */
414: public long getMaxConnectionIdleTime() {
415:
416: return maxConnectionIdleTime;
417:
418: }
419:
420: /**
421: * This method sets the max-connection-idle-time value.
422: *
423: * @param maxConnectionIdleTime
424: *
425: */
426: void setMaxConnectionIdleTime(long maxConnectionIdleTime) {
427:
428: this .maxConnectionIdleTime = maxConnectionIdleTime;
429:
430: }
431:
432: /**
433: * This method sets the Validator-Query.
434: *
435: * @param validatorQuery
436: */
437:
438: void setValidatorQuery(String validatorQuery) {
439:
440: this .validatorQuery = validatorQuery;
441:
442: }
443:
444: /**
445: * This method returns the validatorQuery.
446: *
447: * @return validatorQuery
448: */
449: public String getValidatorQuery() {
450:
451: return validatorQuery;
452:
453: }
454:
455: /**
456: * This metod returns the ConnectionString object with the name <code>name</code>
457: */
458: public ConnectionString getConnectionStringByName(String name) {
459: for (int i = 0; i < connectionString.length; i++) {
460: if (connectionString[i].getName().equals(name)) {
461: return connectionString[i];
462: }
463: }
464: return null;
465: }
466:
467: /**
468: * This metod returns the ConnectionLoaderClass object with the name <code>name</code>
469: */
470: public ConnectionLoaderClass getConnectionLoaderClassByName(
471: String name) {
472: for (int i = 0; i < connectionLoaderClass.length; i++) {
473: if (connectionLoaderClass[i].getName().equals(name)) {
474: return connectionLoaderClass[i];
475: }
476: }
477: return null;
478: }
479:
480: /**
481: * You know what this does.
482: */
483: public String toString() {
484:
485: StringBuffer sb = new StringBuffer();
486: sb.append("\n\nConnection Pool Configuration ======>");
487: sb.append("\n\tPoolName: " + poolName);
488: sb.append("\n\tMax Connections: " + maxConnections);
489: sb.append("\n\tMin Connections: " + minConnections);
490: sb.append("\n\tIncrement-Connections by: " + increment);
491: sb.append("\n\tUser Name: " + userName);
492: sb.append("\n\tPassword: " + password);
493: sb.append("\n\tConnection String: " + connectionString);
494: if (connectionString != null) {
495: for (int i = 0; i < connectionString.length; i++) {
496: sb.append("\n\t "
497: + connectionString[i]);
498: }
499: }
500: sb.append("\n\tThread Skickiness: " + threadStickiness);
501: sb.append("\n\tDriver: " + driver);
502: sb.append("\n\tVakidator Query: " + validatorQuery);
503: sb.append("\n\tDefault Pool: " + isDefaultPool);
504: sb.append("\n\tDetect Leaks: " + detectLeaks);
505: sb
506: .append("\n\tLeak Timeout: " + leakTimeOut
507: + " Milli Seconds");
508: sb.append("\n\tDefault Listener: " + defaultListener);
509: sb.append("\n\tPool Thread Time: " + pollThreadTime
510: + " Milli Seconds");
511: sb.append("\n\tAuto Close: " + autoClose);
512: sb.append("\n\tMax connection for release: "
513: + maxConnectionsForRelease);
514: sb.append("\n\tConnection Loader Class: "
515: + connectionLoaderClass);
516: if (connectionLoaderClass != null) {
517: for (int i = 0; i < connectionLoaderClass.length; i++) {
518: sb.append("\n\t "
519: + connectionLoaderClass[i]);
520: }
521: }
522: sb.append("\n\tConnection Wait Time Out: "
523: + connectionWaitTimeOut + " Milli Seconds");
524: sb.append("\n\tMaximum Connection Idle Time: "
525: + maxConnectionIdleTime + " Milli Seconds");
526: return sb.toString();
527:
528: }
529:
530: public static class ConnectionString {
531:
532: private String name;
533: private String connectString;
534:
535: public String getName() {
536: return name;
537: }
538:
539: public void setName(String name) {
540: this .name = name;
541: }
542:
543: public String getConnectString() {
544: return connectString;
545: }
546:
547: public void setConnectString(String connectString) {
548: this .connectString = connectString;
549: }
550:
551: public String toString() {
552: return "ConnectionString{" + name + "," + connectString
553: + "}";
554: }
555:
556: }
557:
558: public static class ConnectionLoaderClass {
559:
560: private String name;
561: private String connectionLoaderClass;
562:
563: public String getName() {
564: return name;
565: }
566:
567: public void setName(String name) {
568: this .name = name;
569: }
570:
571: public String getConnectionLoaderClass() {
572: return connectionLoaderClass;
573: }
574:
575: public void setConnectionLoaderClass(
576: String connectionLoaderClass) {
577: this .connectionLoaderClass = connectionLoaderClass;
578: }
579:
580: public String toString() {
581: return "ConnectionLoaderClass{" + name + ","
582: + connectionLoaderClass + "}";
583: }
584:
585: }
586:
587: }
|