commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1135312 - in /commons/proper/pool/trunk/src: changes/changes.xml java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java java/org/apache/commons/pool2/impl/GenericObjectPool.java
Date Mon, 13 Jun 2011 22:05:41 GMT
Author: markt
Date: Mon Jun 13 22:05:41 2011
New Revision: 1135312

URL: http://svn.apache.org/viewvc?rev=1135312&view=rev
Log:
POOL-134
Add the ability to specify a per call wait time when borrowing an object.

Modified:
    commons/proper/pool/trunk/src/changes/changes.xml
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java

Modified: commons/proper/pool/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/changes/changes.xml?rev=1135312&r1=1135311&r2=1135312&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Mon Jun 13 22:05:41 2011
@@ -58,6 +58,9 @@
       Ensure GKOP.preparePool() throws an exception if no factory has been
       defined.
     </action>
+    <action dev=markt" type="fix" issue="POOL-134">
+      Add the ability to specify a per call wait time when borrowing an object.
+    </action>
   </release>
   <release version="1.5.6" date="2011-04-03" description="This is a patch release, including
bugfixes only.">
     <action dev="markt" type="fix" issue="POOL-179" due-to="Axel Grossmann">

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1135312&r1=1135311&r2=1135312&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
Mon Jun 13 22:05:41 2011
@@ -666,8 +666,22 @@ public class GenericKeyedObjectPool<K,T>
      * @return object instance from the keyed pool
      * @throws NoSuchElementException if a keyed object instance cannot be returned.
      */
-     @Override
+    @Override
     public T borrowObject(K key) throws Exception {
+        return borrowObject(key, _maxWait);
+    }
+     
+    /**
+     * <p>Borrows an object from the keyed pool associated with the given key
+     * using a user specific waiting time which only applies if
+     * {@link WhenExhaustedAction#BLOCK} is used.</p>
+     * 
+     * @param key pool key
+     * @param borrowMaxWait
+     * @return object instance from the keyed pool
+     * @throws NoSuchElementException if a keyed object instance cannot be returned.
+     */
+    public T borrowObject(K key, long borrowMaxWait) throws Exception {
 
         assertOpen();
 
@@ -676,7 +690,6 @@ public class GenericKeyedObjectPool<K,T>
         // Get local copy of current config so it is consistent for entire
         // method execution
         WhenExhaustedAction whenExhaustedAction = _whenExhaustedAction;
-        long maxWait = _maxWait;
 
         boolean create;
         ObjectDeque<T> objectDeque = register(key);
@@ -707,11 +720,11 @@ public class GenericKeyedObjectPool<K,T>
                         p = create(key);
                     }
                     if (p == null && objectDeque != null) {
-                        if (maxWait < 1) {
+                        if (borrowMaxWait < 1) {
                             p = objectDeque.getIdleObjects().takeFirst();
                         } else {
-                            p = objectDeque.getIdleObjects().pollFirst(maxWait,
-                                    TimeUnit.MILLISECONDS);
+                            p = objectDeque.getIdleObjects().pollFirst(
+                                    borrowMaxWait, TimeUnit.MILLISECONDS);
                         }
                     }
                     if (p == null) {

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java?rev=1135312&r1=1135311&r2=1135312&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
Mon Jun 13 22:05:41 2011
@@ -659,7 +659,20 @@ public class GenericObjectPool<T> extend
      */
     @Override
     public T borrowObject() throws Exception {
-
+        return borrowObject(_maxWait);
+    }
+    
+    /**
+     * Borrow an object from the pool using a user specific waiting time which
+     * only applies if {@link WhenExhaustedAction#BLOCK} is used.
+     * 
+     * @param borrowMaxWait The time to wait in milliseconds for an object to
+     *                      become available
+     * @return object instance
+     * @throws NoSuchElementException
+     *             if an instance cannot be returned
+     */
+    public T borrowObject(long borrowMaxWait) throws Exception {
         assertOpen();
 
         PooledObject<T> p = null;
@@ -667,7 +680,6 @@ public class GenericObjectPool<T> extend
         // Get local copy of current config so it is consistent for entire
         // method execution
         WhenExhaustedAction whenExhaustedAction = _whenExhaustedAction;
-        long maxWait = _maxWait;
 
         boolean create;
 
@@ -692,10 +704,10 @@ public class GenericObjectPool<T> extend
                     p = create();
                 }
                 if (p == null) {
-                    if (maxWait < 1) {
+                    if (borrowMaxWait < 1) {
                         p = _idleObjects.takeFirst();
                     } else {
-                        p = _idleObjects.pollFirst(maxWait,
+                        p = _idleObjects.pollFirst(borrowMaxWait,
                                 TimeUnit.MILLISECONDS);
                     }
                 }



Mime
View raw message