You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@commons.apache.org by gg...@apache.org on 2019/08/10 22:26:46 UTC
svn commit: r1048500 [30/39] - in
/websites/production/commons/content/proper: commons-pool/
commons-pool/apidocs/ commons-pool/apidocs/org/apache/commons/pool2/
commons-pool/apidocs/org/apache/commons/pool2/class-use/
commons-pool/apidocs/org/apache/c...
Added: websites/production/commons/content/proper/commons-pool/jacoco/org.apache.commons.pool2/PoolUtils.java.html
==============================================================================
--- websites/production/commons/content/proper/commons-pool/jacoco/org.apache.commons.pool2/PoolUtils.java.html (added)
+++ websites/production/commons/content/proper/commons-pool/jacoco/org.apache.commons.pool2/PoolUtils.java.html Sat Aug 10 22:26:44 2019
@@ -0,0 +1,1838 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>PoolUtils.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Commons Pool</a> > <a href="index.source.html" class="el_package">org.apache.commons.pool2</a> > <span class="el_source">PoolUtils
.java</span></div><h1>PoolUtils.java</h1><pre class="source lang-java linenums">/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.pool2;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
+
+/**
+ * This class consists exclusively of static methods that operate on or return
+ * ObjectPool or KeyedObjectPool related interfaces.
+ *
+ * @since 2.0
+ */
+public final class PoolUtils {
+
+ private static final String MSG_FACTOR_NEGATIVE = "factor must be positive.";
+ private static final String MSG_MIN_IDLE = "minIdle must be non-negative.";
+ private static final String MSG_NULL_KEY = "key must not be null.";
+ private static final String MSG_NULL_KEYED_POOL = "keyedPool must not be null.";
+ private static final String MSG_NULL_KEYS = "keys must not be null.";
+ private static final String MSG_NULL_POOL = "pool must not be null.";
+
+ /**
+ * Timer used to periodically check pools idle object count. Because a
+ * {@link Timer} creates a {@link Thread}, an IODH is used.
+ */
+<span class="fc" id="L50"> static class TimerHolder {</span>
+<span class="fc" id="L51"> static final Timer MIN_IDLE_TIMER = new Timer(true);</span>
+ }
+
+ /**
+ * PoolUtils instances should NOT be constructed in standard programming.
+ * Instead, the class should be used procedurally: PoolUtils.adapt(aPool);.
+ * This constructor is public to permit tools that require a JavaBean
+ * instance to operate.
+ */
+<span class="fc" id="L60"> public PoolUtils() {</span>
+<span class="fc" id="L61"> }</span>
+
+ /**
+ * Should the supplied Throwable be re-thrown (eg if it is an instance of
+ * one of the Throwables that should never be swallowed). Used by the pool
+ * error handling for operations that throw exceptions that normally need to
+ * be ignored.
+ *
+ * @param t
+ * The Throwable to check
+ * @throws ThreadDeath
+ * if that is passed in
+ * @throws VirtualMachineError
+ * if that is passed in
+ */
+ public static void checkRethrow(final Throwable t) {
+<span class="fc bfc" id="L77" title="All 2 branches covered."> if (t instanceof ThreadDeath) {</span>
+<span class="fc" id="L78"> throw (ThreadDeath) t;</span>
+ }
+<span class="fc bfc" id="L80" title="All 2 branches covered."> if (t instanceof VirtualMachineError) {</span>
+<span class="fc" id="L81"> throw (VirtualMachineError) t;</span>
+ }
+ // All other instances of Throwable will be silently swallowed
+<span class="fc" id="L84"> }</span>
+
+ /**
+ * Periodically check the idle object count for the pool. At most one idle
+ * object will be added per period. If there is an exception when calling
+ * {@link ObjectPool#addObject()} then no more checks will be performed.
+ *
+ * @param pool
+ * the pool to check periodically.
+ * @param minIdle
+ * if the {@link ObjectPool#getNumIdle()} is less than this then
+ * add an idle object.
+ * @param period
+ * the frequency to check the number of idle objects in a pool,
+ * see {@link Timer#schedule(TimerTask, long, long)}.
+ * @param <T> the type of objects in the pool
+ * @return the {@link TimerTask} that will periodically check the pools idle
+ * object count.
+ * @throws IllegalArgumentException
+ * when <code>pool</code> is <code>null</code> or when
+ * <code>minIdle</code> is negative or when <code>period</code>
+ * isn't valid for {@link Timer#schedule(TimerTask, long, long)}
+ */
+ public static <T> TimerTask checkMinIdle(final ObjectPool<T> pool,
+ final int minIdle, final long period)
+ throws IllegalArgumentException {
+<span class="fc bfc" id="L110" title="All 2 branches covered."> if (pool == null) {</span>
+<span class="fc" id="L111"> throw new IllegalArgumentException(MSG_NULL_KEYED_POOL);</span>
+ }
+<span class="fc bfc" id="L113" title="All 2 branches covered."> if (minIdle < 0) {</span>
+<span class="fc" id="L114"> throw new IllegalArgumentException(MSG_MIN_IDLE);</span>
+ }
+<span class="fc" id="L116"> final TimerTask task = new ObjectPoolMinIdleTimerTask<>(pool, minIdle);</span>
+<span class="fc" id="L117"> getMinIdleTimer().schedule(task, 0L, period);</span>
+<span class="fc" id="L118"> return task;</span>
+ }
+
+ /**
+ * Periodically check the idle object count for the key in the keyedPool. At
+ * most one idle object will be added per period. If there is an exception
+ * when calling {@link KeyedObjectPool#addObject(Object)} then no more
+ * checks for that key will be performed.
+ *
+ * @param keyedPool
+ * the keyedPool to check periodically.
+ * @param key
+ * the key to check the idle count of.
+ * @param minIdle
+ * if the {@link KeyedObjectPool#getNumIdle(Object)} is less than
+ * this then add an idle object.
+ * @param period
+ * the frequency to check the number of idle objects in a
+ * keyedPool, see {@link Timer#schedule(TimerTask, long, long)}.
+ * @param <K> the type of the pool key
+ * @param <V> the type of pool entries
+ * @return the {@link TimerTask} that will periodically check the pools idle
+ * object count.
+ * @throws IllegalArgumentException
+ * when <code>keyedPool</code>, <code>key</code> is
+ * <code>null</code> or when <code>minIdle</code> is negative or
+ * when <code>period</code> isn't valid for
+ * {@link Timer#schedule(TimerTask, long, long)}.
+ */
+ public static <K, V> TimerTask checkMinIdle(
+ final KeyedObjectPool<K, V> keyedPool, final K key,
+ final int minIdle, final long period)
+ throws IllegalArgumentException {
+<span class="fc bfc" id="L151" title="All 2 branches covered."> if (keyedPool == null) {</span>
+<span class="fc" id="L152"> throw new IllegalArgumentException(MSG_NULL_KEYED_POOL);</span>
+ }
+<span class="fc bfc" id="L154" title="All 2 branches covered."> if (key == null) {</span>
+<span class="fc" id="L155"> throw new IllegalArgumentException(MSG_NULL_KEY);</span>
+ }
+<span class="fc bfc" id="L157" title="All 2 branches covered."> if (minIdle < 0) {</span>
+<span class="fc" id="L158"> throw new IllegalArgumentException(MSG_MIN_IDLE);</span>
+ }
+<span class="fc" id="L160"> final TimerTask task = new KeyedObjectPoolMinIdleTimerTask<>(</span>
+ keyedPool, key, minIdle);
+<span class="fc" id="L162"> getMinIdleTimer().schedule(task, 0L, period);</span>
+<span class="fc" id="L163"> return task;</span>
+ }
+
+ /**
+ * Periodically check the idle object count for each key in the
+ * <code>Collection</code> <code>keys</code> in the keyedPool. At most one
+ * idle object will be added per period.
+ *
+ * @param keyedPool
+ * the keyedPool to check periodically.
+ * @param keys
+ * a collection of keys to check the idle object count.
+ * @param minIdle
+ * if the {@link KeyedObjectPool#getNumIdle(Object)} is less than
+ * this then add an idle object.
+ * @param period
+ * the frequency to check the number of idle objects in a
+ * keyedPool, see {@link Timer#schedule(TimerTask, long, long)}.
+ * @param <K> the type of the pool key
+ * @param <V> the type of pool entries
+ * @return a {@link Map} of key and {@link TimerTask} pairs that will
+ * periodically check the pools idle object count.
+ * @throws IllegalArgumentException
+ * when <code>keyedPool</code>, <code>keys</code>, or any of the
+ * values in the collection is <code>null</code> or when
+ * <code>minIdle</code> is negative or when <code>period</code>
+ * isn't valid for {@link Timer#schedule(TimerTask, long, long)}
+ * .
+ * @see #checkMinIdle(KeyedObjectPool, Object, int, long)
+ */
+ public static <K, V> Map<K, TimerTask> checkMinIdle(
+ final KeyedObjectPool<K, V> keyedPool, final Collection<K> keys,
+ final int minIdle, final long period)
+ throws IllegalArgumentException {
+<span class="pc bpc" id="L197" title="1 of 2 branches missed."> if (keys == null) {</span>
+<span class="nc" id="L198"> throw new IllegalArgumentException(MSG_NULL_KEYS);</span>
+ }
+<span class="fc" id="L200"> final Map<K, TimerTask> tasks = new HashMap<>(keys.size());</span>
+<span class="fc" id="L201"> final Iterator<K> iter = keys.iterator();</span>
+<span class="fc bfc" id="L202" title="All 2 branches covered."> while (iter.hasNext()) {</span>
+<span class="fc" id="L203"> final K key = iter.next();</span>
+<span class="fc" id="L204"> final TimerTask task = checkMinIdle(keyedPool, key, minIdle, period);</span>
+<span class="fc" id="L205"> tasks.put(key, task);</span>
+<span class="fc" id="L206"> }</span>
+<span class="fc" id="L207"> return tasks;</span>
+ }
+
+ /**
+ * Calls {@link ObjectPool#addObject()} on <code>pool</code> <code>count</code>
+ * number of times.
+ *
+ * @param pool
+ * the pool to prefill.
+ * @param count
+ * the number of idle objects to add.
+ * @param <T> the type of objects in the pool
+ * @throws Exception
+ * when {@link ObjectPool#addObject()} fails.
+ * @throws IllegalArgumentException
+ * when <code>pool</code> is <code>null</code>.
+ */
+ public static <T> void prefill(final ObjectPool<T> pool, final int count)
+ throws Exception, IllegalArgumentException {
+<span class="fc bfc" id="L226" title="All 2 branches covered."> if (pool == null) {</span>
+<span class="fc" id="L227"> throw new IllegalArgumentException(MSG_NULL_POOL);</span>
+ }
+<span class="fc bfc" id="L229" title="All 2 branches covered."> for (int i = 0; i < count; i++) {</span>
+<span class="fc" id="L230"> pool.addObject();</span>
+ }
+<span class="fc" id="L232"> }</span>
+
+ /**
+ * Calls {@link KeyedObjectPool#addObject(Object)} on <code>keyedPool</code> with
+ * <code>key</code> <code>count</code> number of times.
+ *
+ * @param keyedPool
+ * the keyedPool to prefill.
+ * @param key
+ * the key to add objects for.
+ * @param count
+ * the number of idle objects to add for <code>key</code>.
+ * @param <K> the type of the pool key
+ * @param <V> the type of pool entries
+ * @throws Exception
+ * when {@link KeyedObjectPool#addObject(Object)} fails.
+ * @throws IllegalArgumentException
+ * when <code>keyedPool</code> or <code>key</code> is
+ * <code>null</code>.
+ */
+ public static <K, V> void prefill(final KeyedObjectPool<K, V> keyedPool,
+ final K key, final int count) throws Exception,
+ IllegalArgumentException {
+<span class="fc bfc" id="L255" title="All 2 branches covered."> if (keyedPool == null) {</span>
+<span class="fc" id="L256"> throw new IllegalArgumentException(MSG_NULL_KEYED_POOL);</span>
+ }
+<span class="fc bfc" id="L258" title="All 2 branches covered."> if (key == null) {</span>
+<span class="fc" id="L259"> throw new IllegalArgumentException(MSG_NULL_KEY);</span>
+ }
+<span class="fc bfc" id="L261" title="All 2 branches covered."> for (int i = 0; i < count; i++) {</span>
+<span class="fc" id="L262"> keyedPool.addObject(key);</span>
+ }
+<span class="fc" id="L264"> }</span>
+
+ /**
+ * Calls {@link KeyedObjectPool#addObject(Object)} on <code>keyedPool</code> with each
+ * key in <code>keys</code> for <code>count</code> number of times. This has
+ * the same effect as calling {@link #prefill(KeyedObjectPool, Object, int)}
+ * for each key in the <code>keys</code> collection.
+ *
+ * @param keyedPool
+ * the keyedPool to prefill.
+ * @param keys
+ * {@link Collection} of keys to add objects for.
+ * @param count
+ * the number of idle objects to add for each <code>key</code>.
+ * @param <K> the type of the pool key
+ * @param <V> the type of pool entries
+ * @throws Exception
+ * when {@link KeyedObjectPool#addObject(Object)} fails.
+ * @throws IllegalArgumentException
+ * when <code>keyedPool</code>, <code>keys</code>, or any value
+ * in <code>keys</code> is <code>null</code>.
+ * @see #prefill(KeyedObjectPool, Object, int)
+ */
+ public static <K, V> void prefill(final KeyedObjectPool<K, V> keyedPool,
+ final Collection<K> keys, final int count) throws Exception,
+ IllegalArgumentException {
+<span class="fc bfc" id="L290" title="All 2 branches covered."> if (keys == null) {</span>
+<span class="fc" id="L291"> throw new IllegalArgumentException(MSG_NULL_KEYS);</span>
+ }
+<span class="fc" id="L293"> final Iterator<K> iter = keys.iterator();</span>
+<span class="fc bfc" id="L294" title="All 2 branches covered."> while (iter.hasNext()) {</span>
+<span class="fc" id="L295"> prefill(keyedPool, iter.next(), count);</span>
+ }
+<span class="fc" id="L297"> }</span>
+
+ /**
+ * Returns a synchronized (thread-safe) ObjectPool backed by the specified
+ * ObjectPool.
+ * <p>
+ * <b>Note:</b> This should not be used on pool implementations that already
+ * provide proper synchronization such as the pools provided in the Commons
+ * Pool library. Wrapping a pool that {@link #wait() waits} for poolable
+ * objects to be returned before allowing another one to be borrowed with
+ * another layer of synchronization will cause liveliness issues or a
+ * deadlock.
+ * </p>
+ *
+ * @param pool
+ * the ObjectPool to be "wrapped" in a synchronized ObjectPool.
+ * @param <T> the type of objects in the pool
+ * @return a synchronized view of the specified ObjectPool.
+ */
+ public static <T> ObjectPool<T> synchronizedPool(final ObjectPool<T> pool) {
+<span class="fc bfc" id="L317" title="All 2 branches covered."> if (pool == null) {</span>
+<span class="fc" id="L318"> throw new IllegalArgumentException(MSG_NULL_POOL);</span>
+ }
+ /*
+ * assert !(pool instanceof GenericObjectPool) :
+ * "GenericObjectPool is already thread-safe"; assert !(pool instanceof
+ * SoftReferenceObjectPool) :
+ * "SoftReferenceObjectPool is already thread-safe"; assert !(pool
+ * instanceof StackObjectPool) :
+ * "StackObjectPool is already thread-safe"; assert
+ * !"org.apache.commons.pool.composite.CompositeObjectPool"
+ * .equals(pool.getClass().getName()) :
+ * "CompositeObjectPools are already thread-safe";
+ */
+<span class="fc" id="L331"> return new SynchronizedObjectPool<>(pool);</span>
+ }
+
+ /**
+ * Returns a synchronized (thread-safe) KeyedObjectPool backed by the
+ * specified KeyedObjectPool.
+ * <p>
+ * <b>Note:</b> This should not be used on pool implementations that already
+ * provide proper synchronization such as the pools provided in the Commons
+ * Pool library. Wrapping a pool that {@link #wait() waits} for poolable
+ * objects to be returned before allowing another one to be borrowed with
+ * another layer of synchronization will cause liveliness issues or a
+ * deadlock.
+ * </p>
+ *
+ * @param keyedPool
+ * the KeyedObjectPool to be "wrapped" in a synchronized
+ * KeyedObjectPool.
+ * @param <K> the type of the pool key
+ * @param <V> the type of pool entries
+ * @return a synchronized view of the specified KeyedObjectPool.
+ */
+ public static <K, V> KeyedObjectPool<K, V> synchronizedPool(
+ final KeyedObjectPool<K, V> keyedPool) {
+ /*
+ * assert !(keyedPool instanceof GenericKeyedObjectPool) :
+ * "GenericKeyedObjectPool is already thread-safe"; assert !(keyedPool
+ * instanceof StackKeyedObjectPool) :
+ * "StackKeyedObjectPool is already thread-safe"; assert
+ * !"org.apache.commons.pool.composite.CompositeKeyedObjectPool"
+ * .equals(keyedPool.getClass().getName()) :
+ * "CompositeKeyedObjectPools are already thread-safe";
+ */
+<span class="fc" id="L364"> return new SynchronizedKeyedObjectPool<>(keyedPool);</span>
+ }
+
+ /**
+ * Returns a synchronized (thread-safe) PooledObjectFactory backed by the
+ * specified PooledObjectFactory.
+ *
+ * @param factory
+ * the PooledObjectFactory to be "wrapped" in a synchronized
+ * PooledObjectFactory.
+ * @param <T> the type of objects in the pool
+ * @return a synchronized view of the specified PooledObjectFactory.
+ */
+ public static <T> PooledObjectFactory<T> synchronizedPooledFactory(
+ final PooledObjectFactory<T> factory) {
+<span class="fc" id="L379"> return new SynchronizedPooledObjectFactory<>(factory);</span>
+ }
+
+ /**
+ * Returns a synchronized (thread-safe) KeyedPooledObjectFactory backed by
+ * the specified KeyedPoolableObjectFactory.
+ *
+ * @param keyedFactory
+ * the KeyedPooledObjectFactory to be "wrapped" in a
+ * synchronized KeyedPooledObjectFactory.
+ * @param <K> the type of the pool key
+ * @param <V> the type of pool entries
+ * @return a synchronized view of the specified KeyedPooledObjectFactory.
+ */
+ public static <K, V> KeyedPooledObjectFactory<K, V> synchronizedKeyedPooledFactory(
+ final KeyedPooledObjectFactory<K, V> keyedFactory) {
+<span class="fc" id="L395"> return new SynchronizedKeyedPooledObjectFactory<>(keyedFactory);</span>
+ }
+
+ /**
+ * Returns a pool that adaptively decreases its size when idle objects are
+ * no longer needed. This is intended as an always thread-safe alternative
+ * to using an idle object evictor provided by many pool implementations.
+ * This is also an effective way to shrink FIFO ordered pools that
+ * experience load spikes.
+ *
+ * @param pool
+ * the ObjectPool to be decorated so it shrinks its idle count
+ * when possible.
+ * @param <T> the type of objects in the pool
+ * @return a pool that adaptively decreases its size when idle objects are
+ * no longer needed.
+ * @see #erodingPool(ObjectPool, float)
+ */
+ public static <T> ObjectPool<T> erodingPool(final ObjectPool<T> pool) {
+<span class="fc" id="L414"> return erodingPool(pool, 1f);</span>
+ }
+
+ /**
+ * Returns a pool that adaptively decreases its size when idle objects are
+ * no longer needed. This is intended as an always thread-safe alternative
+ * to using an idle object evictor provided by many pool implementations.
+ * This is also an effective way to shrink FIFO ordered pools that
+ * experience load spikes.
+ * <p>
+ * The factor parameter provides a mechanism to tweak the rate at which the
+ * pool tries to shrink its size. Values between 0 and 1 cause the pool to
+ * try to shrink its size more often. Values greater than 1 cause the pool
+ * to less frequently try to shrink its size.
+ * </p>
+ *
+ * @param pool
+ * the ObjectPool to be decorated so it shrinks its idle count
+ * when possible.
+ * @param factor
+ * a positive value to scale the rate at which the pool tries to
+ * reduce its size. If 0 &lt; factor &lt; 1 then the pool
+ * shrinks more aggressively. If 1 &lt; factor then the pool
+ * shrinks less aggressively.
+ * @param <T> the type of objects in the pool
+ * @return a pool that adaptively decreases its size when idle objects are
+ * no longer needed.
+ * @see #erodingPool(ObjectPool)
+ */
+ public static <T> ObjectPool<T> erodingPool(final ObjectPool<T> pool,
+ final float factor) {
+<span class="fc bfc" id="L445" title="All 2 branches covered."> if (pool == null) {</span>
+<span class="fc" id="L446"> throw new IllegalArgumentException(MSG_NULL_POOL);</span>
+ }
+<span class="fc bfc" id="L448" title="All 2 branches covered."> if (factor <= 0f) {</span>
+<span class="fc" id="L449"> throw new IllegalArgumentException(MSG_FACTOR_NEGATIVE);</span>
+ }
+<span class="fc" id="L451"> return new ErodingObjectPool<>(pool, factor);</span>
+ }
+
+ /**
+ * Returns a pool that adaptively decreases its size when idle objects are
+ * no longer needed. This is intended as an always thread-safe alternative
+ * to using an idle object evictor provided by many pool implementations.
+ * This is also an effective way to shrink FIFO ordered pools that
+ * experience load spikes.
+ *
+ * @param keyedPool
+ * the KeyedObjectPool to be decorated so it shrinks its idle
+ * count when possible.
+ * @param <K> the type of the pool key
+ * @param <V> the type of pool entries
+ * @return a pool that adaptively decreases its size when idle objects are
+ * no longer needed.
+ * @see #erodingPool(KeyedObjectPool, float)
+ * @see #erodingPool(KeyedObjectPool, float, boolean)
+ */
+ public static <K, V> KeyedObjectPool<K, V> erodingPool(
+ final KeyedObjectPool<K, V> keyedPool) {
+<span class="fc" id="L473"> return erodingPool(keyedPool, 1f);</span>
+ }
+
+ /**
+ * Returns a pool that adaptively decreases its size when idle objects are
+ * no longer needed. This is intended as an always thread-safe alternative
+ * to using an idle object evictor provided by many pool implementations.
+ * This is also an effective way to shrink FIFO ordered pools that
+ * experience load spikes.
+ * <p>
+ * The factor parameter provides a mechanism to tweak the rate at which the
+ * pool tries to shrink its size. Values between 0 and 1 cause the pool to
+ * try to shrink its size more often. Values greater than 1 cause the pool
+ * to less frequently try to shrink its size.
+ * </p>
+ *
+ * @param keyedPool
+ * the KeyedObjectPool to be decorated so it shrinks its idle
+ * count when possible.
+ * @param factor
+ * a positive value to scale the rate at which the pool tries to
+ * reduce its size. If 0 &lt; factor &lt; 1 then the pool
+ * shrinks more aggressively. If 1 &lt; factor then the pool
+ * shrinks less aggressively.
+ * @param <K> the type of the pool key
+ * @param <V> the type of pool entries
+ * @return a pool that adaptively decreases its size when idle objects are
+ * no longer needed.
+ * @see #erodingPool(KeyedObjectPool, float, boolean)
+ */
+ public static <K, V> KeyedObjectPool<K, V> erodingPool(
+ final KeyedObjectPool<K, V> keyedPool, final float factor) {
+<span class="fc" id="L505"> return erodingPool(keyedPool, factor, false);</span>
+ }
+
+ /**
+ * Returns a pool that adaptively decreases its size when idle objects are
+ * no longer needed. This is intended as an always thread-safe alternative
+ * to using an idle object evictor provided by many pool implementations.
+ * This is also an effective way to shrink FIFO ordered pools that
+ * experience load spikes.
+ * <p>
+ * The factor parameter provides a mechanism to tweak the rate at which the
+ * pool tries to shrink its size. Values between 0 and 1 cause the pool to
+ * try to shrink its size more often. Values greater than 1 cause the pool
+ * to less frequently try to shrink its size.
+ * </p>
+ * <p>
+ * The perKey parameter determines if the pool shrinks on a whole pool basis
+ * or a per key basis. When perKey is false, the keys do not have an effect
+ * on the rate at which the pool tries to shrink its size. When perKey is
+ * true, each key is shrunk independently.
+ * </p>
+ *
+ * @param keyedPool
+ * the KeyedObjectPool to be decorated so it shrinks its idle
+ * count when possible.
+ * @param factor
+ * a positive value to scale the rate at which the pool tries to
+ * reduce its size. If 0 &lt; factor &lt; 1 then the pool
+ * shrinks more aggressively. If 1 &lt; factor then the pool
+ * shrinks less aggressively.
+ * @param perKey
+ * when true, each key is treated independently.
+ * @param <K> the type of the pool key
+ * @param <V> the type of pool entries
+ * @return a pool that adaptively decreases its size when idle objects are
+ * no longer needed.
+ * @see #erodingPool(KeyedObjectPool)
+ * @see #erodingPool(KeyedObjectPool, float)
+ */
+ public static <K, V> KeyedObjectPool<K, V> erodingPool(
+ final KeyedObjectPool<K, V> keyedPool, final float factor,
+ final boolean perKey) {
+<span class="fc bfc" id="L547" title="All 2 branches covered."> if (keyedPool == null) {</span>
+<span class="fc" id="L548"> throw new IllegalArgumentException(MSG_NULL_KEYED_POOL);</span>
+ }
+<span class="fc bfc" id="L550" title="All 2 branches covered."> if (factor <= 0f) {</span>
+<span class="fc" id="L551"> throw new IllegalArgumentException(MSG_FACTOR_NEGATIVE);</span>
+ }
+<span class="fc bfc" id="L553" title="All 2 branches covered."> if (perKey) {</span>
+<span class="fc" id="L554"> return new ErodingPerKeyKeyedObjectPool<>(keyedPool, factor);</span>
+ }
+<span class="fc" id="L556"> return new ErodingKeyedObjectPool<>(keyedPool, factor);</span>
+ }
+
+ /**
+ * Gets the <code>Timer</code> for checking keyedPool's idle count.
+ *
+ * @return the {@link Timer} for checking keyedPool's idle count.
+ */
+ private static Timer getMinIdleTimer() {
+<span class="fc" id="L565"> return TimerHolder.MIN_IDLE_TIMER;</span>
+ }
+
+ /**
+ * Timer task that adds objects to the pool until the number of idle
+ * instances reaches the configured minIdle. Note that this is not the same
+ * as the pool's minIdle setting.
+ *
+ * @param <T> type of objects in the pool
+ */
+ private static final class ObjectPoolMinIdleTimerTask<T> extends TimerTask {
+
+ /** Minimum number of idle instances. Not the same as pool.getMinIdle(). */
+ private final int minIdle;
+
+ /** Object pool */
+ private final ObjectPool<T> pool;
+
+ /**
+ * Create a new ObjectPoolMinIdleTimerTask for the given pool with the
+ * given minIdle setting.
+ *
+ * @param pool
+ * object pool
+ * @param minIdle
+ * number of idle instances to maintain
+ * @throws IllegalArgumentException
+ * if the pool is null
+ */
+ ObjectPoolMinIdleTimerTask(final ObjectPool<T> pool, final int minIdle)
+<span class="fc" id="L595"> throws IllegalArgumentException {</span>
+<span class="pc bpc" id="L596" title="1 of 2 branches missed."> if (pool == null) {</span>
+<span class="nc" id="L597"> throw new IllegalArgumentException(MSG_NULL_POOL);</span>
+ }
+<span class="fc" id="L599"> this.pool = pool;</span>
+<span class="fc" id="L600"> this.minIdle = minIdle;</span>
+<span class="fc" id="L601"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void run() {
+<span class="fc" id="L608"> boolean success = false;</span>
+ try {
+<span class="fc bfc" id="L610" title="All 2 branches covered."> if (pool.getNumIdle() < minIdle) {</span>
+<span class="fc" id="L611"> pool.addObject();</span>
+ }
+<span class="fc" id="L613"> success = true;</span>
+
+<span class="fc" id="L615"> } catch (final Exception e) {</span>
+<span class="fc" id="L616"> cancel();</span>
+ } finally {
+ // detect other types of Throwable and cancel this Timer
+<span class="fc bfc" id="L619" title="All 2 branches covered."> if (!success) {</span>
+<span class="fc" id="L620"> cancel();</span>
+ }
+ }
+<span class="fc" id="L623"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+<span class="fc" id="L630"> final StringBuilder sb = new StringBuilder();</span>
+<span class="fc" id="L631"> sb.append("ObjectPoolMinIdleTimerTask");</span>
+<span class="fc" id="L632"> sb.append("{minIdle=").append(minIdle);</span>
+<span class="fc" id="L633"> sb.append(", pool=").append(pool);</span>
+<span class="fc" id="L634"> sb.append('}');</span>
+<span class="fc" id="L635"> return sb.toString();</span>
+ }
+ }
+
+ /**
+ * Timer task that adds objects to the pool until the number of idle
+ * instances for the given key reaches the configured minIdle. Note that
+ * this is not the same as the pool's minIdle setting.
+ *
+ * @param <K> object pool key type
+ * @param <V> object pool value type
+ */
+ private static final class KeyedObjectPoolMinIdleTimerTask<K, V> extends
+ TimerTask {
+
+ /** Minimum number of idle instances. Not the same as pool.getMinIdle(). */
+ private final int minIdle;
+
+ /** Key to ensure minIdle for */
+ private final K key;
+
+ /** Keyed object pool */
+ private final KeyedObjectPool<K, V> keyedPool;
+
+ /**
+ * Creates a new KeyedObjecPoolMinIdleTimerTask.
+ *
+ * @param keyedPool
+ * keyed object pool
+ * @param key
+ * key to ensure minimum number of idle instances
+ * @param minIdle
+ * minimum number of idle instances
+ * @throws IllegalArgumentException
+ * if the key is null
+ */
+ KeyedObjectPoolMinIdleTimerTask(final KeyedObjectPool<K, V> keyedPool,
+<span class="fc" id="L672"> final K key, final int minIdle) throws IllegalArgumentException {</span>
+<span class="pc bpc" id="L673" title="1 of 2 branches missed."> if (keyedPool == null) {</span>
+<span class="nc" id="L674"> throw new IllegalArgumentException(</span>
+ MSG_NULL_KEYED_POOL);
+ }
+<span class="fc" id="L677"> this.keyedPool = keyedPool;</span>
+<span class="fc" id="L678"> this.key = key;</span>
+<span class="fc" id="L679"> this.minIdle = minIdle;</span>
+<span class="fc" id="L680"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void run() {
+<span class="fc" id="L687"> boolean success = false;</span>
+ try {
+<span class="fc bfc" id="L689" title="All 2 branches covered."> if (keyedPool.getNumIdle(key) < minIdle) {</span>
+<span class="fc" id="L690"> keyedPool.addObject(key);</span>
+ }
+<span class="fc" id="L692"> success = true;</span>
+
+<span class="fc" id="L694"> } catch (final Exception e) {</span>
+<span class="fc" id="L695"> cancel();</span>
+
+ } finally {
+ // detect other types of Throwable and cancel this Timer
+<span class="fc bfc" id="L699" title="All 2 branches covered."> if (!success) {</span>
+<span class="fc" id="L700"> cancel();</span>
+ }
+ }
+<span class="fc" id="L703"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+<span class="fc" id="L710"> final StringBuilder sb = new StringBuilder();</span>
+<span class="fc" id="L711"> sb.append("KeyedObjectPoolMinIdleTimerTask");</span>
+<span class="fc" id="L712"> sb.append("{minIdle=").append(minIdle);</span>
+<span class="fc" id="L713"> sb.append(", key=").append(key);</span>
+<span class="fc" id="L714"> sb.append(", keyedPool=").append(keyedPool);</span>
+<span class="fc" id="L715"> sb.append('}');</span>
+<span class="fc" id="L716"> return sb.toString();</span>
+ }
+ }
+
+ /**
+ * A synchronized (thread-safe) ObjectPool backed by the specified
+ * ObjectPool.
+ * <p>
+ * <b>Note:</b> This should not be used on pool implementations that already
+ * provide proper synchronization such as the pools provided in the Commons
+ * Pool library. Wrapping a pool that {@link #wait() waits} for poolable
+ * objects to be returned before allowing another one to be borrowed with
+ * another layer of synchronization will cause liveliness issues or a
+ * deadlock.
+ * </p>
+ *
+ * @param <T> type of objects in the pool
+ */
+ private static final class SynchronizedObjectPool<T> implements ObjectPool<T> {
+
+ /**
+ * Object whose monitor is used to synchronize methods on the wrapped
+ * pool.
+ */
+<span class="fc" id="L740"> private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();</span>
+
+ /** the underlying object pool */
+ private final ObjectPool<T> pool;
+
+ /**
+ * Creates a new SynchronizedObjectPool wrapping the given pool.
+ *
+ * @param pool
+ * the ObjectPool to be "wrapped" in a synchronized
+ * ObjectPool.
+ * @throws IllegalArgumentException
+ * if the pool is null
+ */
+ SynchronizedObjectPool(final ObjectPool<T> pool)
+<span class="fc" id="L755"> throws IllegalArgumentException {</span>
+<span class="pc bpc" id="L756" title="1 of 2 branches missed."> if (pool == null) {</span>
+<span class="nc" id="L757"> throw new IllegalArgumentException(MSG_NULL_POOL);</span>
+ }
+<span class="fc" id="L759"> this.pool = pool;</span>
+<span class="fc" id="L760"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T borrowObject() throws Exception, NoSuchElementException,
+ IllegalStateException {
+<span class="fc" id="L768"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L769"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L771"> return pool.borrowObject();</span>
+ } finally {
+<span class="fc" id="L773"> writeLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void returnObject(final T obj) {
+<span class="fc" id="L782"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L783"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L785"> pool.returnObject(obj);</span>
+<span class="nc" id="L786"> } catch (final Exception e) {</span>
+ // swallowed as of Pool 2
+ } finally {
+<span class="fc" id="L789"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L791"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void invalidateObject(final T obj) {
+<span class="fc" id="L798"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L799"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L801"> pool.invalidateObject(obj);</span>
+<span class="nc" id="L802"> } catch (final Exception e) {</span>
+ // swallowed as of Pool 2
+ } finally {
+<span class="fc" id="L805"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L807"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addObject() throws Exception, IllegalStateException,
+ UnsupportedOperationException {
+<span class="fc" id="L815"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L816"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L818"> pool.addObject();</span>
+ } finally {
+<span class="fc" id="L820"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L822"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumIdle() {
+<span class="fc" id="L829"> final ReadLock readLock = readWriteLock.readLock();</span>
+<span class="fc" id="L830"> readLock.lock();</span>
+ try {
+<span class="fc" id="L832"> return pool.getNumIdle();</span>
+ } finally {
+<span class="fc" id="L834"> readLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumActive() {
+<span class="fc" id="L843"> final ReadLock readLock = readWriteLock.readLock();</span>
+<span class="fc" id="L844"> readLock.lock();</span>
+ try {
+<span class="fc" id="L846"> return pool.getNumActive();</span>
+ } finally {
+<span class="fc" id="L848"> readLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clear() throws Exception, UnsupportedOperationException {
+<span class="fc" id="L857"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L858"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L860"> pool.clear();</span>
+ } finally {
+<span class="fc" id="L862"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L864"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() {
+<span class="fc" id="L871"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L872"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L874"> pool.close();</span>
+<span class="nc" id="L875"> } catch (final Exception e) {</span>
+ // swallowed as of Pool 2
+ } finally {
+<span class="fc" id="L878"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L880"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+<span class="fc" id="L887"> final StringBuilder sb = new StringBuilder();</span>
+<span class="fc" id="L888"> sb.append("SynchronizedObjectPool");</span>
+<span class="fc" id="L889"> sb.append("{pool=").append(pool);</span>
+<span class="fc" id="L890"> sb.append('}');</span>
+<span class="fc" id="L891"> return sb.toString();</span>
+ }
+ }
+
+ /**
+ * A synchronized (thread-safe) KeyedObjectPool backed by the specified
+ * KeyedObjectPool.
+ * <p>
+ * <b>Note:</b> This should not be used on pool implementations that already
+ * provide proper synchronization such as the pools provided in the Commons
+ * Pool library. Wrapping a pool that {@link #wait() waits} for poolable
+ * objects to be returned before allowing another one to be borrowed with
+ * another layer of synchronization will cause liveliness issues or a
+ * deadlock.
+ * </p>
+ *
+ * @param <K> object pool key type
+ * @param <V> object pool value type
+ */
+ private static final class SynchronizedKeyedObjectPool<K, V> implements
+ KeyedObjectPool<K, V> {
+
+ /**
+ * Object whose monitor is used to synchronize methods on the wrapped
+ * pool.
+ */
+<span class="fc" id="L917"> private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();</span>
+
+ /** Underlying object pool */
+ private final KeyedObjectPool<K, V> keyedPool;
+
+ /**
+ * Creates a new SynchronizedKeyedObjectPool wrapping the given pool
+ *
+ * @param keyedPool
+ * KeyedObjectPool to wrap
+ * @throws IllegalArgumentException
+ * if keyedPool is null
+ */
+ SynchronizedKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool)
+<span class="fc" id="L931"> throws IllegalArgumentException {</span>
+<span class="fc bfc" id="L932" title="All 2 branches covered."> if (keyedPool == null) {</span>
+<span class="fc" id="L933"> throw new IllegalArgumentException(</span>
+ MSG_NULL_KEYED_POOL);
+ }
+<span class="fc" id="L936"> this.keyedPool = keyedPool;</span>
+<span class="fc" id="L937"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public V borrowObject(final K key) throws Exception,
+ NoSuchElementException, IllegalStateException {
+<span class="fc" id="L945"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L946"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L948"> return keyedPool.borrowObject(key);</span>
+ } finally {
+<span class="fc" id="L950"> writeLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void returnObject(final K key, final V obj) {
+<span class="fc" id="L959"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L960"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L962"> keyedPool.returnObject(key, obj);</span>
+<span class="nc" id="L963"> } catch (final Exception e) {</span>
+ // swallowed
+ } finally {
+<span class="fc" id="L966"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L968"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void invalidateObject(final K key, final V obj) {
+<span class="fc" id="L975"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L976"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L978"> keyedPool.invalidateObject(key, obj);</span>
+<span class="nc" id="L979"> } catch (final Exception e) {</span>
+ // swallowed as of Pool 2
+ } finally {
+<span class="fc" id="L982"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L984"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addObject(final K key) throws Exception,
+ IllegalStateException, UnsupportedOperationException {
+<span class="fc" id="L992"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L993"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L995"> keyedPool.addObject(key);</span>
+ } finally {
+<span class="fc" id="L997"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L999"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumIdle(final K key) {
+<span class="fc" id="L1006"> final ReadLock readLock = readWriteLock.readLock();</span>
+<span class="fc" id="L1007"> readLock.lock();</span>
+ try {
+<span class="fc" id="L1009"> return keyedPool.getNumIdle(key);</span>
+ } finally {
+<span class="fc" id="L1011"> readLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumActive(final K key) {
+<span class="fc" id="L1020"> final ReadLock readLock = readWriteLock.readLock();</span>
+<span class="fc" id="L1021"> readLock.lock();</span>
+ try {
+<span class="fc" id="L1023"> return keyedPool.getNumActive(key);</span>
+ } finally {
+<span class="fc" id="L1025"> readLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumIdle() {
+<span class="fc" id="L1034"> final ReadLock readLock = readWriteLock.readLock();</span>
+<span class="fc" id="L1035"> readLock.lock();</span>
+ try {
+<span class="fc" id="L1037"> return keyedPool.getNumIdle();</span>
+ } finally {
+<span class="fc" id="L1039"> readLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumActive() {
+<span class="fc" id="L1048"> final ReadLock readLock = readWriteLock.readLock();</span>
+<span class="fc" id="L1049"> readLock.lock();</span>
+ try {
+<span class="fc" id="L1051"> return keyedPool.getNumActive();</span>
+ } finally {
+<span class="fc" id="L1053"> readLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clear() throws Exception, UnsupportedOperationException {
+<span class="fc" id="L1062"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L1063"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1065"> keyedPool.clear();</span>
+ } finally {
+<span class="fc" id="L1067"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L1069"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clear(final K key) throws Exception,
+ UnsupportedOperationException {
+<span class="fc" id="L1077"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L1078"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1080"> keyedPool.clear(key);</span>
+ } finally {
+<span class="fc" id="L1082"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L1084"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() {
+<span class="fc" id="L1091"> final WriteLock writeLock = readWriteLock.writeLock();</span>
+<span class="fc" id="L1092"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1094"> keyedPool.close();</span>
+<span class="nc" id="L1095"> } catch (final Exception e) {</span>
+ // swallowed as of Pool 2
+ } finally {
+<span class="fc" id="L1098"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L1100"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+<span class="fc" id="L1107"> final StringBuilder sb = new StringBuilder();</span>
+<span class="fc" id="L1108"> sb.append("SynchronizedKeyedObjectPool");</span>
+<span class="fc" id="L1109"> sb.append("{keyedPool=").append(keyedPool);</span>
+<span class="fc" id="L1110"> sb.append('}');</span>
+<span class="fc" id="L1111"> return sb.toString();</span>
+ }
+ }
+
+ /**
+ * A fully synchronized PooledObjectFactory that wraps a
+ * PooledObjectFactory and synchronizes access to the wrapped factory
+ * methods.
+ * <p>
+ * <b>Note:</b> This should not be used on pool implementations that already
+ * provide proper synchronization such as the pools provided in the Commons
+ * Pool library.
+ * </p>
+ *
+ * @param <T> pooled object factory type
+ */
+ private static final class SynchronizedPooledObjectFactory<T> implements
+ PooledObjectFactory<T> {
+
+ /** Synchronization lock */
+<span class="fc" id="L1131"> private final WriteLock writeLock = new ReentrantReadWriteLock().writeLock();</span>
+
+ /** Wrapped factory */
+ private final PooledObjectFactory<T> factory;
+
+ /**
+ * Creates a SynchronizedPoolableObjectFactory wrapping the given
+ * factory.
+ *
+ * @param factory
+ * underlying factory to wrap
+ * @throws IllegalArgumentException
+ * if the factory is null
+ */
+ SynchronizedPooledObjectFactory(final PooledObjectFactory<T> factory)
+<span class="fc" id="L1146"> throws IllegalArgumentException {</span>
+<span class="fc bfc" id="L1147" title="All 2 branches covered."> if (factory == null) {</span>
+<span class="fc" id="L1148"> throw new IllegalArgumentException("factory must not be null.");</span>
+ }
+<span class="fc" id="L1150"> this.factory = factory;</span>
+<span class="fc" id="L1151"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PooledObject<T> makeObject() throws Exception {
+<span class="fc" id="L1158"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1160"> return factory.makeObject();</span>
+ } finally {
+<span class="fc" id="L1162"> writeLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void destroyObject(final PooledObject<T> p) throws Exception {
+<span class="fc" id="L1171"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1173"> factory.destroyObject(p);</span>
+ } finally {
+<span class="fc" id="L1175"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L1177"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean validateObject(final PooledObject<T> p) {
+<span class="fc" id="L1184"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1186"> return factory.validateObject(p);</span>
+ } finally {
+<span class="fc" id="L1188"> writeLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activateObject(final PooledObject<T> p) throws Exception {
+<span class="fc" id="L1197"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1199"> factory.activateObject(p);</span>
+ } finally {
+<span class="fc" id="L1201"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L1203"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void passivateObject(final PooledObject<T> p) throws Exception {
+<span class="fc" id="L1210"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1212"> factory.passivateObject(p);</span>
+ } finally {
+<span class="fc" id="L1214"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L1216"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+<span class="fc" id="L1223"> final StringBuilder sb = new StringBuilder();</span>
+<span class="fc" id="L1224"> sb.append("SynchronizedPoolableObjectFactory");</span>
+<span class="fc" id="L1225"> sb.append("{factory=").append(factory);</span>
+<span class="fc" id="L1226"> sb.append('}');</span>
+<span class="fc" id="L1227"> return sb.toString();</span>
+ }
+ }
+
+ /**
+ * A fully synchronized KeyedPooledObjectFactory that wraps a
+ * KeyedPooledObjectFactory and synchronizes access to the wrapped factory
+ * methods.
+ * <p>
+ * <b>Note:</b> This should not be used on pool implementations that already
+ * provide proper synchronization such as the pools provided in the Commons
+ * Pool library.
+ * </p>
+ *
+ * @param <K> pooled object factory key type
+ * @param <V> pooled object factory key value
+ */
+ private static final class SynchronizedKeyedPooledObjectFactory<K, V>
+ implements KeyedPooledObjectFactory<K, V> {
+
+ /** Synchronization lock */
+<span class="fc" id="L1248"> private final WriteLock writeLock = new ReentrantReadWriteLock().writeLock();</span>
+
+ /** Wrapped factory */
+ private final KeyedPooledObjectFactory<K, V> keyedFactory;
+
+ /**
+ * Creates a SynchronizedKeyedPoolableObjectFactory wrapping the given
+ * factory.
+ *
+ * @param keyedFactory
+ * underlying factory to wrap
+ * @throws IllegalArgumentException
+ * if the factory is null
+ */
+ SynchronizedKeyedPooledObjectFactory(
+ final KeyedPooledObjectFactory<K, V> keyedFactory)
+<span class="fc" id="L1264"> throws IllegalArgumentException {</span>
+<span class="fc bfc" id="L1265" title="All 2 branches covered."> if (keyedFactory == null) {</span>
+<span class="fc" id="L1266"> throw new IllegalArgumentException(</span>
+ "keyedFactory must not be null.");
+ }
+<span class="fc" id="L1269"> this.keyedFactory = keyedFactory;</span>
+<span class="fc" id="L1270"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PooledObject<V> makeObject(final K key) throws Exception {
+<span class="fc" id="L1277"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1279"> return keyedFactory.makeObject(key);</span>
+ } finally {
+<span class="fc" id="L1281"> writeLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void destroyObject(final K key, final PooledObject<V> p) throws Exception {
+<span class="fc" id="L1290"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1292"> keyedFactory.destroyObject(key, p);</span>
+ } finally {
+<span class="fc" id="L1294"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L1296"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean validateObject(final K key, final PooledObject<V> p) {
+<span class="fc" id="L1303"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1305"> return keyedFactory.validateObject(key, p);</span>
+ } finally {
+<span class="fc" id="L1307"> writeLock.unlock();</span>
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activateObject(final K key, final PooledObject<V> p) throws Exception {
+<span class="fc" id="L1316"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1318"> keyedFactory.activateObject(key, p);</span>
+ } finally {
+<span class="fc" id="L1320"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L1322"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void passivateObject(final K key, final PooledObject<V> p) throws Exception {
+<span class="fc" id="L1329"> writeLock.lock();</span>
+ try {
+<span class="fc" id="L1331"> keyedFactory.passivateObject(key, p);</span>
+ } finally {
+<span class="fc" id="L1333"> writeLock.unlock();</span>
+ }
+<span class="fc" id="L1335"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+<span class="fc" id="L1342"> final StringBuilder sb = new StringBuilder();</span>
+<span class="fc" id="L1343"> sb.append("SynchronizedKeyedPoolableObjectFactory");</span>
+<span class="fc" id="L1344"> sb.append("{keyedFactory=").append(keyedFactory);</span>
+<span class="fc" id="L1345"> sb.append('}');</span>
+<span class="fc" id="L1346"> return sb.toString();</span>
+ }
+ }
+
+ /**
+ * Encapsulate the logic for when the next poolable object should be
+ * discarded. Each time update is called, the next time to shrink is
+ * recomputed, based on the float factor, number of idle instances in the
+ * pool and high water mark. Float factor is assumed to be between 0 and 1.
+ * Values closer to 1 cause less frequent erosion events. Erosion event
+ * timing also depends on numIdle. When this value is relatively high (close
+ * to previously established high water mark), erosion occurs more
+ * frequently.
+ */
+ private static final class ErodingFactor {
+ /** Determines frequency of "erosion" events */
+ private final float factor;
+
+ /** Time of next shrink event */
+ private transient volatile long nextShrink;
+
+ /** High water mark - largest numIdle encountered */
+ private transient volatile int idleHighWaterMark;
+
+ /**
+ * Creates a new ErodingFactor with the given erosion factor.
+ *
+ * @param factor
+ * erosion factor
+ */
+<span class="fc" id="L1376"> public ErodingFactor(final float factor) {</span>
+<span class="fc" id="L1377"> this.factor = factor;</span>
+<span class="fc" id="L1378"> nextShrink = System.currentTimeMillis() + (long) (900000 * factor); // now</span>
+ // +
+ // 15
+ // min
+ // *
+ // factor
+<span class="fc" id="L1384"> idleHighWaterMark = 1;</span>
+<span class="fc" id="L1385"> }</span>
+
+ /**
+ * Updates internal state using the supplied time and numIdle.
+ *
+ * @param now
+ * current time
+ * @param numIdle
+ * number of idle elements in the pool
+ */
+ public void update(final long now, final int numIdle) {
+<span class="fc" id="L1396"> final int idle = Math.max(0, numIdle);</span>
+<span class="fc" id="L1397"> idleHighWaterMark = Math.max(idle, idleHighWaterMark);</span>
+<span class="fc" id="L1398"> final float maxInterval = 15f;</span>
+<span class="fc" id="L1399"> final float minutes = maxInterval +</span>
+ ((1f - maxInterval) / idleHighWaterMark) * idle;
+<span class="fc" id="L1401"> nextShrink = now + (long) (minutes * 60000f * factor);</span>
+<span class="fc" id="L1402"> }</span>
+
+ /**
+ * Returns the time of the next erosion event.
+ *
+ * @return next shrink time
+ */
+ public long getNextShrink() {
+<span class="fc" id="L1410"> return nextShrink;</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+<span class="fc" id="L1418"> return "ErodingFactor{" + "factor=" + factor +</span>
+ ", idleHighWaterMark=" + idleHighWaterMark + '}';
+ }
+ }
+
+ /**
+ * Decorates an object pool, adding "eroding" behavior. Based on the
+ * configured {@link #factor erosion factor}, objects returning to the pool
+ * may be invalidated instead of being added to idle capacity.
+ *
+ * @param <T> type of objects in the pool
+ */
+ private static class ErodingObjectPool<T> implements ObjectPool<T> {
+
+ /** Underlying object pool */
+ private final ObjectPool<T> pool;
+
+ /** Erosion factor */
+ private final ErodingFactor factor;
+
+ /**
+ * Creates an ErodingObjectPool wrapping the given pool using the
+ * specified erosion factor.
+ *
+ * @param pool
+ * underlying pool
+ * @param factor
+ * erosion factor - determines the frequency of erosion
+ * events
+ * @see #factor
+ */
+<span class="fc" id="L1449"> public ErodingObjectPool(final ObjectPool<T> pool, final float factor) {</span>
+<span class="fc" id="L1450"> this.pool = pool;</span>
+<span class="fc" id="L1451"> this.factor = new ErodingFactor(factor);</span>
+<span class="fc" id="L1452"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T borrowObject() throws Exception, NoSuchElementException,
+ IllegalStateException {
+<span class="fc" id="L1460"> return pool.borrowObject();</span>
+ }
+
+ /**
+ * Returns obj to the pool, unless erosion is triggered, in which case
+ * obj is invalidated. Erosion is triggered when there are idle
+ * instances in the pool and more than the {@link #factor erosion
+ * factor}-determined time has elapsed since the last returnObject
+ * activation.
+ *
+ * @param obj
+ * object to return or invalidate
+ * @see #factor
+ */
+ @Override
+ public void returnObject(final T obj) {
+<span class="fc" id="L1476"> boolean discard = false;</span>
+<span class="fc" id="L1477"> final long now = System.currentTimeMillis();</span>
+<span class="fc" id="L1478"> synchronized (pool) {</span>
+<span class="fc bfc" id="L1479" title="All 2 branches covered."> if (factor.getNextShrink() < now) { // XXX: Pool 3: move test</span>
+ // out of sync block
+<span class="fc" id="L1481"> final int numIdle = pool.getNumIdle();</span>
+<span class="pc bpc" id="L1482" title="1 of 2 branches missed."> if (numIdle > 0) {</span>
+<span class="fc" id="L1483"> discard = true;</span>
+ }
+
+<span class="fc" id="L1486"> factor.update(now, numIdle);</span>
+ }
+<span class="fc" id="L1488"> }</span>
+ try {
+<span class="fc bfc" id="L1490" title="All 2 branches covered."> if (discard) {</span>
+<span class="fc" id="L1491"> pool.invalidateObject(obj);</span>
+ } else {
+<span class="fc" id="L1493"> pool.returnObject(obj);</span>
+ }
+<span class="nc" id="L1495"> } catch (final Exception e) {</span>
+ // swallowed
+<span class="fc" id="L1497"> }</span>
+<span class="fc" id="L1498"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void invalidateObject(final T obj) {
+ try {
+<span class="nc" id="L1506"> pool.invalidateObject(obj);</span>
+<span class="nc" id="L1507"> } catch (final Exception e) {</span>
+ // swallowed
+<span class="nc" id="L1509"> }</span>
+<span class="nc" id="L1510"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addObject() throws Exception, IllegalStateException,
+ UnsupportedOperationException {
+<span class="fc" id="L1518"> pool.addObject();</span>
+<span class="fc" id="L1519"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumIdle() {
+<span class="fc" id="L1526"> return pool.getNumIdle();</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumActive() {
+<span class="fc" id="L1534"> return pool.getNumActive();</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clear() throws Exception, UnsupportedOperationException {
+<span class="fc" id="L1542"> pool.clear();</span>
+<span class="fc" id="L1543"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() {
+ try {
+<span class="fc" id="L1551"> pool.close();</span>
+<span class="nc" id="L1552"> } catch (final Exception e) {</span>
+ // swallowed
+<span class="fc" id="L1554"> }</span>
+<span class="fc" id="L1555"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+<span class="fc" id="L1562"> return "ErodingObjectPool{" + "factor=" + factor + ", pool=" +</span>
+ pool + '}';
+ }
+ }
+
+ /**
+ * Decorates a keyed object pool, adding "eroding" behavior. Based on the
+ * configured erosion factor, objects returning to the pool
+ * may be invalidated instead of being added to idle capacity.
+ *
+ * @param <K> object pool key type
+ * @param <V> object pool value type
+ */
+ private static class ErodingKeyedObjectPool<K, V> implements
+ KeyedObjectPool<K, V> {
+
+ /** Underlying pool */
+ private final KeyedObjectPool<K, V> keyedPool;
+
+ /** Erosion factor */
+ private final ErodingFactor erodingFactor;
+
+ /**
+ * Creates an ErodingObjectPool wrapping the given pool using the
+ * specified erosion factor.
+ *
+ * @param keyedPool
+ * underlying pool
+ * @param factor
+ * erosion factor - determines the frequency of erosion
+ * events
+ * @see #erodingFactor
+ */
+ public ErodingKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool,
+ final float factor) {
+<span class="fc" id="L1597"> this(keyedPool, new ErodingFactor(factor));</span>
+<span class="fc" id="L1598"> }</span>
+
+ /**
+ * Creates an ErodingObjectPool wrapping the given pool using the
+ * specified erosion factor.
+ *
+ * @param keyedPool
+ * underlying pool - must not be null
+ * @param erodingFactor
+ * erosion factor - determines the frequency of erosion
+ * events
+ * @see #erodingFactor
+ */
+ protected ErodingKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool,
+<span class="fc" id="L1612"> final ErodingFactor erodingFactor) {</span>
+<span class="pc bpc" id="L1613" title="1 of 2 branches missed."> if (keyedPool == null) {</span>
+<span class="nc" id="L1614"> throw new IllegalArgumentException(</span>
+ MSG_NULL_KEYED_POOL);
+ }
+<span class="fc" id="L1617"> this.keyedPool = keyedPool;</span>
+<span class="fc" id="L1618"> this.erodingFactor = erodingFactor;</span>
+<span class="fc" id="L1619"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public V borrowObject(final K key) throws Exception,
+ NoSuchElementException, IllegalStateException {
+<span class="fc" id="L1627"> return keyedPool.borrowObject(key);</span>
+ }
+
+ /**
+ * Returns obj to the pool, unless erosion is triggered, in which case
+ * obj is invalidated. Erosion is triggered when there are idle
+ * instances in the pool associated with the given key and more than the
+ * configured {@link #erodingFactor erosion factor} time has elapsed
+ * since the last returnObject activation.
+ *
+ * @param obj
+ * object to return or invalidate
+ * @param key
+ * key
+ * @see #erodingFactor
+ */
+ @Override
+ public void returnObject(final K key, final V obj) throws Exception {
+<span class="fc" id="L1645"> boolean discard = false;</span>
+<span class="fc" id="L1646"> final long now = System.currentTimeMillis();</span>
+<span class="fc" id="L1647"> final ErodingFactor factor = getErodingFactor(key);</span>
+<span class="fc" id="L1648"> synchronized (keyedPool) {</span>
+<span class="fc bfc" id="L1649" title="All 2 branches covered."> if (factor.getNextShrink() < now) {</span>
+<span class="fc" id="L1650"> final int numIdle = getNumIdle(key);</span>
+<span class="pc bpc" id="L1651" title="1 of 2 branches missed."> if (numIdle > 0) {</span>
+<span class="fc" id="L1652"> discard = true;</span>
+ }
+
+<span class="fc" id="L1655"> factor.update(now, numIdle);</span>
+ }
+<span class="fc" id="L1657"> }</span>
+ try {
+<span class="fc bfc" id="L1659" title="All 2 branches covered."> if (discard) {</span>
+<span class="fc" id="L1660"> keyedPool.invalidateObject(key, obj);</span>
+ } else {
+<span class="fc" id="L1662"> keyedPool.returnObject(key, obj);</span>
+ }
+<span class="nc" id="L1664"> } catch (final Exception e) {</span>
+ // swallowed
+<span class="fc" id="L1666"> }</span>
+<span class="fc" id="L1667"> }</span>
+
+ /**
+ * Returns the eroding factor for the given key
+ *
+ * @param key
+ * key
+ * @return eroding factor for the given keyed pool
+ */
+ protected ErodingFactor getErodingFactor(final K key) {
+<span class="fc" id="L1677"> return erodingFactor;</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void invalidateObject(final K key, final V obj) {
+ try {
+<span class="nc" id="L1686"> keyedPool.invalidateObject(key, obj);</span>
+<span class="nc" id="L1687"> } catch (final Exception e) {</span>
+ // swallowed
+<span class="nc" id="L1689"> }</span>
+<span class="nc" id="L1690"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addObject(final K key) throws Exception,
+ IllegalStateException, UnsupportedOperationException {
+<span class="fc" id="L1698"> keyedPool.addObject(key);</span>
+<span class="fc" id="L1699"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumIdle() {
+<span class="fc" id="L1706"> return keyedPool.getNumIdle();</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumIdle(final K key) {
+<span class="fc" id="L1714"> return keyedPool.getNumIdle(key);</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumActive() {
+<span class="fc" id="L1722"> return keyedPool.getNumActive();</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumActive(final K key) {
+<span class="nc" id="L1730"> return keyedPool.getNumActive(key);</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clear() throws Exception, UnsupportedOperationException {
+<span class="fc" id="L1738"> keyedPool.clear();</span>
+<span class="fc" id="L1739"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clear(final K key) throws Exception,
+ UnsupportedOperationException {
+<span class="nc" id="L1747"> keyedPool.clear(key);</span>
+<span class="nc" id="L1748"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() {
+ try {
+<span class="fc" id="L1756"> keyedPool.close();</span>
+<span class="nc" id="L1757"> } catch (final Exception e) {</span>
+ // swallowed
+<span class="fc" id="L1759"> }</span>
+<span class="fc" id="L1760"> }</span>
+
+ /**
+ * Returns the underlying pool
+ *
+ * @return the keyed pool that this ErodingKeyedObjectPool wraps
+ */
+ protected KeyedObjectPool<K, V> getKeyedPool() {
+<span class="fc" id="L1768"> return keyedPool;</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+<span class="fc" id="L1776"> return "ErodingKeyedObjectPool{" + "factor=" +</span>
+ erodingFactor + ", keyedPool=" + keyedPool + '}';
+ }
+ }
+
+ /**
+ * Extends ErodingKeyedObjectPool to allow erosion to take place on a
+ * per-key basis. Timing of erosion events is tracked separately for
+ * separate keyed pools.
+ *
+ * @param <K> object pool key type
+ * @param <V> object pool value type
+ */
+ private static final class ErodingPerKeyKeyedObjectPool<K, V> extends
+ ErodingKeyedObjectPool<K, V> {
+
+ /** Erosion factor - same for all pools */
+ private final float factor;
+
+ /** Map of ErodingFactor instances keyed on pool keys */
+<span class="fc" id="L1796"> private final Map<K, ErodingFactor> factors = Collections.synchronizedMap(new HashMap<K, ErodingFactor>());</span>
+
+ /**
+ * Creates a new ErordingPerKeyKeyedObjectPool decorating the given keyed
+ * pool with the specified erosion factor.
+ *
+ * @param keyedPool
+ * underlying keyed pool
+ * @param factor
+ * erosion factor
+ */
+ public ErodingPerKeyKeyedObjectPool(
+ final KeyedObjectPool<K, V> keyedPool, final float factor) {
+<span class="fc" id="L1809"> super(keyedPool, null);</span>
+<span class="fc" id="L1810"> this.factor = factor;</span>
+<span class="fc" id="L1811"> }</span>
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ErodingFactor getErodingFactor(final K key) {
+<span class="fc" id="L1818"> ErodingFactor eFactor = factors.get(key);</span>
+ // this may result in two ErodingFactors being created for a key
+ // since they are small and cheap this is okay.
+<span class="fc bfc" id="L1821" title="All 2 branches covered."> if (eFactor == null) {</span>
+<span class="fc" id="L1822"> eFactor = new ErodingFactor(this.factor);</span>
+<span class="fc" id="L1823"> factors.put(key, eFactor);</span>
+ }
+<span class="fc" id="L1825"> return eFactor;</span>
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+<span class="fc" id="L1833"> return "ErodingPerKeyKeyedObjectPool{" + "factor=" + factor +</span>
+<span class="fc" id="L1834"> ", keyedPool=" + getKeyedPool() + '}';</span>
+ }
+ }
+}
+</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.3.201901230119</span></div></body></html>
\ No newline at end of file
Added: websites/production/commons/content/proper/commons-pool/jacoco/org.apache.commons.pool2/PooledObject.html
==============================================================================
--- websites/production/commons/content/proper/commons-pool/jacoco/org.apache.commons.pool2/PooledObject.html (added)
+++ websites/production/commons/content/proper/commons-pool/jacoco/org.apache.commons.pool2/PooledObject.html Sat Aug 10 22:26:44 2019
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>PooledObject</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Commons Pool</a> > <a href="index.html" class="el_package">org.apache.commons.pool2</a> > <span class="el_class">PooledObject</span></div><h1>PooledObject</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><t
r><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">3 of 3</td><td class="ctr2">0%</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">2</td><td class="ctr2">2</td><td class="c
tr1">2</td><td class="ctr2">2</td><td class="ctr1">2</td><td class="ctr2">2</td></tr></tfoot><tbody><tr><td id="a0"><a href="PooledObject.java.html#L66" class="el_method">getBorrowedCount()</a></td><td class="bar" id="b0"><img src="../jacoco-resources/redbar.gif" width="120" height="10" title="2" alt="2"/></td><td class="ctr2" id="c0">0%</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">1</td><td class="ctr2" id="g0">1</td><td class="ctr1" id="h0">1</td><td class="ctr2" id="i0">1</td><td class="ctr1" id="j0">1</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a1"><a href="PooledObject.java.html#L192" class="el_method">setRequireFullStackTrace(boolean)</a></td><td class="bar" id="b1"><img src="../jacoco-resources/redbar.gif" width="60" height="10" title="1" alt="1"/></td><td class="ctr2" id="c1">0%</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">1</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">
1</td><td class="ctr2" id="i1">1</td><td class="ctr1" id="j1">1</td><td class="ctr2" id="k1">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.3.201901230119</span></div></body></html>
\ No newline at end of file