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