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