BaseObjectPoolConfig.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.pool2.impl;

  18. import java.time.Duration;

  19. import org.apache.commons.pool2.BaseObject;

  20. /**
  21.  * 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
  22.  * the public constants.
  23.  * <p>
  24.  * This class is not thread-safe.
  25.  * </p>
  26.  *
  27.  * @param <T> Type of element pooled.
  28.  * @since 2.0
  29.  */
  30. public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Cloneable {

  31.     /**
  32.      * The default value for the {@code lifo} configuration attribute: {@value}.
  33.      *
  34.      * @see GenericObjectPool#getLifo()
  35.      * @see GenericKeyedObjectPool#getLifo()
  36.      */
  37.     public static final boolean DEFAULT_LIFO = true;

  38.     /**
  39.      * The default value for the {@code fairness} configuration attribute: {@value}.
  40.      *
  41.      * @see GenericObjectPool#getFairness()
  42.      * @see GenericKeyedObjectPool#getFairness()
  43.      */
  44.     public static final boolean DEFAULT_FAIRNESS = false;

  45.     /**
  46.      * The default value for the {@code maxWait} configuration attribute: {@value}.
  47.      *
  48.      * @see GenericObjectPool#getMaxWaitDuration()
  49.      * @see GenericKeyedObjectPool#getMaxWaitDuration()
  50.      * @deprecated Use {@link #DEFAULT_MAX_WAIT}.
  51.      */
  52.     @Deprecated
  53.     public static final long DEFAULT_MAX_WAIT_MILLIS = -1L;

  54.     /**
  55.      * The default value for the {@code maxWait} configuration attribute.
  56.      *
  57.      * @see GenericObjectPool#getMaxWaitDuration()
  58.      * @see GenericKeyedObjectPool#getMaxWaitDuration()
  59.      * @since 2.10.0
  60.      */
  61.     public static final Duration DEFAULT_MAX_WAIT = Duration.ofMillis(DEFAULT_MAX_WAIT_MILLIS);

  62.     /**
  63.      * The default value for the {@code minEvictableIdleDuration} configuration attribute: {@value}.
  64.      *
  65.      * @see GenericObjectPool#getMinEvictableIdleDuration()
  66.      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
  67.      * @deprecated Use {@link #DEFAULT_MIN_EVICTABLE_IDLE_TIME}.
  68.      */
  69.     @Deprecated
  70.     public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000L * 60L * 30L;

  71.     /**
  72.      * The default value for the {@code minEvictableIdleDuration} configuration attribute.
  73.      *
  74.      * @see GenericObjectPool#getMinEvictableIdleDuration()
  75.      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
  76.      * @since 2.11.0
  77.      */
  78.     public static final Duration DEFAULT_MIN_EVICTABLE_IDLE_DURATION = Duration.ofMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);

  79.     /**
  80.      * The default value for the {@code minEvictableIdleDuration} configuration attribute.
  81.      *
  82.      * @see GenericObjectPool#getMinEvictableIdleDuration()
  83.      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
  84.      * @since 2.10.0
  85.      * @deprecated Use {@link #DEFAULT_MIN_EVICTABLE_IDLE_DURATION}.
  86.      */
  87.     @Deprecated
  88.     public static final Duration DEFAULT_MIN_EVICTABLE_IDLE_TIME = Duration.ofMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);

  89.     /**
  90.      * The default value for the {@code softMinEvictableIdleTime} configuration attribute: {@value}.
  91.      *
  92.      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
  93.      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
  94.      * @deprecated Use {@link #DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME}.
  95.      */
  96.     @Deprecated
  97.     public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;

  98.     /**
  99.      * The default value for the {@code softMinEvictableIdleTime} configuration attribute.
  100.      *
  101.      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
  102.      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
  103.      * @since 2.10.0
  104.      * @deprecated Use {@link #DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION}.
  105.      */
  106.     @Deprecated
  107.     public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME = Duration.ofMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);

  108.     /**
  109.      * The default value for the {@code softMinEvictableIdleTime} configuration attribute.
  110.      *
  111.      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
  112.      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
  113.      * @since 2.11.0
  114.      */
  115.     public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION = Duration.ofMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);

  116.     /**
  117.      * The default value for {@code evictorShutdownTimeout} configuration attribute: {@value}.
  118.      *
  119.      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
  120.      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
  121.      * @deprecated Use {@link #DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT}.
  122.      */
  123.     @Deprecated
  124.     public static final long DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS = 10L * 1000L;

  125.     /**
  126.      * The default value for {@code evictorShutdownTimeout} configuration attribute.
  127.      *
  128.      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
  129.      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
  130.      * @since 2.10.0
  131.      */
  132.     public static final Duration DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT = Duration.ofMillis(DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS);

  133.     /**
  134.      * The default value for the {@code numTestsPerEvictionRun} configuration attribute: {@value}.
  135.      *
  136.      * @see GenericObjectPool#getNumTestsPerEvictionRun()
  137.      * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun()
  138.      */
  139.     public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;

  140.     /**
  141.      * The default value for the {@code testOnCreate} configuration attribute: {@value}.
  142.      *
  143.      * @see GenericObjectPool#getTestOnCreate()
  144.      * @see GenericKeyedObjectPool#getTestOnCreate()
  145.      * @since 2.2
  146.      */
  147.     public static final boolean DEFAULT_TEST_ON_CREATE = false;

  148.     /**
  149.      * The default value for the {@code testOnBorrow} configuration attribute: {@value}.
  150.      *
  151.      * @see GenericObjectPool#getTestOnBorrow()
  152.      * @see GenericKeyedObjectPool#getTestOnBorrow()
  153.      */
  154.     public static final boolean DEFAULT_TEST_ON_BORROW = false;

  155.     /**
  156.      * The default value for the {@code testOnReturn} configuration attribute: {@value}.
  157.      *
  158.      * @see GenericObjectPool#getTestOnReturn()
  159.      * @see GenericKeyedObjectPool#getTestOnReturn()
  160.      */
  161.     public static final boolean DEFAULT_TEST_ON_RETURN = false;

  162.     /**
  163.      * The default value for the {@code testWhileIdle} configuration attribute: {@value}.
  164.      *
  165.      * @see GenericObjectPool#getTestWhileIdle()
  166.      * @see GenericKeyedObjectPool#getTestWhileIdle()
  167.      */
  168.     public static final boolean DEFAULT_TEST_WHILE_IDLE = false;

  169.     /**
  170.      * The default value for the {@code timeBetweenEvictionRuns} configuration attribute: {@value}.
  171.      *
  172.      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
  173.      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
  174.      * @deprecated Use {@link #DEFAULT_TIME_BETWEEN_EVICTION_RUNS}.
  175.      */
  176.     @Deprecated
  177.     public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;

  178.     /**
  179.      * The default value for the {@code timeBetweenEvictionRuns} configuration attribute.
  180.      *
  181.      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
  182.      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
  183.      * @since 2.12.0
  184.      */
  185.     public static final Duration DEFAULT_DURATION_BETWEEN_EVICTION_RUNS = Duration.ofMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);

  186.     /**
  187.      * The default value for the {@code timeBetweenEvictionRuns} configuration attribute.
  188.      *
  189.      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
  190.      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
  191.      * @deprecated Use {@link #DEFAULT_DURATION_BETWEEN_EVICTION_RUNS}.
  192.      */
  193.     @Deprecated
  194.     public static final Duration DEFAULT_TIME_BETWEEN_EVICTION_RUNS = Duration.ofMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);

  195.     /**
  196.      * The default value for the {@code blockWhenExhausted} configuration attribute: {@value}.
  197.      *
  198.      * @see GenericObjectPool#getBlockWhenExhausted()
  199.      * @see GenericKeyedObjectPool#getBlockWhenExhausted()
  200.      */
  201.     public static final boolean DEFAULT_BLOCK_WHEN_EXHAUSTED = true;

  202.     /**
  203.      * The default value for enabling JMX for pools created with a configuration instance: {@value}.
  204.      */
  205.     public static final boolean DEFAULT_JMX_ENABLE = true;

  206.     /**
  207.      * The default value for the prefix used to name JMX enabled pools created with a configuration instance: {@value}.
  208.      *
  209.      * @see GenericObjectPool#getJmxName()
  210.      * @see GenericKeyedObjectPool#getJmxName()
  211.      */
  212.     public static final String DEFAULT_JMX_NAME_PREFIX = "pool";

  213.     /**
  214.      * 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
  215.      * pool will provide the base name to use.
  216.      *
  217.      * @see GenericObjectPool#getJmxName()
  218.      * @see GenericKeyedObjectPool#getJmxName()
  219.      */
  220.     public static final String DEFAULT_JMX_NAME_BASE = null;

  221.     /**
  222.      * The default value for the {@code evictionPolicyClassName} configuration attribute.
  223.      *
  224.      * @see GenericObjectPool#getEvictionPolicyClassName()
  225.      * @see GenericKeyedObjectPool#getEvictionPolicyClassName()
  226.      */
  227.     public static final String DEFAULT_EVICTION_POLICY_CLASS_NAME = DefaultEvictionPolicy.class.getName();

  228.     private boolean lifo = DEFAULT_LIFO;

  229.     private boolean fairness = DEFAULT_FAIRNESS;

  230.     private Duration maxWaitDuration = DEFAULT_MAX_WAIT;

  231.     private Duration minEvictableIdleDuration = DEFAULT_MIN_EVICTABLE_IDLE_TIME;

  232.     private Duration evictorShutdownTimeoutDuration = DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT;

  233.     private Duration softMinEvictableIdleDuration = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME;

  234.     private int numTestsPerEvictionRun = DEFAULT_NUM_TESTS_PER_EVICTION_RUN;

  235.     private EvictionPolicy<T> evictionPolicy; // Only 2.6.0 applications set this

  236.     private String evictionPolicyClassName = DEFAULT_EVICTION_POLICY_CLASS_NAME;

  237.     private boolean testOnCreate = DEFAULT_TEST_ON_CREATE;

  238.     private boolean testOnBorrow = DEFAULT_TEST_ON_BORROW;

  239.     private boolean testOnReturn = DEFAULT_TEST_ON_RETURN;

  240.     private boolean testWhileIdle = DEFAULT_TEST_WHILE_IDLE;

  241.     private Duration durationBetweenEvictionRuns = DEFAULT_DURATION_BETWEEN_EVICTION_RUNS;

  242.     private boolean blockWhenExhausted = DEFAULT_BLOCK_WHEN_EXHAUSTED;

  243.     private boolean jmxEnabled = DEFAULT_JMX_ENABLE;

  244.     // TODO Consider changing this to a single property for 3.x
  245.     private String jmxNamePrefix = DEFAULT_JMX_NAME_PREFIX;

  246.     private String jmxNameBase = DEFAULT_JMX_NAME_BASE;

  247.     /**
  248.      * Constructs a new instance.
  249.      */
  250.     public BaseObjectPoolConfig() {
  251.         // empty
  252.     }

  253.     /**
  254.      * Gets the value for the {@code blockWhenExhausted} configuration attribute for pools created with this configuration instance.
  255.      *
  256.      * @return The current setting of {@code blockWhenExhausted} for this configuration instance
  257.      * @see GenericObjectPool#getBlockWhenExhausted()
  258.      * @see GenericKeyedObjectPool#getBlockWhenExhausted()
  259.      */
  260.     public boolean getBlockWhenExhausted() {
  261.         return blockWhenExhausted;
  262.     }

  263.     /**
  264.      * Gets the value for the {@code timeBetweenEvictionRuns} configuration attribute for pools created with this configuration instance.
  265.      *
  266.      * @return The current setting of {@code timeBetweenEvictionRuns} for this configuration instance
  267.      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
  268.      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
  269.      * @since 2.11.0
  270.      */
  271.     public Duration getDurationBetweenEvictionRuns() {
  272.         return durationBetweenEvictionRuns;
  273.     }

  274.     /**
  275.      * Gets the value for the {@code evictionPolicyClass} configuration attribute for pools created with this configuration instance.
  276.      *
  277.      * @return The current setting of {@code evictionPolicyClass} for this configuration instance
  278.      * @see GenericObjectPool#getEvictionPolicy()
  279.      * @see GenericKeyedObjectPool#getEvictionPolicy()
  280.      * @since 2.6.0
  281.      */
  282.     public EvictionPolicy<T> getEvictionPolicy() {
  283.         return evictionPolicy;
  284.     }

  285.     /**
  286.      * Gets the value for the {@code evictionPolicyClassName} configuration attribute for pools created with this configuration instance.
  287.      *
  288.      * @return The current setting of {@code evictionPolicyClassName} for this configuration instance
  289.      * @see GenericObjectPool#getEvictionPolicyClassName()
  290.      * @see GenericKeyedObjectPool#getEvictionPolicyClassName()
  291.      */
  292.     public String getEvictionPolicyClassName() {
  293.         return evictionPolicyClassName;
  294.     }

  295.     /**
  296.      * Gets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
  297.      *
  298.      * @return The current setting of {@code evictorShutdownTimeout} for this configuration instance
  299.      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
  300.      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
  301.      * @since 2.10.0
  302.      * @deprecated Use {@link #getEvictorShutdownTimeoutDuration()}.
  303.      */
  304.     @Deprecated
  305.     public Duration getEvictorShutdownTimeout() {
  306.         return evictorShutdownTimeoutDuration;
  307.     }

  308.     /**
  309.      * Gets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
  310.      *
  311.      * @return The current setting of {@code evictorShutdownTimeout} for this configuration instance
  312.      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
  313.      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
  314.      * @since 2.11.0
  315.      */
  316.     public Duration getEvictorShutdownTimeoutDuration() {
  317.         return evictorShutdownTimeoutDuration;
  318.     }

  319.     /**
  320.      * Gets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
  321.      *
  322.      * @return The current setting of {@code evictorShutdownTimeout} for this configuration instance
  323.      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
  324.      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
  325.      * @deprecated Use {@link #getEvictorShutdownTimeout()}.
  326.      */
  327.     @Deprecated
  328.     public long getEvictorShutdownTimeoutMillis() {
  329.         return evictorShutdownTimeoutDuration.toMillis();
  330.     }

  331.     /**
  332.      * Gets the value for the {@code fairness} configuration attribute for pools created with this configuration instance.
  333.      *
  334.      * @return The current setting of {@code fairness} for this configuration instance
  335.      * @see GenericObjectPool#getFairness()
  336.      * @see GenericKeyedObjectPool#getFairness()
  337.      */
  338.     public boolean getFairness() {
  339.         return fairness;
  340.     }

  341.     /**
  342.      * Gets the value of the flag that determines if JMX will be enabled for pools created with this configuration instance.
  343.      *
  344.      * @return The current setting of {@code jmxEnabled} for this configuration instance
  345.      */
  346.     public boolean getJmxEnabled() {
  347.         return jmxEnabled;
  348.     }

  349.     /**
  350.      * 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
  351.      * of {@code null} means that the pool will define the JMX name base.
  352.      *
  353.      * @return The current setting of {@code jmxNameBase} for this configuration instance
  354.      */
  355.     public String getJmxNameBase() {
  356.         return jmxNameBase;
  357.     }

  358.     /**
  359.      * 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.
  360.      *
  361.      * @return The current setting of {@code jmxNamePrefix} for this configuration instance
  362.      */
  363.     public String getJmxNamePrefix() {
  364.         return jmxNamePrefix;
  365.     }

  366.     /**
  367.      * Gets the value for the {@code lifo} configuration attribute for pools created with this configuration instance.
  368.      *
  369.      * @return The current setting of {@code lifo} for this configuration instance
  370.      * @see GenericObjectPool#getLifo()
  371.      * @see GenericKeyedObjectPool#getLifo()
  372.      */
  373.     public boolean getLifo() {
  374.         return lifo;
  375.     }

  376.     /**
  377.      * Gets the value for the {@code maxWait} configuration attribute for pools created with this configuration instance.
  378.      *
  379.      * @return The current setting of {@code maxWait} for this configuration instance
  380.      * @see GenericObjectPool#getMaxWaitDuration()
  381.      * @see GenericKeyedObjectPool#getMaxWaitDuration()
  382.      * @since 2.11.0
  383.      */
  384.     public Duration getMaxWaitDuration() {
  385.         return maxWaitDuration;
  386.     }

  387.     /**
  388.      * Gets the value for the {@code maxWait} configuration attribute for pools created with this configuration instance.
  389.      *
  390.      * @return The current setting of {@code maxWait} for this configuration instance
  391.      * @see GenericObjectPool#getMaxWaitDuration()
  392.      * @see GenericKeyedObjectPool#getMaxWaitDuration()
  393.      * @deprecated Use {@link #getMaxWaitDuration()}.
  394.      */
  395.     @Deprecated
  396.     public long getMaxWaitMillis() {
  397.         return maxWaitDuration.toMillis();
  398.     }

  399.     /**
  400.      * Gets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  401.      *
  402.      * @return The current setting of {@code minEvictableIdleTime} for this configuration instance
  403.      * @see GenericObjectPool#getMinEvictableIdleDuration()
  404.      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
  405.      * @since 2.11.0
  406.      */
  407.     public Duration getMinEvictableIdleDuration() {
  408.         return minEvictableIdleDuration;
  409.     }

  410.     /**
  411.      * Gets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  412.      *
  413.      * @return The current setting of {@code minEvictableIdleTime} for this configuration instance
  414.      * @see GenericObjectPool#getMinEvictableIdleDuration()
  415.      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
  416.      * @since 2.10.0
  417.      * @deprecated Use {@link #getMinEvictableIdleDuration()}.
  418.      */
  419.     @Deprecated
  420.     public Duration getMinEvictableIdleTime() {
  421.         return minEvictableIdleDuration;
  422.     }

  423.     /**
  424.      * Gets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  425.      *
  426.      * @return The current setting of {@code minEvictableIdleTime} for this configuration instance
  427.      * @see GenericObjectPool#getMinEvictableIdleDuration()
  428.      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
  429.      * @deprecated Use {@link #getMinEvictableIdleTime()}.
  430.      */
  431.     @Deprecated
  432.     public long getMinEvictableIdleTimeMillis() {
  433.         return minEvictableIdleDuration.toMillis();
  434.     }

  435.     /**
  436.      * Gets the value for the {@code numTestsPerEvictionRun} configuration attribute for pools created with this configuration instance.
  437.      *
  438.      * @return The current setting of {@code numTestsPerEvictionRun} for this configuration instance
  439.      * @see GenericObjectPool#getNumTestsPerEvictionRun()
  440.      * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun()
  441.      */
  442.     public int getNumTestsPerEvictionRun() {
  443.         return numTestsPerEvictionRun;
  444.     }

  445.     /**
  446.      * Gets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  447.      *
  448.      * @return The current setting of {@code softMinEvictableIdleTime} for this configuration instance
  449.      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
  450.      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
  451.      * @since 2.11.0
  452.      */
  453.     public Duration getSoftMinEvictableIdleDuration() {
  454.         return softMinEvictableIdleDuration;
  455.     }

  456.     /**
  457.      * Gets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  458.      *
  459.      * @return The current setting of {@code softMinEvictableIdleTime} for this configuration instance
  460.      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
  461.      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
  462.      * @since 2.10.0
  463.      * @deprecated Use {@link #getSoftMinEvictableIdleDuration()}.
  464.      */
  465.     @Deprecated
  466.     public Duration getSoftMinEvictableIdleTime() {
  467.         return softMinEvictableIdleDuration;
  468.     }

  469.     /**
  470.      * Gets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  471.      *
  472.      * @return The current setting of {@code softMinEvictableIdleTime} for this configuration instance
  473.      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
  474.      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
  475.      * @deprecated Use {@link #getSoftMinEvictableIdleDuration()}.
  476.      */
  477.     @Deprecated
  478.     public long getSoftMinEvictableIdleTimeMillis() {
  479.         return softMinEvictableIdleDuration.toMillis();
  480.     }

  481.     /**
  482.      * Gets the value for the {@code testOnBorrow} configuration attribute for pools created with this configuration instance.
  483.      *
  484.      * @return The current setting of {@code testOnBorrow} for this configuration instance
  485.      * @see GenericObjectPool#getTestOnBorrow()
  486.      * @see GenericKeyedObjectPool#getTestOnBorrow()
  487.      */
  488.     public boolean getTestOnBorrow() {
  489.         return testOnBorrow;
  490.     }

  491.     /**
  492.      * Gets the value for the {@code testOnCreate} configuration attribute for pools created with this configuration instance.
  493.      *
  494.      * @return The current setting of {@code testOnCreate} for this configuration instance
  495.      * @see GenericObjectPool#getTestOnCreate()
  496.      * @see GenericKeyedObjectPool#getTestOnCreate()
  497.      * @since 2.2
  498.      */
  499.     public boolean getTestOnCreate() {
  500.         return testOnCreate;
  501.     }

  502.     /**
  503.      * Gets the value for the {@code testOnReturn} configuration attribute for pools created with this configuration instance.
  504.      *
  505.      * @return The current setting of {@code testOnReturn} for this configuration instance
  506.      * @see GenericObjectPool#getTestOnReturn()
  507.      * @see GenericKeyedObjectPool#getTestOnReturn()
  508.      */
  509.     public boolean getTestOnReturn() {
  510.         return testOnReturn;
  511.     }

  512.     /**
  513.      * Gets the value for the {@code testWhileIdle} configuration attribute for pools created with this configuration instance.
  514.      *
  515.      * @return The current setting of {@code testWhileIdle} for this configuration instance
  516.      * @see GenericObjectPool#getTestWhileIdle()
  517.      * @see GenericKeyedObjectPool#getTestWhileIdle()
  518.      */
  519.     public boolean getTestWhileIdle() {
  520.         return testWhileIdle;
  521.     }

  522.     /**
  523.      * Gets the value for the {@code timeBetweenEvictionRuns} configuration attribute for pools created with this configuration instance.
  524.      *
  525.      * @return The current setting of {@code timeBetweenEvictionRuns} for this configuration instance
  526.      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
  527.      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
  528.      * @since 2.10.0
  529.      * @deprecated Use {@link #getDurationBetweenEvictionRuns()}.
  530.      */
  531.     @Deprecated
  532.     public Duration getTimeBetweenEvictionRuns() {
  533.         return durationBetweenEvictionRuns;
  534.     }

  535.     /**
  536.      * Gets the value for the {@code timeBetweenEvictionRuns} configuration attribute for pools created with this configuration instance.
  537.      *
  538.      * @return The current setting of {@code timeBetweenEvictionRuns} for this configuration instance
  539.      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
  540.      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
  541.      * @deprecated Use {@link #getDurationBetweenEvictionRuns()}.
  542.      */
  543.     @Deprecated
  544.     public long getTimeBetweenEvictionRunsMillis() {
  545.         return durationBetweenEvictionRuns.toMillis();
  546.     }

  547.     /**
  548.      * Sets the value for the {@code blockWhenExhausted} configuration attribute for pools created with this configuration instance.
  549.      *
  550.      * @param blockWhenExhausted The new setting of {@code blockWhenExhausted} for this configuration instance
  551.      * @see GenericObjectPool#getBlockWhenExhausted()
  552.      * @see GenericKeyedObjectPool#getBlockWhenExhausted()
  553.      */
  554.     public void setBlockWhenExhausted(final boolean blockWhenExhausted) {
  555.         this.blockWhenExhausted = blockWhenExhausted;
  556.     }

  557.     /**
  558.      * Sets the value for the {@code evictionPolicyClass} configuration attribute for pools created with this configuration instance.
  559.      *
  560.      * @param evictionPolicy The new setting of {@code evictionPolicyClass} for this configuration instance
  561.      * @see GenericObjectPool#getEvictionPolicy()
  562.      * @see GenericKeyedObjectPool#getEvictionPolicy()
  563.      * @since 2.6.0
  564.      */
  565.     public void setEvictionPolicy(final EvictionPolicy<T> evictionPolicy) {
  566.         this.evictionPolicy = evictionPolicy;
  567.     }

  568.     /**
  569.      * Sets the value for the {@code evictionPolicyClassName} configuration attribute for pools created with this configuration instance.
  570.      *
  571.      * @param evictionPolicyClassName The new setting of {@code evictionPolicyClassName} for this configuration instance
  572.      * @see GenericObjectPool#getEvictionPolicyClassName()
  573.      * @see GenericKeyedObjectPool#getEvictionPolicyClassName()
  574.      */
  575.     public void setEvictionPolicyClassName(final String evictionPolicyClassName) {
  576.         this.evictionPolicyClassName = evictionPolicyClassName;
  577.     }

  578.     /**
  579.      * Sets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
  580.      *
  581.      * @param evictorShutdownTimeoutDuration The new setting of {@code evictorShutdownTimeout} for this configuration instance
  582.      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
  583.      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
  584.      * @since 2.11.0
  585.      */
  586.     public void setEvictorShutdownTimeout(final Duration evictorShutdownTimeoutDuration) {
  587.         this.evictorShutdownTimeoutDuration = PoolImplUtils.nonNull(evictorShutdownTimeoutDuration, DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT);
  588.     }

  589.     /**
  590.      * Sets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
  591.      *
  592.      * @param evictorShutdownTimeout The new setting of {@code evictorShutdownTimeout} for this configuration instance
  593.      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
  594.      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
  595.      * @since 2.10.0
  596.      * @deprecated Use {@link #setEvictorShutdownTimeout(Duration)}.
  597.      */
  598.     @Deprecated
  599.     public void setEvictorShutdownTimeoutMillis(final Duration evictorShutdownTimeout) {
  600.         setEvictorShutdownTimeout(evictorShutdownTimeout);
  601.     }

  602.     /**
  603.      * Sets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
  604.      *
  605.      * @param evictorShutdownTimeoutMillis The new setting of {@code evictorShutdownTimeout} for this configuration instance
  606.      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
  607.      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
  608.      * @deprecated Use {@link #setEvictorShutdownTimeout(Duration)}.
  609.      */
  610.     @Deprecated
  611.     public void setEvictorShutdownTimeoutMillis(final long evictorShutdownTimeoutMillis) {
  612.         setEvictorShutdownTimeout(Duration.ofMillis(evictorShutdownTimeoutMillis));
  613.     }

  614.     /**
  615.      * Sets the value for the {@code fairness} configuration attribute for pools created with this configuration instance.
  616.      *
  617.      * @param fairness The new setting of {@code fairness} for this configuration instance
  618.      * @see GenericObjectPool#getFairness()
  619.      * @see GenericKeyedObjectPool#getFairness()
  620.      */
  621.     public void setFairness(final boolean fairness) {
  622.         this.fairness = fairness;
  623.     }

  624.     /**
  625.      * Sets the value of the flag that determines if JMX will be enabled for pools created with this configuration instance.
  626.      *
  627.      * @param jmxEnabled The new setting of {@code jmxEnabled} for this configuration instance
  628.      */
  629.     public void setJmxEnabled(final boolean jmxEnabled) {
  630.         this.jmxEnabled = jmxEnabled;
  631.     }

  632.     /**
  633.      * 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
  634.      * of {@code null} means that the pool will define the JMX name base.
  635.      *
  636.      * @param jmxNameBase The new setting of {@code jmxNameBase} for this configuration instance
  637.      */
  638.     public void setJmxNameBase(final String jmxNameBase) {
  639.         this.jmxNameBase = jmxNameBase;
  640.     }

  641.     /**
  642.      * 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.
  643.      *
  644.      * @param jmxNamePrefix The new setting of {@code jmxNamePrefix} for this configuration instance
  645.      */
  646.     public void setJmxNamePrefix(final String jmxNamePrefix) {
  647.         this.jmxNamePrefix = jmxNamePrefix;
  648.     }

  649.     /**
  650.      * Sets the value for the {@code lifo} configuration attribute for pools created with this configuration instance.
  651.      *
  652.      * @param lifo The new setting of {@code lifo} for this configuration instance
  653.      * @see GenericObjectPool#getLifo()
  654.      * @see GenericKeyedObjectPool#getLifo()
  655.      */
  656.     public void setLifo(final boolean lifo) {
  657.         this.lifo = lifo;
  658.     }

  659.     /**
  660.      * Sets the value for the {@code maxWait} configuration attribute for pools created with this configuration instance.
  661.      *
  662.      * @param maxWaitDuration The new setting of {@code maxWaitDuration} for this configuration instance
  663.      * @see GenericObjectPool#getMaxWaitDuration()
  664.      * @see GenericKeyedObjectPool#getMaxWaitDuration()
  665.      * @since 2.11.0
  666.      */
  667.     public void setMaxWait(final Duration maxWaitDuration) {
  668.         this.maxWaitDuration = PoolImplUtils.nonNull(maxWaitDuration, DEFAULT_MAX_WAIT);
  669.     }

  670.     /**
  671.      * Sets the value for the {@code maxWait} configuration attribute for pools created with this configuration instance.
  672.      *
  673.      * @param maxWaitMillis The new setting of {@code maxWaitMillis} for this configuration instance
  674.      * @see GenericObjectPool#getMaxWaitDuration()
  675.      * @see GenericKeyedObjectPool#getMaxWaitDuration()
  676.      * @deprecated Use {@link #setMaxWait(Duration)}.
  677.      */
  678.     @Deprecated
  679.     public void setMaxWaitMillis(final long maxWaitMillis) {
  680.         setMaxWait(Duration.ofMillis(maxWaitMillis));
  681.     }

  682.     /**
  683.      * Sets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  684.      *
  685.      * @param minEvictableIdleTime The new setting of {@code minEvictableIdleTime} for this configuration instance
  686.      * @see GenericObjectPool#getMinEvictableIdleDuration()
  687.      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
  688.      * @since 2.12.0
  689.      */
  690.     public void setMinEvictableIdleDuration(final Duration minEvictableIdleTime) {
  691.         this.minEvictableIdleDuration = PoolImplUtils.nonNull(minEvictableIdleTime, DEFAULT_MIN_EVICTABLE_IDLE_TIME);
  692.     }

  693.     /**
  694.      * Sets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  695.      *
  696.      * @param minEvictableIdleTime The new setting of {@code minEvictableIdleTime} for this configuration instance
  697.      * @see GenericObjectPool#getMinEvictableIdleDuration()
  698.      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
  699.      * @since 2.10.0
  700.      * @deprecated Use {@link #setMinEvictableIdleDuration(Duration)}.
  701.      */
  702.     @Deprecated
  703.     public void setMinEvictableIdleTime(final Duration minEvictableIdleTime) {
  704.         this.minEvictableIdleDuration = PoolImplUtils.nonNull(minEvictableIdleTime, DEFAULT_MIN_EVICTABLE_IDLE_TIME);
  705.     }

  706.     /**
  707.      * Sets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  708.      *
  709.      * @param minEvictableIdleTimeMillis The new setting of {@code minEvictableIdleTime} for this configuration instance
  710.      * @see GenericObjectPool#getMinEvictableIdleDuration()
  711.      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
  712.      * @deprecated Use {@link #setMinEvictableIdleDuration(Duration)}.
  713.      */
  714.     @Deprecated
  715.     public void setMinEvictableIdleTimeMillis(final long minEvictableIdleTimeMillis) {
  716.         this.minEvictableIdleDuration = Duration.ofMillis(minEvictableIdleTimeMillis);
  717.     }

  718.     /**
  719.      * Sets the value for the {@code numTestsPerEvictionRun} configuration attribute for pools created with this configuration instance.
  720.      *
  721.      * @param numTestsPerEvictionRun The new setting of {@code numTestsPerEvictionRun} for this configuration instance
  722.      * @see GenericObjectPool#getNumTestsPerEvictionRun()
  723.      * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun()
  724.      */
  725.     public void setNumTestsPerEvictionRun(final int numTestsPerEvictionRun) {
  726.         this.numTestsPerEvictionRun = numTestsPerEvictionRun;
  727.     }

  728.     /**
  729.      * Sets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  730.      *
  731.      * @param softMinEvictableIdleTime The new setting of {@code softMinEvictableIdleTime} for this configuration instance
  732.      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
  733.      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
  734.      * @since 2.12.0
  735.      */
  736.     public void setSoftMinEvictableIdleDuration(final Duration softMinEvictableIdleTime) {
  737.         this.softMinEvictableIdleDuration = PoolImplUtils.nonNull(softMinEvictableIdleTime, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME);
  738.     }

  739.     /**
  740.      * Sets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  741.      *
  742.      * @param softMinEvictableIdleTime The new setting of {@code softMinEvictableIdleTime} for this configuration instance
  743.      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
  744.      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
  745.      * @since 2.10.0
  746.      * @deprecated Use {@link #setSoftMinEvictableIdleDuration(Duration)}.
  747.      */
  748.     @Deprecated
  749.     public void setSoftMinEvictableIdleTime(final Duration softMinEvictableIdleTime) {
  750.         this.softMinEvictableIdleDuration = PoolImplUtils.nonNull(softMinEvictableIdleTime, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME);
  751.     }

  752.     /**
  753.      * Sets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
  754.      *
  755.      * @param softMinEvictableIdleTimeMillis The new setting of {@code softMinEvictableIdleTime} for this configuration instance
  756.      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
  757.      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
  758.      * @deprecated Use {@link #setSoftMinEvictableIdleDuration(Duration)}.
  759.      */
  760.     @Deprecated
  761.     public void setSoftMinEvictableIdleTimeMillis(final long softMinEvictableIdleTimeMillis) {
  762.         setSoftMinEvictableIdleTime(Duration.ofMillis(softMinEvictableIdleTimeMillis));
  763.     }

  764.     /**
  765.      * Sets the value for the {@code testOnBorrow} configuration attribute for pools created with this configuration instance.
  766.      *
  767.      * @param testOnBorrow The new setting of {@code testOnBorrow} for this configuration instance
  768.      * @see GenericObjectPool#getTestOnBorrow()
  769.      * @see GenericKeyedObjectPool#getTestOnBorrow()
  770.      */
  771.     public void setTestOnBorrow(final boolean testOnBorrow) {
  772.         this.testOnBorrow = testOnBorrow;
  773.     }

  774.     /**
  775.      * Sets the value for the {@code testOnCreate} configuration attribute for pools created with this configuration instance.
  776.      *
  777.      * @param testOnCreate The new setting of {@code testOnCreate} for this configuration instance
  778.      * @see GenericObjectPool#getTestOnCreate()
  779.      * @see GenericKeyedObjectPool#getTestOnCreate()
  780.      * @since 2.2
  781.      */
  782.     public void setTestOnCreate(final boolean testOnCreate) {
  783.         this.testOnCreate = testOnCreate;
  784.     }

  785.     /**
  786.      * Sets the value for the {@code testOnReturn} configuration attribute for pools created with this configuration instance.
  787.      *
  788.      * @param testOnReturn The new setting of {@code testOnReturn} for this configuration instance
  789.      * @see GenericObjectPool#getTestOnReturn()
  790.      * @see GenericKeyedObjectPool#getTestOnReturn()
  791.      */
  792.     public void setTestOnReturn(final boolean testOnReturn) {
  793.         this.testOnReturn = testOnReturn;
  794.     }

  795.     /**
  796.      * Sets the value for the {@code testWhileIdle} configuration attribute for pools created with this configuration instance.
  797.      *
  798.      * @param testWhileIdle The new setting of {@code testWhileIdle} for this configuration instance
  799.      * @see GenericObjectPool#getTestWhileIdle()
  800.      * @see GenericKeyedObjectPool#getTestWhileIdle()
  801.      */
  802.     public void setTestWhileIdle(final boolean testWhileIdle) {
  803.         this.testWhileIdle = testWhileIdle;
  804.     }

  805.     /**
  806.      * Sets the value for the {@code timeBetweenEvictionRuns} configuration attribute for pools created with this configuration instance.
  807.      *
  808.      * @param timeBetweenEvictionRuns The new setting of {@code timeBetweenEvictionRuns} for this configuration instance
  809.      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
  810.      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
  811.      * @since 2.10.0
  812.      */
  813.     public void setTimeBetweenEvictionRuns(final Duration timeBetweenEvictionRuns) {
  814.         this.durationBetweenEvictionRuns = PoolImplUtils.nonNull(timeBetweenEvictionRuns, DEFAULT_DURATION_BETWEEN_EVICTION_RUNS);
  815.     }

  816.     /**
  817.      * Sets the value for the {@code timeBetweenEvictionRuns} configuration attribute for pools created with this configuration instance.
  818.      *
  819.      * @param timeBetweenEvictionRunsMillis The new setting of {@code timeBetweenEvictionRuns} for this configuration instance
  820.      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
  821.      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
  822.      * @deprecated Use {@link #setTimeBetweenEvictionRuns(Duration)}.
  823.      */
  824.     @Deprecated
  825.     public void setTimeBetweenEvictionRunsMillis(final long timeBetweenEvictionRunsMillis) {
  826.         setTimeBetweenEvictionRuns(Duration.ofMillis(timeBetweenEvictionRunsMillis));
  827.     }

  828.     @Override
  829.     protected void toStringAppendFields(final StringBuilder builder) {
  830.         builder.append("lifo=");
  831.         builder.append(lifo);
  832.         builder.append(", fairness=");
  833.         builder.append(fairness);
  834.         builder.append(", maxWaitDuration=");
  835.         builder.append(maxWaitDuration);
  836.         builder.append(", minEvictableIdleTime=");
  837.         builder.append(minEvictableIdleDuration);
  838.         builder.append(", softMinEvictableIdleTime=");
  839.         builder.append(softMinEvictableIdleDuration);
  840.         builder.append(", numTestsPerEvictionRun=");
  841.         builder.append(numTestsPerEvictionRun);
  842.         builder.append(", evictionPolicyClassName=");
  843.         builder.append(evictionPolicyClassName);
  844.         builder.append(", testOnCreate=");
  845.         builder.append(testOnCreate);
  846.         builder.append(", testOnBorrow=");
  847.         builder.append(testOnBorrow);
  848.         builder.append(", testOnReturn=");
  849.         builder.append(testOnReturn);
  850.         builder.append(", testWhileIdle=");
  851.         builder.append(testWhileIdle);
  852.         builder.append(", timeBetweenEvictionRuns=");
  853.         builder.append(durationBetweenEvictionRuns);
  854.         builder.append(", blockWhenExhausted=");
  855.         builder.append(blockWhenExhausted);
  856.         builder.append(", jmxEnabled=");
  857.         builder.append(jmxEnabled);
  858.         builder.append(", jmxNamePrefix=");
  859.         builder.append(jmxNamePrefix);
  860.         builder.append(", jmxNameBase=");
  861.         builder.append(jmxNameBase);
  862.     }
  863. }