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