Author: painter Date: Mon Jan 7 21:25:15 2019 New Revision: 1850691 URL: http://svn.apache.org/viewvc?rev=1850691&view=rev Log: Turbine coding standards compliance, update tests with annotations
Modified: turbine/fulcrum/trunk/pool/NOTICE.txt turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/DefaultPoolService.java turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolBuffer.java turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolException.java turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolService.java turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/Recyclable.java turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/Recycler.java turbine/fulcrum/trunk/pool/src/test/org/apache/fulcrum/pool/PoolServiceTest.java turbine/fulcrum/trunk/pool/xdocs/changes.xml Modified: turbine/fulcrum/trunk/pool/NOTICE.txt URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/NOTICE.txt?rev=1850691&r1=1850690&r2=1850691&view=diff ============================================================================== --- turbine/fulcrum/trunk/pool/NOTICE.txt (original) +++ turbine/fulcrum/trunk/pool/NOTICE.txt Mon Jan 7 21:25:15 2019 @@ -2,5 +2,4 @@ Turbine Fulcrum Pool Component Copyright 2005-2019 The Apache Software Foundation. This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). - +The Apache Software Foundation (http://www.apache.org/). \ No newline at end of file Modified: turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/DefaultPoolService.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/DefaultPoolService.java?rev=1850691&r1=1850690&r2=1850691&view=diff ============================================================================== --- turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/DefaultPoolService.java (original) +++ turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/DefaultPoolService.java Mon Jan 7 21:25:15 2019 @@ -78,11 +78,15 @@ public class DefaultPoolService extends * @return the instance. * @throws PoolException if recycling fails. */ - public Object getInstance(String className) throws PoolException { - try { + public Object getInstance(String className) throws PoolException + { + try + { Object instance = pollInstance(className, null, null); return instance == null ? getFactory().getInstance(className) : instance; - } catch (FactoryException fe) { + } + catch (FactoryException fe) + { throw new PoolException(fe); } } @@ -97,11 +101,15 @@ public class DefaultPoolService extends * @return the instance. * @throws PoolException if recycling fails. */ - public Object getInstance(String className, ClassLoader loader) throws PoolException { - try { + public Object getInstance(String className, ClassLoader loader) throws PoolException + { + try + { Object instance = pollInstance(className, null, null); return instance == null ? getFactory().getInstance(className, loader) : instance; - } catch (FactoryException fe) { + } + catch (FactoryException fe) + { throw new PoolException(fe); } } @@ -118,11 +126,15 @@ public class DefaultPoolService extends * @return the instance. * @throws PoolException if recycling fails. */ - public Object getInstance(String className, Object[] params, String[] signature) throws PoolException { - try { + public Object getInstance(String className, Object[] params, String[] signature) throws PoolException + { + try + { Object instance = pollInstance(className, params, signature); return instance == null ? getFactory().getInstance(className, params, signature) : instance; - } catch (FactoryException fe) { + } + catch (FactoryException fe) + { throw new PoolException(fe); } } @@ -142,11 +154,15 @@ public class DefaultPoolService extends * @throws PoolException if recycling fails. */ public Object getInstance(String className, ClassLoader loader, Object[] params, String[] signature) - throws PoolException { - try { + throws PoolException + { + try + { Object instance = pollInstance(className, params, signature); return instance == null ? getFactory().getInstance(className, loader, params, signature) : instance; - } catch (FactoryException fe) { + } + catch (FactoryException fe) + { throw new PoolException(fe); } } @@ -158,7 +174,8 @@ public class DefaultPoolService extends * @return true if class loaders are supported, false otherwise. * @throws FactoryException if test fails. */ - public boolean isLoaderSupported(String className) throws FactoryException { + public boolean isLoaderSupported(String className) throws FactoryException + { return getFactory().isLoaderSupported(className); } @@ -171,11 +188,15 @@ public class DefaultPoolService extends * @throws PoolException if recycling fails. */ @SuppressWarnings("unchecked") - public Object getInstance(Class clazz) throws PoolException { - try { + public Object getInstance(Class clazz) throws PoolException + { + try + { Object instance = pollInstance(clazz.getName(), null, null); return instance == null ? factoryService.getInstance(clazz) : instance; - } catch (FactoryException fe) { + } + catch (FactoryException fe) + { throw new PoolException(fe); } } @@ -190,17 +211,19 @@ public class DefaultPoolService extends * @return the instance. * @throws PoolException if recycling fails. */ - public Object getInstance(Class clazz, Object params[], String signature[]) throws PoolException { - - try { + public Object getInstance(Class clazz, Object params[], String signature[]) throws PoolException + { + try + { Object instance = pollInstance(clazz.getName(), params, signature); - // FactoryService fs = getFactory(); // TODO There is a whacky .toString() on the clazz object, // but otherwise it won't compile return instance == null ? getFactory().getInstance(clazz.toString(), params, signature) : instance; - } catch (FactoryException fe) { + } + catch (FactoryException fe) + { throw new PoolException(fe); } } @@ -214,17 +237,21 @@ public class DefaultPoolService extends * @return true if the instance was accepted. */ @SuppressWarnings("unchecked") - public boolean putInstance(Object instance) { - if (instance != null) { + public boolean putInstance(Object instance) + { + if (instance != null) + { HashMap<String, PoolBuffer> repository = poolRepository; String className = instance.getClass().getName(); PoolBuffer pool = (PoolBuffer) repository.get(className); - if (pool == null) { + if (pool == null) + { pool = new PoolBuffer(getCapacity(className)); repository = (HashMap<String, PoolBuffer>) repository.clone(); repository.put(className, pool); poolRepository = repository; - if (instance instanceof ArrayCtorRecyclable) { + if (instance instanceof ArrayCtorRecyclable) + { pool.setArrayCtorRecyclable(true); } } @@ -239,14 +266,18 @@ public class DefaultPoolService extends * * @param className the name of the class. */ - public int getCapacity(String className) { + public int getCapacity(String className) + { PoolBuffer pool = (PoolBuffer) poolRepository.get(className); - if (pool == null) { + if (pool == null) + { /* Check class specific capacity. */ int capacity = poolCapacity; - if (capacityMap != null) { + if (capacityMap != null) + { Integer cap = (Integer) capacityMap.get(className); - if (cap != null) { + if (cap != null) + { capacity = cap.intValue(); } } @@ -264,7 +295,8 @@ public class DefaultPoolService extends * @param capacity the new capacity. */ @SuppressWarnings("unchecked") - public void setCapacity(String className, int capacity) { + public void setCapacity(String className, int capacity) + { HashMap<String, PoolBuffer> repository = poolRepository; repository = repository != null ? (HashMap<String, PoolBuffer>) repository.clone() : new HashMap<String, PoolBuffer>(); @@ -277,7 +309,8 @@ public class DefaultPoolService extends * * @param className the name of the class. */ - public int getSize(String className) { + public int getSize(String className) + { PoolBuffer pool = (PoolBuffer) poolRepository.get(className); return pool != null ? pool.size() : 0; } @@ -288,9 +321,11 @@ public class DefaultPoolService extends * @param className the name of the class. */ @SuppressWarnings("unchecked") - public void clearPool(String className) { + public void clearPool(String className) + { HashMap<String, PoolBuffer> repository = poolRepository; - if (repository.get(className) != null) { + if (repository.get(className) != null) + { repository = (HashMap<String, PoolBuffer>) repository.clone(); repository.remove(className); poolRepository = repository; @@ -300,7 +335,8 @@ public class DefaultPoolService extends /** * Clears all instances from the pool. */ - public void clearPool() { + public void clearPool() + { poolRepository = new HashMap<String, PoolBuffer>(); } @@ -313,7 +349,8 @@ public class DefaultPoolService extends * @return the object or null. * @throws PoolException if recycling fails. */ - private Object pollInstance(String className, Object[] params, String[] signature) throws PoolException { + private Object pollInstance(String className, Object[] params, String[] signature) throws PoolException + { PoolBuffer pool = (PoolBuffer) poolRepository.get(className); return pool != null ? pool.poll(params, signature, factoryService) : null; } @@ -323,7 +360,8 @@ public class DefaultPoolService extends * * @return the factory service. */ - protected FactoryService getFactory() { + protected FactoryService getFactory() + { return factoryService; } @@ -332,26 +370,35 @@ public class DefaultPoolService extends * Avalon component lifecycle method * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) */ - public void configure(Configuration conf) { + public void configure(Configuration conf) + { final Configuration capacities = conf.getChild(POOL_CAPACITY, false); - if (capacities != null) { + if (capacities != null) + { Configuration defaultConf = capacities.getChild("default"); int capacity = defaultConf.getValueAsInteger(DEFAULT_POOL_CAPACITY); - if (capacity <= 0) { + if (capacity <= 0) + { throw new IllegalArgumentException("Capacity must be >0"); } poolCapacity = capacity; Configuration[] nameVal = capacities.getChildren(); - for (int i = 0; i < nameVal.length; i++) { + for (int i = 0; i < nameVal.length; i++) + { String key = nameVal[i].getName(); - if (!"default".equals(key)) { + if (!"default".equals(key)) + { capacity = nameVal[i].getValueAsInteger(poolCapacity); - if (capacity < 0) { + if (capacity < 0) + { capacity = poolCapacity; } - if (capacityMap == null) { + + if (capacityMap == null) + { capacityMap = new HashMap<String, Integer>(); } + capacityMap.put(key, capacity); } } @@ -365,7 +412,8 @@ public class DefaultPoolService extends * * @param manager the service manager */ - public void service(ServiceManager manager) { + public void service(ServiceManager manager) + { this.manager = manager; } @@ -375,10 +423,14 @@ public class DefaultPoolService extends * * @throws Exception if initialization fails. */ - public void initialize() throws Exception { - try { + public void initialize() throws Exception + { + try + { factoryService = (FactoryService) manager.lookup(FactoryService.ROLE); - } catch (Exception e) { + } + catch (Exception e) + { throw new Exception("DefaultPoolService.initialize: Failed to get a Factory object", e); } } @@ -386,8 +438,10 @@ public class DefaultPoolService extends /** * Avalon component lifecycle method */ - public void dispose() { - if (factoryService != null) { + public void dispose() + { + if (factoryService != null) + { manager.release(factoryService); } factoryService = null; Modified: turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolBuffer.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolBuffer.java?rev=1850691&r1=1850690&r2=1850691&view=diff ============================================================================== --- turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolBuffer.java (original) +++ turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolBuffer.java Mon Jan 7 21:25:15 2019 @@ -27,7 +27,8 @@ import org.apache.fulcrum.factory.Factor /** * An inner class for class specific pools. */ -public class PoolBuffer { +public class PoolBuffer +{ /** * A buffer for class instances. @@ -49,7 +50,8 @@ public class PoolBuffer { * * @param capacity a capacity. */ - public PoolBuffer(int capacity) { + public PoolBuffer(int capacity) + { pool = new BoundedBuffer(capacity); } @@ -59,7 +61,8 @@ public class PoolBuffer { * * @param isArrayCtor a <code>boolean</code> value */ - public void setArrayCtorRecyclable(boolean isArrayCtor) { + public void setArrayCtorRecyclable(boolean isArrayCtor) + { arrayCtorRecyclable = isArrayCtor; } @@ -73,21 +76,28 @@ public class PoolBuffer { * @throws PoolException if service failed to be found * @return an instance or null. */ - public Object poll(Object[] params, String[] signature, FactoryService factoryService) throws PoolException { + public Object poll(Object[] params, String[] signature, FactoryService factoryService) throws PoolException + { Object instance = pool.poll(); - if (instance != null) { - if (arrayCtorRecyclable) { + if (instance != null) + { + if (arrayCtorRecyclable) + { ((ArrayCtorRecyclable) instance).recycle(params); } else if (instance instanceof Recyclable) { - try { - if (signature != null && signature.length > 0) { + try + { + if (signature != null && signature.length > 0) + { /* Get the recycle method from the cache. */ Method recycle = getRecycle(signature); - if (recycle == null) { + if (recycle == null) + { synchronized (this) { /* Make a synchronized recheck. */ recycle = getRecycle(signature); - if (recycle == null) { + if (recycle == null) + { Class<? extends Object> clazz = instance.getClass(); recycle = clazz.getMethod("recycle", factoryService.getSignature(clazz, params, signature)); @@ -105,7 +115,9 @@ public class PoolBuffer { } else { ((Recyclable) instance).recycle(); } - } catch (Exception x) { + } + catch (Exception x) + { throw new PoolException("Recycling failed for " + instance.getClass().getName(), x); } } @@ -119,11 +131,16 @@ public class PoolBuffer { * @param instance an instance. * @return false if failed to dispose */ - public boolean offer(Object instance) { - if (instance instanceof Recyclable) { - try { + public boolean offer(Object instance) + { + if (instance instanceof Recyclable) + { + try + { ((Recyclable) instance).dispose(); - } catch (Exception x) { + } + catch (Exception x) + { return false; } } @@ -135,7 +152,8 @@ public class PoolBuffer { * * @return the capacity. */ - public int capacity() { + public int capacity() + { return pool.capacity(); } @@ -144,7 +162,8 @@ public class PoolBuffer { * * @return the size. */ - public int size() { + public int size() + { return pool.size(); } @@ -154,11 +173,14 @@ public class PoolBuffer { * @param signature the signature. * @return the recycle method or null. */ - private Method getRecycle(String[] signature) { + private Method getRecycle(String[] signature) + { ArrayList<Recycler> cache = recyclers; - if (cache != null) { + if (cache != null) + { Method recycle; - for (Recycler recycler : cache) { + for (Recycler recycler : cache) + { recycle = recycler.match(signature); if (recycle != null) return recycle; Modified: turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolException.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolException.java?rev=1850691&r1=1850690&r2=1850691&view=diff ============================================================================== --- turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolException.java (original) +++ turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolException.java Mon Jan 7 21:25:15 2019 @@ -25,22 +25,26 @@ package org.apache.fulcrum.pool; * @author <a href="mailto:ep...@upstate.com">Eric Pugh</a> * @version $Id$ */ -public class PoolException extends Exception { +public class PoolException extends Exception +{ /** * Serial number */ private static final long serialVersionUID = 8192045560423973532L; - public PoolException(String msg) { + public PoolException(String msg) + { super(msg); } - public PoolException(Exception ex) { + public PoolException(Exception ex) + { super(ex); } - public PoolException(String msg, Exception ex) { + public PoolException(String msg, Exception ex) + { super(msg, ex); } } Modified: turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolService.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolService.java?rev=1850691&r1=1850690&r2=1850691&view=diff ============================================================================== --- turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolService.java (original) +++ turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolService.java Mon Jan 7 21:25:15 2019 @@ -30,12 +30,14 @@ package org.apache.fulcrum.pool; * For objects implementing the Recyclable interface, a recycle method will be * called, when they are taken from the pool, and a dispose method, when they * are returned to the pool. + * </p> * * @author <a href="mailto:ilkka.pr...@simsoft.fi">Ilkka Priha</a> * @author <a href="mailto:mcconn...@apache.org">Stephen McConnell</a> * @version $Id$ */ -public interface PoolService { +public interface PoolService +{ /** Avalon role - used to id the component within the manager */ String ROLE = PoolService.class.getName(); Modified: turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/Recyclable.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/Recyclable.java?rev=1850691&r1=1850690&r2=1850691&view=diff ============================================================================== --- turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/Recyclable.java (original) +++ turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/Recyclable.java Mon Jan 7 21:25:15 2019 @@ -26,7 +26,8 @@ package org.apache.fulcrum.pool; * @author <a href="mailto:ilkka.pr...@simsoft.fi">Ilkka Priha</a> * @version $Id$ */ -public interface Recyclable { +public interface Recyclable +{ /** * Recycles the object for a new client. Recycle methods with parameters must be Modified: turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/Recycler.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/Recycler.java?rev=1850691&r1=1850690&r2=1850691&view=diff ============================================================================== --- turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/Recycler.java (original) +++ turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/Recycler.java Mon Jan 7 21:25:15 2019 @@ -64,7 +64,8 @@ public class Recycler } else { // test if there is a match - if ( !Arrays.equals(sign, signature) ) { + if ( !Arrays.equals(sign, signature) ) + { return null; } else { return recycle; Modified: turbine/fulcrum/trunk/pool/src/test/org/apache/fulcrum/pool/PoolServiceTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/src/test/org/apache/fulcrum/pool/PoolServiceTest.java?rev=1850691&r1=1850690&r2=1850691&view=diff ============================================================================== --- turbine/fulcrum/trunk/pool/src/test/org/apache/fulcrum/pool/PoolServiceTest.java (original) +++ turbine/fulcrum/trunk/pool/src/test/org/apache/fulcrum/pool/PoolServiceTest.java Mon Jan 7 21:25:15 2019 @@ -20,13 +20,17 @@ package org.apache.fulcrum.pool; */ import org.apache.fulcrum.testcontainer.BaseUnitTest; +import org.junit.Before; +import org.junit.Test; /** * @author Eric Pugh * @author <a href="mailto:mcconn...@apache.org">Stephen McConnell</a> * */ -public class PoolServiceTest extends BaseUnitTest { +public class PoolServiceTest extends BaseUnitTest +{ + /** Default pool service **/ private PoolService poolService = null; /** @@ -34,7 +38,8 @@ public class PoolServiceTest extends Bas * * @param name the testcase's name. */ - public PoolServiceTest(String name) { + public PoolServiceTest(String name) + { super(name); } @@ -43,7 +48,9 @@ public class PoolServiceTest extends Bas * * @throws Exception generic exception */ - public void setUp() throws Exception { + @Before + public void setUp() throws Exception + { super.setUp(); poolService = (PoolService) this.resolve(PoolService.class.getName()); @@ -54,13 +61,17 @@ public class PoolServiceTest extends Bas * * @throws PoolException generic exception */ - public void testGetInstanceClass() throws PoolException { + @Test + public void testGetInstanceClass() throws PoolException + { Object object = poolService.getInstance(StringBuilder.class); assertTrue(object instanceof StringBuilder); } - public void testPutInstance() { + @Test + public void testPutInstance() + { String s = "I am a string"; assertEquals(0, poolService.getSize("java.lang.String")); poolService.putInstance(s); @@ -68,14 +79,18 @@ public class PoolServiceTest extends Bas } - public void testGetSetCapacity() { + @Test + public void testGetSetCapacity() + { assertEquals(128, poolService.getCapacity("java.lang.String")); poolService.setCapacity("java.lang.String", 278); assertEquals(278, poolService.getCapacity("java.lang.String")); } - public void testGetSize() { + @Test + public void testGetSize() + { String s = "I am a string"; assertEquals(0, poolService.getSize("java.lang.String")); poolService.putInstance(s); @@ -83,31 +98,37 @@ public class PoolServiceTest extends Bas } - /* + /** * Class to test for void clearPool(String) */ - public void testClearPoolString() { + @Test + public void testClearPoolString() + { String s = "I am a string"; assertEquals(0, poolService.getSize("java.lang.String")); + poolService.putInstance(s); assertEquals(1, poolService.getSize("java.lang.String")); + poolService.clearPool("java.lang.String"); assertEquals(0, poolService.getSize("java.lang.String")); - } /* * Class to test for void clearPool() */ - public void testClearPool() { + @Test + public void testClearPool() + { String s = "I am a string"; assertEquals(0, poolService.getSize("java.lang.String")); + poolService.putInstance(s); poolService.putInstance(new Double(32)); assertEquals(1, poolService.getSize("java.lang.String")); + poolService.clearPool(); assertEquals(0, poolService.getSize("java.lang.String")); assertEquals(0, poolService.getSize("java.lang.Double")); - } } Modified: turbine/fulcrum/trunk/pool/xdocs/changes.xml URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/xdocs/changes.xml?rev=1850691&r1=1850690&r2=1850691&view=diff ============================================================================== --- turbine/fulcrum/trunk/pool/xdocs/changes.xml (original) +++ turbine/fulcrum/trunk/pool/xdocs/changes.xml Mon Jan 7 21:25:15 2019 @@ -28,6 +28,9 @@ <action dev="painter" type="update"> Derive from Turbine parent POM 5 </action> + <action dev="painter" type="update"> + Update dependencies to yaafi and testcontainer 1.0.8 + </action> </release> <release version="1.0.4" date="2009-06-21"> <action dev="tv" type="add">