You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2011/06/03 12:05:40 UTC
svn commit: r1130971 - in
/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl:
BaseObjectPoolConfig.java GenericKeyedObjectPoolConfig.java
GenericObjectPoolConfig.java
Author: markt
Date: Fri Jun 3 10:05:40 2011
New Revision: 1130971
URL: http://svn.apache.org/viewvc?rev=1130971&view=rev
Log:
Add ObjectFactory support into the PoolConfig classes which allows them to completely replace the ObjectPoolFactory classes
Added:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java (with props)
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
Added: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java?rev=1130971&view=auto
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java (added)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java Fri Jun 3 10:05:40 2011
@@ -0,0 +1,238 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.pool2.impl;
+
+/**
+ * Provides the common configuration attributes used by object pool
+ * configurations.
+ */
+public abstract class BaseObjectPoolConfig {
+
+ /**
+ * The default cap on the total number of active instances from the pool.
+ */
+ public static final int DEFAULT_MAX_TOTAL = 8;
+
+ /**
+ * The default LIFO status. True means that borrowObject returns the most
+ * recently used ("last in") idle object in the pool (if there are idle
+ * instances available). False means that the pool behaves as a FIFO queue -
+ * objects are taken from the idle object pool in the order that they are
+ * returned to the pool.
+ */
+ public static final boolean DEFAULT_LIFO = true;
+
+ /**
+ * The default maximum amount of time (in milliseconds) the
+ * {@link #borrowObject} method should block before throwing an exception
+ * when the pool is exhausted and the {@link #getWhenExhaustedAction
+ * "when exhausted" action} is {@link #WHEN_EXHAUSTED_BLOCK}.
+ */
+ public static final long DEFAULT_MAX_WAIT = -1L;
+
+ /**
+ * The default cap on the number of "sleeping" instances in the pool.
+ */
+ public static final int DEFAULT_MAX_IDLE = 8;
+
+ /**
+ * The default value for {@link #getMinEvictableIdleTimeMillis}.
+ */
+ public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS =
+ 1000L * 60L * 30L;
+
+ /**
+ * The default minimum number of "sleeping" instances in the pool before
+ * before the evictor thread (if active) spawns new objects.
+ */
+ public static final int DEFAULT_MIN_IDLE = 0;
+
+ /**
+ * The default number of objects to examine per run in the idle object
+ * evictor.
+ */
+ public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;
+
+ /**
+ * The default value for {@link #getSoftMinEvictableIdleTimeMillis}.
+ */
+ public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;
+
+ /**
+ * The default "test on borrow" value.
+ */
+ public static final boolean DEFAULT_TEST_ON_BORROW = false;
+
+ /**
+ * The default "test on return" value.
+ */
+ public static final boolean DEFAULT_TEST_ON_RETURN = false;
+
+ /**
+ * The default "test while idle" value.
+ */
+ public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
+
+ /**
+ * The default "time between eviction runs" value.
+ */
+ public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
+
+ /**
+ * The default "when exhausted action" for the pool.
+ */
+ public static final WhenExhaustedAction DEFAULT_WHEN_EXHAUSTED_ACTION =
+ WhenExhaustedAction.BLOCK;
+
+
+ private int maxTotal = DEFAULT_MAX_TOTAL;
+
+ private boolean lifo = DEFAULT_LIFO;
+
+ private int maxIdle = DEFAULT_MAX_IDLE;
+
+ private long maxWait = DEFAULT_MAX_WAIT;
+
+ private long minEvictableIdleTimeMillis =
+ DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+
+ private int minIdle = DEFAULT_MIN_IDLE;
+
+ private int numTestsPerEvictionRun =
+ DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+
+ private long softMinEvictableIdleTimeMillis =
+ DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+
+ 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 WhenExhaustedAction whenExhaustedAction =
+ DEFAULT_WHEN_EXHAUSTED_ACTION;
+
+
+ public int getMaxTotal() {
+ return maxTotal;
+ }
+
+ public void setMaxTotal(int maxTotal) {
+ this.maxTotal = maxTotal;
+ }
+
+ public boolean getLifo() {
+ return lifo;
+ }
+
+ public void setLifo(boolean lifo) {
+ this.lifo = lifo;
+ }
+
+ public int getMaxIdle() {
+ return maxIdle;
+ }
+
+ public void setMaxIdle(int maxIdle) {
+ this.maxIdle = maxIdle;
+ }
+
+ public long getMaxWait() {
+ return maxWait;
+ }
+
+ public void setMaxWait(long maxWait) {
+ this.maxWait = maxWait;
+ }
+
+ public long getMinEvictableIdleTimeMillis() {
+ return minEvictableIdleTimeMillis;
+ }
+
+ public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
+ this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+ }
+
+ public int getMinIdle() {
+ return minIdle;
+ }
+
+ public void setMinIdle(int minIdle) {
+ this.minIdle = minIdle;
+ }
+
+ public int getNumTestsPerEvictionRun() {
+ return numTestsPerEvictionRun;
+ }
+
+ public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
+ this.numTestsPerEvictionRun = numTestsPerEvictionRun;
+ }
+
+ public long getSoftMinEvictableIdleTimeMillis() {
+ return softMinEvictableIdleTimeMillis;
+ }
+
+ public void setSoftMinEvictableIdleTimeMillis(
+ long softMinEvictableIdleTimeMillis) {
+ this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+ }
+
+ public boolean getTestOnBorrow() {
+ return testOnBorrow;
+ }
+
+ public void setTestOnBorrow(boolean testOnBorrow) {
+ this.testOnBorrow = testOnBorrow;
+ }
+
+ public boolean getTestOnReturn() {
+ return testOnReturn;
+ }
+
+ public void setTestOnReturn(boolean testOnReturn) {
+ this.testOnReturn = testOnReturn;
+ }
+
+ public boolean getTestWhileIdle() {
+ return testWhileIdle;
+ }
+
+ public void setTestWhileIdle(boolean testWhileIdle) {
+ this.testWhileIdle = testWhileIdle;
+ }
+
+ public long getTimeBetweenEvictionRunsMillis() {
+ return timeBetweenEvictionRunsMillis;
+ }
+
+ public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
+ this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+ }
+
+ public WhenExhaustedAction getWhenExhaustedAction() {
+ return whenExhaustedAction;
+ }
+
+ public void setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
+ this.whenExhaustedAction = whenExhaustedAction;
+ }
+}
Propchange: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java?rev=1130971&r1=1130970&r2=1130971&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java Fri Jun 3 10:05:40 2011
@@ -16,13 +16,15 @@
*/
package org.apache.commons.pool2.impl;
+import org.apache.commons.pool2.KeyedObjectPoolFactory;
+
/**
* A simple "struct" encapsulating the configuration for a
- * {@link GenericKeyedObjectPool} excluding the factory used to create objects.
+ * {@link GenericKeyedObjectPool}.
*
* @since Pool 2.0
*/
-public class GenericKeyedObjectPoolConfig extends GenericObjectPoolConfig {
+public class GenericKeyedObjectPoolConfig extends BaseObjectPoolConfig {
public static final int DEFAULT_MAX_TOTAL_PER_KEY = 8;
@@ -31,13 +33,23 @@ public class GenericKeyedObjectPoolConfi
private int maxTotalPerKey = DEFAULT_MAX_TOTAL_PER_KEY;
+ private KeyedObjectPoolFactory<?,?> factory = null;
+
public GenericKeyedObjectPoolConfig() {
// Uses a different default for maxTotal
setMaxTotal(DEFAULT_MAX_TOTAL);
}
-
-
+
+
+ public KeyedObjectPoolFactory<?,?> getFactory() {
+ return factory;
+ }
+
+ public void setFactory(KeyedObjectPoolFactory<?,?> factory) {
+ this.factory = factory;
+ }
+
public int getMaxTotalPerKey() {
return maxTotalPerKey;
}
Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java?rev=1130971&r1=1130970&r2=1130971&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java Fri Jun 3 10:05:40 2011
@@ -16,225 +16,24 @@
*/
package org.apache.commons.pool2.impl;
+import org.apache.commons.pool2.ObjectPoolFactory;
+
/**
* A simple "struct" encapsulating the configuration for a
- * {@link GenericObjectPool} excluding the factory used to create objects.
+ * {@link GenericObjectPool}.
*
* @since Pool 2.0
*/
-public class GenericObjectPoolConfig {
-
- /**
- * The default LIFO status. True means that borrowObject returns the most
- * recently used ("last in") idle object in the pool (if there are idle
- * instances available). False means that the pool behaves as a FIFO queue -
- * objects are taken from the idle object pool in the order that they are
- * returned to the pool.
- */
- public static final boolean DEFAULT_LIFO = true;
-
- /**
- * The default cap on the total number of active instances from the pool.
- */
- public static final int DEFAULT_MAX_TOTAL = 8;
-
- /**
- * The default maximum amount of time (in milliseconds) the
- * {@link #borrowObject} method should block before throwing an exception
- * when the pool is exhausted and the {@link #getWhenExhaustedAction
- * "when exhausted" action} is {@link #WHEN_EXHAUSTED_BLOCK}.
- */
- public static final long DEFAULT_MAX_WAIT = -1L;
-
- /**
- * The default cap on the number of "sleeping" instances in the pool.
- */
- public static final int DEFAULT_MAX_IDLE = 8;
-
- /**
- * The default value for {@link #getMinEvictableIdleTimeMillis}.
- */
- public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS =
- 1000L * 60L * 30L;
-
- /**
- * The default minimum number of "sleeping" instances in the pool before
- * before the evictor thread (if active) spawns new objects.
- */
- public static final int DEFAULT_MIN_IDLE = 0;
-
- /**
- * The default number of objects to examine per run in the idle object
- * evictor.
- */
- public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;
-
- /**
- * The default value for {@link #getSoftMinEvictableIdleTimeMillis}.
- */
- public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;
-
- /**
- * The default "test on borrow" value.
- */
- public static final boolean DEFAULT_TEST_ON_BORROW = false;
-
- /**
- * The default "test on return" value.
- */
- public static final boolean DEFAULT_TEST_ON_RETURN = false;
-
- /**
- * The default "test while idle" value.
- */
- public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
-
- /**
- * The default "time between eviction runs" value.
- */
- public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
-
- /**
- * The default "when exhausted action" for the pool.
- */
- public static final WhenExhaustedAction DEFAULT_WHEN_EXHAUSTED_ACTION =
- WhenExhaustedAction.BLOCK;
-
-
- private boolean lifo = DEFAULT_LIFO;
-
- private int maxIdle = DEFAULT_MAX_IDLE;
-
- private int maxTotal = DEFAULT_MAX_TOTAL;
-
- private long maxWait = DEFAULT_MAX_WAIT;
+public class GenericObjectPoolConfig extends BaseObjectPoolConfig {
- private long minEvictableIdleTimeMillis =
- DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
-
- private int minIdle = DEFAULT_MIN_IDLE;
-
- private int numTestsPerEvictionRun =
- DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
-
- private long softMinEvictableIdleTimeMillis =
- DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
-
- 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 WhenExhaustedAction whenExhaustedAction =
- DEFAULT_WHEN_EXHAUSTED_ACTION;
-
-
- public boolean getLifo() {
- return lifo;
- }
-
- public void setLifo(boolean lifo) {
- this.lifo = lifo;
- }
-
- public int getMaxIdle() {
- return maxIdle;
- }
-
- public void setMaxIdle(int maxIdle) {
- this.maxIdle = maxIdle;
- }
-
- public int getMaxTotal() {
- return maxTotal;
- }
+ private ObjectPoolFactory<?> factory = null;
- public void setMaxTotal(int maxTotal) {
- this.maxTotal = maxTotal;
- }
-
- public long getMaxWait() {
- return maxWait;
- }
-
- public void setMaxWait(long maxWait) {
- this.maxWait = maxWait;
- }
-
- public long getMinEvictableIdleTimeMillis() {
- return minEvictableIdleTimeMillis;
- }
-
- public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
- this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
- }
-
- public int getMinIdle() {
- return minIdle;
- }
-
- public void setMinIdle(int minIdle) {
- this.minIdle = minIdle;
- }
-
- public int getNumTestsPerEvictionRun() {
- return numTestsPerEvictionRun;
- }
-
- public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
- this.numTestsPerEvictionRun = numTestsPerEvictionRun;
- }
-
- public long getSoftMinEvictableIdleTimeMillis() {
- return softMinEvictableIdleTimeMillis;
- }
-
- public void setSoftMinEvictableIdleTimeMillis(
- long softMinEvictableIdleTimeMillis) {
- this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
- }
-
- public boolean getTestOnBorrow() {
- return testOnBorrow;
- }
-
- public void setTestOnBorrow(boolean testOnBorrow) {
- this.testOnBorrow = testOnBorrow;
- }
-
- public boolean getTestOnReturn() {
- return testOnReturn;
- }
-
- public void setTestOnReturn(boolean testOnReturn) {
- this.testOnReturn = testOnReturn;
- }
-
- public boolean getTestWhileIdle() {
- return testWhileIdle;
- }
-
- public void setTestWhileIdle(boolean testWhileIdle) {
- this.testWhileIdle = testWhileIdle;
- }
-
- public long getTimeBetweenEvictionRunsMillis() {
- return timeBetweenEvictionRunsMillis;
- }
-
- public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
- this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
- }
- public WhenExhaustedAction getWhenExhaustedAction() {
- return whenExhaustedAction;
+ public ObjectPoolFactory<?> getFactory() {
+ return factory;
}
- public void setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
- this.whenExhaustedAction = whenExhaustedAction;
+ public void setFactory(ObjectPoolFactory<?> factory) {
+ this.factory = factory;
}
}