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