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/java/org/apache/commons/pool/impl GenericKeyedObjectPool.java
Date Thu, 13 Mar 2003 18:47:54 GMT
rwaldhoff    2003/03/13 10:47:54

  Modified:    pool/src/java/org/apache/commons/pool/impl
                        GenericKeyedObjectPool.java
  Log:
  apply Quinton McCombs's javadoc and clean patch
  see <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17962>
  
  Revision  Changes    Path
  1.13      +44 -78    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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- GenericKeyedObjectPool.java	5 Mar 2003 19:22:52 -0000	1.12
  +++ GenericKeyedObjectPool.java	13 Mar 2003 18:47:53 -0000	1.13
  @@ -121,7 +121,7 @@
    *    When {@link #setTestOnBorrow <i>testOnBorrow</i>} is set, the pool will
    *    attempt to validate each object before it is returned from the
    *    {@link #borrowObject} method. (Using the provided factory's
  - *    {@link PoolableObjectFactory#validateObject} method.)  Objects that fail
  + *    {@link org.apache.commons.pool.PoolableObjectFactory#validateObject} method.)  Objects
that fail
    *    to validate will be dropped from the pool, and a different object will
    *    be borrowed.
    *  </li>
  @@ -129,7 +129,7 @@
    *    When {@link #setTestOnReturn <i>testOnReturn</i>} is set, the pool will
    *    attempt to validate each object before it is returned to the pool in the
    *    {@link #returnObject} method. (Using the provided factory's
  - *    {@link PoolableObjectFactory#validateObject}
  + *    {@link org.apache.commons.pool.PoolableObjectFactory#validateObject}
    *    method.)  Objects that fail to validate will be dropped from the pool.
    *  </li>
    * </ul>
  @@ -153,12 +153,12 @@
    *  <li>
    *   {@link #setTestWhileIdle <i>testWhileIdle</i>} indicates whether or not
idle
    *   objects should be validated using the factory's
  - *   {@link PoolableObjectFactory#validateObject} method.  Objects
  + *   {@link org.apache.commons.pool.PoolableObjectFactory#validateObject} method.  Objects
    *   that fail to validate will be dropped from the pool.
    *  </li>
    * </ul>
    * <p>
  - * GenericKeyedObjectPool is not usable without a {@link KeyedPoolableObjectFactory}. 
A 
  + * GenericKeyedObjectPool is not usable without a {@link KeyedPoolableObjectFactory}. 
A
    * non-<code>null</code> factory must be provided either as a constructor argument
    * or via a call to {@link #setFactory} before the pool is used.
    * </p>
  @@ -544,7 +544,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * {@link PoolableObjectFactory#validateObject validated}
  +     * {@link org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned by the {@link #borrowObject}
        * method.  If the object fails to validate,
        * it will be dropped from the pool, and we will attempt
  @@ -558,7 +558,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * {@link PoolableObjectFactory#validateObject validated}
  +     * {@link org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned by the {@link #borrowObject}
        * method.  If the object fails to validate,
        * it will be dropped from the pool, and we will attempt
  @@ -572,7 +572,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * {@link PoolableObjectFactory#validateObject validated}
  +     * {@link org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned to the pool within the
        * {@link #returnObject}.
        *
  @@ -584,7 +584,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * {@link PoolableObjectFactory#validateObject validated}
  +     * {@link org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned to the pool within the
        * {@link #returnObject}.
        *
  @@ -645,7 +645,7 @@
        * Sets the number of objects to examine during each run of the
        * idle object evictor thread (if any).
        * <p>
  -     * When a negative value is supplied, <tt>ceil({@link #numIdle})/abs({@link #getNumTestsPerEvictionRun})</tt>
  +     * When a negative value is supplied, <tt>ceil({@link #getNumIdle})/abs({@link
#getNumTestsPerEvictionRun})</tt>
        * tests will be run.  I.e., when the value is <i>-n</i>, roughly one <i>n</i>th
of the
        * idle objects will be tested per run.
        *
  @@ -684,7 +684,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * {@link PoolableObjectFactory#validateObject validated}
  +     * {@link org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * by the idle object evictor (if any).  If an object
        * fails to validate, it will be dropped from the pool.
        *
  @@ -697,7 +697,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * {@link PoolableObjectFactory#validateObject validated}
  +     * {@link org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * by the idle object evictor (if any).  If an object
        * fails to validate, it will be dropped from the pool.
        *
  @@ -788,11 +788,6 @@
               }
               _factory.activateObject(key,pair.value);
               if(_testOnBorrow && !_factory.validateObject(key,pair.value)) {
  -                try {
  -                    _factory.passivateObject(key,pair.value);
  -                } catch(Exception e) {
  -                    ; // ignored, we're throwing it out anyway
  -                }
                   _factory.destroyObject(key,pair.value);
               } else {
                   Integer active = (Integer)(_activeMap.get(key));
  @@ -808,12 +803,10 @@
       }
   
       public synchronized void clear() {
  -        Iterator keyiter = _poolList.iterator();
  -        while(keyiter.hasNext()) {
  +        for(Iterator keyiter = _poolList.iterator(); keyiter.hasNext(); ) {
               Object key = keyiter.next();
               CursorableLinkedList list = (CursorableLinkedList)(_poolMap.get(key));
  -            Iterator it = list.iterator();
  -            while(it.hasNext()) {
  +            for(Iterator it = list.iterator(); it.hasNext(); ) {
                   try {
                       _factory.destroyObject(key,((ObjectTimestampPair)(it.next())).value);
                   } catch(Exception e) {
  @@ -834,8 +827,7 @@
               return;
           } else {
               _poolList.remove(key);
  -            Iterator it = pool.iterator();
  -            while(it.hasNext()) {
  +            for(Iterator it = pool.iterator(); it.hasNext(); ) {
                   try {
                       _factory.destroyObject(key,((ObjectTimestampPair)(it.next())).value);
                   } catch(Exception e) {
  @@ -1014,71 +1006,45 @@
                   // if the _evictionCursor has a previous object, then test it
                   if(_evictionCursor.hasPrevious()) {
                       ObjectTimestampPair pair = (ObjectTimestampPair)(_evictionCursor.previous());
  +                    boolean removeObject=false;
                       if(_minEvictableIdleTimeMillis > 0 &&
                          System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis)
{
  -                        try {
  -                            _evictionCursor.remove();
  -                            _totalIdle--;
  -                            _factory.destroyObject(key,pair.value);
  -
  -                            // if that was the last object for that key, drop that pool
  -                            if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty() )
{
  -                                _poolMap.remove(key);
  -                                _poolList.remove(key);
  -                            }
  -
  -
  -                        } catch(Exception e) {
  -                            ; // ignored
  -                        }
  +                       removeObject=true;
                       } else if(_testWhileIdle) {
                           boolean active = false;
                           try {
                               _factory.activateObject(key,pair.value);
                               active = true;
                           } catch(Exception e) {
  -                            _evictionCursor.remove();
  -                            try {
  -                                _factory.passivateObject(key,pair.value);
  -                            } catch(Exception ex) {
  -                                ; // ignored
  -                            }
  -                            _factory.destroyObject(key,pair.value);
  +                            removeObject=true;
                           }
                           if(active) {
                               if(!_factory.validateObject(key,pair.value)) {
  -                                try {
  -                                    _evictionCursor.remove();
  -                                    _totalIdle--;
  -                                    try {
  -                                        _factory.passivateObject(key,pair.value);
  -                                    } catch(Exception e) {
  -                                        ; // ignored
  -                                    }
  -                                    _factory.destroyObject(key,pair.value);
  -                                    if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty()
) {
  -                                        _poolMap.remove(key);
  -                                        _poolList.remove(key);
  -                                    }
  -
  -                                } catch(Exception e) {
  -                                    ; // ignored
  -                                }
  +                                removeObject=true;
                               } else {
                                   try {
                                       _factory.passivateObject(key,pair.value);
                                   } catch(Exception e) {
  -                                    _evictionCursor.remove();
  -                                    _totalIdle--;
  -                                    _factory.destroyObject(key,pair.value);
  -                                    if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty()
) {
  -                                        _poolMap.remove(key);
  -                                        _poolList.remove(key);
  -                                    }
  +                                    removeObject=true;
                                   }
                               }
                           }
                       }
  +                    if(removeObject) {
  +                        try {
  +                            _evictionCursor.remove();
  +                            _totalIdle--;
  +                            _factory.destroyObject(key,pair.value);
  +
  +                            // if that was the last object for that key, drop that pool
  +                            if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty() )
{
  +                                _poolMap.remove(key);
  +                                _poolList.remove(key);
  +                            }
  +                        } catch(Exception e) {
  +                            ; // ignored
  +                        }
  +                    }
                   } else {
                       // else the _evictionCursor is done, so close it and loop around
                       if(_evictionCursor != null) {
  @@ -1089,7 +1055,7 @@
               }
           }
       }
  -    
  +
       //--- package methods --------------------------------------------
   
       synchronized String debugInfo() {
  @@ -1245,7 +1211,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * {@link PoolableObjectFactory#validateObject validated}
  +     * {@link org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned by the {@link #borrowObject}
        * method.  If the object fails to validate,
        * it will be dropped from the pool, and we will attempt
  @@ -1258,7 +1224,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * {@link PoolableObjectFactory#validateObject validated}
  +     * {@link org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned to the pool within the
        * {@link #returnObject}.
        *
  @@ -1269,7 +1235,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * {@link PoolableObjectFactory#validateObject validated}
  +     * {@link org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * by the idle object evictor (if any).  If an object
        * fails to validate, it will be dropped from the pool.
        *
  @@ -1295,7 +1261,7 @@
        * The number of objects to examine during each run of the
        * idle object evictor thread (if any).
        * <p>
  -     * When a negative value is supplied, <tt>ceil({@link #numIdle})/abs({@link #getNumTestsPerEvictionRun})</tt>
  +     * When a negative value is supplied, <tt>ceil({@link #getNumIdle})/abs({@link
#getNumTestsPerEvictionRun})</tt>
        * tests will be run.  I.e., when the value is <i>-n</i>, roughly one <i>n</i>th
of the
        * idle objects will be tested per run.
        *
  @@ -1345,7 +1311,7 @@
        * My idle object eviction thread, if any.
        */
       private Evictor _evictor = null;
  -    
  +
       private CursorableLinkedList.Cursor _evictionCursor = null;
       private CursorableLinkedList.Cursor _evictionKeyCursor = null;
   
  
  
  

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


Mime
View raw message