Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 19B6E5E0F for ; Tue, 10 May 2011 16:30:46 +0000 (UTC) Received: (qmail 98687 invoked by uid 500); 10 May 2011 16:30:45 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 98628 invoked by uid 500); 10 May 2011 16:30:45 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 98621 invoked by uid 99); 10 May 2011 16:30:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 May 2011 16:30:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 May 2011 16:30:42 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EF7E023889ED; Tue, 10 May 2011 16:30:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1101531 - /commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java Date: Tue, 10 May 2011 16:30:20 -0000 To: commits@commons.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110510163020.EF7E023889ED@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: markt Date: Tue May 10 16:30:20 2011 New Revision: 1101531 URL: http://svn.apache.org/viewvc?rev=1101531&view=rev Log: Various renames in preparation for the next big change. Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java 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=1101531&r1=1101530&r2=1101531&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 Tue May 10 16:30:20 2011 @@ -19,6 +19,7 @@ package org.apache.commons.pool2.impl; import java.util.ArrayList; import java.util.Collection; +import java.util.Deque; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -596,7 +597,7 @@ public class GenericObjectPool extend _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis; _testWhileIdle = testWhileIdle; - _pool = new LinkedBlockingDeque>(); + _idleObjects = new LinkedBlockingDeque>(); startEvictor(_timeBetweenEvictionRunsMillis); } @@ -1147,7 +1148,7 @@ public class GenericObjectPool extend } else { // Case 3: An object has been allocated _numInternalProcessing--; - _numActive++; + _numActiveOld++; returnObject(latch.getPair().getObject()); } } @@ -1205,7 +1206,7 @@ public class GenericObjectPool extend } synchronized(this) { _numInternalProcessing--; - _numActive++; + _numActiveOld++; } return latch.getPair().getObject(); } @@ -1247,9 +1248,9 @@ public class GenericObjectPool extend // First use any objects in the pool to clear the queue for (;;) { - if (!_pool.isEmpty() && !_allocationQueue.isEmpty()) { + if (!_idleObjects.isEmpty() && !_allocationQueue.isEmpty()) { Latch latch = _allocationQueue.removeFirst(); - latch.setPair(_pool.removeFirst()); + latch.setPair(_idleObjects.removeFirst()); _numInternalProcessing++; synchronized (latch) { latch.notify(); @@ -1261,7 +1262,7 @@ public class GenericObjectPool extend // Second utilise any spare capacity to create new objects for(;;) { - if((!_allocationQueue.isEmpty()) && (_maxActive < 0 || (_numActive + _numInternalProcessing) < _maxActive)) { + if((!_allocationQueue.isEmpty()) && (_maxActive < 0 || (_numActiveOld + _numInternalProcessing) < _maxActive)) { Latch latch = _allocationQueue.removeFirst(); latch.setMayCreate(true); _numInternalProcessing++; @@ -1288,7 +1289,7 @@ public class GenericObjectPool extend } } finally { synchronized (this) { - _numActive--; + _numActiveOld--; } allocate(); } @@ -1314,9 +1315,9 @@ public class GenericObjectPool extend List> toDestroy = new ArrayList>(); synchronized(this) { - toDestroy.addAll(_pool); - _numInternalProcessing = _numInternalProcessing + _pool.size(); - _pool.clear(); + toDestroy.addAll(_idleObjects); + _numInternalProcessing = _numInternalProcessing + _idleObjects.size(); + _idleObjects.clear(); } destroy(toDestroy, _factory); } @@ -1352,7 +1353,7 @@ public class GenericObjectPool extend */ @Override public synchronized int getNumActive() { - return _numActive; + return _numActiveOld; } /** @@ -1362,7 +1363,7 @@ public class GenericObjectPool extend */ @Override public synchronized int getNumIdle() { - return _pool.size(); + return _idleObjects.size(); } /** @@ -1399,7 +1400,7 @@ public class GenericObjectPool extend // These two methods should be refactored, removing the // "behavior flag", decrementNumActive, from addObjectToPool. synchronized(this) { - _numActive--; + _numActiveOld--; } allocate(); } @@ -1436,18 +1437,18 @@ public class GenericObjectPool extend if (isClosed()) { shouldDestroy = true; } else { - if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) { + if((_maxIdle >= 0) && (_idleObjects.size() >= _maxIdle)) { shouldDestroy = true; } else if(success) { // borrowObject always takes the first element from the queue, // so for LIFO, push on top, FIFO add to end if (_lifo) { - _pool.addFirst(new PooledObject(obj)); + _idleObjects.addFirst(new PooledObject(obj)); } else { - _pool.addLast(new PooledObject(obj)); + _idleObjects.addLast(new PooledObject(obj)); } if (decrementNumActive) { - _numActive--; + _numActiveOld--; } doAllocate = true; } @@ -1467,7 +1468,7 @@ public class GenericObjectPool extend // Decrement active count *after* destroy if applicable if (decrementNumActive) { synchronized(this) { - _numActive--; + _numActiveOld--; } allocate(); } @@ -1516,9 +1517,9 @@ public class GenericObjectPool extend if(0 < getNumActive()) { throw new IllegalStateException("Objects are already active"); } else { - toDestroy.addAll(_pool); - _numInternalProcessing = _numInternalProcessing + _pool.size(); - _pool.clear(); + toDestroy.addAll(_idleObjects); + _numInternalProcessing = _numInternalProcessing + _idleObjects.size(); + _idleObjects.clear(); } _factory = factory; } @@ -1541,7 +1542,7 @@ public class GenericObjectPool extend public void evict() throws Exception { assertOpen(); - if (_pool.size() == 0) { + if (_idleObjects.size() == 0) { return; } @@ -1550,9 +1551,9 @@ public class GenericObjectPool extend for (int i = 0, m = getNumTests(); i < m; i++) { if (_evictionIterator == null || !_evictionIterator.hasNext()) { if (getLifo()) { - _evictionIterator = _pool.descendingIterator(); + _evictionIterator = _idleObjects.descendingIterator(); } else { - _evictionIterator = _pool.iterator(); + _evictionIterator = _idleObjects.iterator(); } } if (!_evictionIterator.hasNext()) { @@ -1583,7 +1584,7 @@ public class GenericObjectPool extend (getSoftMinEvictableIdleTimeMillis() > 0 && getSoftMinEvictableIdleTimeMillis() < underTest.getIdleTimeMillis() && - getMinIdle() < _pool.size())) { + getMinIdle() < _idleObjects.size())) { destroy(underTest); } else { if (getTestWhileIdle()) { @@ -1617,7 +1618,7 @@ public class GenericObjectPool extend } private void destroy(PooledObject toDestory) { - _pool.remove(toDestory); + _idleObjects.remove(toDestory); try { _factory.destroyObject(toDestory.getObject()); } catch (Exception e) { @@ -1728,7 +1729,7 @@ public class GenericObjectPool extend buf.append("Active: ").append(getNumActive()).append("\n"); buf.append("Idle: ").append(getNumIdle()).append("\n"); buf.append("Idle Objects:\n"); - for (PooledObject pair : _pool) { + for (PooledObject pair : _idleObjects) { buf.append("\t").append(pair.toString()); } return buf.toString(); @@ -1744,9 +1745,9 @@ public class GenericObjectPool extend */ private int getNumTests() { if(_numTestsPerEvictionRun >= 0) { - return Math.min(_numTestsPerEvictionRun, _pool.size()); + return Math.min(_numTestsPerEvictionRun, _idleObjects.size()); } else { - return(int)(Math.ceil(_pool.size()/Math.abs((double)_numTestsPerEvictionRun))); + return(int)(Math.ceil(_idleObjects.size()/Math.abs((double)_numTestsPerEvictionRun))); } } @@ -2048,10 +2049,6 @@ public class GenericObjectPool extend /** Whether or not the pool behaves as a LIFO queue (last in first out) */ private boolean _lifo = DEFAULT_LIFO; - /** My pool. */ - private LinkedBlockingDeque> _pool = null; - - private Iterator> _evictionIterator = null; /** My {@link PoolableObjectFactory}. */ private PoolableObjectFactory _factory; @@ -2060,7 +2057,7 @@ public class GenericObjectPool extend * The number of objects {@link #borrowObject} borrowed * from the pool, but not yet returned. */ - private int _numActive = 0; + private int _numActiveOld = 0; /** * My idle object eviction {@link TimerTask}, if any. @@ -2081,4 +2078,11 @@ public class GenericObjectPool extend */ private final LinkedList _allocationQueue = new LinkedList(); + + + /** The queue of idle objects */ + private Deque> _idleObjects = null; + + /** An iterator for {@link #_idleObjects} that is used by the evictor. */ + private Iterator> _evictionIterator = null; }