diff --git a/build.third_step6.gradle b/build.third_step6.gradle
index d87976633..6fc167808 100644
--- a/build.third_step6.gradle
+++ b/build.third_step6.gradle
@@ -4,19 +4,19 @@ tasks.withType(JavaCompile){
options.encoding = 'UTF-8'
destinationDir = file('build/classes/6')
}
-//Ö¸¶¨¹¹½¨µÄjdk°æ±¾
+//ָ��������jdk�汾
sourceCompatibility=1.5
def jarname="fine-third-10.0.jar"
def classesDir='build/classes/6'
def ftpreport='E:/ftp/share/report/'
-//½âѹlibϵÄjarµ½classesÎļþ¼Ð
+//��ѹlib�µ�jar��classes�ļ���
jar{
baseName="fine-third_6-10.0"
}
def srcDir="."
-//ÉèÖÃÔ´Âë·¾¶
+//����Դ��·��
sourceSets{
main{
java{
@@ -30,6 +30,9 @@ sourceSets{
"${srcDir}/fine-lucene/resources",
"${srcDir}/fine-cglib/src",
"${srcDir}/fine-cglib/resources",
+ "${srcDir}/fine-jedis/src",
+ "${srcDir}/fine-jedis/resources",
+
]
}
}
@@ -41,12 +44,12 @@ repositories{
mavenCentral()
}
-//»ñȡʲô·ÖÖ§Ãû
+//��ȡʲô��֧��
FileTree files =fileTree(dir:'./',include:'build.*.gradle')
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('/'))
def branchName=buildDir.substring(buildDir.lastIndexOf ('/')+1)
-//Ö¸¶¨ÒÀÀµ
+//ָ������
dependencies{
compile fileTree(dir:"${srcDir}/fine-jackson/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/fine-ehcache/lib",include:'**/*.jar')
@@ -56,7 +59,7 @@ dependencies{
testCompile 'junit:junit:4.12'
}
-//Ö¸Ã÷ÎÞ·¨±àÒëÎļþËùÔÚ·¾¶
+//ָ���޷������ļ�����·��
def dataContent ={def dir ->
copySpec{
from ("${dir}"){
@@ -80,6 +83,8 @@ task copyFiles(type:Copy,dependsOn:'compileJava'){
with dataContent.call("${srcDir}/fine-lucene/resources")
with dataContent.call("${srcDir}/fine-cglib/src")
with dataContent.call("${srcDir}/fine-cglib/resources")
+ with dataContent.call("${srcDir}/fine-jedis/src")
+ with dataContent.call("${srcDir}/fine-jedis/resources")
into "${classesDir}"
}
}
diff --git a/fine-jedis/src/com/fr/third/org/apache/commons/pool2/BaseKeyedPooledObjectFactory.java b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/BaseKeyedPooledObjectFactory.java
new file mode 100755
index 000000000..65b362ac4
--- /dev/null
+++ b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/BaseKeyedPooledObjectFactory.java
@@ -0,0 +1,118 @@
+/*
+ * 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 com.fr.third.org.apache.commons.pool2;
+
+/**
+ * A base implementation of KeyedPooledObjectFactory
.
+ *
+ * All operations defined here are essentially no-op's. + *
+ * This class is immutable, and therefore thread-safe. + * + * @see KeyedPooledObjectFactory + * + * @param
+ * The default implementation is a no-op.
+ *
+ * @param key the key used when selecting the instance
+ * @param p a {@code PooledObject} wrapping the instance to be destroyed
+ */
+ @Override
+ public void destroyObject(final K key, final PooledObject
+ * The default implementation always returns {@code true}.
+ *
+ * @param key the key used when selecting the object
+ * @param p a {@code PooledObject} wrapping the instance to be validated
+ * @return always
+ * The default implementation is a no-op.
+ *
+ * @param key the key used when selecting the object
+ * @param p a {@code PooledObject} wrapping the instance to be activated
+ */
+ @Override
+ public void activateObject(final K key, final PooledObject
+ * The default implementation is a no-op.
+ *
+ * @param key the key used when selecting the object
+ * @param p a {@code PooledObject} wrapping the instance to be passivated
+ */
+ @Override
+ public void passivateObject(final K key, final PooledObject
+ * This class is intended to be thread-safe.
+ *
+ * @param
+ * This affects the behavior of
+ * All operations defined here are essentially no-op's.
+ *
+ * This class is immutable, and therefore thread-safe
+ *
+ * @param This method must support concurrent, multi-threaded
+ * activation.
+ * A keyed pool maintains a pool of instances for each key value.
+ *
+ * Example of use:
+ *
+ * {@link KeyedObjectPool} implementations may choose to store at most
+ * one instance per key value, or may choose to maintain a pool of instances
+ * for each key (essentially creating a {@link java.util.Map Map} of
+ * {@link ObjectPool pools}).
+ *
+ * See {@link org.apache.commons.pool2.impl.GenericKeyedObjectPool
+ * GenericKeyedObjectPool} for an implementation.
+ *
+ * @param
+ * Instances returned from this method will have been either newly created
+ * with {@link KeyedPooledObjectFactory#makeObject makeObject} or will be
+ * a previously idle object and have been activated with
+ * {@link KeyedPooledObjectFactory#activateObject activateObject} and then
+ * (optionally) validated with
+ * {@link KeyedPooledObjectFactory#validateObject validateObject}.
+ *
+ * By contract, clients must return the borrowed object
+ * using {@link #returnObject returnObject},
+ * {@link #invalidateObject invalidateObject}, or a related method as
+ * defined in an implementation or sub-interface, using a
+ * The behaviour of this method when the pool has been exhausted is not
+ * strictly specified (although it may be specified by implementations).
+ *
+ * @param key the key used to obtain the object
+ *
+ * @return an instance from this pool.
+ *
+ * @throws IllegalStateException
+ * after {@link #close close} has been called on this pool
+ * @throws Exception
+ * when {@link KeyedPooledObjectFactory#makeObject
+ * makeObject} throws an exception
+ * @throws NoSuchElementException
+ * when the pool is exhausted and cannot or will not return
+ * another instance
+ */
+ V borrowObject(K key) throws Exception, NoSuchElementException, IllegalStateException;
+
+ /**
+ * Return an instance to the pool. By contract,
+ * By contract,
+ * This method should be used when an object that has been borrowed is
+ * determined (due to an exception or other problem) to be invalid.
+ *
+ * @param key the key used to obtain the object
+ * @param obj a {@link #borrowObject borrowed} instance to be returned.
+ *
+ * @throws Exception if the instance cannot be invalidated
+ */
+ void invalidateObject(K key, V obj) throws Exception;
+
+ /**
+ * Create an object using the {@link KeyedPooledObjectFactory factory} or
+ * other implementation dependent mechanism, passivate it, and then place it
+ * in the idle object pool.
+ * Calling {@link #addObject addObject} or
+ * {@link #borrowObject borrowObject} after invoking this method on a pool
+ * will cause them to throw an {@link IllegalStateException}.
+ *
+ * Implementations should silently fail if not all resources can be freed.
+ */
+ @Override
+ void close();
+}
diff --git a/fine-jedis/src/com/fr/third/org/apache/commons/pool2/KeyedPooledObjectFactory.java b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/KeyedPooledObjectFactory.java
new file mode 100755
index 000000000..688304881
--- /dev/null
+++ b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/KeyedPooledObjectFactory.java
@@ -0,0 +1,148 @@
+/*
+ * 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 com.fr.third.org.apache.commons.pool2;
+
+/**
+ * An interface defining life-cycle methods for
+ * instances to be served by a {@link KeyedObjectPool}.
+ *
+ * By contract, when an {@link KeyedObjectPool}
+ * delegates to a {@link KeyedPooledObjectFactory},
+ *
+ * While clients of a {@link KeyedObjectPool} borrow and return instances of
+ * the underlying value type V, the factory methods act on instances of
+ * {@link PooledObject PooledObject<V>}. These are the object wrappers that
+ * pools use to track and maintain state informations about the objects that
+ * they manage.
+ *
+ * @see KeyedObjectPool
+ * @see BaseKeyedPooledObjectFactory
+ *
+ * @param
+ * It is important for implementations of this method to be aware that there
+ * is no guarantee about what state
+ * Also, an implementation must take in to consideration that instances lost
+ * to the garbage collector may never be destroyed.
+ *
+ * @param key the key used when selecting the instance
+ * @param p a {@code PooledObject} wrapping the instance to be destroyed
+ *
+ * @throws Exception should be avoided as it may be swallowed by
+ * the pool implementation.
+ *
+ * @see #validateObject
+ * @see KeyedObjectPool#invalidateObject
+ */
+ void destroyObject(K key, PooledObject
+ * Example of use:
+ *
+ * See {@link BaseObjectPool} for a simple base implementation.
+ *
+ * @param
+ * Instances returned from this method will have been either newly created
+ * with {@link PooledObjectFactory#makeObject} or will be a previously
+ * idle object and have been activated with
+ * {@link PooledObjectFactory#activateObject} and then validated with
+ * {@link PooledObjectFactory#validateObject}.
+ *
+ * By contract, clients must return the borrowed instance
+ * using {@link #returnObject}, {@link #invalidateObject}, or a related
+ * method as defined in an implementation or sub-interface.
+ *
+ * The behaviour of this method when the pool has been exhausted
+ * is not strictly specified (although it may be specified by
+ * implementations).
+ *
+ * @return an instance from this pool.
+ *
+ * @throws IllegalStateException
+ * after {@link #close close} has been called on this pool.
+ * @throws Exception
+ * when {@link PooledObjectFactory#makeObject} throws an
+ * exception.
+ * @throws NoSuchElementException
+ * when the pool is exhausted and cannot or will not return
+ * another instance.
+ */
+ T borrowObject() throws Exception, NoSuchElementException,
+ IllegalStateException;
+
+ /**
+ * Return an instance to the pool. By contract,
+ * By contract,
+ * This method should be used when an object that has been borrowed is
+ * determined (due to an exception or other problem) to be invalid.
+ *
+ * @param obj a {@link #borrowObject borrowed} instance to be disposed.
+ *
+ * @throws Exception if the instance cannot be invalidated
+ */
+ void invalidateObject(T obj) throws Exception;
+
+ /**
+ * Create an object using the {@link PooledObjectFactory factory} or other
+ * implementation dependent mechanism, passivate it, and then place it in
+ * the idle object pool.
+ * Calling {@link #addObject} or {@link #borrowObject} after invoking this
+ * method on a pool will cause them to throw an {@link IllegalStateException}.
+ *
+ * Implementations should silently fail if not all resources can be freed.
+ */
+ @Override
+ void close();
+}
diff --git a/fine-jedis/src/com/fr/third/org/apache/commons/pool2/PoolUtils.java b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/PoolUtils.java
new file mode 100755
index 000000000..ed63f1af5
--- /dev/null
+++ b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/PoolUtils.java
@@ -0,0 +1,1824 @@
+/*
+ * 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 com.fr.third.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 {
+
+ /**
+ * Timer used to periodically check pools idle object count. Because a
+ * {@link Timer} creates a {@link Thread}, an IODH is used.
+ */
+ static class TimerHolder {
+ static final Timer MIN_IDLE_TIMER = new Timer(true);
+ }
+
+ /**
+ * 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.
+ */
+ public PoolUtils() {
+ }
+
+ /**
+ * 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) {
+ if (t instanceof ThreadDeath) {
+ throw (ThreadDeath) t;
+ }
+ if (t instanceof VirtualMachineError) {
+ throw (VirtualMachineError) t;
+ }
+ // All other instances of Throwable will be silently swallowed
+ }
+
+ /**
+ * 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
+ * Note: 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.
+ *
+ * Note: 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * Note: 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.
+ *
+ * Note: 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.
+ *
+ * Note: This should not be used on pool implementations that already
+ * provide proper synchronization such as the pools provided in the Commons
+ * Pool library.
+ *
+ * Note: This should not be used on pool implementations that already
+ * provide proper synchronization such as the pools provided in the Commons
+ * Pool library.
+ *
+ * Implementations of this class are required to be thread-safe.
+ *
+ * @param
+ * Note: This class has a natural ordering that is inconsistent with
+ * equals if distinct objects have the same identity hash code.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ int compareTo(PooledObject
+ * {@inheritDoc}
+ */
+ @Override
+ String toString();
+
+ /**
+ * Attempt to place the pooled object in the
+ * {@link PooledObjectState#EVICTION} state.
+ *
+ * @return
+ * By contract, when an {@link ObjectPool} delegates to a
+ * {@link PooledObjectFactory},
+ *
+ * While clients of a {@link KeyedObjectPool} borrow and return instances of
+ * the underlying value type {@code V}, the factory methods act on instances of
+ * {@link PooledObject PooledObject<V>}. These are the object wrappers that
+ * pools use to track and maintain state information about the objects that
+ * they manage.
+ *
+ * @param
+ * It is important for implementations of this method to be aware that there
+ * is no guarantee about what state
+ * Also, an implementation must take in to consideration that instances lost
+ * to the garbage collector may never be destroyed.
+ * Flag to remove abandoned objects if they exceed the
+ * removeAbandonedTimeout when borrowObject is invoked. The default value is false. If set to true, abandoned objects are removed by borrowObject if
+ * there are fewer than 2 idle objects available in the pool and
+ * Flag to remove abandoned objects if they exceed the
+ * removeAbandonedTimeout when borrowObject is invoked. Flag to remove abandoned objects if they exceed the
+ * removeAbandonedTimeout when pool maintenance (the "evictor")
+ * runs. The default value is false. If set to true, abandoned objects are removed by the pool
+ * maintenance thread when it runs. This setting has no effect
+ * unless maintenance is enabled by setting
+ *{@link GenericObjectPool#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis}
+ * to a positive number. Flag to remove abandoned objects if they exceed the
+ * removeAbandonedTimeout when pool maintenance runs. Timeout in seconds before an abandoned object can be removed. The time of most recent use of an object is the maximum (latest) of
+ * {@link TrackedUse#getLastUsed()} (if this class of the object implements
+ * TrackedUse) and the time when the object was borrowed from the pool. The default value is 300 seconds. Sets the timeout in seconds before an abandoned object can be
+ * removed Setting this property has no effect if
+ * {@link #getRemoveAbandonedOnBorrow() removeAbandonedOnBorrow} and
+ * {@link #getRemoveAbandonedOnMaintenance() removeAbandonedOnMaintenance}
+ * are both false. Perform Starts the evictor with the given delay. If there is an evictor
+ * running when this method is called, it is stopped and replaced with a
+ * new evictor with the specified delay. This method needs to be final, since it is called from a constructor.
+ * See POOL-195.
+ * This class is not thread-safe.
+ *
+ * @since 2.0
+ */
+public abstract class BaseObjectPoolConfig extends BaseObject implements Cloneable {
+
+ /**
+ * The default value for the {@code lifo} configuration attribute.
+ * @see GenericObjectPool#getLifo()
+ * @see GenericKeyedObjectPool#getLifo()
+ */
+ public static final boolean DEFAULT_LIFO = true;
+
+ /**
+ * The default value for the {@code fairness} configuration attribute.
+ * @see GenericObjectPool#getFairness()
+ * @see GenericKeyedObjectPool#getFairness()
+ */
+ public static final boolean DEFAULT_FAIRNESS = false;
+
+ /**
+ * The default value for the {@code maxWait} configuration attribute.
+ * @see GenericObjectPool#getMaxWaitMillis()
+ * @see GenericKeyedObjectPool#getMaxWaitMillis()
+ */
+ public static final long DEFAULT_MAX_WAIT_MILLIS = -1L;
+
+ /**
+ * The default value for the {@code minEvictableIdleTimeMillis}
+ * configuration attribute.
+ * @see GenericObjectPool#getMinEvictableIdleTimeMillis()
+ * @see GenericKeyedObjectPool#getMinEvictableIdleTimeMillis()
+ */
+ public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS =
+ 1000L * 60L * 30L;
+
+ /**
+ * The default value for the {@code softMinEvictableIdleTimeMillis}
+ * configuration attribute.
+ * @see GenericObjectPool#getSoftMinEvictableIdleTimeMillis()
+ * @see GenericKeyedObjectPool#getSoftMinEvictableIdleTimeMillis()
+ */
+ public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;
+
+ /**
+ * The default value for {@code evictorShutdownTimeoutMillis} configuration
+ * attribute.
+ * @see GenericObjectPool#getEvictorShutdownTimeoutMillis()
+ * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutMillis()
+ */
+ public static final long DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS =
+ 10L * 1000L;
+
+ /**
+ * The default value for the {@code numTestsPerEvictionRun} configuration
+ * attribute.
+ * @see GenericObjectPool#getNumTestsPerEvictionRun()
+ * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun()
+ */
+ public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;
+
+ /**
+ * The default value for the {@code testOnCreate} configuration attribute.
+ * @see GenericObjectPool#getTestOnCreate()
+ * @see GenericKeyedObjectPool#getTestOnCreate()
+ *
+ * @since 2.2
+ */
+ public static final boolean DEFAULT_TEST_ON_CREATE = false;
+
+ /**
+ * The default value for the {@code testOnBorrow} configuration attribute.
+ * @see GenericObjectPool#getTestOnBorrow()
+ * @see GenericKeyedObjectPool#getTestOnBorrow()
+ */
+ public static final boolean DEFAULT_TEST_ON_BORROW = false;
+
+ /**
+ * The default value for the {@code testOnReturn} configuration attribute.
+ * @see GenericObjectPool#getTestOnReturn()
+ * @see GenericKeyedObjectPool#getTestOnReturn()
+ */
+ public static final boolean DEFAULT_TEST_ON_RETURN = false;
+
+ /**
+ * The default value for the {@code testWhileIdle} configuration attribute.
+ * @see GenericObjectPool#getTestWhileIdle()
+ * @see GenericKeyedObjectPool#getTestWhileIdle()
+ */
+ public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
+
+ /**
+ * The default value for the {@code timeBetweenEvictionRunsMillis}
+ * configuration attribute.
+ * @see GenericObjectPool#getTimeBetweenEvictionRunsMillis()
+ * @see GenericKeyedObjectPool#getTimeBetweenEvictionRunsMillis()
+ */
+ public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
+
+ /**
+ * The default value for the {@code blockWhenExhausted} configuration
+ * attribute.
+ * @see GenericObjectPool#getBlockWhenExhausted()
+ * @see GenericKeyedObjectPool#getBlockWhenExhausted()
+ */
+ public static final boolean DEFAULT_BLOCK_WHEN_EXHAUSTED = true;
+
+ /**
+ * The default value for enabling JMX for pools created with a configuration
+ * instance.
+ */
+ public static final boolean DEFAULT_JMX_ENABLE = true;
+
+ /**
+ * The default value for the prefix used to name JMX enabled pools created
+ * with a configuration instance.
+ * @see GenericObjectPool#getJmxName()
+ * @see GenericKeyedObjectPool#getJmxName()
+ */
+ public static final String DEFAULT_JMX_NAME_PREFIX = "pool";
+
+ /**
+ * The default value for the base name to use to name JMX enabled pools
+ * created with a configuration instance. The default is
+ * This class is intended to be thread-safe.
+ *
+ * @param
+ * This class is immutable and thread-safe.
+ *
+ * @since 2.0
+ */
+public class EvictionConfig {
+
+ private final long idleEvictTime;
+ private final long idleSoftEvictTime;
+ private final int minIdle;
+
+ /**
+ * Create a new eviction configuration with the specified parameters.
+ * Instances are immutable.
+ *
+ * @param poolIdleEvictTime Expected to be provided by
+ * {@link BaseGenericObjectPool#getMinEvictableIdleTimeMillis()}
+ * @param poolIdleSoftEvictTime Expected to be provided by
+ * {@link BaseGenericObjectPool#getSoftMinEvictableIdleTimeMillis()}
+ * @param minIdle Expected to be provided by
+ * {@link GenericObjectPool#getMinIdle()} or
+ * {@link GenericKeyedObjectPool#getMinIdlePerKey()}
+ */
+ public EvictionConfig(final long poolIdleEvictTime, final long poolIdleSoftEvictTime,
+ final int minIdle) {
+ if (poolIdleEvictTime > 0) {
+ idleEvictTime = poolIdleEvictTime;
+ } else {
+ idleEvictTime = Long.MAX_VALUE;
+ }
+ if (poolIdleSoftEvictTime > 0) {
+ idleSoftEvictTime = poolIdleSoftEvictTime;
+ } else {
+ idleSoftEvictTime = Long.MAX_VALUE;
+ }
+ this.minIdle = minIdle;
+ }
+
+ /**
+ * Obtain the {@code idleEvictTime} for this eviction configuration
+ * instance.
+ *
+ * How the evictor behaves based on this value will be determined by the
+ * configured {@link EvictionPolicy}.
+ *
+ * @return The {@code idleEvictTime} in milliseconds
+ */
+ public long getIdleEvictTime() {
+ return idleEvictTime;
+ }
+
+ /**
+ * Obtain the {@code idleSoftEvictTime} for this eviction configuration
+ * instance.
+ *
+ * How the evictor behaves based on this value will be determined by the
+ * configured {@link EvictionPolicy}.
+ *
+ * @return The (@code idleSoftEvictTime} in milliseconds
+ */
+ public long getIdleSoftEvictTime() {
+ return idleSoftEvictTime;
+ }
+
+ /**
+ * Obtain the {@code minIdle} for this eviction configuration instance.
+ *
+ * How the evictor behaves based on this value will be determined by the
+ * configured {@link EvictionPolicy}.
+ *
+ * @return The {@code minIdle}
+ */
+ public int getMinIdle() {
+ return minIdle;
+ }
+
+ /**
+ * @since 2.4
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("EvictionConfig [idleEvictTime=");
+ builder.append(idleEvictTime);
+ builder.append(", idleSoftEvictTime=");
+ builder.append(idleSoftEvictTime);
+ builder.append(", minIdle=");
+ builder.append(minIdle);
+ builder.append("]");
+ return builder.toString();
+ }
+}
diff --git a/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/EvictionPolicy.java b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/EvictionPolicy.java
new file mode 100755
index 000000000..4914f62f6
--- /dev/null
+++ b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/EvictionPolicy.java
@@ -0,0 +1,45 @@
+/*
+ * 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 com.fr.third.org.apache.commons.pool2.impl;
+
+import com.fr.third.org.apache.commons.pool2.PooledObject;
+
+/**
+ * To provide a custom eviction policy (i.e. something other than {@link
+ * DefaultEvictionPolicy} for a pool, users must provide an implementation of
+ * this interface that provides the required eviction policy.
+ *
+ * @param
+ * This class has package scope to prevent its inclusion in the pool public API.
+ * The class declaration below should *not* be changed to public.
+ *
+ * This class is intended to be thread-safe.
+ *
+ * @since 2.0
+ */
+class EvictionTimer {
+
+ /** Executor instance */
+ private static ScheduledThreadPoolExecutor executor; //@GuardedBy("EvictionTimer.class")
+
+ /** Static usage count tracker */
+ private static int usageCount; //@GuardedBy("EvictionTimer.class")
+
+ /** Prevent instantiation */
+ private EvictionTimer() {
+ // Hide the default constructor
+ }
+
+
+ /**
+ * @since 2.4.3
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("EvictionTimer []");
+ return builder.toString();
+ }
+
+
+ /**
+ * Add the specified eviction task to the timer. Tasks that are added with a
+ * call to this method *must* call {@link #cancel(TimerTask)} to cancel the
+ * task to prevent memory and/or thread leaks in application server
+ * environments.
+ * @param task Task to be scheduled
+ * @param delay Delay in milliseconds before task is executed
+ * @param period Time in milliseconds between executions
+ */
+ static synchronized void schedule(final Runnable task, final long delay, final long period) {
+ if (null == executor) {
+ executor = new ScheduledThreadPoolExecutor(1, new EvictorThreadFactory());
+ }
+ usageCount++;
+ executor.scheduleWithFixedDelay(task, delay, period, TimeUnit.MILLISECONDS);
+ }
+
+ /**
+ * Remove the specified eviction task from the timer.
+ *
+ * @param task Task to be cancelled
+ * @param timeout If the associated executor is no longer required, how
+ * long should this thread wait for the executor to
+ * terminate?
+ * @param unit The units for the specified timeout
+ */
+ static synchronized void cancel(final TimerTask task, final long timeout, final TimeUnit unit) {
+ task.cancel();
+ usageCount--;
+ if (usageCount == 0) {
+ executor.shutdown();
+ try {
+ executor.awaitTermination(timeout, unit);
+ } catch (final InterruptedException e) {
+ // Swallow
+ // Significant API changes would be required to propagate this
+ }
+ executor.setCorePoolSize(0);
+ executor = null;
+ }
+ }
+
+ /**
+ * Thread factory that creates a thread, with the context classloader from this class.
+ */
+ private static class EvictorThreadFactory implements ThreadFactory {
+
+ @Override
+ public Thread newThread(final Runnable r) {
+ final Thread t = new Thread(null, r, "commons-pool-evictor-thread");
+
+ AccessController.doPrivileged(new PrivilegedAction
+ * When coupled with the appropriate {@link KeyedPooledObjectFactory},
+ *
+ * Note that the current implementation uses a ConcurrentHashMap which uses
+ * equals() to compare keys.
+ * This means that distinct instance keys must be distinguishable using equals.
+ *
+ * Optionally, one may configure the pool to examine and possibly evict objects
+ * as they sit idle in the pool and to ensure that a minimum number of idle
+ * objects is maintained for each key. This is performed by an "idle object
+ * eviction" thread, which runs asynchronously. Caution should be used when
+ * configuring this optional feature. Eviction runs contend with client threads
+ * for access to objects in the pool, so if they run too frequently performance
+ * issues may result.
+ *
+ * Implementation note: To prevent possible deadlocks, care has been taken to
+ * ensure that no call to a factory method will occur within a synchronization
+ * block. See POOL-125 and DBCP-44 for more information.
+ *
+ * This class is intended to be thread-safe.
+ *
+ * @see GenericObjectPool
+ *
+ * @param
+ * If the configured value of minIdlePerKey is greater than the configured
+ * value for maxIdlePerKey then the value of maxIdlePerKey will be used
+ * instead.
+ *
+ * @param minIdlePerKey The minimum size of the each keyed pool
+ *
+ * @see #getMinIdlePerKey
+ * @see #getMaxIdlePerKey()
+ * @see #setTimeBetweenEvictionRunsMillis
+ */
+ public void setMinIdlePerKey(final int minIdlePerKey) {
+ this.minIdlePerKey = minIdlePerKey;
+ }
+
+ /**
+ * Returns the target for the minimum number of idle objects to maintain in
+ * each of the keyed sub-pools. This setting only has an effect if it is
+ * positive and {@link #getTimeBetweenEvictionRunsMillis()} is greater than
+ * zero. If this is the case, an attempt is made to ensure that each
+ * sub-pool has the required minimum number of instances during idle object
+ * eviction runs.
+ *
+ * If the configured value of minIdlePerKey is greater than the configured
+ * value for maxIdlePerKey then the value of maxIdlePerKey will be used
+ * instead.
+ *
+ * @return minimum size of the each keyed pool
+ *
+ * @see #setTimeBetweenEvictionRunsMillis
+ */
+ @Override
+ public int getMinIdlePerKey() {
+ final int maxIdlePerKeySave = getMaxIdlePerKey();
+ if (this.minIdlePerKey > maxIdlePerKeySave) {
+ return maxIdlePerKeySave;
+ }
+ return minIdlePerKey;
+ }
+
+ /**
+ * Sets the configuration.
+ *
+ * @param conf the new configuration to use. This is used by value.
+ *
+ * @see GenericKeyedObjectPoolConfig
+ */
+ public void setConfig(final GenericKeyedObjectPoolConfig conf) {
+ setLifo(conf.getLifo());
+ setMaxIdlePerKey(conf.getMaxIdlePerKey());
+ setMaxTotalPerKey(conf.getMaxTotalPerKey());
+ setMaxTotal(conf.getMaxTotal());
+ setMinIdlePerKey(conf.getMinIdlePerKey());
+ setMaxWaitMillis(conf.getMaxWaitMillis());
+ setBlockWhenExhausted(conf.getBlockWhenExhausted());
+ setTestOnCreate(conf.getTestOnCreate());
+ setTestOnBorrow(conf.getTestOnBorrow());
+ setTestOnReturn(conf.getTestOnReturn());
+ setTestWhileIdle(conf.getTestWhileIdle());
+ setNumTestsPerEvictionRun(conf.getNumTestsPerEvictionRun());
+ setMinEvictableIdleTimeMillis(conf.getMinEvictableIdleTimeMillis());
+ setSoftMinEvictableIdleTimeMillis(
+ conf.getSoftMinEvictableIdleTimeMillis());
+ setTimeBetweenEvictionRunsMillis(
+ conf.getTimeBetweenEvictionRunsMillis());
+ setEvictionPolicyClassName(conf.getEvictionPolicyClassName());
+ setEvictorShutdownTimeoutMillis(conf.getEvictorShutdownTimeoutMillis());
+ }
+
+ /**
+ * Obtain a reference to the factory used to create, destroy and validate
+ * the objects used by this pool.
+ *
+ * @return the factory
+ */
+ public KeyedPooledObjectFactory
+ * {@inheritDoc}
+ */
+ @Override
+ public T borrowObject(final K key) throws Exception {
+ return borrowObject(key, getMaxWaitMillis());
+ }
+
+ /**
+ * Borrows an object from the sub-pool associated with the given key using
+ * the specified waiting time which only applies if
+ * {@link #getBlockWhenExhausted()} is true.
+ *
+ * If there is one or more idle instances available in the sub-pool
+ * associated with the given key, then an idle instance will be selected
+ * based on the value of {@link #getLifo()}, activated and returned. If
+ * activation fails, or {@link #getTestOnBorrow() testOnBorrow} is set to
+ *
+ * If there are no idle instances available in the sub-pool associated with
+ * the given key, behavior depends on the {@link #getMaxTotalPerKey()
+ * maxTotalPerKey}, {@link #getMaxTotal() maxTotal}, and (if applicable)
+ * {@link #getBlockWhenExhausted()} and the value passed in to the
+ *
+ * If the associated sub-pool is exhausted (no available idle instances and
+ * no capacity to create new ones), this method will either block
+ * ({@link #getBlockWhenExhausted()} is true) or throw a
+ *
+ * When
+ * When the pool is exhausted, multiple calling threads may be
+ * simultaneously blocked waiting for instances to become available. A
+ * "fairness" algorithm has been implemented to ensure that threads receive
+ * available instances in request arrival order.
+ *
+ * @param key pool key
+ * @param borrowMaxWaitMillis The time to wait in milliseconds for an object
+ * to become available
+ *
+ * @return object instance from the keyed pool
+ *
+ * @throws NoSuchElementException if a keyed object instance cannot be
+ * returned because the pool is exhausted.
+ *
+ * @throws Exception if a keyed object instance cannot be returned due to an
+ * error
+ */
+ public T borrowObject(final K key, final long borrowMaxWaitMillis) throws Exception {
+ assertOpen();
+
+ PooledObject
+ * If {@link #getMaxIdlePerKey() maxIdle} is set to a positive value and the
+ * number of idle instances under the given key has reached this value, the
+ * returning instance is destroyed.
+ *
+ * If {@link #getTestOnReturn() testOnReturn} == true, the returning
+ * instance is validated before being returned to the idle instance sub-pool
+ * under the given key. In this case, if validation fails, the instance is
+ * destroyed.
+ *
+ * Exceptions encountered destroying objects for any reason are swallowed
+ * but notified via a {@link SwallowedExceptionListener}.
+ *
+ * @param key pool key
+ * @param obj instance to return to the keyed pool
+ *
+ * @throws IllegalStateException if an object is returned to the pool that
+ * was not borrowed from it or if an object is
+ * returned to the pool multiple times
+ */
+ @Override
+ public void returnObject(final K key, final T obj) {
+
+ final ObjectDequetrue
in the default implementation
+ */
+ @Override
+ public boolean validateObject(final K key, final PooledObjectisClosed
and
+ * assertOpen
.
+ */
+ @Override
+ public void close() {
+ closed = true;
+ }
+
+ /**
+ * Has this pool instance been closed.
+ *
+ * @return true
when this pool has been closed.
+ */
+ public final boolean isClosed() {
+ return closed;
+ }
+
+ /**
+ * Throws an IllegalStateException
when this pool has been
+ * closed.
+ *
+ * @throws IllegalStateException when this pool has been closed.
+ *
+ * @see #isClosed()
+ */
+ protected final void assertOpen() throws IllegalStateException {
+ if (isClosed()) {
+ throw new IllegalStateException("Pool not open");
+ }
+ }
+
+ private volatile boolean closed = false;
+
+ @Override
+ protected void toStringAppendFields(final StringBuilder builder) {
+ builder.append("closed=");
+ builder.append(closed);
+ }
+}
diff --git a/fine-jedis/src/com/fr/third/org/apache/commons/pool2/BasePooledObjectFactory.java b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/BasePooledObjectFactory.java
new file mode 100755
index 000000000..ac0dae5fe
--- /dev/null
+++ b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/BasePooledObjectFactory.java
@@ -0,0 +1,104 @@
+/*
+ * 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 com.fr.third.org.apache.commons.pool2;
+
+/**
+ * A base implementation of PoolableObjectFactory
.
+ * Object obj =
+ * null
;
+ * Object key = "Key"
;
+ *
+ * try
{
+ * obj = pool.borrowObject(key);
+ * //...use the object...
+ * } catch
(Exception e) {
+ * // invalidate the object
+ * pool.invalidateObject(key, obj);
+ * // do not return the object to the pool twice
+ * obj = null
;
+ * } finally
{
+ * // make sure the object is returned to the pool
+ * if
(null
!= obj) {
+ * pool.returnObject(key, obj);
+ * }
+ * }key
.
+ * key
+ * that is {@link Object#equals equivalent} to the one used to borrow the
+ * instance in the first place.
+ * obj
+ * must have been obtained using
+ * {@link #borrowObject borrowObject} or a related method as defined in an
+ * implementation or sub-interface using a key
that is
+ * equivalent to the one used to borrow the instance in the first place.
+ *
+ * @param key the key used to obtain the object
+ * @param obj a {@link #borrowObject borrowed} instance to be returned.
+ *
+ * @throws IllegalStateException
+ * if an attempt is made to return an object to the pool that
+ * is in any state other than allocated (i.e. borrowed).
+ * Attempting to return an object more than once or attempting
+ * to return an object that was never borrowed from the pool
+ * will trigger this exception.
+ *
+ * @throws Exception if an instance cannot be returned to the pool
+ */
+ void returnObject(K key, V obj) throws Exception;
+
+ /**
+ * Invalidates an object from the pool.
+ * obj
must have been obtained
+ * using {@link #borrowObject borrowObject} or a related method as defined
+ * in an implementation or sub-interface using a key
that is
+ * equivalent to the one used to borrow the Object
in the first
+ * place.
+ * addObject
is useful for
+ * "pre-loading" a pool with idle objects (Optional operation).
+ *
+ * @param key the key a new instance should be added to
+ *
+ * @throws Exception
+ * when {@link KeyedPooledObjectFactory#makeObject} fails.
+ * @throws IllegalStateException
+ * after {@link #close} has been called on this pool.
+ * @throws UnsupportedOperationException
+ * when this pool cannot add new idle objects.
+ */
+ void addObject(K key) throws Exception, IllegalStateException,
+ UnsupportedOperationException;
+
+ /**
+ * Returns the number of instances corresponding to the given
+ * key
currently idle in this pool. Returns a negative value if
+ * this information is not available.
+ *
+ * @param key the key to query
+ * @return the number of instances corresponding to the given
+ * key
currently idle in this pool.
+ */
+ int getNumIdle(K key);
+
+ /**
+ * Returns the number of instances currently borrowed from but not yet
+ * returned to the pool corresponding to the given key
.
+ * Returns a negative value if this information is not available.
+ *
+ * @param key the key to query
+ * @return the number of instances currently borrowed from but not yet
+ * returned to the pool corresponding to the given key
.
+= */
+ int getNumActive(K key);
+
+ /**
+ * Returns the total number of instances currently idle in this pool.
+ * Returns a negative value if this information is not available.
+ * @return the total number of instances currently idle in this pool.
+ = */
+ int getNumIdle();
+
+ /**
+ * Returns the total number of instances current borrowed from this pool but
+ * not yet returned. Returns a negative value if this information is not
+ * available.
+ * @return the total number of instances current borrowed from this pool but
+ * not yet returned.
+ */
+ int getNumActive();
+
+ /**
+ * Clears the pool, removing all pooled instances (optional operation).
+ *
+ * @throws UnsupportedOperationException when this implementation doesn't
+ * support the operation
+ *
+ * @throws Exception if the pool cannot be cleared
+ */
+ void clear() throws Exception, UnsupportedOperationException;
+
+ /**
+ * Clears the specified pool, removing all pooled instances corresponding to
+ * the given key
(optional operation).
+ *
+ * @param key the key to clear
+ *
+ * @throws UnsupportedOperationException when this implementation doesn't
+ * support the operation
+ *
+ * @throws Exception if the key cannot be cleared
+ */
+ void clear(K key) throws Exception, UnsupportedOperationException;
+
+ /**
+ * Close this pool, and free any resources associated with it.
+ *
+ *
+ * {@link KeyedPooledObjectFactory} must be thread-safe. The only promise
+ * an {@link KeyedObjectPool} makes is that the same instance of an object will
+ * not be passed to more than one method of a
+ * validateObject
may also be used to test an
+ * instance being {@link KeyedObjectPool#returnObject returned} to the pool
+ * before it is {@link #passivateObject passivated}. It will only be invoked
+ * on an activated instance.
+ * validateObject
,
+ * or for reasons specific to the pool implementation.) There is no
+ * guarantee that the instance being destroyed will
+ * be considered active, passive or in a generally consistent state.
+ * KeyedPoolableObjectFactory
at a time.
+ * obj
will be in and the
+ * implementation should be prepared to handle unexpected errors.
+ * false
if obj
is not valid and should
+ * be dropped from the pool, true
otherwise.
+ */
+ boolean validateObject(K key, PooledObjectobj
,
+ * this exception may be swallowed by the pool.
+ *
+ * @see #destroyObject
+ */
+ void activateObject(K key, PooledObjectobj
,
+ * this exception may be swallowed by the pool.
+ *
+ * @see #destroyObject
+ */
+ void passivateObject(K key, PooledObject Object obj =
+ * null
;
+ *
+ * try
{
+ * obj = pool.borrowObject();
+ * try
{
+ * //...use the object...
+ * } catch
(Exception e) {
+ * // invalidate the object
+ * pool.invalidateObject(obj);
+ * // do not return the object to the pool twice
+ * obj = null
;
+ * } finally
{
+ * // make sure the object is returned to the pool
+ * if
(null
!= obj) {
+ * pool.returnObject(obj);
+ * }
+ * }
+ * } catch
(Exception e) {
+ * // failed to borrow an object
+ * }obj
+ * must have been obtained using {@link #borrowObject()} or
+ * a related method as defined in an implementation or sub-interface.
+ *
+ * @param obj a {@link #borrowObject borrowed} instance to be returned.
+ *
+ * @throws IllegalStateException
+ * if an attempt is made to return an object to the pool that
+ * is in any state other than allocated (i.e. borrowed).
+ * Attempting to return an object more than once or attempting
+ * to return an object that was never borrowed from the pool
+ * will trigger this exception.
+ *
+ * @throws Exception if an instance cannot be returned to the pool
+ */
+ void returnObject(T obj) throws Exception;
+
+ /**
+ * Invalidates an object from the pool.
+ * obj
must have been obtained
+ * using {@link #borrowObject} or a related method as defined in an
+ * implementation or sub-interface.
+ * addObject
is useful for "pre-loading"
+ * a pool with idle objects. (Optional operation).
+ *
+ * @throws Exception
+ * when {@link PooledObjectFactory#makeObject} fails.
+ * @throws IllegalStateException
+ * after {@link #close} has been called on this pool.
+ * @throws UnsupportedOperationException
+ * when this pool cannot add new idle objects.
+ */
+ void addObject() throws Exception, IllegalStateException,
+ UnsupportedOperationException;
+
+ /**
+ * Return the number of instances currently idle in this pool. This may be
+ * considered an approximation of the number of objects that can be
+ * {@link #borrowObject borrowed} without creating any new instances.
+ * Returns a negative value if this information is not available.
+ * @return the number of instances currently idle in this pool.
+ */
+ int getNumIdle();
+
+ /**
+ * Return the number of instances currently borrowed from this pool. Returns
+ * a negative value if this information is not available.
+ * @return the number of instances currently borrowed from this pool.
+ */
+ int getNumActive();
+
+ /**
+ * Clears any objects sitting idle in the pool, releasing any associated
+ * resources (optional operation). Idle objects cleared must be
+ * {@link PooledObjectFactory#destroyObject(PooledObject)}.
+ *
+ * @throws UnsupportedOperationException
+ * if this implementation does not support the operation
+ *
+ * @throws Exception if the pool cannot be cleared
+ */
+ void clear() throws Exception, UnsupportedOperationException;
+
+ /**
+ * Close this pool, and free any resources associated with it.
+ * pool
is null
or when
+ * minIdle
is negative or when period
+ * isn't valid for {@link Timer#schedule(TimerTask, long, long)}
+ */
+ public static keyedPool
, key
is
+ * null
or when minIdle
is negative or
+ * when period
isn't valid for
+ * {@link Timer#schedule(TimerTask, long, long)}.
+ */
+ public static Collection
keys
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 keyedPool
, keys
, or any of the
+ * values in the collection is null
or when
+ * minIdle
is negative or when period
+ * isn't valid for {@link Timer#schedule(TimerTask, long, long)}
+ * .
+ * @see #checkMinIdle(KeyedObjectPool, Object, int, long)
+ */
+ public static addObject()
on pool
count
+ * number of times.
+ *
+ * @param pool
+ * the pool to prefill.
+ * @param count
+ * the number of idle objects to add.
+ * @param pool
is null
.
+ */
+ public static addObject(Object)
on keyedPool
with
+ * key
count
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 key
.
+ * @param keyedPool
or key
is
+ * null
.
+ */
+ public static addObject(Object)
on keyedPool
with each
+ * key in keys
for count
number of times. This has
+ * the same effect as calling {@link #prefill(KeyedObjectPool, Object, int)}
+ * for each key in the keys
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 key
.
+ * @param keyedPool
, keys
, or any value
+ * in keys
is null
.
+ * @see #prefill(KeyedObjectPool, Object, int)
+ */
+ public static Timer
for checking keyedPool's idle count.
+ *
+ * @return the {@link Timer} for checking keyedPool's idle count.
+ */
+ private static Timer getMinIdleTimer() {
+ return TimerHolder.MIN_IDLE_TIMER;
+ }
+
+ /**
+ * 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 true
if the object was placed in the
+ * {@link PooledObjectState#EVICTION} state otherwise
+ * false
+ */
+ boolean startEvictionTest();
+
+ /**
+ * Called to inform the object that the eviction test has ended.
+ *
+ * @param idleQueue The queue of idle objects to which the object should be
+ * returned
+ *
+ * @return Currently not used
+ */
+ boolean endEvictionTest(Deque
+ *
+ * {@link PooledObjectFactory} must be thread-safe. The only promise
+ * an {@link ObjectPool} makes is that the same instance of an object will not
+ * be passed to more than one method of a PoolableObjectFactory
+ * at a time.
+ * obj
will be in and the
+ * implementation should be prepared to handle unexpected errors.
+ * false
if obj
is not valid and should
+ * be dropped from the pool, true
otherwise.
+ */
+ boolean validateObject(PooledObjectobj
,
+ * this exception may be swallowed by the pool.
+ *
+ * @see #destroyObject
+ */
+ void activateObject(PooledObjectobj
,
+ * this exception may be swallowed by the pool.
+ *
+ * @see #destroyObject
+ */
+ void passivateObject(PooledObjectgetNumActive() > getMaxTotal() - 3
true
if usage tracking is enabled
+ */
+ public boolean getUseUsageTracking() {
+ return useUsageTracking;
+ }
+
+ /**
+ * If the pool implements {@link UsageTracking}, configure whether the pool
+ * should record a stack trace every time a method is called on a pooled
+ * object and retain the most recent stack trace to aid debugging of
+ * abandoned objects.
+ *
+ * @param useUsageTracking A value of true
will enable
+ * the recording of a stack trace on every use
+ * of a pooled object
+ */
+ public void setUseUsageTracking(final boolean useUsageTracking) {
+ this.useUsageTracking = useUsageTracking;
+ }
+
+ /**
+ * @since 2.4.3
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("AbandonedConfig [removeAbandonedOnBorrow=");
+ builder.append(removeAbandonedOnBorrow);
+ builder.append(", removeAbandonedOnMaintenance=");
+ builder.append(removeAbandonedOnMaintenance);
+ builder.append(", removeAbandonedTimeout=");
+ builder.append(removeAbandonedTimeout);
+ builder.append(", logAbandoned=");
+ builder.append(logAbandoned);
+ builder.append(", logWriter=");
+ builder.append(logWriter);
+ builder.append(", useUsageTracking=");
+ builder.append(useUsageTracking);
+ builder.append("]");
+ return builder.toString();
+ }
+}
diff --git a/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/BaseGenericObjectPool.java b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
new file mode 100755
index 000000000..1f602a228
--- /dev/null
+++ b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
@@ -0,0 +1,1339 @@
+/*
+ * 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 com.fr.third.org.apache.commons.pool2.impl;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.lang.management.ManagementFactory;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.TimerTask;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+
+import com.fr.third.org.apache.commons.pool2.BaseObject;
+import com.fr.third.org.apache.commons.pool2.PooledObject;
+import com.fr.third.org.apache.commons.pool2.SwallowedExceptionListener;
+
+/**
+ * Base class that provides common functionality for {@link GenericObjectPool}
+ * and {@link GenericKeyedObjectPool}. The primary reason this class exists is
+ * reduce code duplication between the two pool implementations.
+ *
+ * @param borrowObject()
method is
+ * invoked when the pool is exhausted (the maximum number of "active"
+ * objects has been reached).
+ *
+ * @return true
if borrowObject()
should block
+ * when the pool is exhausted
+ *
+ * @see #setBlockWhenExhausted
+ */
+ public final boolean getBlockWhenExhausted() {
+ return blockWhenExhausted;
+ }
+
+ /**
+ * Sets whether to block when the borrowObject()
method is
+ * invoked when the pool is exhausted (the maximum number of "active"
+ * objects has been reached).
+ *
+ * @param blockWhenExhausted true
if
+ * borrowObject()
should block
+ * when the pool is exhausted
+ *
+ * @see #getBlockWhenExhausted
+ */
+ public final void setBlockWhenExhausted(final boolean blockWhenExhausted) {
+ this.blockWhenExhausted = blockWhenExhausted;
+ }
+
+ /**
+ * Returns the maximum amount of time (in milliseconds) the
+ * borrowObject()
method should block before throwing an
+ * exception when the pool is exhausted and
+ * {@link #getBlockWhenExhausted} is true. When less than 0, the
+ * borrowObject()
method may block indefinitely.
+ *
+ * @return the maximum number of milliseconds borrowObject()
+ * will block.
+ *
+ * @see #setMaxWaitMillis
+ * @see #setBlockWhenExhausted
+ */
+ public final long getMaxWaitMillis() {
+ return maxWaitMillis;
+ }
+
+ /**
+ * Sets the maximum amount of time (in milliseconds) the
+ * borrowObject()
method should block before throwing an
+ * exception when the pool is exhausted and
+ * {@link #getBlockWhenExhausted} is true. When less than 0, the
+ * borrowObject()
method may block indefinitely.
+ *
+ * @param maxWaitMillis the maximum number of milliseconds
+ * borrowObject()
will block or negative
+ * for indefinitely.
+ *
+ * @see #getMaxWaitMillis
+ * @see #setBlockWhenExhausted
+ */
+ public final void setMaxWaitMillis(final long maxWaitMillis) {
+ this.maxWaitMillis = maxWaitMillis;
+ }
+
+ /**
+ * Returns whether the pool has LIFO (last in, first out) behaviour with
+ * respect to idle objects - always returning the most recently used object
+ * from the pool, or as a FIFO (first in, first out) queue, where the pool
+ * always returns the oldest object in the idle object pool.
+ *
+ * @return true
if the pool is configured with LIFO behaviour
+ * or false
if the pool is configured with FIFO
+ * behaviour
+ *
+ * @see #setLifo
+ */
+ public final boolean getLifo() {
+ return lifo;
+ }
+
+ /**
+ * Returns whether or not the pool serves threads waiting to borrow objects fairly.
+ * True means that waiting threads are served as if waiting in a FIFO queue.
+ *
+ * @return true
if waiting threads are to be served
+ * by the pool in arrival order
+ */
+ public final boolean getFairness() {
+ return fairness;
+ }
+
+ /**
+ * Sets whether the pool has LIFO (last in, first out) behaviour with
+ * respect to idle objects - always returning the most recently used object
+ * from the pool, or as a FIFO (first in, first out) queue, where the pool
+ * always returns the oldest object in the idle object pool.
+ *
+ * @param lifo true
if the pool is to be configured with LIFO
+ * behaviour or false
if the pool is to be
+ * configured with FIFO behaviour
+ *
+ * @see #getLifo()
+ */
+ public final void setLifo(final boolean lifo) {
+ this.lifo = lifo;
+ }
+
+ /**
+ * Returns whether objects created for the pool will be validated before
+ * being returned from the borrowObject()
method. Validation is
+ * performed by the validateObject()
method of the factory
+ * associated with the pool. If the object fails to validate, then
+ * borrowObject()
will fail.
+ *
+ * @return true
if newly created objects are validated before
+ * being returned from the borrowObject()
method
+ *
+ * @see #setTestOnCreate
+ *
+ * @since 2.2
+ */
+ public final boolean getTestOnCreate() {
+ return testOnCreate;
+ }
+
+ /**
+ * Sets whether objects created for the pool will be validated before
+ * being returned from the borrowObject()
method. Validation is
+ * performed by the validateObject()
method of the factory
+ * associated with the pool. If the object fails to validate, then
+ * borrowObject()
will fail.
+ *
+ * @param testOnCreate true
if newly created objects should be
+ * validated before being returned from the
+ * borrowObject()
method
+ *
+ * @see #getTestOnCreate
+ *
+ * @since 2.2
+ */
+ public final void setTestOnCreate(final boolean testOnCreate) {
+ this.testOnCreate = testOnCreate;
+ }
+
+ /**
+ * Returns whether objects borrowed from the pool will be validated before
+ * being returned from the borrowObject()
method. Validation is
+ * performed by the validateObject()
method of the factory
+ * associated with the pool. If the object fails to validate, it will be
+ * removed from the pool and destroyed, and a new attempt will be made to
+ * borrow an object from the pool.
+ *
+ * @return true
if objects are validated before being returned
+ * from the borrowObject()
method
+ *
+ * @see #setTestOnBorrow
+ */
+ public final boolean getTestOnBorrow() {
+ return testOnBorrow;
+ }
+
+ /**
+ * Sets whether objects borrowed from the pool will be validated before
+ * being returned from the borrowObject()
method. Validation is
+ * performed by the validateObject()
method of the factory
+ * associated with the pool. If the object fails to validate, it will be
+ * removed from the pool and destroyed, and a new attempt will be made to
+ * borrow an object from the pool.
+ *
+ * @param testOnBorrow true
if objects should be validated
+ * before being returned from the
+ * borrowObject()
method
+ *
+ * @see #getTestOnBorrow
+ */
+ public final void setTestOnBorrow(final boolean testOnBorrow) {
+ this.testOnBorrow = testOnBorrow;
+ }
+
+ /**
+ * Returns whether objects borrowed from the pool will be validated when
+ * they are returned to the pool via the returnObject()
method.
+ * Validation is performed by the validateObject()
method of
+ * the factory associated with the pool. Returning objects that fail validation
+ * are destroyed rather then being returned the pool.
+ *
+ * @return true
if objects are validated on return to
+ * the pool via the returnObject()
method
+ *
+ * @see #setTestOnReturn
+ */
+ public final boolean getTestOnReturn() {
+ return testOnReturn;
+ }
+
+ /**
+ * Sets whether objects borrowed from the pool will be validated when
+ * they are returned to the pool via the returnObject()
method.
+ * Validation is performed by the validateObject()
method of
+ * the factory associated with the pool. Returning objects that fail validation
+ * are destroyed rather then being returned the pool.
+ *
+ * @param testOnReturn true
if objects are validated on
+ * return to the pool via the
+ * returnObject()
method
+ *
+ * @see #getTestOnReturn
+ */
+ public final void setTestOnReturn(final boolean testOnReturn) {
+ this.testOnReturn = testOnReturn;
+ }
+
+ /**
+ * Returns whether objects sitting idle in the pool will be validated by the
+ * idle object evictor (if any - see
+ * {@link #setTimeBetweenEvictionRunsMillis(long)}). Validation is performed
+ * by the validateObject()
method of the factory associated
+ * with the pool. If the object fails to validate, it will be removed from
+ * the pool and destroyed.
+ *
+ * @return true
if objects will be validated by the evictor
+ *
+ * @see #setTestWhileIdle
+ * @see #setTimeBetweenEvictionRunsMillis
+ */
+ public final boolean getTestWhileIdle() {
+ return testWhileIdle;
+ }
+
+ /**
+ * Returns whether objects sitting idle in the pool will be validated by the
+ * idle object evictor (if any - see
+ * {@link #setTimeBetweenEvictionRunsMillis(long)}). Validation is performed
+ * by the validateObject()
method of the factory associated
+ * with the pool. If the object fails to validate, it will be removed from
+ * the pool and destroyed. Note that setting this property has no effect
+ * unless the idle object evictor is enabled by setting
+ * timeBetweenEvictionRunsMillis
to a positive value.
+ *
+ * @param testWhileIdle
+ * true
so objects will be validated by the evictor
+ *
+ * @see #getTestWhileIdle
+ * @see #setTimeBetweenEvictionRunsMillis
+ */
+ public final void setTestWhileIdle(final boolean testWhileIdle) {
+ this.testWhileIdle = testWhileIdle;
+ }
+
+ /**
+ * Returns the number of milliseconds to sleep between runs of the idle
+ * object evictor thread. When non-positive, no idle object evictor thread
+ * will be run.
+ *
+ * @return number of milliseconds to sleep between evictor runs
+ *
+ * @see #setTimeBetweenEvictionRunsMillis
+ */
+ public final long getTimeBetweenEvictionRunsMillis() {
+ return timeBetweenEvictionRunsMillis;
+ }
+
+ /**
+ * Sets the number of milliseconds to sleep between runs of the idle
+ * object evictor thread. When non-positive, no idle object evictor thread
+ * will be run.
+ *
+ * @param timeBetweenEvictionRunsMillis
+ * number of milliseconds to sleep between evictor runs
+ *
+ * @see #getTimeBetweenEvictionRunsMillis
+ */
+ public final void setTimeBetweenEvictionRunsMillis(
+ final long timeBetweenEvictionRunsMillis) {
+ this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+ startEvictor(timeBetweenEvictionRunsMillis);
+ }
+
+ /**
+ * Returns the maximum number of objects to examine during each run (if any)
+ * of the idle object evictor thread. When positive, the number of tests
+ * performed for a run will be the minimum of the configured value and the
+ * number of idle instances in the pool. When negative, the number of tests
+ * performed will be ceil({@link #getNumIdle}/
+ * abs({@link #getNumTestsPerEvictionRun}))
which means that when the
+ * value is -n
roughly one nth of the idle objects will be
+ * tested per run.
+ *
+ * @return max number of objects to examine during each evictor run
+ *
+ * @see #setNumTestsPerEvictionRun
+ * @see #setTimeBetweenEvictionRunsMillis
+ */
+ public final int getNumTestsPerEvictionRun() {
+ return numTestsPerEvictionRun;
+ }
+
+ /**
+ * Sets the maximum number of objects to examine during each run (if any)
+ * of the idle object evictor thread. When positive, the number of tests
+ * performed for a run will be the minimum of the configured value and the
+ * number of idle instances in the pool. When negative, the number of tests
+ * performed will be ceil({@link #getNumIdle}/
+ * abs({@link #getNumTestsPerEvictionRun}))
which means that when the
+ * value is -n
roughly one nth of the idle objects will be
+ * tested per run.
+ *
+ * @param numTestsPerEvictionRun
+ * max number of objects to examine during each evictor run
+ *
+ * @see #getNumTestsPerEvictionRun
+ * @see #setTimeBetweenEvictionRunsMillis
+ */
+ public final void setNumTestsPerEvictionRun(final int numTestsPerEvictionRun) {
+ this.numTestsPerEvictionRun = numTestsPerEvictionRun;
+ }
+
+ /**
+ * Returns the minimum amount of time an object may sit idle in the pool
+ * before it is eligible for eviction by the idle object evictor (if any -
+ * see {@link #setTimeBetweenEvictionRunsMillis(long)}). When non-positive,
+ * no objects will be evicted from the pool due to idle time alone.
+ *
+ * @return minimum amount of time an object may sit idle in the pool before
+ * it is eligible for eviction
+ *
+ * @see #setMinEvictableIdleTimeMillis
+ * @see #setTimeBetweenEvictionRunsMillis
+ */
+ public final long getMinEvictableIdleTimeMillis() {
+ return minEvictableIdleTimeMillis;
+ }
+
+ /**
+ * Sets the minimum amount of time an object may sit idle in the pool
+ * before it is eligible for eviction by the idle object evictor (if any -
+ * see {@link #setTimeBetweenEvictionRunsMillis(long)}). When non-positive,
+ * no objects will be evicted from the pool due to idle time alone.
+ *
+ * @param minEvictableIdleTimeMillis
+ * minimum amount of time an object may sit idle in the pool
+ * before it is eligible for eviction
+ *
+ * @see #getMinEvictableIdleTimeMillis
+ * @see #setTimeBetweenEvictionRunsMillis
+ */
+ public final void setMinEvictableIdleTimeMillis(
+ final long minEvictableIdleTimeMillis) {
+ this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+ }
+
+ /**
+ * Returns the minimum amount of time an object may sit idle in the pool
+ * before it is eligible for eviction by the idle object evictor (if any -
+ * see {@link #setTimeBetweenEvictionRunsMillis(long)}),
+ * with the extra condition that at least minIdle
object
+ * instances remain in the pool. This setting is overridden by
+ * {@link #getMinEvictableIdleTimeMillis} (that is, if
+ * {@link #getMinEvictableIdleTimeMillis} is positive, then
+ * {@link #getSoftMinEvictableIdleTimeMillis} is ignored).
+ *
+ * @return minimum amount of time an object may sit idle in the pool before
+ * it is eligible for eviction if minIdle instances are available
+ *
+ * @see #setSoftMinEvictableIdleTimeMillis
+ */
+ public final long getSoftMinEvictableIdleTimeMillis() {
+ return softMinEvictableIdleTimeMillis;
+ }
+
+ /**
+ * Sets the minimum amount of time an object may sit idle in the pool
+ * before it is eligible for eviction by the idle object evictor (if any -
+ * see {@link #setTimeBetweenEvictionRunsMillis(long)}),
+ * with the extra condition that at least minIdle
object
+ * instances remain in the pool. This setting is overridden by
+ * {@link #getMinEvictableIdleTimeMillis} (that is, if
+ * {@link #getMinEvictableIdleTimeMillis} is positive, then
+ * {@link #getSoftMinEvictableIdleTimeMillis} is ignored).
+ *
+ * @param softMinEvictableIdleTimeMillis
+ * minimum amount of time an object may sit idle in the pool
+ * before it is eligible for eviction if minIdle instances are
+ * available
+ *
+ * @see #getSoftMinEvictableIdleTimeMillis
+ */
+ public final void setSoftMinEvictableIdleTimeMillis(
+ final long softMinEvictableIdleTimeMillis) {
+ this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+ }
+
+ /**
+ * Returns the name of the {@link EvictionPolicy} implementation that is
+ * used by this pool.
+ *
+ * @return The fully qualified class name of the {@link EvictionPolicy}
+ *
+ * @see #setEvictionPolicyClassName(String)
+ */
+ public final String getEvictionPolicyClassName() {
+ return evictionPolicy.getClass().getName();
+ }
+
+ /**
+ * Sets the name of the {@link EvictionPolicy} implementation that is
+ * used by this pool. The Pool will attempt to load the class using the
+ * thread context class loader. If that fails, the Pool will attempt to load
+ * the class using the class loader that loaded this class.
+ *
+ * @param evictionPolicyClassName the fully qualified class name of the
+ * new eviction policy
+ *
+ * @see #getEvictionPolicyClassName()
+ */
+ public final void setEvictionPolicyClassName(
+ final String evictionPolicyClassName) {
+ try {
+ Class> clazz;
+ try {
+ clazz = Class.forName(evictionPolicyClassName, true,
+ Thread.currentThread().getContextClassLoader());
+ } catch (final ClassNotFoundException e) {
+ clazz = Class.forName(evictionPolicyClassName);
+ }
+ final Object policy = clazz.getConstructor().newInstance();
+ if (policy instanceof EvictionPolicy>) {
+ @SuppressWarnings("unchecked") // safe, because we just checked the class
+ final
+ EvictionPolicytrue
when this pool has been closed.
+ */
+ public final boolean isClosed() {
+ return closed;
+ }
+
+ /**
+ * numTests
idle object eviction tests, evicting
+ * examined objects that meet the criteria for eviction. If
+ * testWhileIdle
is true, examined objects are validated
+ * when visited (and removed if invalid); otherwise only objects that
+ * have been idle for more than minEvicableIdleTimeMillis
+ * are removed.null
if the pool has not been
+ * registered.
+ * @return the JMX name
+ */
+ public final ObjectName getJmxName() {
+ return oname;
+ }
+
+ /**
+ * Provides the stack trace for the call that created this pool. JMX
+ * registration may trigger a memory leak so it is important that pools are
+ * deregistered when no longer used by calling the {@link #close()} method.
+ * This method is provided to assist with identifying code that creates but
+ * does not close it thereby creating a memory leak.
+ * @return pool creation stack trace
+ */
+ public final String getCreationStackTrace() {
+ return creationStackTrace;
+ }
+
+ /**
+ * The total number of objects successfully borrowed from this pool over the
+ * lifetime of the pool.
+ * @return the borrowed object count
+ */
+ public final long getBorrowedCount() {
+ return borrowedCount.get();
+ }
+
+ /**
+ * The total number of objects returned to this pool over the lifetime of
+ * the pool. This excludes attempts to return the same object multiple
+ * times.
+ * @return the returned object count
+ */
+ public final long getReturnedCount() {
+ return returnedCount.get();
+ }
+
+ /**
+ * The total number of objects created for this pool over the lifetime of
+ * the pool.
+ * @return the created object count
+ */
+ public final long getCreatedCount() {
+ return createdCount.get();
+ }
+
+ /**
+ * The total number of objects destroyed by this pool over the lifetime of
+ * the pool.
+ * @return the destroyed object count
+ */
+ public final long getDestroyedCount() {
+ return destroyedCount.get();
+ }
+
+ /**
+ * The total number of objects destroyed by the evictor associated with this
+ * pool over the lifetime of the pool.
+ * @return the evictor destroyed object count
+ */
+ public final long getDestroyedByEvictorCount() {
+ return destroyedByEvictorCount.get();
+ }
+
+ /**
+ * The total number of objects destroyed by this pool as a result of failing
+ * validation during borrowObject()
over the lifetime of the
+ * pool.
+ * @return validation destroyed object count
+ */
+ public final long getDestroyedByBorrowValidationCount() {
+ return destroyedByBorrowValidationCount.get();
+ }
+
+ /**
+ * The mean time objects are active for based on the last {@link
+ * #MEAN_TIMING_STATS_CACHE_SIZE} objects returned to the pool.
+ * @return mean time an object has been checked out from the pool among
+ * recently returned objects
+ */
+ public final long getMeanActiveTimeMillis() {
+ return activeTimes.getMean();
+ }
+
+ /**
+ * The mean time objects are idle for based on the last {@link
+ * #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool.
+ * @return mean time an object has been idle in the pool among recently
+ * borrowed objects
+ */
+ public final long getMeanIdleTimeMillis() {
+ return idleTimes.getMean();
+ }
+
+ /**
+ * The mean time threads wait to borrow an object based on the last {@link
+ * #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool.
+ * @return mean time in milliseconds that a recently served thread has had
+ * to wait to borrow an object from the pool
+ */
+ public final long getMeanBorrowWaitTimeMillis() {
+ return waitTimes.getMean();
+ }
+
+ /**
+ * The maximum time a thread has waited to borrow objects from the pool.
+ * @return maximum wait time in milliseconds since the pool was created
+ */
+ public final long getMaxBorrowWaitTimeMillis() {
+ return maxBorrowWaitTimeMillis.get();
+ }
+
+ /**
+ * The number of instances currently idle in this pool.
+ * @return count of instances available for checkout from the pool
+ */
+ public abstract int getNumIdle();
+
+ /**
+ * The listener used (if any) to receive notifications of exceptions
+ * unavoidably swallowed by the pool.
+ *
+ * @return The listener or null
for no listener
+ */
+ public final SwallowedExceptionListener getSwallowedExceptionListener() {
+ return swallowedExceptionListener;
+ }
+
+ /**
+ * The listener used (if any) to receive notifications of exceptions
+ * unavoidably swallowed by the pool.
+ *
+ * @param swallowedExceptionListener The listener or null
+ * for no listener
+ */
+ public final void setSwallowedExceptionListener(
+ final SwallowedExceptionListener swallowedExceptionListener) {
+ this.swallowedExceptionListener = swallowedExceptionListener;
+ }
+
+ /**
+ * Swallows an exception and notifies the configured listener for swallowed
+ * exceptions queue.
+ *
+ * @param e exception to be swallowed
+ */
+ final void swallowException(final Exception e) {
+ final SwallowedExceptionListener listener = getSwallowedExceptionListener();
+
+ if (listener == null) {
+ return;
+ }
+
+ try {
+ listener.onSwallowException(e);
+ } catch (final OutOfMemoryError oome) {
+ throw oome;
+ } catch (final VirtualMachineError vme) {
+ throw vme;
+ } catch (final Throwable t) {
+ // Ignore. Enjoy the irony.
+ }
+ }
+
+ /**
+ * Updates statistics after an object is borrowed from the pool.
+ * @param p object borrowed from the pool
+ * @param waitTime time (in milliseconds) that the borrowing thread had to wait
+ */
+ final void updateStatsBorrow(final PooledObjectjmxNameBase + jmxNamePrefix + i
where i is the least
+ * integer greater than or equal to 1 such that the name is not already
+ * registered. Swallows MBeanRegistrationException, NotCompliantMBeanException
+ * returning null.
+ *
+ * @param config Pool configuration
+ * @param jmxNameBase default base JMX name for this pool
+ * @param jmxNamePrefix name prefix
+ * @return registered ObjectName, null if registration fails
+ */
+ private ObjectName jmxRegister(final BaseObjectPoolConfig config,
+ final String jmxNameBase, String jmxNamePrefix) {
+ ObjectName objectName = null;
+ final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ int i = 1;
+ boolean registered = false;
+ String base = config.getJmxNameBase();
+ if (base == null) {
+ base = jmxNameBase;
+ }
+ while (!registered) {
+ try {
+ ObjectName objName;
+ // Skip the numeric suffix for the first pool in case there is
+ // only one so the names are cleaner.
+ if (i == 1) {
+ objName = new ObjectName(base + jmxNamePrefix);
+ } else {
+ objName = new ObjectName(base + jmxNamePrefix + i);
+ }
+ mbs.registerMBean(this, objName);
+ objectName = objName;
+ registered = true;
+ } catch (final MalformedObjectNameException e) {
+ if (BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX.equals(
+ jmxNamePrefix) && jmxNameBase.equals(base)) {
+ // Shouldn't happen. Skip registration if it does.
+ registered = true;
+ } else {
+ // Must be an invalid name. Use the defaults instead.
+ jmxNamePrefix =
+ BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX;
+ base = jmxNameBase;
+ }
+ } catch (final InstanceAlreadyExistsException e) {
+ // Increment the index and try again
+ i++;
+ } catch (final MBeanRegistrationException e) {
+ // Shouldn't happen. Skip registration if it does.
+ registered = true;
+ } catch (final NotCompliantMBeanException e) {
+ // Shouldn't happen. Skip registration if it does.
+ registered = true;
+ }
+ }
+ return objectName;
+ }
+
+ /**
+ * Gets the stack trace of an exception as a string.
+ * @param e exception to trace
+ * @return exception stack trace as a string
+ */
+ private String getStackTrace(final Exception e) {
+ // Need the exception in string form to prevent the retention of
+ // references to classes in the stack trace that could trigger a memory
+ // leak in a container environment.
+ final Writer w = new StringWriter();
+ final PrintWriter pw = new PrintWriter(w);
+ e.printStackTrace(pw);
+ return w.toString();
+ }
+
+ // Inner classes
+
+ /**
+ * The idle object evictor {@link TimerTask}.
+ *
+ * @see GenericKeyedObjectPool#setTimeBetweenEvictionRunsMillis
+ */
+ class Evictor extends TimerTask {
+ /**
+ * Run pool maintenance. Evict objects qualifying for eviction and then
+ * ensure that the minimum number of idle instances are available.
+ * Since the Timer that invokes Evictors is shared for all Pools but
+ * pools may exist in different class loaders, the Evictor ensures that
+ * any actions taken are under the class loader of the factory
+ * associated with the pool.
+ */
+ @Override
+ public void run() {
+ final ClassLoader savedClassLoader =
+ Thread.currentThread().getContextClassLoader();
+ try {
+ if (factoryClassLoader != null) {
+ // Set the class loader for the factory
+ final ClassLoader cl = factoryClassLoader.get();
+ if (cl == null) {
+ // The pool has been dereferenced and the class loader
+ // GC'd. Cancel this timer so the pool can be GC'd as
+ // well.
+ cancel();
+ return;
+ }
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+
+ // Evict from the pool
+ try {
+ evict();
+ } catch(final Exception e) {
+ swallowException(e);
+ } catch(final OutOfMemoryError oome) {
+ // Log problem but give evictor thread a chance to continue
+ // in case error is recoverable
+ oome.printStackTrace(System.err);
+ }
+ // Re-create idle instances.
+ try {
+ ensureMinIdle();
+ } catch (final Exception e) {
+ swallowException(e);
+ }
+ } finally {
+ // Restore the previous CCL
+ Thread.currentThread().setContextClassLoader(savedClassLoader);
+ }
+ }
+ }
+
+ /**
+ * Maintains a cache of values for a single metric and reports
+ * statistics on the cached values.
+ */
+ private class StatsStore {
+
+ private final AtomicLong values[];
+ private final int size;
+ private int index;
+
+ /**
+ * Create a StatsStore with the given cache size.
+ *
+ * @param size number of values to maintain in the cache.
+ */
+ public StatsStore(final int size) {
+ this.size = size;
+ values = new AtomicLong[size];
+ for (int i = 0; i < size; i++) {
+ values[i] = new AtomicLong(-1);
+ }
+ }
+
+ /**
+ * Adds a value to the cache. If the cache is full, one of the
+ * existing values is replaced by the new value.
+ *
+ * @param value new value to add to the cache.
+ */
+ public synchronized void add(final long value) {
+ values[index].set(value);
+ index++;
+ if (index == size) {
+ index = 0;
+ }
+ }
+
+ /**
+ * Returns the mean of the cached values.
+ *
+ * @return the mean of the cache, truncated to long
+ */
+ public long getMean() {
+ double result = 0;
+ int counter = 0;
+ for (int i = 0; i < size; i++) {
+ final long value = values[i].get();
+ if (value != -1) {
+ counter++;
+ result = result * ((counter - 1) / (double) counter) +
+ value/(double) counter;
+ }
+ }
+ return (long) result;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("StatsStore [values=");
+ builder.append(Arrays.toString(values));
+ builder.append(", size=");
+ builder.append(size);
+ builder.append(", index=");
+ builder.append(index);
+ builder.append("]");
+ return builder.toString();
+ }
+ }
+
+ /**
+ * The idle object eviction iterator. Holds a reference to the idle objects.
+ */
+ class EvictionIterator implements Iteratornull
+ * which means the pool will provide the base name to use.
+ * @see GenericObjectPool#getJmxName()
+ * @see GenericKeyedObjectPool#getJmxName()
+ */
+ public static final String DEFAULT_JMX_NAME_BASE = null;
+
+ /**
+ * The default value for the {@code evictionPolicyClassName} configuration
+ * attribute.
+ * @see GenericObjectPool#getEvictionPolicyClassName()
+ * @see GenericKeyedObjectPool#getEvictionPolicyClassName()
+ */
+ public static final String DEFAULT_EVICTION_POLICY_CLASS_NAME =
+ "org.apache.commons.pool2.impl.DefaultEvictionPolicy";
+
+
+ private boolean lifo = DEFAULT_LIFO;
+
+ private boolean fairness = DEFAULT_FAIRNESS;
+
+ private long maxWaitMillis = DEFAULT_MAX_WAIT_MILLIS;
+
+ private long minEvictableIdleTimeMillis =
+ DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+
+ private long evictorShutdownTimeoutMillis =
+ DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS;
+
+ private long softMinEvictableIdleTimeMillis =
+ DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+
+ private int numTestsPerEvictionRun =
+ DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+
+ private String evictionPolicyClassName = DEFAULT_EVICTION_POLICY_CLASS_NAME;
+
+ private boolean testOnCreate = DEFAULT_TEST_ON_CREATE;
+
+ private boolean testOnBorrow = DEFAULT_TEST_ON_BORROW;
+
+ private boolean testOnReturn = DEFAULT_TEST_ON_RETURN;
+
+ private boolean testWhileIdle = DEFAULT_TEST_WHILE_IDLE;
+
+ private long timeBetweenEvictionRunsMillis =
+ DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
+
+ private boolean blockWhenExhausted = DEFAULT_BLOCK_WHEN_EXHAUSTED;
+
+ private boolean jmxEnabled = DEFAULT_JMX_ENABLE;
+
+ // TODO Consider changing this to a single property for 3.x
+ private String jmxNamePrefix = DEFAULT_JMX_NAME_PREFIX;
+
+ private String jmxNameBase = DEFAULT_JMX_NAME_BASE;
+
+
+ /**
+ * Get the value for the {@code lifo} configuration attribute for pools
+ * created with this configuration instance.
+ *
+ * @return The current setting of {@code lifo} for this configuration
+ * instance
+ *
+ * @see GenericObjectPool#getLifo()
+ * @see GenericKeyedObjectPool#getLifo()
+ */
+ public boolean getLifo() {
+ return lifo;
+ }
+
+ /**
+ * Get the value for the {@code fairness} configuration attribute for pools
+ * created with this configuration instance.
+ *
+ * @return The current setting of {@code fairness} for this configuration
+ * instance
+ *
+ * @see GenericObjectPool#getFairness()
+ * @see GenericKeyedObjectPool#getFairness()
+ */
+ public boolean getFairness() {
+ return fairness;
+ }
+
+ /**
+ * Set the value for the {@code lifo} configuration attribute for pools
+ * created with this configuration instance.
+ *
+ * @param lifo The new setting of {@code lifo}
+ * for this configuration instance
+ *
+ * @see GenericObjectPool#getLifo()
+ * @see GenericKeyedObjectPool#getLifo()
+ */
+ public void setLifo(final boolean lifo) {
+ this.lifo = lifo;
+ }
+
+ /**
+ * Set the value for the {@code fairness} configuration attribute for pools
+ * created with this configuration instance.
+ *
+ * @param fairness The new setting of {@code fairness}
+ * for this configuration instance
+ *
+ * @see GenericObjectPool#getFairness()
+ * @see GenericKeyedObjectPool#getFairness()
+ */
+ public void setFairness(final boolean fairness) {
+ this.fairness = fairness;
+ }
+
+ /**
+ * Get the value for the {@code maxWait} configuration attribute for pools
+ * created with this configuration instance.
+ *
+ * @return The current setting of {@code maxWait} for this
+ * configuration instance
+ *
+ * @see GenericObjectPool#getMaxWaitMillis()
+ * @see GenericKeyedObjectPool#getMaxWaitMillis()
+ */
+ public long getMaxWaitMillis() {
+ return maxWaitMillis;
+ }
+
+ /**
+ * Set the value for the {@code maxWait} configuration attribute for pools
+ * created with this configuration instance.
+ *
+ * @param maxWaitMillis The new setting of {@code maxWaitMillis}
+ * for this configuration instance
+ *
+ * @see GenericObjectPool#getMaxWaitMillis()
+ * @see GenericKeyedObjectPool#getMaxWaitMillis()
+ */
+ public void setMaxWaitMillis(final long maxWaitMillis) {
+ this.maxWaitMillis = maxWaitMillis;
+ }
+
+ /**
+ * Get the value for the {@code minEvictableIdleTimeMillis} configuration
+ * attribute for pools created with this configuration instance.
+ *
+ * @return The current setting of {@code minEvictableIdleTimeMillis} for
+ * this configuration instance
+ *
+ * @see GenericObjectPool#getMinEvictableIdleTimeMillis()
+ * @see GenericKeyedObjectPool#getMinEvictableIdleTimeMillis()
+ */
+ public long getMinEvictableIdleTimeMillis() {
+ return minEvictableIdleTimeMillis;
+ }
+
+ /**
+ * Set the value for the {@code minEvictableIdleTimeMillis} configuration
+ * attribute for pools created with this configuration instance.
+ *
+ * @param minEvictableIdleTimeMillis The new setting of
+ * {@code minEvictableIdleTimeMillis} for this configuration instance
+ *
+ * @see GenericObjectPool#getMinEvictableIdleTimeMillis()
+ * @see GenericKeyedObjectPool#getMinEvictableIdleTimeMillis()
+ */
+ public void setMinEvictableIdleTimeMillis(final long minEvictableIdleTimeMillis) {
+ this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+ }
+
+ /**
+ * Get the value for the {@code softMinEvictableIdleTimeMillis}
+ * configuration attribute for pools created with this configuration
+ * instance.
+ *
+ * @return The current setting of {@code softMinEvictableIdleTimeMillis}
+ * for this configuration instance
+ *
+ * @see GenericObjectPool#getSoftMinEvictableIdleTimeMillis()
+ * @see GenericKeyedObjectPool#getSoftMinEvictableIdleTimeMillis()
+ */
+ public long getSoftMinEvictableIdleTimeMillis() {
+ return softMinEvictableIdleTimeMillis;
+ }
+
+ /**
+ * Set the value for the {@code softMinEvictableIdleTimeMillis}
+ * configuration attribute for pools created with this configuration
+ * instance.
+ *
+ * @param softMinEvictableIdleTimeMillis The new setting of
+ * {@code softMinEvictableIdleTimeMillis} for this configuration
+ * instance
+ *
+ * @see GenericObjectPool#getSoftMinEvictableIdleTimeMillis()
+ * @see GenericKeyedObjectPool#getSoftMinEvictableIdleTimeMillis()
+ */
+ public void setSoftMinEvictableIdleTimeMillis(
+ final long softMinEvictableIdleTimeMillis) {
+ this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+ }
+
+ /**
+ * Get the value for the {@code numTestsPerEvictionRun} configuration
+ * attribute for pools created with this configuration instance.
+ *
+ * @return The current setting of {@code numTestsPerEvictionRun} for this
+ * configuration instance
+ *
+ * @see GenericObjectPool#getNumTestsPerEvictionRun()
+ * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun()
+ */
+ public int getNumTestsPerEvictionRun() {
+ return numTestsPerEvictionRun;
+ }
+
+ /**
+ * Set the value for the {@code numTestsPerEvictionRun} configuration
+ * attribute for pools created with this configuration instance.
+ *
+ * @param numTestsPerEvictionRun The new setting of
+ * {@code numTestsPerEvictionRun} for this configuration instance
+ *
+ * @see GenericObjectPool#getNumTestsPerEvictionRun()
+ * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun()
+ */
+ public void setNumTestsPerEvictionRun(final int numTestsPerEvictionRun) {
+ this.numTestsPerEvictionRun = numTestsPerEvictionRun;
+ }
+
+ /**
+ * Get the value for the {@code evictorShutdownTimeoutMillis} configuration
+ * attribute for pools created with this configuration instance.
+ *
+ * @return The current setting of {@code evictorShutdownTimeoutMillis} for
+ * this configuration instance
+ *
+ * @see GenericObjectPool#getEvictorShutdownTimeoutMillis()
+ * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutMillis()
+ */
+ public long getEvictorShutdownTimeoutMillis() {
+ return evictorShutdownTimeoutMillis;
+ }
+
+ /**
+ * Set the value for the {@code evictorShutdownTimeoutMillis} configuration
+ * attribute for pools created with this configuration instance.
+ *
+ * @param evictorShutdownTimeoutMillis The new setting of
+ * {@code evictorShutdownTimeoutMillis} for this configuration
+ * instance
+ *
+ * @see GenericObjectPool#getEvictorShutdownTimeoutMillis()
+ * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutMillis()
+ */
+ public void setEvictorShutdownTimeoutMillis(
+ final long evictorShutdownTimeoutMillis) {
+ this.evictorShutdownTimeoutMillis = evictorShutdownTimeoutMillis;
+ }
+
+ /**
+ * Get the value for the {@code testOnCreate} configuration attribute for
+ * pools created with this configuration instance.
+ *
+ * @return The current setting of {@code testOnCreate} for this
+ * configuration instance
+ *
+ * @see GenericObjectPool#getTestOnCreate()
+ * @see GenericKeyedObjectPool#getTestOnCreate()
+ *
+ * @since 2.2
+ */
+ public boolean getTestOnCreate() {
+ return testOnCreate;
+ }
+
+ /**
+ * Set the value for the {@code testOnCreate} configuration attribute for
+ * pools created with this configuration instance.
+ *
+ * @param testOnCreate The new setting of {@code testOnCreate}
+ * for this configuration instance
+ *
+ * @see GenericObjectPool#getTestOnCreate()
+ * @see GenericKeyedObjectPool#getTestOnCreate()
+ *
+ * @since 2.2
+ */
+ public void setTestOnCreate(final boolean testOnCreate) {
+ this.testOnCreate = testOnCreate;
+ }
+
+ /**
+ * Get the value for the {@code testOnBorrow} configuration attribute for
+ * pools created with this configuration instance.
+ *
+ * @return The current setting of {@code testOnBorrow} for this
+ * configuration instance
+ *
+ * @see GenericObjectPool#getTestOnBorrow()
+ * @see GenericKeyedObjectPool#getTestOnBorrow()
+ */
+ public boolean getTestOnBorrow() {
+ return testOnBorrow;
+ }
+
+ /**
+ * Set the value for the {@code testOnBorrow} configuration attribute for
+ * pools created with this configuration instance.
+ *
+ * @param testOnBorrow The new setting of {@code testOnBorrow}
+ * for this configuration instance
+ *
+ * @see GenericObjectPool#getTestOnBorrow()
+ * @see GenericKeyedObjectPool#getTestOnBorrow()
+ */
+ public void setTestOnBorrow(final boolean testOnBorrow) {
+ this.testOnBorrow = testOnBorrow;
+ }
+
+ /**
+ * Get the value for the {@code testOnReturn} configuration attribute for
+ * pools created with this configuration instance.
+ *
+ * @return The current setting of {@code testOnReturn} for this
+ * configuration instance
+ *
+ * @see GenericObjectPool#getTestOnReturn()
+ * @see GenericKeyedObjectPool#getTestOnReturn()
+ */
+ public boolean getTestOnReturn() {
+ return testOnReturn;
+ }
+
+ /**
+ * Set the value for the {@code testOnReturn} configuration attribute for
+ * pools created with this configuration instance.
+ *
+ * @param testOnReturn The new setting of {@code testOnReturn}
+ * for this configuration instance
+ *
+ * @see GenericObjectPool#getTestOnReturn()
+ * @see GenericKeyedObjectPool#getTestOnReturn()
+ */
+ public void setTestOnReturn(final boolean testOnReturn) {
+ this.testOnReturn = testOnReturn;
+ }
+
+ /**
+ * Get the value for the {@code testWhileIdle} configuration attribute for
+ * pools created with this configuration instance.
+ *
+ * @return The current setting of {@code testWhileIdle} for this
+ * configuration instance
+ *
+ * @see GenericObjectPool#getTestWhileIdle()
+ * @see GenericKeyedObjectPool#getTestWhileIdle()
+ */
+ public boolean getTestWhileIdle() {
+ return testWhileIdle;
+ }
+
+ /**
+ * Set the value for the {@code testWhileIdle} configuration attribute for
+ * pools created with this configuration instance.
+ *
+ * @param testWhileIdle The new setting of {@code testWhileIdle}
+ * for this configuration instance
+ *
+ * @see GenericObjectPool#getTestWhileIdle()
+ * @see GenericKeyedObjectPool#getTestWhileIdle()
+ */
+ public void setTestWhileIdle(final boolean testWhileIdle) {
+ this.testWhileIdle = testWhileIdle;
+ }
+
+ /**
+ * Get the value for the {@code timeBetweenEvictionRunsMillis} configuration
+ * attribute for pools created with this configuration instance.
+ *
+ * @return The current setting of {@code timeBetweenEvictionRunsMillis} for
+ * this configuration instance
+ *
+ * @see GenericObjectPool#getTimeBetweenEvictionRunsMillis()
+ * @see GenericKeyedObjectPool#getTimeBetweenEvictionRunsMillis()
+ */
+ public long getTimeBetweenEvictionRunsMillis() {
+ return timeBetweenEvictionRunsMillis;
+ }
+
+ /**
+ * Set the value for the {@code timeBetweenEvictionRunsMillis} configuration
+ * attribute for pools created with this configuration instance.
+ *
+ * @param timeBetweenEvictionRunsMillis The new setting of
+ * {@code timeBetweenEvictionRunsMillis} for this configuration
+ * instance
+ *
+ * @see GenericObjectPool#getTimeBetweenEvictionRunsMillis()
+ * @see GenericKeyedObjectPool#getTimeBetweenEvictionRunsMillis()
+ */
+ public void setTimeBetweenEvictionRunsMillis(
+ final long timeBetweenEvictionRunsMillis) {
+ this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+ }
+
+ /**
+ * Get the value for the {@code evictionPolicyClassName} configuration
+ * attribute for pools created with this configuration instance.
+ *
+ * @return The current setting of {@code evictionPolicyClassName} for this
+ * configuration instance
+ *
+ * @see GenericObjectPool#getEvictionPolicyClassName()
+ * @see GenericKeyedObjectPool#getEvictionPolicyClassName()
+ */
+ public String getEvictionPolicyClassName() {
+ return evictionPolicyClassName;
+ }
+
+ /**
+ * Set the value for the {@code evictionPolicyClassName} configuration
+ * attribute for pools created with this configuration instance.
+ *
+ * @param evictionPolicyClassName The new setting of
+ * {@code evictionPolicyClassName} for this configuration instance
+ *
+ * @see GenericObjectPool#getEvictionPolicyClassName()
+ * @see GenericKeyedObjectPool#getEvictionPolicyClassName()
+ */
+ public void setEvictionPolicyClassName(final String evictionPolicyClassName) {
+ this.evictionPolicyClassName = evictionPolicyClassName;
+ }
+
+ /**
+ * Get the value for the {@code blockWhenExhausted} configuration attribute
+ * for pools created with this configuration instance.
+ *
+ * @return The current setting of {@code blockWhenExhausted} for this
+ * configuration instance
+ *
+ * @see GenericObjectPool#getBlockWhenExhausted()
+ * @see GenericKeyedObjectPool#getBlockWhenExhausted()
+ */
+ public boolean getBlockWhenExhausted() {
+ return blockWhenExhausted;
+ }
+
+ /**
+ * Set the value for the {@code blockWhenExhausted} configuration attribute
+ * for pools created with this configuration instance.
+ *
+ * @param blockWhenExhausted The new setting of {@code blockWhenExhausted}
+ * for this configuration instance
+ *
+ * @see GenericObjectPool#getBlockWhenExhausted()
+ * @see GenericKeyedObjectPool#getBlockWhenExhausted()
+ */
+ public void setBlockWhenExhausted(final boolean blockWhenExhausted) {
+ this.blockWhenExhausted = blockWhenExhausted;
+ }
+
+ /**
+ * Gets the value of the flag that determines if JMX will be enabled for
+ * pools created with this configuration instance.
+ *
+ * @return The current setting of {@code jmxEnabled} for this configuration
+ * instance
+ */
+ public boolean getJmxEnabled() {
+ return jmxEnabled;
+ }
+
+ /**
+ * Sets the value of the flag that determines if JMX will be enabled for
+ * pools created with this configuration instance.
+ *
+ * @param jmxEnabled The new setting of {@code jmxEnabled}
+ * for this configuration instance
+ */
+ public void setJmxEnabled(final boolean jmxEnabled) {
+ this.jmxEnabled = jmxEnabled;
+ }
+
+ /**
+ * 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 of null
means that the pool will define
+ * the JMX name base.
+ *
+ * @return The current setting of {@code jmxNameBase} for this
+ * configuration instance
+ */
+ public String getJmxNameBase() {
+ return jmxNameBase;
+ }
+
+ /**
+ * 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 of null
means that the pool will define
+ * the JMX name base.
+ *
+ * @param jmxNameBase The new setting of {@code jmxNameBase}
+ * for this configuration instance
+ */
+ public void setJmxNameBase(final String jmxNameBase) {
+ this.jmxNameBase = jmxNameBase;
+ }
+
+ /**
+ * 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.
+ *
+ * @return The current setting of {@code jmxNamePrefix} for this
+ * configuration instance
+ */
+ public String getJmxNamePrefix() {
+ return jmxNamePrefix;
+ }
+
+ /**
+ * 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.
+ *
+ * @param jmxNamePrefix The new setting of {@code jmxNamePrefix}
+ * for this configuration instance
+ */
+ public void setJmxNamePrefix(final String jmxNamePrefix) {
+ this.jmxNamePrefix = jmxNamePrefix;
+ }
+
+ @Override
+ protected void toStringAppendFields(final StringBuilder builder) {
+ builder.append("lifo=");
+ builder.append(lifo);
+ builder.append(", fairness=");
+ builder.append(fairness);
+ builder.append(", maxWaitMillis=");
+ builder.append(maxWaitMillis);
+ builder.append(", minEvictableIdleTimeMillis=");
+ builder.append(minEvictableIdleTimeMillis);
+ builder.append(", softMinEvictableIdleTimeMillis=");
+ builder.append(softMinEvictableIdleTimeMillis);
+ builder.append(", numTestsPerEvictionRun=");
+ builder.append(numTestsPerEvictionRun);
+ builder.append(", evictionPolicyClassName=");
+ builder.append(evictionPolicyClassName);
+ builder.append(", testOnCreate=");
+ builder.append(testOnCreate);
+ builder.append(", testOnBorrow=");
+ builder.append(testOnBorrow);
+ builder.append(", testOnReturn=");
+ builder.append(testOnReturn);
+ builder.append(", testWhileIdle=");
+ builder.append(testWhileIdle);
+ builder.append(", timeBetweenEvictionRunsMillis=");
+ builder.append(timeBetweenEvictionRunsMillis);
+ builder.append(", blockWhenExhausted=");
+ builder.append(blockWhenExhausted);
+ builder.append(", jmxEnabled=");
+ builder.append(jmxEnabled);
+ builder.append(", jmxNamePrefix=");
+ builder.append(jmxNamePrefix);
+ builder.append(", jmxNameBase=");
+ builder.append(jmxNameBase);
+ }
+}
diff --git a/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/CallStack.java b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/CallStack.java
new file mode 100755
index 000000000..7b757cf63
--- /dev/null
+++ b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/CallStack.java
@@ -0,0 +1,54 @@
+/*
+ * 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 com.fr.third.org.apache.commons.pool2.impl;
+
+import com.fr.third.org.apache.commons.pool2.PooledObject;
+import com.fr.third.org.apache.commons.pool2.UsageTracking;
+
+import java.io.PrintWriter;
+
+/**
+ * Strategy for obtaining and printing the current call stack. This is primarily useful for
+ * {@linkplain UsageTracking usage tracking} so that different JVMs and configurations can use more efficient strategies
+ * for obtaining the current call stack depending on metadata needs.
+ *
+ * @see CallStackUtils
+ * @since 2.4.3
+ */
+public interface CallStack {
+
+ /**
+ * Prints the current stack trace if available to a PrintWriter. The format is undefined and is primarily useful
+ * for debugging issues with {@link PooledObject} usage in user code.
+ *
+ * @param writer a PrintWriter to write the current stack trace to if available
+ * @return true if a stack trace was available to print or false if nothing was printed
+ */
+ boolean printStackTrace(final PrintWriter writer);
+
+ /**
+ * Takes a snapshot of the current call stack. Subsequent calls to {@link #printStackTrace(PrintWriter)} will print
+ * out that stack trace until it is {@linkplain #clear() cleared}.
+ */
+ void fillInStackTrace();
+
+ /**
+ * Clears the current stack trace snapshot. Subsequent calls to {@link #printStackTrace(PrintWriter)} will be
+ * no-ops until another call to {@link #fillInStackTrace()}.
+ */
+ void clear();
+}
diff --git a/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/CallStackUtils.java b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/CallStackUtils.java
new file mode 100755
index 000000000..2ab2152ba
--- /dev/null
+++ b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/CallStackUtils.java
@@ -0,0 +1,89 @@
+/*
+ * 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 com.fr.third.org.apache.commons.pool2.impl;
+
+import java.security.AccessControlException;
+
+/**
+ * Utility methods for {@link CallStack}.
+ *
+ * @since 2.4.3
+ */
+public final class CallStackUtils {
+
+ private static final boolean CAN_CREATE_SECURITY_MANAGER;
+
+ static {
+ CAN_CREATE_SECURITY_MANAGER = canCreateSecurityManager();
+ }
+
+ /**
+ * @return {@code true} if it is able to create a security manager in the current environment, {@code false}
+ * otherwise.
+ */
+ private static boolean canCreateSecurityManager() {
+ final SecurityManager manager = System.getSecurityManager();
+ if (manager == null) {
+ return true;
+ }
+ try {
+ manager.checkPermission(new RuntimePermission("createSecurityManager"));
+ return true;
+ } catch (final AccessControlException ignored) {
+ return false;
+ }
+ }
+
+ /**
+ * Constructs a new {@link CallStack} using the fastest allowed strategy.
+ *
+ * @param messageFormat message (or format) to print first in stack traces
+ * @param useTimestamp if true, interpret message as a SimpleDateFormat and print the created timestamp; otherwise,
+ * print message format literally
+ * @return a new CallStack
+ * @deprecated use {@link #newCallStack(String, boolean, boolean)}
+ */
+ @Deprecated
+ public static CallStack newCallStack(final String messageFormat, final boolean useTimestamp) {
+ return newCallStack(messageFormat, useTimestamp, false);
+ }
+
+ /**
+ * Constructs a new {@link CallStack} using the fasted allowed strategy.
+ *
+ * @param messageFormat message (or format) to print first in stack traces
+ * @param useTimestamp if true, interpret message as a SimpleDateFormat and print the created timestamp;
+ * otherwise, print message format literally
+ * @param requireFullStackTrace if true, forces the use of a stack walking mechanism that includes full stack trace
+ * information; otherwise, uses a faster implementation if possible
+ * @return a new CallStack
+ * @since 2.5
+ */
+ public static CallStack newCallStack(final String messageFormat,
+ final boolean useTimestamp,
+ final boolean requireFullStackTrace) {
+ return CAN_CREATE_SECURITY_MANAGER && !requireFullStackTrace
+ ? new SecurityManagerCallStack(messageFormat, useTimestamp)
+ : new ThrowableCallStack(messageFormat, useTimestamp);
+ }
+
+ /**
+ * Hidden constructor.
+ */
+ private CallStackUtils() {
+ }
+}
diff --git a/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/DefaultEvictionPolicy.java b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/DefaultEvictionPolicy.java
new file mode 100755
index 000000000..d5e2c333b
--- /dev/null
+++ b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/DefaultEvictionPolicy.java
@@ -0,0 +1,53 @@
+/*
+ * 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 com.fr.third.org.apache.commons.pool2.impl;
+
+import com.fr.third.org.apache.commons.pool2.PooledObject;
+
+/**
+ * Provides the default implementation of {@link EvictionPolicy} used by the
+ * pools. Objects will be evicted if the following conditions are met:
+ *
+ *
+ * This class is immutable and thread-safe.
+ *
+ * @param yyyy-MM-dd HH:mm:ss Z
+ */
+ String getCreateTimeFormatted();
+
+ /**
+ * Obtain the time (using the same basis as
+ * {@link System#currentTimeMillis()}) the polled object was last borrowed.
+ *
+ * @return The time the pooled object was last borrowed
+ */
+ long getLastBorrowTime();
+
+ /**
+ * Obtain the time that pooled object was last borrowed.
+ *
+ * @return The last borrowed time for the pooled object formated as
+ * yyyy-MM-dd HH:mm:ss Z
+ */
+ String getLastBorrowTimeFormatted();
+
+ /**
+ * Obtain the stack trace recorded when the pooled object was last borrowed.
+ *
+ * @return The stack trace showing which code last borrowed the pooled
+ * object
+ */
+ String getLastBorrowTrace();
+
+
+ /**
+ * Obtain the time (using the same basis as
+ * {@link System#currentTimeMillis()})the wrapped object was last returned.
+ *
+ * @return The time the object was last returned
+ */
+ long getLastReturnTime();
+
+ /**
+ * Obtain the time that pooled object was last returned.
+ *
+ * @return The last returned time for the pooled object formated as
+ * yyyy-MM-dd HH:mm:ss Z
+ */
+ String getLastReturnTimeFormatted();
+
+ /**
+ * Obtain the name of the class of the pooled object.
+ *
+ * @return The pooled object's class name
+ *
+ * @see Class#getName()
+ */
+ String getPooledObjectType();
+
+ /**
+ * Provides a String form of the wrapper for debug purposes. The format is
+ * not fixed and may change at any time.
+ *
+ * @return A string representation of the pooled object
+ *
+ * @see Object#toString()
+ */
+ String getPooledObjectToString();
+
+ /**
+ * Get the number of times this object has been borrowed.
+ * @return The number of times this object has been borrowed.
+ * @since 2.1
+ */
+ long getBorrowedCount();
+}
diff --git a/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/EvictionConfig.java b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/EvictionConfig.java
new file mode 100755
index 000000000..94d436c05
--- /dev/null
+++ b/fine-jedis/src/com/fr/third/org/apache/commons/pool2/impl/EvictionConfig.java
@@ -0,0 +1,114 @@
+/*
+ * 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 com.fr.third.org.apache.commons.pool2.impl;
+
+/**
+ * This class is used by pool implementations to pass configuration information
+ * to {@link EvictionPolicy} instances. The {@link EvictionPolicy} may also have
+ * its own specific configuration attributes.
+ * true
if the object should be evicted, otherwise
+ * false
+ */
+ boolean evict(EvictionConfig config, PooledObjectKeyedObjectPool
implementation.
+ * GenericKeyedObjectPool
provides robust pooling functionality for
+ * keyed objects. A GenericKeyedObjectPool
can be viewed as a map
+ * of sub-pools, keyed on the (unique) key values provided to the
+ * {@link #preparePool preparePool}, {@link #addObject addObject} or
+ * {@link #borrowObject borrowObject} methods. Each time a new key value is
+ * provided to one of these methods, a sub-new pool is created under the given
+ * key to be managed by the containing GenericKeyedObjectPool.
+ * GenericKeyedObjectPool
using defaults from
+ * {@link GenericKeyedObjectPoolConfig}.
+ * @param factory the factory to be used to create entries
+ */
+ public GenericKeyedObjectPool(final KeyedPooledObjectFactoryGenericKeyedObjectPool
using a specific
+ * configuration.
+ *
+ * @param factory the factory to be used to create entries
+ * @param config The configuration to use for this pool instance. The
+ * configuration is used by value. Subsequent changes to
+ * the configuration object will not be reflected in the
+ * pool.
+ */
+ public GenericKeyedObjectPool(final KeyedPooledObjectFactory{@link #borrowObject(Object, long) borrowObject}(key,
+ * {@link #getMaxWaitMillis()})
.
+ * true
and validation fails, the instance is destroyed and the
+ * next available instance is examined. This continues until either a valid
+ * instance is returned or there are no more idle instances available.
+ * borrowMaxWaitMillis
parameter. If the number of instances checked
+ * out from the sub-pool under the given key is less than
+ * maxTotalPerKey
and the total number of instances in
+ * circulation (under all keys) is less than maxTotal
, a new
+ * instance is created, activated and (if applicable) validated and returned
+ * to the caller. If validation fails, a NoSuchElementException
+ * will be thrown.
+ * NoSuchElementException
+ * ({@link #getBlockWhenExhausted()} is false).
+ * The length of time that this method will block when
+ * {@link #getBlockWhenExhausted()} is true is determined by the value
+ * passed in to the borrowMaxWait
parameter.
+ * maxTotal
is set to a positive value and this method is
+ * invoked when at the limit with no idle instances available under the requested
+ * key, an attempt is made to create room by clearing the oldest 15% of the
+ * elements from the keyed sub-pools.
+ *