Author: painter
Date: Mon Nov 5 15:42:25 2018
New Revision: 1845817
URL: http://svn.apache.org/viewvc?rev=1845817&view=rev
Log:
Fix/update javadocs for pool and localization for mvn site to build cleanly
Modified:
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/DefaultLocalizationService.java
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/LocalizationService.java
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/SimpleLocalizationService.java
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/SimpleLocalizationServiceImpl.java
turbine/fulcrum/trunk/localization/src/test/org/apache/fulcrum/localization/LocalizationTest.java
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/ArrayCtorRecyclable.java
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/BoundedBuffer.java
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/DefaultPoolService.java
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/InitableRecyclable.java
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolBuffer.java
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/PoolService.java
turbine/fulcrum/trunk/pool/src/test/org/apache/fulcrum/pool/PoolServiceTest.java
Modified:
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/DefaultLocalizationService.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/DefaultLocalizationService.java?rev=1845817&r1=1845816&r2=1845817&view=diff
==============================================================================
---
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/DefaultLocalizationService.java
(original)
+++
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/DefaultLocalizationService.java
Mon Nov 5 15:42:25 2018
@@ -33,13 +33,15 @@ import org.apache.commons.lang3.StringUt
*
* <p>Usage example:</p>
*
- * <blockquote><code><pre>
+ * <pre>
+ * <code>
* LocalizationService ls = (LocalizationService) TurbineServices
* .getInstance().getService(LocalizationService.SERVICE_NAME);
- * </pre></code></blockquote>
+ * </code>
+ * </pre>
*
* <p>Then call {@link #getString(String, Locale, String)}, or one of
- * four methods to retrieve a ResourceBundle:
+ * four methods to retrieve a ResourceBundle:</p>
*
* <ul>
* <li>getBundle("MyBundleName")</li>
@@ -47,7 +49,7 @@ import org.apache.commons.lang3.StringUt
* <li>etBundle("MyBundleName", HttpServletRequest)</li>
* <li>getBundle("MyBundleName", Locale)</li>
* <li>etc.</li>
- * </ul></p>
+ * </ul>
*
* @author <a href="mailto:[email protected]">Jonas Maurus</a>
* @author <a href="mailto:[email protected]">Jon S. Stevens</a>
@@ -57,8 +59,8 @@ import org.apache.commons.lang3.StringUt
* @author <a href="mailto:[email protected]">Stephen McConnell</a>
* @author <a href="mailto:[email protected]">Thomas Vandahl</a>
* @version $Id$
- * @avalon.component name="localization" lifestyle="singleton"
- * @avalon.service type="org.apache.fulcrum.localization.LocalizationService"
+ * avalon.component name="localization" lifestyle="singleton"
+ * avalon.service type="org.apache.fulcrum.localization.LocalizationService"
*/
public class DefaultLocalizationService
extends SimpleLocalizationServiceImpl
Modified:
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/LocalizationService.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/LocalizationService.java?rev=1845817&r1=1845816&r2=1845817&view=diff
==============================================================================
---
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/LocalizationService.java
(original)
+++
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/LocalizationService.java
Mon Nov 5 15:42:25 2018
@@ -102,7 +102,7 @@ public interface LocalizationService ext
* Parses the <code>Accept-Language</code> header and attempts to
* create a <code>Locale</code> from it.
*
- * @param header The language header (i.e. <code>en, es;q=0.8,
+ * @param languageHeader The language header (i.e. <code>en, es;q=0.8,
* zh-TW;q=0.1</code>), or <code>null</code> for the locale
* corresponding to the default language and country.
* @return The parsed locale, or a locale corresponding to the
Modified:
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/SimpleLocalizationService.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/SimpleLocalizationService.java?rev=1845817&r1=1845816&r2=1845817&view=diff
==============================================================================
---
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/SimpleLocalizationService.java
(original)
+++
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/SimpleLocalizationService.java
Mon Nov 5 15:42:25 2018
@@ -51,18 +51,23 @@ public interface SimpleLocalizationServi
/**
* Retrieves the default language (as specified in the config
* file).
+ * @return the default language
*/
String getDefaultLanguage();
/**
* Retrieves the default country (as specified in the config
* file).
+ *
+ * @return the default country
*/
String getDefaultCountry();
/**
* Retrieves the default Locale (as created from default
* language and default country).
+ *
+ * @return the default locale
*/
Locale getDefaultLocale();
@@ -70,6 +75,8 @@ public interface SimpleLocalizationServi
* Retrieves the name of the default bundle (as specified in the
* config file), or the first in the list if there are more than
* one.
+ *
+ * @return the default bundle name
*/
String getDefaultBundleName();
@@ -117,6 +124,7 @@ public interface SimpleLocalizationServi
* @param locale Locale to get text for.
* @param key Name of the text to retrieve.
* @return Localized text.
+ * @throws MissingResourceException if the resource is not found
*/
String getString(String bundleName, Locale locale, String key) throws
MissingResourceException;
@@ -156,7 +164,9 @@ public interface SimpleLocalizationServi
* @param key The identifier for the localized text to retrieve,
* @param arg1 The object to use as {0} when formatting the localized text.
* @param arg2 The object to use as {1} when formatting the localized text.
+ *
* @return Formatted localized text.
+ *
* @see #format(String, Locale, String, Object[])
*/
String format(String bundleName, Locale locale,
Modified:
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/SimpleLocalizationServiceImpl.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/SimpleLocalizationServiceImpl.java?rev=1845817&r1=1845816&r2=1845817&view=diff
==============================================================================
---
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/SimpleLocalizationServiceImpl.java
(original)
+++
turbine/fulcrum/trunk/localization/src/java/org/apache/fulcrum/localization/SimpleLocalizationServiceImpl.java
Mon Nov 5 15:42:25 2018
@@ -40,19 +40,21 @@ import org.apache.commons.lang3.StringUt
*
* <p>Usage example:</p>
*
- * <blockquote><code><pre>
+ * <pre>
+ * <code>
* SimpleLocalizationService ls = (SimpleLocalizationService) TurbineServices
* .getInstance().getService(SimpleLocalizationService.SERVICE_NAME);
- * </pre></code></blockquote>
+ * </code>
+ * </pre>
*
* <p>Then call {@link #getString(String, Locale, String)}, or one of
- * two methods to retrieve a ResourceBundle:
+ * two methods to retrieve a ResourceBundle:</p>
*
* <ul>
* <li>getBundle("MyBundleName")</li>
* <li>getBundle("MyBundleName", Locale)</li>
* <li>etc.</li>
- * </ul></p>
+ * </ul>
*
* @author <a href="mailto:[email protected]">Jonas Maurus</a>
* @author <a href="mailto:[email protected]">Jon S. Stevens</a>
@@ -62,8 +64,9 @@ import org.apache.commons.lang3.StringUt
* @author <a href="mailto:[email protected]">Stephen McConnell</a>
* @author <a href="mailto:[email protected]">Thomas Vandahl</a>
* @version $Id: DefaultLocalizationService.java 535465 2007-05-05 06:58:06Z
tv $
- * @avalon.component name="localization" lifestyle="singleton"
- * @avalon.service
type="org.apache.fulcrum.localization.SimpleLocalizationService"
+ *
+ * avalon.component name="localization" lifestyle="singleton"
+ * avalon.service
type="org.apache.fulcrum.localization.SimpleLocalizationService"
*/
public class SimpleLocalizationServiceImpl
extends AbstractLogEnabled
@@ -110,7 +113,10 @@ public class SimpleLocalizationServiceIm
/**
* Avalon lifecycle method
*
- * @see {@link Configurable}
+ * {@link org.apache.avalon.framework.configuration.Configurable}
+ *
+ * @param conf the configuration
+ * @throws ConfigurationException if failed to configure
*/
@Override
public void configure(Configuration conf) throws ConfigurationException
@@ -149,6 +155,8 @@ public class SimpleLocalizationServiceIm
/**
* Called the first time the Service is used.
+ *
+ * @throws Exception generic exception
*/
@Override
public void initialize() throws Exception
@@ -164,7 +172,7 @@ public class SimpleLocalizationServiceIm
/**
* Initialize list of default bundle names.
*
- * @param ignored names Ignored.
+ * @param intBundleNames set bundle names
*/
protected void initBundleNames(String[] intBundleNames)
{
@@ -199,6 +207,8 @@ public class SimpleLocalizationServiceIm
/**
* Retrieves the default language (specified in the config file).
+ *
+ * @return the default language
*/
@Override
public String getDefaultLanguage()
@@ -208,6 +218,8 @@ public class SimpleLocalizationServiceIm
/**
* Retrieves the default country (specified in the config file).
+ *
+ * @return the default country
*/
@Override
public String getDefaultCountry()
@@ -218,6 +230,8 @@ public class SimpleLocalizationServiceIm
/**
* Retrieves the default Locale (as created from default
* language and default country).
+ *
+ * @return the default locale
*/
@Override
public Locale getDefaultLocale()
@@ -226,7 +240,9 @@ public class SimpleLocalizationServiceIm
}
/**
- * @see
org.apache.fulcrum.localization.SimpleLocalizationService#getDefaultBundleName()
+ * {@link
org.apache.fulcrum.localization.SimpleLocalizationService#getDefaultBundleName()}
+ *
+ * @return the default bundle name
*/
@Override
public String getDefaultBundleName()
@@ -235,7 +251,9 @@ public class SimpleLocalizationServiceIm
}
/**
- * @see
org.apache.fulcrum.localization.SimpleLocalizationService#getBundleNames()
+ * {@link
org.apache.fulcrum.localization.SimpleLocalizationService#getBundleNames()}
+ *
+ * @return list of bundle names available
*/
@Override
public String[] getBundleNames()
@@ -244,7 +262,9 @@ public class SimpleLocalizationServiceIm
}
/**
- * @see
org.apache.fulcrum.localization.SimpleLocalizationService#getBundle()
+ * {@link
org.apache.fulcrum.localization.SimpleLocalizationService#getBundle()}
+ *
+ * @return the default resource bundle
*/
@Override
public ResourceBundle getBundle()
@@ -253,7 +273,10 @@ public class SimpleLocalizationServiceIm
}
/**
- * @see
org.apache.fulcrum.localization.SimpleLocalizationService#getBundle(String)
+ * {@link
org.apache.fulcrum.localization.SimpleLocalizationService#getBundle(String)}
+ *
+ * @param bundleName the name of a bundle
+ * @return the resource bundle
*/
@Override
public ResourceBundle getBundle(String bundleName)
@@ -307,7 +330,12 @@ public class SimpleLocalizationServiceIm
* relatively expensive in terms of memory use, but is optimized
* for run-time speed in the usual case.
*
- * @exception MissingResourceException Bundle not found.
+ * @param bundleName Name of bundle (or <code>null</code> for the
+ * default bundle).
+ * @param locale The locale (or <code>null</code> for the locale
+ * indicated by the default language and country).
+ * @throws MissingResourceException Bundle not found.
+ * @return a localized resource bundle
*/
private synchronized ResourceBundle cacheBundle(
String bundleName,
@@ -363,6 +391,14 @@ public class SimpleLocalizationServiceIm
*
* <p>Since we're really just guessing at possible bundles to use,
* we don't ever throw <code>MissingResourceException</code>.</p>
+ *
+ * @param bundleName Name of bundle (or <code>null</code> for the
+ * default bundle).
+ * @param locale The locale (or <code>null</code> for the locale
+ * indicated by the default language and country).
+ * @param bundleByLocale map of locales and resource bundles
+ * @return a localized resource bundle
+ *
*/
private ResourceBundle findBundleByLocale(
String bundleName,
@@ -410,6 +446,11 @@ public class SimpleLocalizationServiceIm
* <code>ResourceBundle.getBundle(String, Locale)</code> method,
* returning <code>null</code> instead of throwing
* <code>MissingResourceException</code>.
+ *
+ * @param bundleName Name of bundle (or <code>null</code> for the
+ * default bundle).
+ * @param locale The locale (or <code>null</code> for the locale
+ * indicated by the default language and country).
*/
private final ResourceBundle getBundleIgnoreException(
String bundleName,
@@ -451,8 +492,9 @@ public class SimpleLocalizationServiceIm
}
/**
- * @exception MissingResourceException Specified key cannot be matched.
- * @see
org.apache.fulcrum.localization.SimpleLocalizationService#getString(String,
Locale, String)
+ *
+ * {@link
org.apache.fulcrum.localization.SimpleLocalizationService#getString(String,
Locale, String)}
+ * @throws MissingResourceException Specified key cannot be matched.
*/
@Override
public String getString(String bundleName, Locale locale, String key)
@@ -523,6 +565,10 @@ public class SimpleLocalizationServiceIm
* Gets localized text from a bundle if it's there. Otherwise,
* returns <code>null</code> (ignoring a possible
* <code>MissingResourceException</code>).
+ *
+ * @param rb resource bundle
+ * @param key The key to retrieve the value for.
+ * @return name of resource
*/
protected final String getStringOrNull(ResourceBundle rb, String key)
{
@@ -541,7 +587,11 @@ public class SimpleLocalizationServiceIm
}
/**
- * @see
org.apache.fulcrum.localization.SimpleLocalizationService#format(String,
Locale, String, Object)
+ * {@link
org.apache.fulcrum.localization.SimpleLocalizationService#format(String,
Locale, String, Object)}
+ * @param bundleName the bundle name
+ * @param locale locale
+ * @param key key to lookup
+ * @param arg1 bundle arguments
*/
@Override
public String format(
@@ -554,7 +604,7 @@ public class SimpleLocalizationServiceIm
}
/**
- * @see
org.apache.fulcrum.localization.SimpleLocalizationService#format(String,
Locale, String, Object, Object)
+ * {@link
org.apache.fulcrum.localization.SimpleLocalizationService#format(String,
Locale, String, Object, Object)}
*/
@Override
public String format(
Modified:
turbine/fulcrum/trunk/localization/src/test/org/apache/fulcrum/localization/LocalizationTest.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/localization/src/test/org/apache/fulcrum/localization/LocalizationTest.java?rev=1845817&r1=1845816&r2=1845817&view=diff
==============================================================================
---
turbine/fulcrum/trunk/localization/src/test/org/apache/fulcrum/localization/LocalizationTest.java
(original)
+++
turbine/fulcrum/trunk/localization/src/test/org/apache/fulcrum/localization/LocalizationTest.java
Mon Nov 5 15:42:25 2018
@@ -42,6 +42,11 @@ public class LocalizationTest extends Ba
super( name );
}
+ /**
+ * Perform test setup
+ *
+ * @throws Exception generic exception
+ */
public void setUp() throws Exception
{
super.setUp();
@@ -54,10 +59,20 @@ public class LocalizationTest extends Ba
fail(e.getMessage());
}
}
+
+
+ /**
+ * Test init
+ */
public void testInitialization()
{
assertTrue(true);
}
+
+ /**
+ * Test localization
+ * @throws Exception generic exception
+ */
public void testLocalization() throws Exception
{
// Test retrieval of text using multiple default bundles
@@ -118,11 +133,12 @@ public class LocalizationTest extends Ba
/**
* Putting this in a seperate testcase because it fails.. Why? I don't
know. I have never
* used localization, so I leave it to brains better then mine. -dep
- * @todo Figure out why this test fails.
- * @throws Exception
+ *
+ * @throws Exception generic exception
*/
public void OFFtestRetrievingOddLocale() throws Exception
{
+ // TODO Figure out why this test fails!
String s = ls.getString(null, new Locale("fr", "US"), "key3");
assertEquals("Unable to retrieve localized text for locale: fr", "[fr]
value3", s);
}
Modified:
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/ArrayCtorRecyclable.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/ArrayCtorRecyclable.java?rev=1845817&r1=1845816&r2=1845817&view=diff
==============================================================================
---
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/ArrayCtorRecyclable.java
(original)
+++
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/ArrayCtorRecyclable.java
Mon Nov 5 15:42:25 2018
@@ -35,6 +35,8 @@ public interface ArrayCtorRecyclable ext
* Recycles the object for a new client. Objects implementing
* this interface must also provide a matching constructor.
* The recycle methods must call their super.
+ *
+ * @param params the parameters to recycle
*/
public void recycle(Object[] params);
}
Modified:
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/BoundedBuffer.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/BoundedBuffer.java?rev=1845817&r1=1845816&r2=1845817&view=diff
==============================================================================
---
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/BoundedBuffer.java
(original)
+++
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/BoundedBuffer.java
Mon Nov 5 15:42:25 2018
@@ -107,7 +107,7 @@ public class BoundedBuffer
/**
* Puts an item in the buffer only if there is capacity available.
*
- * @param item the item to be inserted.
+ * @param x the item to be inserted.
* @return true if accepted, else false.
*/
public synchronized boolean offer(Object x)
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=1845817&r1=1845816&r2=1845817&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 Nov 5 15:42:25 2018
@@ -34,402 +34,360 @@ import org.apache.fulcrum.factory.Factor
import org.apache.fulcrum.factory.FactoryService;
/**
- * The Pool Service extends the Factory Service by adding support
- * for pooling instantiated objects. When a new instance is
- * requested, the service first checks its pool if one is available.
- * If the the pool is empty, a new instance will be requested
- * from the FactoryService.
+ * The Pool Service extends the Factory Service by adding support for pooling
+ * instantiated objects. When a new instance is requested, the service first
+ * checks its pool if one is available. If the the pool is empty, a new
instance
+ * will be requested from the FactoryService.
*
- * For objects implementing the Recyclable interface, a recycle
- * method will be called, when they taken from the pool, and
- * a dispose method, when they are returned to the pool.
+ * For objects implementing the Recyclable interface, a recycle method will be
+ * called, when they taken from the pool, and a dispose method, when they are
+ * returned to the pool.
*
* @author <a href="mailto:[email protected]">Ilkka Priha</a>
* @author <a href="mailto:[email protected]">Stephen McConnell</a>
* @version $Id$
*
- * @avalon.component name="pool" lifestyle="transient"
- * @avalon.service type="org.apache.fulcrum.pool.PoolService"
+ * avalon.component name="pool" lifestyle="transient"
+ * avalon.service type="org.apache.fulcrum.pool.PoolService"
*/
-public class DefaultPoolService extends AbstractLogEnabled implements
PoolService, Serviceable, Disposable, Initializable, Configurable
-{
- /**
- * The property specifying the pool capacity.
- */
- public static final String POOL_CAPACITY = "capacity";
- /**
- * The default capacity of pools.
- */
- private int poolCapacity = DEFAULT_POOL_CAPACITY;
- /**
- * The pool repository, one pool for each class.
- */
- private HashMap<String, PoolBuffer> poolRepository = new HashMap<>();
- private Map<String, Integer> capacityMap;
- private FactoryService factoryService;
- private ServiceManager manager;
-
- /**
- * Gets an instance of a named class either from the pool
- * or by calling the Factory Service if the pool is empty.
- *
- * @param className the name of the class.
- * @return the instance.
- * @throws PoolException if recycling fails.
- */
- public Object getInstance(String className) throws PoolException
- {
- try
- {
- Object instance = pollInstance(className, null, null);
- return instance == null ? getFactory().getInstance(className) :
instance;
- }
- catch (FactoryException fe)
- {
- throw new PoolException(fe);
- }
- }
- /**
- * Gets an instance of a named class either from the pool
- * or by calling the Factory Service if the pool is empty.
- * The specified class loader will be passed to the Factory Service.
- *
- * @param className the name of the class.
- * @param loader the class loader.
- * @return the instance.
- * @throws PoolException if recycling fails.
- */
- 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)
- {
- throw new PoolException(fe);
- }
- }
- /**
- * Gets an instance of a named class either from the pool
- * or by calling the Factory Service if the pool is empty.
- * Parameters for its constructor are given as an array of objects,
- * primitive types must be wrapped with a corresponding class.
- *
- * @param className the name of the class.
- * @param loader the class loader.
- * @param params an array containing the parameters of the constructor.
- * @param signature an array containing the signature of the constructor.
- * @return the instance.
- * @throws PoolException if recycling fails.
- */
- 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)
- {
- throw new PoolException(fe);
- }
- }
- /**
- * Gets an instance of a named class either from the pool
- * or by calling the Factory Service if the pool is empty.
- * Parameters for its constructor are given as an array of objects,
- * primitive types must be wrapped with a corresponding class.
- * The specified class loader will be passed to the Factory Service.
- *
- * @param className the name of the class.
- * @param loader the class loader.
- * @param params an array containing the parameters of the constructor.
- * @param signature an array containing the signature of the constructor.
- * @return the instance.
- * @throws PoolException if recycling fails.
- */
- public Object getInstance(String className, ClassLoader loader, Object[]
params, String[] signature)
- throws PoolException
- {
- try
- {
- Object instance = pollInstance(className, params, signature);
- return instance == null ? getFactory().getInstance(className,
loader, params, signature) : instance;
- }
- catch (FactoryException fe)
- {
- throw new PoolException(fe);
- }
- }
- /**
- * Tests if specified class loaders are supported for a named class.
- *
- * @param className the name of the class.
- * @return true if class loaders are supported, false otherwise.
- * @throws PoolException if test fails.
- */
- public boolean isLoaderSupported(String className) throws FactoryException
- {
- return getFactory().isLoaderSupported(className);
- }
- /**
- * Gets an instance of a specified class either from the pool
- * or by instatiating from the class if the pool is empty.
- *
- * @param clazz the class.
- * @return the instance.
- * @throws PoolException if recycling fails.
- */
- @SuppressWarnings("unchecked")
- 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)
- {
- throw new PoolException(fe);
- }
- }
- /**
- * Gets an instance of a specified class either from the pool
- * or by instatiating from the class if the pool is empty.
- *
- * @todo There is a whacky .toString() on the clazzz, but otherwise it
- * won't compile..
- * @param clazz the class.
- * @param params an array containing the parameters of the constructor.
- * @param signature an array containing the signature of the constructor.
- * @return the instance.
- * @throws PoolException if recycling fails.
- */
- public Object getInstance(Class clazz, Object params[], String
signature[]) throws PoolException
- {
- try
- {
- Object instance = pollInstance(clazz.getName(), params, signature);
- //FactoryService fs = getFactory();
- return instance == null ?
getFactory().getInstance(clazz.toString(), params, signature) : instance;
- }
- catch (FactoryException fe)
- {
- throw new PoolException(fe);
- }
- }
- /**
- * Puts a used object back to the pool. Objects implementing
- * the Recyclable interface can provide a recycle method to
- * be called when they are reused and a dispose method to be
- * called when they are returned to the pool.
- *
- * @param instance the object instance to recycle.
- * @return true if the instance was accepted.
- */
- @SuppressWarnings("unchecked")
- 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)
- {
- pool = new PoolBuffer(getCapacity(className));
- repository = (HashMap<String, PoolBuffer>) repository.clone();
- repository.put(className, pool);
- poolRepository = repository;
- if (instance instanceof ArrayCtorRecyclable)
- {
- pool.setArrayCtorRecyclable(true);
- }
- }
- return pool.offer(instance);
- }
- else
- {
- return false;
- }
- }
- /**
- * Gets the capacity of the pool for a named class.
- *
- * @param className the name of the class.
- */
- public int getCapacity(String className)
- {
- PoolBuffer pool = (PoolBuffer) poolRepository.get(className);
- if (pool == null)
- {
- /* Check class specific capacity. */
- int capacity = poolCapacity;
- if (capacityMap != null)
- {
- Integer cap = (Integer) capacityMap.get(className);
- if (cap != null)
- {
- capacity = cap.intValue();
- }
- }
- return capacity;
- }
- else
- {
- return pool.capacity();
- }
- }
- /**
- * Sets the capacity of the pool for a named class.
- * Note that the pool will be cleared after the change.
- *
- * @param className the name of the class.
- * @param capacity the new capacity.
- */
- @SuppressWarnings("unchecked")
- public void setCapacity(String className, int capacity)
- {
- HashMap<String, PoolBuffer> repository = poolRepository;
- repository = repository != null ? (HashMap<String, PoolBuffer>)
repository.clone() : new HashMap<String, PoolBuffer>();
- repository.put(className, new PoolBuffer(capacity));
- poolRepository = repository;
- }
- /**
- * Gets the current size of the pool for a named class.
- *
- * @param className the name of the class.
- */
- public int getSize(String className)
- {
- PoolBuffer pool = (PoolBuffer) poolRepository.get(className);
- return pool != null ? pool.size() : 0;
- }
- /**
- * Clears instances of a named class from the pool.
- *
- * @param className the name of the class.
- */
- @SuppressWarnings("unchecked")
- public void clearPool(String className)
- {
- HashMap<String, PoolBuffer> repository = poolRepository;
- if (repository.get(className) != null)
- {
- repository = (HashMap<String, PoolBuffer>) repository.clone();
- repository.remove(className);
- poolRepository = repository;
- }
- }
- /**
- * Clears all instances from the pool.
- */
- public void clearPool()
- {
- poolRepository = new HashMap<String, PoolBuffer>();
- }
- /**
- * Polls and recycles an object of the named class from the pool.
- *
- * @param className the name of the class.
- * @param params an array containing the parameters of the constructor.
- * @param signature an array containing the signature of the constructor.
- * @return the object or null.
- * @throws PoolException if recycling fails.
- */
- 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;
- }
- /**
- * Gets the factory service.
- *
- * @return the factory service.
- */
- protected FactoryService getFactory()
- {
- return factoryService;
- }
-
- // ---------------- Avalon Lifecycle Methods ---------------------
- /**
- * Avalon component lifecycle method
- */
- public void configure(Configuration conf)
- {
- final Configuration capacities = conf.getChild(POOL_CAPACITY, false);
- if (capacities != null)
- {
- Configuration defaultConf = capacities.getChild("default");
- int capacity =
defaultConf.getValueAsInteger(DEFAULT_POOL_CAPACITY);
- if (capacity <= 0)
- {
- throw new IllegalArgumentException("Capacity must be >0");
- }
- poolCapacity = capacity;
- Configuration[] nameVal = capacities.getChildren();
- for (int i = 0; i < nameVal.length; i++)
- {
- String key = nameVal[i].getName();
- if (!"default".equals(key))
- {
- capacity = nameVal[i].getValueAsInteger(poolCapacity);
- if (capacity < 0)
- {
- capacity = poolCapacity;
- }
- if (capacityMap == null)
- {
- capacityMap = new HashMap<String, Integer>();
- }
- capacityMap.put(key, new Integer(capacity));
- }
- }
- }
- }
-
- /**
- * Avalon component lifecycle method
- * @avalon.dependency type="org.apache.fulcrum.factory.FactoryService"
- */
- public void service(ServiceManager manager)
- {
- this.manager = manager;
- }
-
- /**
- * Avalon component lifecycle method
- * Initializes the service by loading default class loaders
- * and customized object factories.
- *
- * @throws InitializationException if initialization fails.
- */
- public void initialize() throws Exception
- {
- try
- {
- factoryService = (FactoryService)
manager.lookup(FactoryService.ROLE);
- }
- catch (Exception e)
- {
- throw new Exception(
- "DefaultPoolService.initialize: Failed to get a Factory
object", e);
- }
- }
-
- /**
- * Avalon component lifecycle method
- */
- public void dispose()
- {
- if (factoryService != null)
- {
- manager.release(factoryService);
- }
- factoryService = null;
- manager = null;
- }
+public class DefaultPoolService extends AbstractLogEnabled
+ implements PoolService, Serviceable, Disposable, Initializable,
Configurable {
+ /**
+ * The property specifying the pool capacity.
+ */
+ public static final String POOL_CAPACITY = "capacity";
+ /**
+ * The default capacity of pools.
+ */
+ private int poolCapacity = DEFAULT_POOL_CAPACITY;
+ /**
+ * The pool repository, one pool for each class.
+ */
+ private HashMap<String, PoolBuffer> poolRepository = new HashMap<>();
+ private Map<String, Integer> capacityMap;
+ private FactoryService factoryService;
+ private ServiceManager manager;
+
+ /**
+ * Gets an instance of a named class either from the pool or by calling
the
+ * Factory Service if the pool is empty.
+ *
+ * @param className the name of the class.
+ * @return the instance.
+ * @throws PoolException if recycling fails.
+ */
+ public Object getInstance(String className) throws PoolException {
+ try {
+ Object instance = pollInstance(className, null, null);
+ return instance == null ?
getFactory().getInstance(className) : instance;
+ } catch (FactoryException fe) {
+ throw new PoolException(fe);
+ }
+ }
+
+ /**
+ * Gets an instance of a named class either from the pool or by calling
the
+ * Factory Service if the pool is empty. The specified class loader
will be
+ * passed to the Factory Service.
+ *
+ * @param className the name of the class.
+ * @param loader the class loader.
+ * @return the instance.
+ * @throws PoolException if recycling fails.
+ */
+ 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) {
+ throw new PoolException(fe);
+ }
+ }
+
+ /**
+ * Gets an instance of a named class either from the pool or by calling
the
+ * Factory Service if the pool is empty. Parameters for its constructor
are
+ * given as an array of objects, primitive types must be wrapped with a
+ * corresponding class.
+ *
+ * @param className the name of the class.
+ * @param params an array containing the parameters of the
constructor.
+ * @param signature an array containing the signature of the
constructor.
+ * @return the instance.
+ * @throws PoolException if recycling fails.
+ */
+ 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) {
+ throw new PoolException(fe);
+ }
+ }
+
+ /**
+ * Gets an instance of a named class either from the pool or by calling
the
+ * Factory Service if the pool is empty. Parameters for its constructor
are
+ * given as an array of objects, primitive types must be wrapped with a
+ * corresponding class. The specified class loader will be passed to
the Factory
+ * Service.
+ *
+ * @param className the name of the class.
+ * @param loader the class loader.
+ * @param params an array containing the parameters of the
constructor.
+ * @param signature an array containing the signature of the
constructor.
+ * @return the instance.
+ * @throws PoolException if recycling fails.
+ */
+ public Object getInstance(String className, ClassLoader loader,
Object[] params, String[] signature)
+ throws PoolException {
+ try {
+ Object instance = pollInstance(className, params,
signature);
+ return instance == null ?
getFactory().getInstance(className, loader, params, signature) : instance;
+ } catch (FactoryException fe) {
+ throw new PoolException(fe);
+ }
+ }
+
+ /**
+ * Tests if specified class loaders are supported for a named class.
+ *
+ * @param className the name of the class.
+ * @return true if class loaders are supported, false otherwise.
+ * @throws FactoryException if test fails.
+ */
+ public boolean isLoaderSupported(String className) throws
FactoryException {
+ return getFactory().isLoaderSupported(className);
+ }
+
+ /**
+ * Gets an instance of a specified class either from the pool or by
instatiating
+ * from the class if the pool is empty.
+ *
+ * @param clazz the class.
+ * @return the instance.
+ * @throws PoolException if recycling fails.
+ */
+ @SuppressWarnings("unchecked")
+ 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) {
+ throw new PoolException(fe);
+ }
+ }
+
+ /**
+ * Gets an instance of a specified class either from the pool or by
instatiating
+ * from the class if the pool is empty.
+ *
+ * @param clazz the class.
+ * @param params an array containing the parameters of the
constructor.
+ * @param signature an array containing the signature of the
constructor.
+ * @return the instance.
+ * @throws PoolException if recycling fails.
+ */
+ 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) {
+ throw new PoolException(fe);
+ }
+ }
+
+ /**
+ * Puts a used object back to the pool. Objects implementing the
Recyclable
+ * interface can provide a recycle method to be called when they are
reused and
+ * a dispose method to be called when they are returned to the pool.
+ *
+ * @param instance the object instance to recycle.
+ * @return true if the instance was accepted.
+ */
+ @SuppressWarnings("unchecked")
+ 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) {
+ pool = new PoolBuffer(getCapacity(className));
+ repository = (HashMap<String, PoolBuffer>)
repository.clone();
+ repository.put(className, pool);
+ poolRepository = repository;
+ if (instance instanceof ArrayCtorRecyclable) {
+ pool.setArrayCtorRecyclable(true);
+ }
+ }
+ return pool.offer(instance);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Gets the capacity of the pool for a named class.
+ *
+ * @param className the name of the class.
+ */
+ public int getCapacity(String className) {
+ PoolBuffer pool = (PoolBuffer) poolRepository.get(className);
+ if (pool == null) {
+ /* Check class specific capacity. */
+ int capacity = poolCapacity;
+ if (capacityMap != null) {
+ Integer cap = (Integer)
capacityMap.get(className);
+ if (cap != null) {
+ capacity = cap.intValue();
+ }
+ }
+ return capacity;
+ } else {
+ return pool.capacity();
+ }
+ }
+
+ /**
+ * Sets the capacity of the pool for a named class. Note that the pool
will be
+ * cleared after the change.
+ *
+ * @param className the name of the class.
+ * @param capacity the new capacity.
+ */
+ @SuppressWarnings("unchecked")
+ public void setCapacity(String className, int capacity) {
+ HashMap<String, PoolBuffer> repository = poolRepository;
+ repository = repository != null ? (HashMap<String, PoolBuffer>)
repository.clone()
+ : new HashMap<String, PoolBuffer>();
+ repository.put(className, new PoolBuffer(capacity));
+ poolRepository = repository;
+ }
+
+ /**
+ * Gets the current size of the pool for a named class.
+ *
+ * @param className the name of the class.
+ */
+ public int getSize(String className) {
+ PoolBuffer pool = (PoolBuffer) poolRepository.get(className);
+ return pool != null ? pool.size() : 0;
+ }
+
+ /**
+ * Clears instances of a named class from the pool.
+ *
+ * @param className the name of the class.
+ */
+ @SuppressWarnings("unchecked")
+ public void clearPool(String className) {
+ HashMap<String, PoolBuffer> repository = poolRepository;
+ if (repository.get(className) != null) {
+ repository = (HashMap<String, PoolBuffer>)
repository.clone();
+ repository.remove(className);
+ poolRepository = repository;
+ }
+ }
+
+ /**
+ * Clears all instances from the pool.
+ */
+ public void clearPool() {
+ poolRepository = new HashMap<String, PoolBuffer>();
+ }
+
+ /**
+ * Polls and recycles an object of the named class from the pool.
+ *
+ * @param className the name of the class.
+ * @param params an array containing the parameters of the
constructor.
+ * @param signature an array containing the signature of the
constructor.
+ * @return the object or null.
+ * @throws PoolException if recycling fails.
+ */
+ 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;
+ }
+
+ /**
+ * Gets the factory service.
+ *
+ * @return the factory service.
+ */
+ protected FactoryService getFactory() {
+ return factoryService;
+ }
+
+ // ---------------- Avalon Lifecycle Methods ---------------------
+ /**
+ * Avalon component lifecycle method
+ */
+ public void configure(Configuration conf) {
+ final Configuration capacities = conf.getChild(POOL_CAPACITY,
false);
+ if (capacities != null) {
+ Configuration defaultConf =
capacities.getChild("default");
+ int capacity =
defaultConf.getValueAsInteger(DEFAULT_POOL_CAPACITY);
+ if (capacity <= 0) {
+ throw new IllegalArgumentException("Capacity
must be >0");
+ }
+ poolCapacity = capacity;
+ Configuration[] nameVal = capacities.getChildren();
+ for (int i = 0; i < nameVal.length; i++) {
+ String key = nameVal[i].getName();
+ if (!"default".equals(key)) {
+ capacity =
nameVal[i].getValueAsInteger(poolCapacity);
+ if (capacity < 0) {
+ capacity = poolCapacity;
+ }
+ if (capacityMap == null) {
+ capacityMap = new
HashMap<String, Integer>();
+ }
+ capacityMap.put(key, new
Integer(capacity));
+ }
+ }
+ }
+ }
+
+ /**
+ * Avalon component lifecycle method
+ *
+ * {@link org.apache.fulcrum.factory.FactoryService}
+ *
+ * @param manager the service manager
+ */
+ public void service(ServiceManager manager) {
+ this.manager = manager;
+ }
+
+ /**
+ * Avalon component lifecycle method Initializes the service by loading
default
+ * class loaders and customized object factories.
+ *
+ * @throws Exception if initialization fails.
+ */
+ public void initialize() throws Exception {
+ try {
+ factoryService = (FactoryService)
manager.lookup(FactoryService.ROLE);
+ } catch (Exception e) {
+ throw new Exception("DefaultPoolService.initialize:
Failed to get a Factory object", e);
+ }
+ }
+
+ /**
+ * Avalon component lifecycle method
+ */
+ public void dispose() {
+ if (factoryService != null) {
+ manager.release(factoryService);
+ }
+ factoryService = null;
+ manager = null;
+ }
}
Modified:
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/InitableRecyclable.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/InitableRecyclable.java?rev=1845817&r1=1845816&r2=1845817&view=diff
==============================================================================
---
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/InitableRecyclable.java
(original)
+++
turbine/fulcrum/trunk/pool/src/java/org/apache/fulcrum/pool/InitableRecyclable.java
Mon Nov 5 15:42:25 2018
@@ -1,6 +1,5 @@
package org.apache.fulcrum.pool;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -21,13 +20,10 @@ package org.apache.fulcrum.pool;
*/
-
-
-
/**
* An interface for objects that can be pooled and recycled several times
* by different clients. Pooled objects that implement this interface
- * use no argument ctor and recycle methods. Initialization is taken
+ * use no argument or recycle methods. Initialization is taken
* care of using the init method. This is a way to avoid
* introspection/reflection when pooling an object.
*
@@ -39,6 +35,9 @@ public interface InitableRecyclable exte
/**
* This method should be called after retrieving the object from
* the pool.
+ *
+ * @param initObj the object to initialize
+ * @throws PoolException pool exception if failed to initialize
*/
public void init(Object initObj) throws PoolException;
}
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=1845817&r1=1845816&r2=1845817&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 Nov 5 15:42:25 2018
@@ -64,8 +64,12 @@ public class PoolBuffer
}
/**
* Polls for an instance from the pool.
- * @param factoryService
- *
+ *
+ *
+ * @param params object paramaters
+ * @param signature signature of the class
+ * @param factoryService service to add
+ * @throws PoolException if service failed to be found
* @return an instance or null.
*/
public Object poll(Object[] params, String[] signature, FactoryService
factoryService) throws PoolException
@@ -98,7 +102,9 @@ public class PoolBuffer
clazz.getMethod(
"recycle",
factoryService.getSignature(clazz,
params, signature));
- ArrayList<Recycler> cache =
+
+ @SuppressWarnings("unchecked")
+
ArrayList<Recycler> cache =
recyclers != null ?
(ArrayList<Recycler>) recyclers.clone() : new ArrayList<Recycler>();
cache.add(new Recycler(recycle,
signature));
recyclers = cache;
@@ -120,10 +126,12 @@ public class PoolBuffer
}
return instance;
}
+
/**
* Offers an instance to the pool.
- *
+ *
* @param instance an instance.
+ * @return false if failed to dispose
*/
public boolean offer(Object instance)
{
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=1845817&r1=1845816&r2=1845817&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 Nov 5 15:42:25 2018
@@ -90,6 +90,7 @@ public interface PoolService
* Gets the capacity of the pool for a named class.
*
* @param className the name of the class.
+ * @return total capacity
*/
public int getCapacity(String className);
@@ -106,7 +107,8 @@ public interface PoolService
/**
* Gets the current size of the pool for a named class.
*
- * @param className the name of the class.
+ * @param className the name of the class
+ * @return the size of the pool for the class
*/
public int getSize(String className);
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=1845817&r1=1845816&r2=1845817&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 Nov 5 15:42:25 2018
@@ -25,88 +25,89 @@ import org.apache.fulcrum.testcontainer.
* @author Eric Pugh
* @author <a href="mailto:[email protected]">Stephen McConnell</a>
*
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
*/
-public class PoolServiceTest extends BaseUnitTest
-{
- private PoolService poolService = null;
- /**
- * Defines the testcase name for JUnit.
- *
- * @param name the testcase's name.
- */
- public PoolServiceTest(String name)
- {
- super(name);
- }
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- poolService = (PoolService) this.resolve( PoolService.class.getName()
);
- }
-
- /*
- * Class to test for Object getInstance(Class)
- */
- public void testGetInstanceClass() throws PoolException
- {
- Object object = poolService.getInstance(StringBuilder.class);
- assertTrue(object instanceof StringBuilder);
-
- }
-
- public void testPutInstance()
- {
- String s = "I am a string";
- assertEquals(0, poolService.getSize("java.lang.String"));
- poolService.putInstance(s);
- assertEquals(1, poolService.getSize("java.lang.String"));
-
- }
- 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()
- {
- String s = "I am a string";
- assertEquals(0, poolService.getSize("java.lang.String"));
- poolService.putInstance(s);
- assertEquals(1, poolService.getSize("java.lang.String"));
-
- }
- /*
- * Class to test for void clearPool(String)
- */
- 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()
- {
- 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"));
+public class PoolServiceTest extends BaseUnitTest {
+ private PoolService poolService = null;
- }
+ /**
+ * Defines the testcase name for JUnit.
+ *
+ * @param name the testcase's name.
+ */
+ public PoolServiceTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Perform pool service setup
+ *
+ * @throws Exception generic exception
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+
+ poolService = (PoolService)
this.resolve(PoolService.class.getName());
+ }
+
+ /**
+ * Class to test for Object getInstance(Class)
+ *
+ * @throws PoolException generic exception
+ */
+ public void testGetInstanceClass() throws PoolException {
+ Object object = poolService.getInstance(StringBuilder.class);
+ assertTrue(object instanceof StringBuilder);
+
+ }
+
+ public void testPutInstance() {
+ String s = "I am a string";
+ assertEquals(0, poolService.getSize("java.lang.String"));
+ poolService.putInstance(s);
+ assertEquals(1, poolService.getSize("java.lang.String"));
+
+ }
+
+ 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() {
+ String s = "I am a string";
+ assertEquals(0, poolService.getSize("java.lang.String"));
+ poolService.putInstance(s);
+ assertEquals(1, poolService.getSize("java.lang.String"));
+
+ }
+
+ /*
+ * Class to test for void clearPool(String)
+ */
+ 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() {
+ 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"));
+
+ }
}