001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.pool2.impl; 018 019import java.time.Duration; 020 021import org.apache.commons.pool2.BaseObject; 022 023/** 024 * Provides the implementation for the common attributes shared by the 025 * sub-classes. New instances of this class will be created using the defaults 026 * defined by the public constants. 027 * <p> 028 * This class is not thread-safe. 029 * </p> 030 * 031 * @param <T> Type of element pooled. 032 * @since 2.0 033 */ 034public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Cloneable { 035 036 /** 037 * The default value for the {@code lifo} configuration attribute. 038 * @see GenericObjectPool#getLifo() 039 * @see GenericKeyedObjectPool#getLifo() 040 */ 041 public static final boolean DEFAULT_LIFO = true; 042 043 /** 044 * The default value for the {@code fairness} configuration attribute. 045 * @see GenericObjectPool#getFairness() 046 * @see GenericKeyedObjectPool#getFairness() 047 */ 048 public static final boolean DEFAULT_FAIRNESS = false; 049 050 /** 051 * The default value for the {@code maxWait} configuration attribute. 052 * @see GenericObjectPool#getMaxWaitDuration() 053 * @see GenericKeyedObjectPool#getMaxWaitDuration() 054 * @deprecated Use {@link #DEFAULT_MAX_WAIT}. 055 */ 056 @Deprecated 057 public static final long DEFAULT_MAX_WAIT_MILLIS = -1L; 058 059 /** 060 * The default value for the {@code maxWait} configuration attribute. 061 * @see GenericObjectPool#getMaxWaitDuration() 062 * @see GenericKeyedObjectPool#getMaxWaitDuration() 063 * @since 2.10.0 064 */ 065 public static final Duration DEFAULT_MAX_WAIT = Duration.ofMillis(DEFAULT_MAX_WAIT_MILLIS); 066 067 /** 068 * The default value for the {@code minEvictableIdleDuration} 069 * configuration attribute. 070 * @see GenericObjectPool#getMinEvictableIdleDuration() 071 * @see GenericKeyedObjectPool#getMinEvictableIdleDuration() 072 * @deprecated Use {@link #DEFAULT_MIN_EVICTABLE_IDLE_TIME}. 073 */ 074 @Deprecated 075 public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000L * 60L * 30L; 076 077 /** 078 * The default value for the {@code minEvictableIdleDuration} 079 * configuration attribute. 080 * @see GenericObjectPool#getMinEvictableIdleDuration() 081 * @see GenericKeyedObjectPool#getMinEvictableIdleDuration() 082 * @since 2.11.0 083 */ 084 public static final Duration DEFAULT_MIN_EVICTABLE_IDLE_DURATION = 085 Duration.ofMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); 086 087 /** 088 * The default value for the {@code minEvictableIdleDuration} 089 * configuration attribute. 090 * @see GenericObjectPool#getMinEvictableIdleDuration() 091 * @see GenericKeyedObjectPool#getMinEvictableIdleDuration() 092 * @since 2.10.0 093 * @deprecated Use {@link #DEFAULT_MIN_EVICTABLE_IDLE_DURATION}. 094 */ 095 @Deprecated 096 public static final Duration DEFAULT_MIN_EVICTABLE_IDLE_TIME = 097 Duration.ofMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); 098 099 /** 100 * The default value for the {@code softMinEvictableIdleTime} 101 * configuration attribute. 102 * @see GenericObjectPool#getSoftMinEvictableIdleDuration() 103 * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration() 104 * @deprecated Use {@link #DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME}. 105 */ 106 @Deprecated 107 public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1; 108 109 /** 110 * The default value for the {@code softMinEvictableIdleTime} 111 * configuration attribute. 112 * @see GenericObjectPool#getSoftMinEvictableIdleDuration() 113 * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration() 114 * @since 2.10.0 115 * @deprecated Use {@link #DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION}. 116 */ 117 @Deprecated 118 public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME = 119 Duration.ofMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS); 120 121 /** 122 * The default value for the {@code softMinEvictableIdleTime} 123 * configuration attribute. 124 * @see GenericObjectPool#getSoftMinEvictableIdleDuration() 125 * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration() 126 * @since 2.11.0 127 */ 128 public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION = 129 Duration.ofMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS); 130 131 /** 132 * The default value for {@code evictorShutdownTimeout} configuration 133 * attribute. 134 * @see GenericObjectPool#getEvictorShutdownTimeoutDuration() 135 * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration() 136 * @deprecated Use {@link #DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT}. 137 */ 138 @Deprecated 139 public static final long DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS = 10L * 1000L; 140 141 /** 142 * The default value for {@code evictorShutdownTimeout} configuration 143 * attribute. 144 * @see GenericObjectPool#getEvictorShutdownTimeoutDuration() 145 * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration() 146 * @since 2.10.0 147 */ 148 public static final Duration DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT = 149 Duration.ofMillis(DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS); 150 151 /** 152 * The default value for the {@code numTestsPerEvictionRun} configuration 153 * attribute. 154 * @see GenericObjectPool#getNumTestsPerEvictionRun() 155 * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun() 156 */ 157 public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3; 158 159 /** 160 * The default value for the {@code testOnCreate} configuration attribute. 161 * @see GenericObjectPool#getTestOnCreate() 162 * @see GenericKeyedObjectPool#getTestOnCreate() 163 * 164 * @since 2.2 165 */ 166 public static final boolean DEFAULT_TEST_ON_CREATE = false; 167 168 /** 169 * The default value for the {@code testOnBorrow} configuration attribute. 170 * @see GenericObjectPool#getTestOnBorrow() 171 * @see GenericKeyedObjectPool#getTestOnBorrow() 172 */ 173 public static final boolean DEFAULT_TEST_ON_BORROW = false; 174 175 /** 176 * The default value for the {@code testOnReturn} configuration attribute. 177 * @see GenericObjectPool#getTestOnReturn() 178 * @see GenericKeyedObjectPool#getTestOnReturn() 179 */ 180 public static final boolean DEFAULT_TEST_ON_RETURN = false; 181 182 /** 183 * The default value for the {@code testWhileIdle} configuration attribute. 184 * @see GenericObjectPool#getTestWhileIdle() 185 * @see GenericKeyedObjectPool#getTestWhileIdle() 186 */ 187 public static final boolean DEFAULT_TEST_WHILE_IDLE = false; 188 189 /** 190 * The default value for the {@code timeBetweenEvictionRuns} 191 * configuration attribute. 192 * @see GenericObjectPool#getDurationBetweenEvictionRuns() 193 * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns() 194 * @deprecated Use {@link #DEFAULT_TIME_BETWEEN_EVICTION_RUNS}. 195 */ 196 @Deprecated 197 public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L; 198 199 /** 200 * The default value for the {@code timeBetweenEvictionRuns} 201 * configuration attribute. 202 * @see GenericObjectPool#getDurationBetweenEvictionRuns() 203 * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns() 204 */ 205 public static final Duration DEFAULT_TIME_BETWEEN_EVICTION_RUNS = Duration 206 .ofMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS); 207 208 /** 209 * The default value for the {@code blockWhenExhausted} configuration 210 * attribute. 211 * @see GenericObjectPool#getBlockWhenExhausted() 212 * @see GenericKeyedObjectPool#getBlockWhenExhausted() 213 */ 214 public static final boolean DEFAULT_BLOCK_WHEN_EXHAUSTED = true; 215 216 /** 217 * The default value for enabling JMX for pools created with a configuration 218 * instance. 219 */ 220 public static final boolean DEFAULT_JMX_ENABLE = true; 221 222 /** 223 * The default value for the prefix used to name JMX enabled pools created 224 * with a configuration instance. 225 * @see GenericObjectPool#getJmxName() 226 * @see GenericKeyedObjectPool#getJmxName() 227 */ 228 public static final String DEFAULT_JMX_NAME_PREFIX = "pool"; 229 230 /** 231 * The default value for the base name to use to name JMX enabled pools 232 * created with a configuration instance. The default is {@code null} 233 * which means the pool will provide the base name to use. 234 * @see GenericObjectPool#getJmxName() 235 * @see GenericKeyedObjectPool#getJmxName() 236 */ 237 public static final String DEFAULT_JMX_NAME_BASE = null; 238 239 /** 240 * The default value for the {@code evictionPolicyClassName} configuration 241 * attribute. 242 * @see GenericObjectPool#getEvictionPolicyClassName() 243 * @see GenericKeyedObjectPool#getEvictionPolicyClassName() 244 */ 245 public static final String DEFAULT_EVICTION_POLICY_CLASS_NAME = DefaultEvictionPolicy.class.getName(); 246 247 private boolean lifo = DEFAULT_LIFO; 248 249 private boolean fairness = DEFAULT_FAIRNESS; 250 251 private Duration maxWaitDuration = DEFAULT_MAX_WAIT; 252 253 private Duration minEvictableIdleDuration = DEFAULT_MIN_EVICTABLE_IDLE_TIME; 254 255 private Duration evictorShutdownTimeoutDuration = DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT; 256 257 private Duration softMinEvictableIdleDuration = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME; 258 259 private int numTestsPerEvictionRun = DEFAULT_NUM_TESTS_PER_EVICTION_RUN; 260 261 private EvictionPolicy<T> evictionPolicy; // Only 2.6.0 applications set this 262 263 private String evictionPolicyClassName = DEFAULT_EVICTION_POLICY_CLASS_NAME; 264 265 private boolean testOnCreate = DEFAULT_TEST_ON_CREATE; 266 267 private boolean testOnBorrow = DEFAULT_TEST_ON_BORROW; 268 269 private boolean testOnReturn = DEFAULT_TEST_ON_RETURN; 270 271 private boolean testWhileIdle = DEFAULT_TEST_WHILE_IDLE; 272 273 private Duration durationBetweenEvictionRuns = DEFAULT_TIME_BETWEEN_EVICTION_RUNS; 274 275 private boolean blockWhenExhausted = DEFAULT_BLOCK_WHEN_EXHAUSTED; 276 277 private boolean jmxEnabled = DEFAULT_JMX_ENABLE; 278 279 // TODO Consider changing this to a single property for 3.x 280 private String jmxNamePrefix = DEFAULT_JMX_NAME_PREFIX; 281 282 private String jmxNameBase = DEFAULT_JMX_NAME_BASE; 283 284 285 /** 286 * Gets the value for the {@code blockWhenExhausted} configuration attribute 287 * for pools created with this configuration instance. 288 * 289 * @return The current setting of {@code blockWhenExhausted} for this 290 * configuration instance 291 * 292 * @see GenericObjectPool#getBlockWhenExhausted() 293 * @see GenericKeyedObjectPool#getBlockWhenExhausted() 294 */ 295 public boolean getBlockWhenExhausted() { 296 return blockWhenExhausted; 297 } 298 299 /** 300 * Gets the value for the {@code evictionPolicyClass} configuration 301 * attribute for pools created with this configuration instance. 302 * 303 * @return The current setting of {@code evictionPolicyClass} for this 304 * configuration instance 305 * 306 * @see GenericObjectPool#getEvictionPolicy() 307 * @see GenericKeyedObjectPool#getEvictionPolicy() 308 * @since 2.6.0 309 */ 310 public EvictionPolicy<T> getEvictionPolicy() { 311 return evictionPolicy; 312 } 313 314 /** 315 * Gets the value for the {@code evictionPolicyClassName} configuration 316 * attribute for pools created with this configuration instance. 317 * 318 * @return The current setting of {@code evictionPolicyClassName} for this 319 * configuration instance 320 * 321 * @see GenericObjectPool#getEvictionPolicyClassName() 322 * @see GenericKeyedObjectPool#getEvictionPolicyClassName() 323 */ 324 public String getEvictionPolicyClassName() { 325 return evictionPolicyClassName; 326 } 327 328 /** 329 * Gets the value for the {@code evictorShutdownTimeout} configuration 330 * attribute for pools created with this configuration instance. 331 * 332 * @return The current setting of {@code evictorShutdownTimeout} for 333 * this configuration instance 334 * 335 * @see GenericObjectPool#getEvictorShutdownTimeoutDuration() 336 * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration() 337 * @since 2.10.0 338 * @deprecated Use {@link #getEvictorShutdownTimeoutDuration()}. 339 */ 340 @Deprecated 341 public Duration getEvictorShutdownTimeout() { 342 return evictorShutdownTimeoutDuration; 343 } 344 345 /** 346 * Gets the value for the {@code evictorShutdownTimeout} configuration 347 * attribute for pools created with this configuration instance. 348 * 349 * @return The current setting of {@code evictorShutdownTimeout} for 350 * this configuration instance 351 * 352 * @see GenericObjectPool#getEvictorShutdownTimeoutDuration() 353 * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration() 354 * @since 2.11.0 355 */ 356 public Duration getEvictorShutdownTimeoutDuration() { 357 return evictorShutdownTimeoutDuration; 358 } 359 360 /** 361 * Gets the value for the {@code evictorShutdownTimeout} configuration 362 * attribute for pools created with this configuration instance. 363 * 364 * @return The current setting of {@code evictorShutdownTimeout} for 365 * this configuration instance 366 * 367 * @see GenericObjectPool#getEvictorShutdownTimeoutDuration() 368 * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration() 369 * @deprecated Use {@link #getEvictorShutdownTimeout()}. 370 */ 371 @Deprecated 372 public long getEvictorShutdownTimeoutMillis() { 373 return evictorShutdownTimeoutDuration.toMillis(); 374 } 375 376 /** 377 * Gets the value for the {@code fairness} configuration attribute for pools 378 * created with this configuration instance. 379 * 380 * @return The current setting of {@code fairness} for this configuration 381 * instance 382 * 383 * @see GenericObjectPool#getFairness() 384 * @see GenericKeyedObjectPool#getFairness() 385 */ 386 public boolean getFairness() { 387 return fairness; 388 } 389 390 /** 391 * Gets the value of the flag that determines if JMX will be enabled for 392 * pools created with this configuration instance. 393 * 394 * @return The current setting of {@code jmxEnabled} for this configuration 395 * instance 396 */ 397 public boolean getJmxEnabled() { 398 return jmxEnabled; 399 } 400 401 /** 402 * Gets the value of the JMX name base that will be used as part of the 403 * name assigned to JMX enabled pools created with this configuration 404 * instance. A value of {@code null} means that the pool will define 405 * the JMX name base. 406 * 407 * @return The current setting of {@code jmxNameBase} for this 408 * configuration instance 409 */ 410 public String getJmxNameBase() { 411 return jmxNameBase; 412 } 413 414 /** 415 * Gets the value of the JMX name prefix that will be used as part of the 416 * name assigned to JMX enabled pools created with this configuration 417 * instance. 418 * 419 * @return The current setting of {@code jmxNamePrefix} for this 420 * configuration instance 421 */ 422 public String getJmxNamePrefix() { 423 return jmxNamePrefix; 424 } 425 426 /** 427 * Gets the value for the {@code lifo} configuration attribute for pools 428 * created with this configuration instance. 429 * 430 * @return The current setting of {@code lifo} for this configuration 431 * instance 432 * 433 * @see GenericObjectPool#getLifo() 434 * @see GenericKeyedObjectPool#getLifo() 435 */ 436 public boolean getLifo() { 437 return lifo; 438 } 439 440 /** 441 * Gets the value for the {@code maxWait} configuration attribute for pools 442 * created with this configuration instance. 443 * 444 * @return The current setting of {@code maxWait} for this 445 * configuration instance 446 * 447 * @see GenericObjectPool#getMaxWaitDuration() 448 * @see GenericKeyedObjectPool#getMaxWaitDuration() 449 * @since 2.11.0 450 */ 451 public Duration getMaxWaitDuration() { 452 return maxWaitDuration; 453 } 454 455 /** 456 * Gets the value for the {@code maxWait} configuration attribute for pools 457 * created with this configuration instance. 458 * 459 * @return The current setting of {@code maxWait} for this 460 * configuration instance 461 * 462 * @see GenericObjectPool#getMaxWaitDuration() 463 * @see GenericKeyedObjectPool#getMaxWaitDuration() 464 * @deprecated Use {@link #getMaxWaitDuration()}. 465 */ 466 @Deprecated 467 public long getMaxWaitMillis() { 468 return maxWaitDuration.toMillis(); 469 } 470 471 /** 472 * Gets the value for the {@code minEvictableIdleTime} configuration 473 * attribute for pools created with this configuration instance. 474 * 475 * @return The current setting of {@code minEvictableIdleTime} for 476 * this configuration instance 477 * 478 * @see GenericObjectPool#getMinEvictableIdleDuration() 479 * @see GenericKeyedObjectPool#getMinEvictableIdleDuration() 480 * @since 2.11.0 481 */ 482 public Duration getMinEvictableIdleDuration() { 483 return minEvictableIdleDuration; 484 } 485 486 /** 487 * Gets the value for the {@code minEvictableIdleTime} configuration 488 * attribute for pools created with this configuration instance. 489 * 490 * @return The current setting of {@code minEvictableIdleTime} for 491 * this configuration instance 492 * 493 * @see GenericObjectPool#getMinEvictableIdleDuration() 494 * @see GenericKeyedObjectPool#getMinEvictableIdleDuration() 495 * @since 2.10.0 496 * @deprecated Use {@link #getMinEvictableIdleDuration()}. 497 */ 498 @Deprecated 499 public Duration getMinEvictableIdleTime() { 500 return minEvictableIdleDuration; 501 } 502 503 /** 504 * Gets the value for the {@code minEvictableIdleTime} configuration 505 * attribute for pools created with this configuration instance. 506 * 507 * @return The current setting of {@code minEvictableIdleTime} for 508 * this configuration instance 509 * 510 * @see GenericObjectPool#getMinEvictableIdleDuration() 511 * @see GenericKeyedObjectPool#getMinEvictableIdleDuration() 512 * @deprecated Use {@link #getMinEvictableIdleTime()}. 513 */ 514 @Deprecated 515 public long getMinEvictableIdleTimeMillis() { 516 return minEvictableIdleDuration.toMillis(); 517 } 518 519 /** 520 * Gets the value for the {@code numTestsPerEvictionRun} configuration 521 * attribute for pools created with this configuration instance. 522 * 523 * @return The current setting of {@code numTestsPerEvictionRun} for this 524 * configuration instance 525 * 526 * @see GenericObjectPool#getNumTestsPerEvictionRun() 527 * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun() 528 */ 529 public int getNumTestsPerEvictionRun() { 530 return numTestsPerEvictionRun; 531 } 532 533 /** 534 * Gets the value for the {@code softMinEvictableIdleTime} 535 * configuration attribute for pools created with this configuration 536 * instance. 537 * 538 * @return The current setting of {@code softMinEvictableIdleTime} 539 * for this configuration instance 540 * 541 * @see GenericObjectPool#getSoftMinEvictableIdleDuration() 542 * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration() 543 * @since 2.11.0 544 */ 545 public Duration getSoftMinEvictableIdleDuration() { 546 return softMinEvictableIdleDuration; 547 } 548 549 /** 550 * Gets the value for the {@code softMinEvictableIdleTime} 551 * configuration attribute for pools created with this configuration 552 * instance. 553 * 554 * @return The current setting of {@code softMinEvictableIdleTime} 555 * for this configuration instance 556 * 557 * @see GenericObjectPool#getSoftMinEvictableIdleDuration() 558 * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration() 559 * @since 2.10.0 560 * @deprecated Use {@link #getSoftMinEvictableIdleDuration()}. 561 */ 562 @Deprecated 563 public Duration getSoftMinEvictableIdleTime() { 564 return softMinEvictableIdleDuration; 565 } 566 567 /** 568 * Gets the value for the {@code softMinEvictableIdleTime} 569 * configuration attribute for pools created with this configuration 570 * instance. 571 * 572 * @return The current setting of {@code softMinEvictableIdleTime} 573 * for this configuration instance 574 * 575 * @see GenericObjectPool#getSoftMinEvictableIdleDuration() 576 * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration() 577 * @deprecated Use {@link #getSoftMinEvictableIdleDuration()}. 578 */ 579 @Deprecated 580 public long getSoftMinEvictableIdleTimeMillis() { 581 return softMinEvictableIdleDuration.toMillis(); 582 } 583 584 /** 585 * Gets the value for the {@code testOnBorrow} configuration attribute for 586 * pools created with this configuration instance. 587 * 588 * @return The current setting of {@code testOnBorrow} for this 589 * configuration instance 590 * 591 * @see GenericObjectPool#getTestOnBorrow() 592 * @see GenericKeyedObjectPool#getTestOnBorrow() 593 */ 594 public boolean getTestOnBorrow() { 595 return testOnBorrow; 596 } 597 598 /** 599 * Gets the value for the {@code testOnCreate} configuration attribute for 600 * pools created with this configuration instance. 601 * 602 * @return The current setting of {@code testOnCreate} for this 603 * configuration instance 604 * 605 * @see GenericObjectPool#getTestOnCreate() 606 * @see GenericKeyedObjectPool#getTestOnCreate() 607 * 608 * @since 2.2 609 */ 610 public boolean getTestOnCreate() { 611 return testOnCreate; 612 } 613 614 /** 615 * Gets the value for the {@code testOnReturn} configuration attribute for 616 * pools created with this configuration instance. 617 * 618 * @return The current setting of {@code testOnReturn} for this 619 * configuration instance 620 * 621 * @see GenericObjectPool#getTestOnReturn() 622 * @see GenericKeyedObjectPool#getTestOnReturn() 623 */ 624 public boolean getTestOnReturn() { 625 return testOnReturn; 626 } 627 628 /** 629 * Gets the value for the {@code testWhileIdle} configuration attribute for 630 * pools created with this configuration instance. 631 * 632 * @return The current setting of {@code testWhileIdle} for this 633 * configuration instance 634 * 635 * @see GenericObjectPool#getTestWhileIdle() 636 * @see GenericKeyedObjectPool#getTestWhileIdle() 637 */ 638 public boolean getTestWhileIdle() { 639 return testWhileIdle; 640 } 641 642 /** 643 * Gets the value for the {@code timeBetweenEvictionRuns} configuration 644 * attribute for pools created with this configuration instance. 645 * 646 * @return The current setting of {@code timeBetweenEvictionRuns} for 647 * this configuration instance 648 * 649 * @see GenericObjectPool#getDurationBetweenEvictionRuns() 650 * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns() 651 * @since 2.11.0 652 */ 653 public Duration getDurationBetweenEvictionRuns() { 654 return durationBetweenEvictionRuns; 655 } 656 657 /** 658 * Gets the value for the {@code timeBetweenEvictionRuns} configuration 659 * attribute for pools created with this configuration instance. 660 * 661 * @return The current setting of {@code timeBetweenEvictionRuns} for 662 * this configuration instance 663 * 664 * @see GenericObjectPool#getDurationBetweenEvictionRuns() 665 * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns() 666 * @since 2.10.0 667 * @deprecated Use {@link #getDurationBetweenEvictionRuns()}. 668 */ 669 @Deprecated 670 public Duration getTimeBetweenEvictionRuns() { 671 return durationBetweenEvictionRuns; 672 } 673 674 /** 675 * Gets the value for the {@code timeBetweenEvictionRuns} configuration 676 * attribute for pools created with this configuration instance. 677 * 678 * @return The current setting of {@code timeBetweenEvictionRuns} for 679 * this configuration instance 680 * 681 * @see GenericObjectPool#getDurationBetweenEvictionRuns() 682 * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns() 683 * @deprecated Use {@link #getDurationBetweenEvictionRuns()}. 684 */ 685 @Deprecated 686 public long getTimeBetweenEvictionRunsMillis() { 687 return durationBetweenEvictionRuns.toMillis(); 688 } 689 690 /** 691 * Sets the value for the {@code blockWhenExhausted} configuration attribute 692 * for pools created with this configuration instance. 693 * 694 * @param blockWhenExhausted The new setting of {@code blockWhenExhausted} 695 * for this configuration instance 696 * 697 * @see GenericObjectPool#getBlockWhenExhausted() 698 * @see GenericKeyedObjectPool#getBlockWhenExhausted() 699 */ 700 public void setBlockWhenExhausted(final boolean blockWhenExhausted) { 701 this.blockWhenExhausted = blockWhenExhausted; 702 } 703 704 /** 705 * Sets the value for the {@code evictionPolicyClass} configuration 706 * attribute for pools created with this configuration instance. 707 * 708 * @param evictionPolicy The new setting of 709 * {@code evictionPolicyClass} for this configuration instance 710 * 711 * @see GenericObjectPool#getEvictionPolicy() 712 * @see GenericKeyedObjectPool#getEvictionPolicy() 713 * @since 2.6.0 714 */ 715 public void setEvictionPolicy(final EvictionPolicy<T> evictionPolicy) { 716 this.evictionPolicy = evictionPolicy; 717 } 718 719 /** 720 * Sets the value for the {@code evictionPolicyClassName} configuration 721 * attribute for pools created with this configuration instance. 722 * 723 * @param evictionPolicyClassName The new setting of 724 * {@code evictionPolicyClassName} for this configuration instance 725 * 726 * @see GenericObjectPool#getEvictionPolicyClassName() 727 * @see GenericKeyedObjectPool#getEvictionPolicyClassName() 728 */ 729 public void setEvictionPolicyClassName(final String evictionPolicyClassName) { 730 this.evictionPolicyClassName = evictionPolicyClassName; 731 } 732 733 /** 734 * Sets the value for the {@code evictorShutdownTimeout} configuration 735 * attribute for pools created with this configuration instance. 736 * 737 * @param evictorShutdownTimeout The new setting of 738 * {@code evictorShutdownTimeout} for this configuration 739 * instance 740 * 741 * @see GenericObjectPool#getEvictorShutdownTimeoutDuration() 742 * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration() 743 * @since 2.10.0 744 * @deprecated Use {@link #setEvictorShutdownTimeout(Duration)}. 745 */ 746 @Deprecated 747 public void setEvictorShutdownTimeoutMillis(final Duration evictorShutdownTimeout) { 748 setEvictorShutdownTimeout(evictorShutdownTimeout); 749 } 750 751 /** 752 * Sets the value for the {@code evictorShutdownTimeout} configuration 753 * attribute for pools created with this configuration instance. 754 * 755 * @param evictorShutdownTimeoutDuration The new setting of 756 * {@code evictorShutdownTimeout} for this configuration 757 * instance 758 * 759 * @see GenericObjectPool#getEvictorShutdownTimeoutDuration() 760 * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration() 761 * @since 2.11.0 762 */ 763 public void setEvictorShutdownTimeout(final Duration evictorShutdownTimeoutDuration) { 764 this.evictorShutdownTimeoutDuration = PoolImplUtils.nonNull(evictorShutdownTimeoutDuration, DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT); 765 } 766 767 /** 768 * Sets the value for the {@code evictorShutdownTimeout} configuration 769 * attribute for pools created with this configuration instance. 770 * 771 * @param evictorShutdownTimeoutMillis The new setting of 772 * {@code evictorShutdownTimeout} for this configuration 773 * instance 774 * 775 * @see GenericObjectPool#getEvictorShutdownTimeoutDuration() 776 * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration() 777 * @deprecated Use {@link #setEvictorShutdownTimeout(Duration)}. 778 */ 779 @Deprecated 780 public void setEvictorShutdownTimeoutMillis(final long evictorShutdownTimeoutMillis) { 781 setEvictorShutdownTimeout(Duration.ofMillis(evictorShutdownTimeoutMillis)); 782 } 783 784 /** 785 * Sets the value for the {@code fairness} configuration attribute for pools 786 * created with this configuration instance. 787 * 788 * @param fairness The new setting of {@code fairness} 789 * for this configuration instance 790 * 791 * @see GenericObjectPool#getFairness() 792 * @see GenericKeyedObjectPool#getFairness() 793 */ 794 public void setFairness(final boolean fairness) { 795 this.fairness = fairness; 796 } 797 798 /** 799 * Sets the value of the flag that determines if JMX will be enabled for 800 * pools created with this configuration instance. 801 * 802 * @param jmxEnabled The new setting of {@code jmxEnabled} 803 * for this configuration instance 804 */ 805 public void setJmxEnabled(final boolean jmxEnabled) { 806 this.jmxEnabled = jmxEnabled; 807 } 808 809 /** 810 * Sets the value of the JMX name base that will be used as part of the 811 * name assigned to JMX enabled pools created with this configuration 812 * instance. A value of {@code null} means that the pool will define 813 * the JMX name base. 814 * 815 * @param jmxNameBase The new setting of {@code jmxNameBase} 816 * for this configuration instance 817 */ 818 public void setJmxNameBase(final String jmxNameBase) { 819 this.jmxNameBase = jmxNameBase; 820 } 821 822 /** 823 * Sets the value of the JMX name prefix that will be used as part of the 824 * name assigned to JMX enabled pools created with this configuration 825 * instance. 826 * 827 * @param jmxNamePrefix The new setting of {@code jmxNamePrefix} 828 * for this configuration instance 829 */ 830 public void setJmxNamePrefix(final String jmxNamePrefix) { 831 this.jmxNamePrefix = jmxNamePrefix; 832 } 833 834 /** 835 * Sets the value for the {@code lifo} configuration attribute for pools 836 * created with this configuration instance. 837 * 838 * @param lifo The new setting of {@code lifo} 839 * for this configuration instance 840 * 841 * @see GenericObjectPool#getLifo() 842 * @see GenericKeyedObjectPool#getLifo() 843 */ 844 public void setLifo(final boolean lifo) { 845 this.lifo = lifo; 846 } 847 848 /** 849 * Sets the value for the {@code maxWait} configuration attribute for pools 850 * created with this configuration instance. 851 * 852 * @param maxWaitMillis The new setting of {@code maxWaitMillis} 853 * for this configuration instance 854 * 855 * @see GenericObjectPool#getMaxWaitDuration() 856 * @see GenericKeyedObjectPool#getMaxWaitDuration() 857 * @deprecated Use {@link #setMaxWait(Duration)}. 858 */ 859 @Deprecated 860 public void setMaxWaitMillis(final long maxWaitMillis) { 861 setMaxWait(Duration.ofMillis(maxWaitMillis)); 862 } 863 864 /** 865 * Sets the value for the {@code maxWait} configuration attribute for pools 866 * created with this configuration instance. 867 * 868 * @param maxWaitDuration The new setting of {@code maxWaitDuration} 869 * for this configuration instance 870 * 871 * @see GenericObjectPool#getMaxWaitDuration() 872 * @see GenericKeyedObjectPool#getMaxWaitDuration() 873 * @since 2.11.0 874 */ 875 public void setMaxWait(final Duration maxWaitDuration) { 876 this.maxWaitDuration = PoolImplUtils.nonNull(maxWaitDuration, DEFAULT_MAX_WAIT); 877 } 878 879 /** 880 * Sets the value for the {@code minEvictableIdleTime} configuration 881 * attribute for pools created with this configuration instance. 882 * 883 * @param minEvictableIdleTime The new setting of 884 * {@code minEvictableIdleTime} for this configuration instance 885 * 886 * @see GenericObjectPool#getMinEvictableIdleDuration() 887 * @see GenericKeyedObjectPool#getMinEvictableIdleDuration() 888 * @since 2.10.0 889 */ 890 public void setMinEvictableIdleTime(final Duration minEvictableIdleTime) { 891 this.minEvictableIdleDuration = PoolImplUtils.nonNull(minEvictableIdleTime, DEFAULT_MIN_EVICTABLE_IDLE_TIME); 892 } 893 894 /** 895 * Sets the value for the {@code minEvictableIdleTime} configuration 896 * attribute for pools created with this configuration instance. 897 * 898 * @param minEvictableIdleTimeMillis The new setting of 899 * {@code minEvictableIdleTime} for this configuration instance 900 * 901 * @see GenericObjectPool#getMinEvictableIdleDuration() 902 * @see GenericKeyedObjectPool#getMinEvictableIdleDuration() 903 * @deprecated Use {@link #setMinEvictableIdleTime(Duration)}. 904 */ 905 @Deprecated 906 public void setMinEvictableIdleTimeMillis(final long minEvictableIdleTimeMillis) { 907 this.minEvictableIdleDuration = Duration.ofMillis(minEvictableIdleTimeMillis); 908 } 909 910 /** 911 * Sets the value for the {@code numTestsPerEvictionRun} configuration 912 * attribute for pools created with this configuration instance. 913 * 914 * @param numTestsPerEvictionRun The new setting of 915 * {@code numTestsPerEvictionRun} for this configuration instance 916 * 917 * @see GenericObjectPool#getNumTestsPerEvictionRun() 918 * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun() 919 */ 920 public void setNumTestsPerEvictionRun(final int numTestsPerEvictionRun) { 921 this.numTestsPerEvictionRun = numTestsPerEvictionRun; 922 } 923 924 /** 925 * Sets the value for the {@code softMinEvictableIdleTime} 926 * configuration attribute for pools created with this configuration 927 * instance. 928 * 929 * @param softMinEvictableIdleTime The new setting of 930 * {@code softMinEvictableIdleTime} for this configuration 931 * instance 932 * 933 * @see GenericObjectPool#getSoftMinEvictableIdleDuration() 934 * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration() 935 * @since 2.10.0 936 */ 937 public void setSoftMinEvictableIdleTime(final Duration softMinEvictableIdleTime) { 938 this.softMinEvictableIdleDuration = PoolImplUtils.nonNull(softMinEvictableIdleTime, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME); 939 } 940 941 /** 942 * Sets the value for the {@code softMinEvictableIdleTime} 943 * configuration attribute for pools created with this configuration 944 * instance. 945 * 946 * @param softMinEvictableIdleTimeMillis The new setting of 947 * {@code softMinEvictableIdleTime} for this configuration 948 * instance 949 * 950 * @see GenericObjectPool#getSoftMinEvictableIdleDuration() 951 * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration() 952 * @deprecated Use {@link #setSoftMinEvictableIdleTime(Duration)}. 953 */ 954 @Deprecated 955 public void setSoftMinEvictableIdleTimeMillis( 956 final long softMinEvictableIdleTimeMillis) { 957 setSoftMinEvictableIdleTime(Duration.ofMillis(softMinEvictableIdleTimeMillis)); 958 } 959 960 /** 961 * Sets the value for the {@code testOnBorrow} configuration attribute for 962 * pools created with this configuration instance. 963 * 964 * @param testOnBorrow The new setting of {@code testOnBorrow} 965 * for this configuration instance 966 * 967 * @see GenericObjectPool#getTestOnBorrow() 968 * @see GenericKeyedObjectPool#getTestOnBorrow() 969 */ 970 public void setTestOnBorrow(final boolean testOnBorrow) { 971 this.testOnBorrow = testOnBorrow; 972 } 973 974 /** 975 * Sets the value for the {@code testOnCreate} configuration attribute for 976 * pools created with this configuration instance. 977 * 978 * @param testOnCreate The new setting of {@code testOnCreate} 979 * for this configuration instance 980 * 981 * @see GenericObjectPool#getTestOnCreate() 982 * @see GenericKeyedObjectPool#getTestOnCreate() 983 * 984 * @since 2.2 985 */ 986 public void setTestOnCreate(final boolean testOnCreate) { 987 this.testOnCreate = testOnCreate; 988 } 989 990 /** 991 * Sets the value for the {@code testOnReturn} configuration attribute for 992 * pools created with this configuration instance. 993 * 994 * @param testOnReturn The new setting of {@code testOnReturn} 995 * for this configuration instance 996 * 997 * @see GenericObjectPool#getTestOnReturn() 998 * @see GenericKeyedObjectPool#getTestOnReturn() 999 */ 1000 public void setTestOnReturn(final boolean testOnReturn) { 1001 this.testOnReturn = testOnReturn; 1002 } 1003 1004 /** 1005 * Sets the value for the {@code testWhileIdle} configuration attribute for 1006 * pools created with this configuration instance. 1007 * 1008 * @param testWhileIdle The new setting of {@code testWhileIdle} 1009 * for this configuration instance 1010 * 1011 * @see GenericObjectPool#getTestWhileIdle() 1012 * @see GenericKeyedObjectPool#getTestWhileIdle() 1013 */ 1014 public void setTestWhileIdle(final boolean testWhileIdle) { 1015 this.testWhileIdle = testWhileIdle; 1016 } 1017 1018 /** 1019 * Sets the value for the {@code timeBetweenEvictionRuns} configuration 1020 * attribute for pools created with this configuration instance. 1021 * 1022 * @param timeBetweenEvictionRuns The new setting of 1023 * {@code timeBetweenEvictionRuns} for this configuration 1024 * instance 1025 * 1026 * @see GenericObjectPool#getDurationBetweenEvictionRuns() 1027 * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns() 1028 * @since 2.10.0 1029 */ 1030 public void setTimeBetweenEvictionRuns(final Duration timeBetweenEvictionRuns) { 1031 this.durationBetweenEvictionRuns = PoolImplUtils.nonNull(timeBetweenEvictionRuns, DEFAULT_TIME_BETWEEN_EVICTION_RUNS); 1032 } 1033 1034 /** 1035 * Sets the value for the {@code timeBetweenEvictionRuns} configuration 1036 * attribute for pools created with this configuration instance. 1037 * 1038 * @param timeBetweenEvictionRunsMillis The new setting of 1039 * {@code timeBetweenEvictionRuns} for this configuration 1040 * instance 1041 * 1042 * @see GenericObjectPool#getDurationBetweenEvictionRuns() 1043 * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns() 1044 * @deprecated Use {@link #setTimeBetweenEvictionRuns(Duration)}. 1045 */ 1046 @Deprecated 1047 public void setTimeBetweenEvictionRunsMillis(final long timeBetweenEvictionRunsMillis) { 1048 setTimeBetweenEvictionRuns(Duration.ofMillis(timeBetweenEvictionRunsMillis)); 1049 } 1050 1051 @Override 1052 protected void toStringAppendFields(final StringBuilder builder) { 1053 builder.append("lifo="); 1054 builder.append(lifo); 1055 builder.append(", fairness="); 1056 builder.append(fairness); 1057 builder.append(", maxWaitDuration="); 1058 builder.append(maxWaitDuration); 1059 builder.append(", minEvictableIdleTime="); 1060 builder.append(minEvictableIdleDuration); 1061 builder.append(", softMinEvictableIdleTime="); 1062 builder.append(softMinEvictableIdleDuration); 1063 builder.append(", numTestsPerEvictionRun="); 1064 builder.append(numTestsPerEvictionRun); 1065 builder.append(", evictionPolicyClassName="); 1066 builder.append(evictionPolicyClassName); 1067 builder.append(", testOnCreate="); 1068 builder.append(testOnCreate); 1069 builder.append(", testOnBorrow="); 1070 builder.append(testOnBorrow); 1071 builder.append(", testOnReturn="); 1072 builder.append(testOnReturn); 1073 builder.append(", testWhileIdle="); 1074 builder.append(testWhileIdle); 1075 builder.append(", timeBetweenEvictionRuns="); 1076 builder.append(durationBetweenEvictionRuns); 1077 builder.append(", blockWhenExhausted="); 1078 builder.append(blockWhenExhausted); 1079 builder.append(", jmxEnabled="); 1080 builder.append(jmxEnabled); 1081 builder.append(", jmxNamePrefix="); 1082 builder.append(jmxNamePrefix); 1083 builder.append(", jmxNameBase="); 1084 builder.append(jmxNameBase); 1085 } 1086}