Author: markt Date: Thu Jan 10 15:07:12 2013 New Revision: 1431401 URL: http://svn.apache.org/viewvc?rev=1431401&view=rev Log: Fix various IDE warnings
Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java?rev=1431401&r1=1431400&r2=1431401&view=diff ============================================================================== --- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java (original) +++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java Thu Jan 10 15:07:12 2013 @@ -45,7 +45,7 @@ import org.apache.commons.pool2.Poolable * <p> * The pool can also be configured to detect and remove "abandoned" objects, * i.e. objects that have been checked out of the pool but neither used nor - * returned before the configured + * returned before the configured * {@link AbandonedConfig#getRemoveAbandonedTimeout() removeAbandonedTimeout}. * Abandoned object removal can be configured to happen when * <code>borrowObject</code> is invoked and the pool is close to starvation, or @@ -104,7 +104,7 @@ public class GenericObjectPool<T> extend startEvictor(getTimeBetweenEvictionRunsMillis()); } - + /** * Create a new <code>GenericObjectPool</code> that tracks and destroys * objects that are checked out, but never returned to the pool. @@ -207,54 +207,60 @@ public class GenericObjectPool<T> extend return minIdle; } } - + /** * Whether or not abandoned object removal is configured for this pool. - * + * * @return true if this pool is configured to detect and remove * abandoned objects */ + @Override public boolean isAbandonedConfig() { return abandonedConfig != null; } + /** * Returns true if abandoned object removal is configured for this pool * and removal events are to be logged. - * + * * See {@link AbandonedConfig#getLogAbandoned()} */ + @Override public boolean getLogAbandoned() { return isAbandonedConfig() && abandonedConfig.getLogAbandoned(); } - + /** * Returns true if abandoned object removal is configured to be * activated by borrowObject. - * + * * See {@link AbandonedConfig#getRemoveAbandonedOnBorrow()} */ + @Override public boolean getRemoveAbandonedOnBorrow() { return isAbandonedConfig() && abandonedConfig.getRemoveAbandonedOnBorrow(); } - + /** * Returns true if abandoned object removal is configured to be * activated when the evictor runs. - * + * * See {@link AbandonedConfig#getRemoveAbandonedOnMaintenance()} */ + @Override public boolean getRemoveAbandonedOnMaintenance() { return isAbandonedConfig() && abandonedConfig.getRemoveAbandonedOnMaintenance(); } - + /** * Returns the abandoned object timeout if abandoned object removal * is configured for this pool; Integer.MAX_VALUE otherwise. - * + * * See {@link AbandonedConfig#getRemoveAbandonedTimeout()} */ + @Override public int getRemoveAbandonedTimeout() { return isAbandonedConfig() ? abandonedConfig.getRemoveAbandonedTimeout() : @@ -287,7 +293,7 @@ public class GenericObjectPool<T> extend conf.getSoftMinEvictableIdleTimeMillis()); setEvictionPolicyClassName(conf.getEvictionPolicyClassName()); } - + /** * Sets the abandoned object removal configuration. * @@ -366,7 +372,7 @@ public class GenericObjectPool<T> extend */ public T borrowObject(long borrowMaxWaitMillis) throws Exception { assertOpen(); - + if (isAbandonedConfig() && abandonedConfig.getRemoveAbandonedOnBorrow() && (getNumIdle() < 2) && @@ -491,16 +497,16 @@ public class GenericObjectPool<T> extend @Override public void returnObject(T obj) { PooledObject<T> p = allObjects.get(obj); - + if (!isAbandonedConfig()) { if (p == null) { throw new IllegalStateException( "Returned object not currently part of this pool"); - } + } } else { if (p == null) { return; // Object was abandoned and removed - } else { + } else { // Make sure object is not being reclaimed synchronized(p) { final PooledObjectState state = p.getState(); @@ -511,7 +517,7 @@ public class GenericObjectPool<T> extend p.markReturning(); // Keep from being marked abandoned } } - } + } } long activeTime = p.getActiveTimeMillis(); @@ -583,7 +589,7 @@ public class GenericObjectPool<T> extend throw new IllegalStateException( "Invalidated object not currently part of this pool"); } - } + } synchronized (p) { if (p.getState() != PooledObjectState.INVALID) { destroy(p); @@ -681,7 +687,7 @@ public class GenericObjectPool<T> extend assertOpen(); if (idleObjects.size() > 0) { - + PooledObject<T> underTest = null; EvictionPolicy<T> evictionPolicy = getEvictionPolicy(); @@ -861,7 +867,7 @@ public class GenericObjectPool<T> extend Math.abs((double) numTestsPerEvictionRun))); } } - + /** * Recover abandoned objects which have been checked out but * not used since longer than the removeAbandonedTimeout. @@ -889,15 +895,15 @@ public class GenericObjectPool<T> extend PooledObject<T> pooledObject = itr.next(); if (abandonedConfig.getLogAbandoned()) { pooledObject.printStackTrace(); - } + } try { invalidateObject(pooledObject.getObject()); } catch (Exception e) { e.printStackTrace(); } - } + } } - + //--- JMX support ---------------------------------------------------------- /** @@ -947,7 +953,7 @@ public class GenericObjectPool<T> extend // JMX specific attributes private static final String ONAME_BASE = "org.apache.commoms.pool2:type=GenericObjectPool,name="; - + // Additional configuration properties for abandoned object tracking private volatile AbandonedConfig abandonedConfig = null; } Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java?rev=1431401&r1=1431400&r2=1431401&view=diff ============================================================================== --- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java (original) +++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/TestPoolUtils.java Thu Jan 10 15:07:12 2013 @@ -759,7 +759,6 @@ public class TestPoolUtils { } private static <T> T createProxy(final Class<T> clazz, final InvocationHandler handler) { - @SuppressWarnings("unchecked") T ret = (T) Proxy.newProxyInstance( clazz.getClassLoader(), new Class[] { clazz }, handler); return ret; Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java?rev=1431401&r1=1431400&r2=1431401&view=diff ============================================================================== --- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java (original) +++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestAbandonedObjectPool.java Thu Jan 10 15:07:12 2013 @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,7 +32,7 @@ import org.junit.Assert; /** * TestCase for AbandonedObjectPool - * + * * @version $Revision: 1158659 $ $Date: 2011-08-17 05:37:26 -0700 (Wed, 17 Aug 2011) $ */ public class TestAbandonedObjectPool extends TestCase { @@ -42,10 +42,10 @@ public class TestAbandonedObjectPool ext @Override public void setUp() throws Exception { abandonedConfig = new AbandonedConfig(); - - // -- Uncomment the following line to enable logging -- + + // -- Uncomment the following line to enable logging -- // abandonedConfig.setLogAbandoned(true); - + abandonedConfig.setRemoveAbandonedOnBorrow(true); abandonedConfig.setRemoveAbandonedTimeout(1); pool = new GenericObjectPool<PooledTestObject>( @@ -81,7 +81,7 @@ public class TestAbandonedObjectPool ext /** * Tests fix for Bug 28579, a bug in AbandonedObjectPool that causes numActive to go negative * in GenericObjectPool - * + * */ public void testConcurrentInvalidation() throws Exception { final int POOL_SIZE = 30; @@ -94,10 +94,10 @@ public class TestAbandonedObjectPool ext for (int i = 0; i < POOL_SIZE; i++) { vec.add(pool.borrowObject()); } - + // Abandon all borrowed objects for (int i = 0; i < vec.size(); i++) { - ((PooledTestObject)vec.get(i)).setAbandoned(true); + vec.get(i).setAbandoned(true); } // Try launching a bunch of borrows concurrently. Abandoned sweep will be triggered for each. @@ -112,26 +112,26 @@ public class TestAbandonedObjectPool ext for (int i = 0; i < CONCURRENT_BORROWS; i++) { threads[i].join(); } - + // Return all objects that have not been destroyed for (int i = 0; i < vec.size(); i++) { - PooledTestObject pto = (PooledTestObject)vec.get(i); + PooledTestObject pto = vec.get(i); if (pto.isActive()) { pool.returnObject(pto); } } - + // Now, the number of active instances should be 0 assertTrue("numActive should have been 0, was " + pool.getNumActive(), pool.getNumActive() == 0); } - + /** * Verify that an object that gets flagged as abandoned and is subsequently returned * is destroyed instead of being returned to the pool (and possibly later destroyed * inappropriately). */ public void testAbandonedReturn() throws Exception { - abandonedConfig = new AbandonedConfig(); + abandonedConfig = new AbandonedConfig(); abandonedConfig.setRemoveAbandonedOnBorrow(true); abandonedConfig.setRemoveAbandonedTimeout(1); pool.close(); // Unregister pool created by setup @@ -156,13 +156,13 @@ public class TestAbandonedObjectPool ext assertEquals(0, pool.getNumIdle()); assertEquals(1, pool.getNumActive()); } - + /** * Verify that an object that gets flagged as abandoned and is subsequently * invalidated is only destroyed (and pool counter decremented) once. */ public void testAbandonedInvalidate() throws Exception { - abandonedConfig = new AbandonedConfig(); + abandonedConfig = new AbandonedConfig(); abandonedConfig.setRemoveAbandonedOnMaintenance(true); abandonedConfig.setRemoveAbandonedTimeout(1); pool.close(); // Unregister pool created by setup @@ -176,20 +176,20 @@ public class TestAbandonedObjectPool ext PooledTestObject obj = null; for (int i = 0; i < 5; i++) { obj = pool.borrowObject(); - } + } Thread.sleep(1000); // abandon checked out instances and let evictor start pool.invalidateObject(obj); // Should not trigger another destroy / decrement Thread.sleep(2000); // give evictor time to finish destroys assertEquals(0, pool.getNumActive()); assertEquals(5, pool.getDestroyedCount()); } - + /** * Verify that an object that the evictor identifies as abandoned while it * is in process of being returned to the pool is not destroyed. */ public void testRemoveAbandonedWhileReturning() throws Exception { - abandonedConfig = new AbandonedConfig(); + abandonedConfig = new AbandonedConfig(); abandonedConfig.setRemoveAbandonedOnMaintenance(true); abandonedConfig.setRemoveAbandonedTimeout(1); pool.close(); // Unregister pool created by setup @@ -209,16 +209,16 @@ public class TestAbandonedObjectPool ext pool.returnObject(obj); // evictor will run during validation PooledTestObject obj2 = pool.borrowObject(); assertEquals(obj, obj2); // should get original back - assertTrue(!obj2.isDestroyed()); // and not destroyed + assertTrue(!obj2.isDestroyed()); // and not destroyed } - + class ConcurrentBorrower extends Thread { private ArrayList<PooledTestObject> _borrowed; - + public ConcurrentBorrower(ArrayList<PooledTestObject> borrowed) { _borrowed = borrowed; } - + @Override public void run() { try { @@ -228,7 +228,7 @@ public class TestAbandonedObjectPool ext } } } - + class ConcurrentReturner extends Thread { private PooledTestObject returned; public ConcurrentReturner(PooledTestObject obj) { @@ -244,26 +244,28 @@ public class TestAbandonedObjectPool ext } } } - + class SimpleFactory implements PoolableObjectFactory<PooledTestObject> { - + private final long destroyLatency; private final long validateLatency; - + public SimpleFactory() { destroyLatency = 0; validateLatency = 0; } - + public SimpleFactory(long destroyLatency, long validateLatency) { this.destroyLatency = destroyLatency; this.validateLatency = validateLatency; } + @Override public PooledTestObject makeObject() { return new PooledTestObject(abandonedConfig); } - + + @Override public boolean validateObject(PooledTestObject obj) { try { Thread.sleep(validateLatency); @@ -272,15 +274,18 @@ public class TestAbandonedObjectPool ext } return true; } - + + @Override public void activateObject(PooledTestObject obj) { - ((PooledTestObject)obj).setActive(true); + obj.setActive(true); } - + + @Override public void passivateObject(PooledTestObject obj) { - ((PooledTestObject)obj).setActive(false); + obj.setActive(false); } + @Override public void destroyObject(PooledTestObject obj) throws Exception { obj.setActive(false); // while destroying instances, yield control to other threads @@ -300,11 +305,11 @@ class PooledTestObject implements Tracke private int _hash = 0; private boolean _abandoned = false; private static AtomicInteger hash = new AtomicInteger(); - + public PooledTestObject(AbandonedConfig config) { _hash = hash.incrementAndGet(); } - + public synchronized void setActive(boolean b) { active = b; } @@ -312,24 +317,25 @@ class PooledTestObject implements Tracke public synchronized boolean isActive() { return active; } - + public void destroy() { destroyed = true; } - + public boolean isDestroyed() { return destroyed; } - + @Override public int hashCode() { return _hash; } - + public void setAbandoned(boolean b) { _abandoned = b; } - + + @Override public long getLastUsed() { if (_abandoned) { // Abandoned object sweep will occur no matter what the value of removeAbandonedTimeout, @@ -340,7 +346,7 @@ class PooledTestObject implements Tracke return 0; } } - + @Override public boolean equals(Object obj) { if (!(obj instanceof PooledTestObject)) return false;