commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons/pool/src/test/org/apache/commons/pool/impl TestGenericKeyedObjectPool.java TestGenericObjectPool.java TestSoftReferenceObjectPool.java TestStackKeyedObjectPool.java TestStackObjectPool.java
Date Wed, 30 Oct 2002 22:54:42 GMT
rwaldhoff    2002/10/30 14:54:42

  Modified:    pool/src/java/org/apache/commons/pool
                        BaseKeyedObjectPool.java BaseObjectPool.java
                        KeyedObjectPool.java ObjectPool.java
               pool/src/java/org/apache/commons/pool/impl
                        GenericKeyedObjectPool.java GenericObjectPool.java
                        SoftReferenceObjectPool.java
                        StackKeyedObjectPool.java StackObjectPool.java
               pool/src/test/org/apache/commons/pool/impl
                        TestGenericKeyedObjectPool.java
                        TestGenericObjectPool.java
                        TestSoftReferenceObjectPool.java
                        TestStackKeyedObjectPool.java
                        TestStackObjectPool.java
  Log:
  add invalidateObject methods to ObjectPool and KeyedObjectPool, along the lines of Nayan
Hajratwala's patch (see <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13705>)
  add simple tests for this as well
  
  Revision  Changes    Path
  1.4       +5 -4      jakarta-commons/pool/src/java/org/apache/commons/pool/BaseKeyedObjectPool.java
  
  Index: BaseKeyedObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/BaseKeyedObjectPool.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BaseKeyedObjectPool.java	3 May 2002 17:01:06 -0000	1.3
  +++ BaseKeyedObjectPool.java	30 Oct 2002 22:54:41 -0000	1.4
  @@ -72,6 +72,7 @@
   public abstract class BaseKeyedObjectPool implements KeyedObjectPool {
       public abstract Object borrowObject(Object key) throws Exception;
       public abstract void returnObject(Object key, Object obj) throws Exception;
  +    public abstract void invalidateObject(Object key, Object obj) throws Exception;
   
       /** @deprecated Use {@link #getNumIdle} instead. Will be removed by release 2.0. */
       public final int numIdle(Object key) throws UnsupportedOperationException {
  
  
  
  1.6       +5 -4      jakarta-commons/pool/src/java/org/apache/commons/pool/BaseObjectPool.java
  
  Index: BaseObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/BaseObjectPool.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BaseObjectPool.java	3 May 2002 17:01:06 -0000	1.5
  +++ BaseObjectPool.java	30 Oct 2002 22:54:41 -0000	1.6
  @@ -72,6 +72,7 @@
   public abstract class BaseObjectPool implements ObjectPool {
       public abstract Object borrowObject() throws Exception;
       public abstract void returnObject(Object obj) throws Exception;
  +    public abstract void invalidateObject(Object obj) throws Exception;
   
       /**
        * @deprecated Use {@link #getNumIdle} instead. Will be removed by release 2.0.
  
  
  
  1.7       +24 -5     jakarta-commons/pool/src/java/org/apache/commons/pool/KeyedObjectPool.java
  
  Index: KeyedObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/KeyedObjectPool.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- KeyedObjectPool.java	3 May 2002 17:01:06 -0000	1.6
  +++ KeyedObjectPool.java	30 Oct 2002 22:54:41 -0000	1.7
  @@ -120,7 +120,7 @@
        * By contract, <i>obj</i> MUST have been obtained
        * using {@link #borrowObject(java.lang.Object) <tt>borrowObject</tt>}
        * or a related method as defined in an implementation
  -     * or sub-interface,
  +     * or sub-interface 
        * using a <i>key</i> that is equivalent to the one used to
        * borrow the <tt>Object</tt> in the first place.
        *
  @@ -128,6 +128,25 @@
        * @param obj a {@link #borrowObject(java.lang.Object) borrowed} instance to be returned.
        */
       void returnObject(Object key, Object obj) throws Exception;
  +
  +    /**
  +     * Invalidates an object from the pool
  +     * By contract, <i>obj</i> MUST have been obtained
  +     * using {@link #borrowObject() borrowObject}
  +     * or a related method as defined in an implementation
  +     * or sub-interface 
  +     * using a <i>key</i> that is equivalent to the one used to
  +     * borrow the <tt>Object</tt> in the first place.
  +     * <p>
  +     * This method should be used when an object that has been borrowed
  +     * is determined (due to an exception or other problem) to be invalid.
  +     * If the connection should be validated before or after borrowing,
  +     * then the {@link PoolableObjectFactory#validateObject} method should be
  +     * used instead.
  +     *
  +     * @param obj a {@link #borrowObject borrowed} instance to be returned.
  +     */
  +    void invalidateObject(Object key, Object obj) throws Exception;
   
       /**
        * Returns the number of instances
  
  
  
  1.7       +22 -5     jakarta-commons/pool/src/java/org/apache/commons/pool/ObjectPool.java
  
  Index: ObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/ObjectPool.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ObjectPool.java	1 May 2002 06:02:34 -0000	1.6
  +++ ObjectPool.java	30 Oct 2002 22:54:41 -0000	1.7
  @@ -111,9 +111,26 @@
        * or a related method as defined in an implementation
        * or sub-interface.
        *
  -     * @param obj a {@link #borrowObject() borrowed} instance to be returned.
  +     * @param obj a {@link #borrowObject borrowed} instance to be returned.
        */
       void returnObject(Object obj) throws Exception;
  +
  +    /**
  +     * Invalidates an object from the pool
  +     * By contract, <i>obj</i> MUST have been obtained
  +     * using {@link #borrowObject() borrowObject}
  +     * or a related method as defined in an implementation
  +     * or sub-interface.
  +     * <p>
  +     * This method should be used when an object that has been borrowed
  +     * is determined (due to an exception or other problem) to be invalid.
  +     * If the connection should be validated before or after borrowing,
  +     * then the {@link PoolableObjectFactory#validateObject} method should be
  +     * used instead.
  +     *
  +     * @param obj a {@link #borrowObject borrowed} instance to be returned.
  +     */
  +    void invalidateObject(Object obj) throws Exception;
   
       /**
        * Return the number of instances
  
  
  
  1.8       +18 -4     jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java
  
  Index: GenericKeyedObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPool.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- GenericKeyedObjectPool.java	5 Sep 2002 18:10:06 -0000	1.7
  +++ GenericKeyedObjectPool.java	30 Oct 2002 22:54:41 -0000	1.8
  @@ -926,6 +926,20 @@
           }
       }
   
  +    public synchronized void invalidateObject(Object key, Object obj) throws Exception
{
  +        _totalActive--;
  +        Integer active = (Integer)(_activeMap.get(key));
  +        if(null == active) {
  +            // do nothing, either null or zero is OK
  +        } else if(active.intValue() <= 1) {
  +            _activeMap.remove(key);
  +        } else {
  +            _activeMap.put(key, new Integer(active.intValue() - 1));
  +        }
  +        _factory.destroyObject(key,obj);
  +        notifyAll(); // _totalActive has changed
  +    }
  +
       synchronized public void close() throws Exception {
           clear();
           _poolList = null;
  
  
  
  1.9       +10 -4     jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
  
  Index: GenericObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- GenericObjectPool.java	30 Oct 2002 00:55:06 -0000	1.8
  +++ GenericObjectPool.java	30 Oct 2002 22:54:41 -0000	1.9
  @@ -770,6 +770,12 @@
           }
       }
   
  +    public synchronized void invalidateObject(Object obj) throws Exception {
  +        _numActive--;
  +        _factory.destroyObject(obj);
  +        notifyAll(); // _numActive has changed
  +    }
  +
       public synchronized void clear() {
           Iterator it = _pool.iterator();
           while(it.hasNext()) {
  
  
  
  1.6       +10 -4     jakarta-commons/pool/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
  
  Index: SoftReferenceObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SoftReferenceObjectPool.java	1 May 2002 06:02:34 -0000	1.5
  +++ SoftReferenceObjectPool.java	30 Oct 2002 22:54:42 -0000	1.6
  @@ -152,6 +152,12 @@
   
       }
   
  +    public synchronized void invalidateObject(Object obj) throws Exception {
  +        _numActive--;
  +        _factory.destroyObject(obj);
  +        notifyAll(); // _numActive has changed
  +    }
  +
       /** Returns an approximation not less than the of the number of idle instances in the
pool. */
       public int getNumIdle() {
           return _pool.size();
  
  
  
  1.6       +12 -4     jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
  
  Index: StackKeyedObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StackKeyedObjectPool.java	5 Jun 2002 22:02:22 -0000	1.5
  +++ StackKeyedObjectPool.java	30 Oct 2002 22:54:42 -0000	1.6
  @@ -219,6 +219,14 @@
           _activeCount.put(key,new Integer(old.intValue() - 1));
       }
   
  +    public synchronized void invalidateObject(Object key, Object obj) throws Exception
{
  +        _totActive--;
  +        Integer old = (Integer)(_activeCount.get(key));
  +        _activeCount.put(key,new Integer(old.intValue() - 1));
  +        _factory.destroyObject(key,obj);
  +        notifyAll(); // _totalActive has changed
  +    }
  +
       public int getNumIdle() {
           return _totIdle;
       }
  
  
  
  1.6       +10 -4     jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackObjectPool.java
  
  Index: StackObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/StackObjectPool.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StackObjectPool.java	1 May 2002 06:02:34 -0000	1.5
  +++ StackObjectPool.java	30 Oct 2002 22:54:42 -0000	1.6
  @@ -205,6 +205,12 @@
           }
       }
   
  +    public synchronized void invalidateObject(Object obj) throws Exception {
  +        _numActive--;
  +        _factory.destroyObject(obj);
  +        notifyAll(); // _numActive has changed
  +    }
  +
       public int getNumIdle() {
           return _pool.size();
       }
  
  
  
  1.7       +19 -4     jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
  
  Index: TestGenericKeyedObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestGenericKeyedObjectPool.java	5 Sep 2002 18:10:06 -0000	1.6
  +++ TestGenericKeyedObjectPool.java	30 Oct 2002 22:54:42 -0000	1.7
  @@ -227,6 +227,21 @@
           assertEquals("2",obj2);
       }
   
  +    public void testInvalidateObject() throws Exception {
  +        assertEquals(0,pool.getNumActive(""));
  +        assertEquals(0,pool.getNumIdle(""));
  +        Object obj0 = pool.borrowObject("");
  +        Object obj1 = pool.borrowObject("");
  +        assertEquals(2,pool.getNumActive(""));
  +        assertEquals(0,pool.getNumIdle(""));
  +        pool.invalidateObject("",obj0);
  +        assertEquals(1,pool.getNumActive(""));
  +        assertEquals(0,pool.getNumIdle(""));
  +        pool.invalidateObject("",obj1);
  +        assertEquals(0,pool.getNumActive(""));
  +        assertEquals(0,pool.getNumIdle(""));
  +    }
  +
       public void testMaxIdle() throws Exception {
           pool.setMaxActive(100);
           pool.setMaxIdle(8);
  
  
  
  1.7       +19 -4     jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
  
  Index: TestGenericObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestGenericObjectPool.java	5 Sep 2002 18:10:06 -0000	1.6
  +++ TestGenericObjectPool.java	30 Oct 2002 22:54:42 -0000	1.7
  @@ -178,6 +178,21 @@
           assertEquals("2",obj2);
       }
   
  +    public void testInvalidateObject() throws Exception {
  +        assertEquals(0,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +        Object obj0 = pool.borrowObject();
  +        Object obj1 = pool.borrowObject();
  +        assertEquals(2,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +        pool.invalidateObject(obj0);
  +        assertEquals(1,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +        pool.invalidateObject(obj1);
  +        assertEquals(0,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +    }
  +
       public void testMaxIdle() throws Exception {
           pool.setMaxActive(100);
           pool.setMaxIdle(8);
  
  
  
  1.3       +19 -4     jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java
  
  Index: TestSoftReferenceObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestSoftReferenceObjectPool.java	1 May 2002 06:02:35 -0000	1.2
  +++ TestSoftReferenceObjectPool.java	30 Oct 2002 22:54:42 -0000	1.3
  @@ -166,4 +166,19 @@
           assertEquals("2",obj2);
       }
   
  +    public void testInvalidateObject() throws Exception {
  +        assertEquals(0,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +        Object obj0 = pool.borrowObject();
  +        Object obj1 = pool.borrowObject();
  +        assertEquals(2,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +        pool.invalidateObject(obj0);
  +        assertEquals(1,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +        pool.invalidateObject(obj1);
  +        assertEquals(0,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +    }
  +
   }
  
  
  
  1.5       +19 -4     jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java
  
  Index: TestStackKeyedObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestStackKeyedObjectPool.java	5 Jun 2002 22:02:22 -0000	1.4
  +++ TestStackKeyedObjectPool.java	30 Oct 2002 22:54:42 -0000	1.5
  @@ -211,6 +211,21 @@
           assertEquals("2",obj2);
       }
   
  +    public void testInvalidateObject() throws Exception {
  +        assertEquals(0,pool.getNumActive(""));
  +        assertEquals(0,pool.getNumIdle(""));
  +        Object obj0 = pool.borrowObject("");
  +        Object obj1 = pool.borrowObject("");
  +        assertEquals(2,pool.getNumActive(""));
  +        assertEquals(0,pool.getNumIdle(""));
  +        pool.invalidateObject("",obj0);
  +        assertEquals(1,pool.getNumActive(""));
  +        assertEquals(0,pool.getNumIdle(""));
  +        pool.invalidateObject("",obj1);
  +        assertEquals(0,pool.getNumActive(""));
  +        assertEquals(0,pool.getNumIdle(""));
  +    }
  +
       public void testCloseBug() throws Exception {
           {
               Object obj0 = pool.borrowObject("");
  
  
  
  1.4       +19 -4     jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
  
  Index: TestStackObjectPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestStackObjectPool.java	1 May 2002 06:02:35 -0000	1.3
  +++ TestStackObjectPool.java	30 Oct 2002 22:54:42 -0000	1.4
  @@ -162,6 +162,21 @@
           assertEquals("2",obj2);
       }
   
  +    public void testInvalidateObject() throws Exception {
  +        assertEquals(0,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +        Object obj0 = pool.borrowObject();
  +        Object obj1 = pool.borrowObject();
  +        assertEquals(2,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +        pool.invalidateObject(obj0);
  +        assertEquals(1,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +        pool.invalidateObject(obj1);
  +        assertEquals(0,pool.getNumActive());
  +        assertEquals(0,pool.getNumIdle());
  +    }
  +
       public void testIdleCap() throws Exception {
           Object[] active = new Object[100];
           for(int i=0;i<100;i++) {
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message