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 [EMAIL PROTECTED] #setTestOnBorrow <i>testOnBorrow</i>} is set, the pool 
will
    *    attempt to validate each object before it is returned from the
    *    [EMAIL PROTECTED] #borrowObject} method. (Using the provided factory's
  - *    [EMAIL PROTECTED] PoolableObjectFactory#validateObject} method.)  Objects 
that fail
  + *    [EMAIL PROTECTED] 
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 [EMAIL PROTECTED] #setTestOnReturn <i>testOnReturn</i>} is set, the pool 
will
    *    attempt to validate each object before it is returned to the pool in the
    *    [EMAIL PROTECTED] #returnObject} method. (Using the provided factory's
  - *    [EMAIL PROTECTED] PoolableObjectFactory#validateObject}
  + *    [EMAIL PROTECTED] 
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>
    *   [EMAIL PROTECTED] #setTestWhileIdle <i>testWhileIdle</i>} indicates whether or 
not idle
    *   objects should be validated using the factory's
  - *   [EMAIL PROTECTED] PoolableObjectFactory#validateObject} method.  Objects
  + *   [EMAIL PROTECTED] 
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 [EMAIL PROTECTED] 
KeyedPoolableObjectFactory}.  A 
  + * GenericKeyedObjectPool is not usable without a [EMAIL PROTECTED] 
KeyedPoolableObjectFactory}.  A
    * non-<code>null</code> factory must be provided either as a constructor argument
    * or via a call to [EMAIL PROTECTED] #setFactory} before the pool is used.
    * </p>
  @@ -544,7 +544,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * [EMAIL PROTECTED] PoolableObjectFactory#validateObject validated}
  +     * [EMAIL PROTECTED] 
org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned by the [EMAIL PROTECTED] #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
  -     * [EMAIL PROTECTED] PoolableObjectFactory#validateObject validated}
  +     * [EMAIL PROTECTED] 
org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned by the [EMAIL PROTECTED] #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
  -     * [EMAIL PROTECTED] PoolableObjectFactory#validateObject validated}
  +     * [EMAIL PROTECTED] 
org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned to the pool within the
        * [EMAIL PROTECTED] #returnObject}.
        *
  @@ -584,7 +584,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * [EMAIL PROTECTED] PoolableObjectFactory#validateObject validated}
  +     * [EMAIL PROTECTED] 
org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned to the pool within the
        * [EMAIL PROTECTED] #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([EMAIL PROTECTED] 
#numIdle})/abs([EMAIL PROTECTED] #getNumTestsPerEvictionRun})</tt>
  +     * When a negative value is supplied, <tt>ceil([EMAIL PROTECTED] 
#getNumIdle})/abs([EMAIL PROTECTED] #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
  -     * [EMAIL PROTECTED] PoolableObjectFactory#validateObject validated}
  +     * [EMAIL PROTECTED] 
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
  -     * [EMAIL PROTECTED] PoolableObjectFactory#validateObject validated}
  +     * [EMAIL PROTECTED] 
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
  -     * [EMAIL PROTECTED] PoolableObjectFactory#validateObject validated}
  +     * [EMAIL PROTECTED] 
org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned by the [EMAIL PROTECTED] #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
  -     * [EMAIL PROTECTED] PoolableObjectFactory#validateObject validated}
  +     * [EMAIL PROTECTED] 
org.apache.commons.pool.PoolableObjectFactory#validateObject validated}
        * before being returned to the pool within the
        * [EMAIL PROTECTED] #returnObject}.
        *
  @@ -1269,7 +1235,7 @@
   
       /**
        * When <tt>true</tt>, objects will be
  -     * [EMAIL PROTECTED] PoolableObjectFactory#validateObject validated}
  +     * [EMAIL PROTECTED] 
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([EMAIL PROTECTED] 
#numIdle})/abs([EMAIL PROTECTED] #getNumTestsPerEvictionRun})</tt>
  +     * When a negative value is supplied, <tt>ceil([EMAIL PROTECTED] 
#getNumIdle})/abs([EMAIL PROTECTED] #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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to