1 4 5 package org.smartlib.pool.core; 6 7 13 14 15 public class PoolConfig implements ConfigMonitor { 16 17 18 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 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 poolName; 34 private int maxConnections; 35 private int minConnections; 36 private int increment = INCREMENT_BY; 37 private String userName; 38 private String password; 39 private ConnectionString connectionString[]; 40 private String driver; 41 private boolean isDefaultPool = DEFAULT_POOL_VALUE; 42 private boolean detectLeaks = DETECT_LEAKS; 43 44 private long leakTimeOut = LEAK_TIME_OUT; 46 private String defaultListener; 47 48 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 private long connectionWaitTimeOut = CONNECTION_WAIT_TIME_OUT; 58 private String validatorQuery = VALIDATION_QUERY; 59 60 61 private long maxConnectionIdleTime = MAX_CONNECTION_IDLE_TIME; 63 private boolean threadStickiness; 64 65 66 PoolConfig() { 67 } 68 69 72 PoolConfig(String poolName, int maxConnections, 73 int minConnections, String userName, 74 String password, ConnectionString connectionString[], 75 int increment, String 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 94 public String getMultiPoolName() { 95 96 return poolName; 97 98 } 99 100 101 void setMultiPoolName(String 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 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 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 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 167 public String getUserName() { 168 169 return userName; 170 171 } 172 173 void setUserName(String userName) { 174 175 this.userName = userName; 176 177 } 178 179 183 public String getPassword() { 184 185 return password; 186 187 } 188 189 void setPassword(String password) { 190 191 this.password = password; 192 193 } 194 195 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 213 public String getDriver() { 214 215 return driver; 216 217 } 218 219 void setDriver(String driver) { 220 221 this.driver = driver; 222 223 } 224 225 228 public boolean isDefaultPool() { 229 230 return isDefaultPool; 231 232 } 233 234 void setDefaultPool(boolean b) { 235 236 isDefaultPool = b; 237 238 } 239 240 243 public boolean isDetectLeaks() { 244 245 return detectLeaks; 246 247 } 248 249 void setDetectLeaks(boolean b) { 250 251 detectLeaks = b; 252 253 } 254 255 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 273 public String getDefaultListener() { 274 275 return defaultListener; 276 277 } 278 279 void setDefaultListener(String defaultListener) { 280 281 this.defaultListener= defaultListener ; 282 283 } 284 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 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 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 347 public boolean isAllowAnonymousConnections() { 348 349 return (allowAnonymousConnections); 350 351 } 352 353 354 358 359 void setConnectionLoaderClass(ConnectionLoaderClass connectionLoaderClass[]) { 360 361 if (connectionLoaderClass != null) 362 externalPooling = true; 363 this.connectionLoaderClass = connectionLoaderClass; 364 365 } 366 367 371 372 public ConnectionLoaderClass[] getConnectionLoaderClass() { 373 374 return (connectionLoaderClass); 375 376 } 377 378 384 public boolean isExternalPooling() { 385 386 return externalPooling; 387 388 } 389 390 391 397 void setExternalPooling(boolean externalPooling) { 398 399 this.externalPooling = externalPooling; 400 401 } 402 403 406 public long getConnectionWaitTimeOut() { 407 408 return connectionWaitTimeOut; 409 410 } 411 412 418 void setConnectionWaitTimeOut(long connectionWaitTimeOut) { 419 420 this.connectionWaitTimeOut = connectionWaitTimeOut; 421 422 } 423 424 427 public long getMaxConnectionIdleTime() { 428 429 return maxConnectionIdleTime; 430 431 } 432 433 439 void setMaxConnectionIdleTime(long maxConnectionIdleTime) { 440 441 this.maxConnectionIdleTime = maxConnectionIdleTime; 442 443 } 444 445 450 451 void setValidatorQuery(String validatorQuery) { 452 453 this.validatorQuery = validatorQuery; 454 455 } 456 457 462 public String getValidatorQuery() { 463 464 return validatorQuery; 465 466 } 467 468 471 public ConnectionString getConnectionStringByName(String 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 483 public ConnectionLoaderClass getConnectionLoaderClassByName(String 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 496 public String toString() { 497 498 StringBuffer sb = new StringBuffer (); 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 name; 537 private String connectString; 538 539 public String getName() { 540 return name; 541 } 542 543 public void setName(String name) { 544 this.name = name; 545 } 546 547 public String getConnectString() { 548 return connectString; 549 } 550 551 public void setConnectString(String connectString) { 552 this.connectString = connectString; 553 } 554 555 public String toString() { 556 return "ConnectionString{" + name + "," + connectString +"}"; 557 } 558 559 } 560 561 public static class ConnectionLoaderClass { 562 563 private String name; 564 private String connectionLoaderClass; 565 566 public String getName() { 567 return name; 568 } 569 570 public void setName(String name) { 571 this.name = name; 572 } 573 574 public String getConnectionLoaderClass() { 575 return connectionLoaderClass; 576 } 577 578 public void setConnectionLoaderClass(String connectionLoaderClass) { 579 this.connectionLoaderClass = connectionLoaderClass; 580 } 581 582 public String toString() { 583 return "ConnectionLoaderClass{" + name + "," + connectionLoaderClass +"}"; 584 } 585 586 } 587 588 } 589 | Popular Tags |