You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ep...@apache.org on 2003/11/19 12:26:55 UTC

cvs commit: jakarta-turbine-fulcrum/pool/impl/src/test/org/apache/fulcrum/pool PoolServiceTest.java

epugh       2003/11/19 03:26:55

  Added:       pool/impl/src/java/org/apache/fulcrum/pool
                        ObjectInputStreamForContext.java
                        DefaultPoolService.java ArrayCtorRecyclable.java
                        BoundedBuffer.java
               pool/impl project.xml maven.xml .cvsignore
               pool/api/src/java/org/apache/fulcrum/pool Recyclable.java
                        PoolService.java InitableRecyclable.java
                        PoolException.java
               pool/api project.xml .cvsignore
               pool/impl/conf block.xml config.xml
               pool/impl/src/test/org/apache/fulcrum/pool
                        PoolServiceTest.java
  Removed:     pool/src/test/org/apache/fulcrum/pool PoolServiceTest.java
               pool/src/java/org/apache/fulcrum/pool PoolService.java
                        PoolException.java InitableRecyclable.java
                        DefaultPoolService.java BoundedBuffer.java
                        ArrayCtorRecyclable.java Recyclable.java
                        ObjectInputStreamForContext.java
               pool/src/test TestRoleConfig.xml TestComponentConfig.xml
               pool     project.xml .cvsignore LICENSE.txt
                        project.properties
  Log:
  Merlinize the Pool component.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-fulcrum/pool/impl/src/java/org/apache/fulcrum/pool/ObjectInputStreamForContext.java
  
  Index: ObjectInputStreamForContext.java
  ===================================================================
  package org.apache.fulcrum.pool;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.InputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectStreamClass;
  import java.io.IOException;
  
  /**
   * A deserialization stream for a specific class loader context.
   *
   * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
   * @version $Id: ObjectInputStreamForContext.java,v 1.1 2003/11/19 11:26:54 epugh Exp $
   */
  public class ObjectInputStreamForContext extends ObjectInputStream
  {
      /**
       * The class loader of the context.
       */
      private ClassLoader classLoader;
  
      // this is to make the proxy happy.
      public ObjectInputStreamForContext()
          throws IOException
      {
      }
  
      /**
       * Contructs a new object stream for a context.
       *
       * @param in the serialized input stream.
       * @param loader the class loader of the context.
       * @throws IOException on errors.
       */
      public  ObjectInputStreamForContext(InputStream in,
                                          ClassLoader loader)
                                          throws IOException
      {
          super(in);
          classLoader = loader;
      }
  
      protected Class resolveClass(ObjectStreamClass v)
                                   throws IOException,
                                   ClassNotFoundException
      {
          return classLoader == null ?
              super.resolveClass(v) : classLoader.loadClass(v.getName());
      }
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/impl/src/java/org/apache/fulcrum/pool/DefaultPoolService.java
  
  Index: DefaultPoolService.java
  ===================================================================
  package org.apache.fulcrum.pool;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import java.lang.reflect.Method;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.fulcrum.factory.FactoryException;
  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.
   *
   * 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:ilkka.priha@simsoft.fi">Ilkka Priha</a>
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Id: DefaultPoolService.java,v 1.1 2003/11/19 11:26:54 epugh Exp $
   *
   * @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";
      /**
       * An inner class for class specific pools.
       */
      private class PoolBuffer
      {
          /**
           * An inner class for cached recycle methods.
           */
          private class Recycler
          {
              /**
               * The method.
               */
              private final Method recycle;
              /**
               * The signature.
               */
              private final String[] signature;
              /**
               * Constructs a new recycler.
               *
               * @param rec the recycle method.
               * @param sign the signature.
               */
              public Recycler(Method rec, String[] sign)
              {
                  recycle = rec;
                  signature = (sign != null) && (sign.length > 0) ? sign : null;
              }
              /**
               * Matches the given signature against
               * that of the recycle method of this recycler.
               *
               * @param sign the signature.
               * @return the matching recycle method or null.
               */
              public Method match(String[] sign)
              {
                  if ((sign != null) && (sign.length > 0))
                  {
                      if ((signature != null) && (sign.length == signature.length))
                      {
                          for (int i = 0; i < signature.length; i++)
                          {
                              if (!signature[i].equals(sign[i]))
                              {
                                  return null;
                              }
                          }
                          return recycle;
                      }
                      else
                      {
                          return null;
                      }
                  }
                  else if (signature == null)
                  {
                      return recycle;
                  }
                  else
                  {
                      return null;
                  }
              }
          }
          /**
           * A buffer for class instances.
           */
          private BoundedBuffer pool;
          /**
           * A flag to determine if a more efficient recycler is implemented.
           */
          private boolean arrayCtorRecyclable;
          /**
           * A cache for recycling methods.
           */
          private ArrayList recyclers;
          /**
           * Contructs a new pool buffer with a specific capacity.
           *
           * @param capacity a capacity.
           */
          public PoolBuffer(int capacity)
          {
              pool = new BoundedBuffer(capacity);
          }
          /**
           * Tells pool that it contains objects which can be
           * initialized using an Object array.
           *
           * @param isArrayCtor a <code>boolean</code> value
           */
          public void setArrayCtorRecyclable(boolean isArrayCtor)
          {
              arrayCtorRecyclable = isArrayCtor;
          }
          /**
           * Polls for an instance from the pool.
           *
           * @return an instance or null.
           */
          public Object poll(Object[] params, String[] signature) throws PoolException
          {
              Object instance = pool.poll();
              if (instance != null)
              {
                  if (arrayCtorRecyclable)
                  {
                      ((ArrayCtorRecyclable) instance).recycle(params);
                  }
                  else if (instance instanceof Recyclable)
                  {
                      try
                      {
                          if ((signature != null) && (signature.length > 0))
                          {
                              /* Get the recycle method from the cache. */
                              Method recycle = getRecycle(signature);
                              if (recycle == null)
                              {
                                  synchronized (this)
                                  {
                                      /* Make a synchronized recheck. */
                                      recycle = getRecycle(signature);
                                      if (recycle == null)
                                      {
                                          Class clazz = instance.getClass();
                                          recycle =
                                              clazz.getMethod(
                                                  "recycle",
                                                  getFactory().getSignature(clazz, params, signature));
                                          ArrayList cache =
                                              recyclers != null ? (ArrayList) recyclers.clone() : new ArrayList();
                                          cache.add(new Recycler(recycle, signature));
                                          recyclers = cache;
                                      }
                                  }
                              }
                              recycle.invoke(instance, params);
                          }
                          else
                          {
                              ((Recyclable) instance).recycle();
                          }
                      }
                      catch (Exception x)
                      {
                          throw new PoolException("Recycling failed for " + instance.getClass().getName(), x);
                      }
                  }
              }
              return instance;
          }
          /**
           * Offers an instance to the pool.
           *
           * @param instance an instance.
           */
          public boolean offer(Object instance)
          {
              if (instance instanceof Recyclable)
              {
                  try
                  {
                      ((Recyclable) instance).dispose();
                  }
                  catch (Exception x)
                  {
                      return false;
                  }
              }
              return pool.offer(instance);
          }
          /**
           * Returns the capacity of the pool.
           *
           * @return the capacity.
           */
          public int capacity()
          {
              return pool.capacity();
          }
          /**
           * Returns the size of the pool.
           *
           * @return the size.
           */
          public int size()
          {
              return pool.size();
          }
          /**
           * Returns a cached recycle method
           * corresponding to the given signature.
           *
           * @param signature the signature.
           * @return the recycle method or null.
           */
          private Method getRecycle(String[] signature)
          {
              ArrayList cache = recyclers;
              if (cache != null)
              {
                  Method recycle;
                  for (Iterator i = cache.iterator(); i.hasNext();)
                  {
                      recycle = ((Recycler) i.next()).match(signature);
                      if (recycle != null)
                      {
                          return recycle;
                      }
                  }
              }
              return null;
          }
      }
      /**
       * The default capacity of pools.
       */
      private int poolCapacity = DEFAULT_POOL_CAPACITY;
      /**
       * The pool repository, one pool for each class.
       */
      private HashMap poolRepository = new HashMap();
      private Map capacityMap;
      private FactoryService factoryService;
      private ServiceManager manager;
      private boolean disposed;
      /**
       * Constructs a Pool Service.
       */
      public DefaultPoolService()
      {
      }
      /**
       * 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.
       */
      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.
       */
      public boolean putInstance(Object instance)
      {
          if (instance != null)
          {
              HashMap repository = poolRepository;
              String className = instance.getClass().getName();
              PoolBuffer pool = (PoolBuffer) repository.get(className);
              if (pool == null)
              {
                  pool = new PoolBuffer(getCapacity(className));
                  repository = (HashMap) 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.
       */
      public void setCapacity(String className, int capacity)
      {
          HashMap repository = poolRepository;
          repository = repository != null ? (HashMap) repository.clone() : new HashMap();
          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.
       */
      public void clearPool(String className)
      {
          HashMap repository = poolRepository;
          if (repository.get(className) != null)
          {
              repository = (HashMap) repository.clone();
              repository.remove(className);
              poolRepository = repository;
          }
      }
      /**
       * Clears all instances from the pool.
       */
      public void clearPool()
      {
          poolRepository = new HashMap();
      }
      /**
       * 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) : null;
      }
      /**
       * Gets the factory service.
       *
       * @return the factory service.
       */
      private 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();
                      }
                      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(
                 "TurbineCryptoService.init: Failed to get a Factory object", e);
          }
      }
  
      /**
       * Avalon component lifecycle method
       */
      public void dispose()
      {
          if (factoryService != null)
          {
              manager.release(factoryService);
          }
          factoryService = null;
          manager = null;
          disposed = true;
      }
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/impl/src/java/org/apache/fulcrum/pool/ArrayCtorRecyclable.java
  
  Index: ArrayCtorRecyclable.java
  ===================================================================
  package org.apache.fulcrum.pool;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   * An interface for objects that can be pooled and
   * recycled several times by different clients.  This interface
   * presents a recycle method that does not require introspection/reflection.
   *
   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
   * @version $Id: ArrayCtorRecyclable.java,v 1.1 2003/11/19 11:26:54 epugh Exp $
   */
  public interface ArrayCtorRecyclable extends Recyclable
  {
      /**
       * Recycles the object for a new client. Objects implementing
       * this interface must also provide a matching constructor.
       * The recycle methods must call their super.
       */
      public void recycle(Object[] params);
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/impl/src/java/org/apache/fulcrum/pool/BoundedBuffer.java
  
  Index: BoundedBuffer.java
  ===================================================================
  package org.apache.fulcrum.pool;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   * Efficient array-based bounded buffer class.
   * Adapted from CPJ, chapter 8, which describes design.
   * Originally written by Doug Lea and released into the public domain.
   * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] <p>
   *
   * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
   * @version $Id: BoundedBuffer.java,v 1.1 2003/11/19 11:26:54 epugh Exp $
   */
  public class BoundedBuffer
  {
      /**
       * The default capacity.
       */
      public static final int DEFAULT_CAPACITY = 1024;
  
      protected final Object[]  array_;      // the elements
  
      protected int takePtr_ = 0;            // circular indices
      protected int putPtr_ = 0;
  
      protected int usedSlots_ = 0;          // length
      protected int emptySlots_;             // capacity - length
  
      /**
       * Creates a buffer with the given capacity.
       *
       * @param capacity the capacity.
       * @throws IllegalArgumentException if capacity less or equal to zero.
       */
      public BoundedBuffer(int capacity)
                           throws IllegalArgumentException
      {
          if (capacity <= 0)
             throw new IllegalArgumentException();
  
          array_ = new Object[capacity];
          emptySlots_ = capacity;
      }
  
      /**
       * Creates a buffer with the default capacity
       */
      public BoundedBuffer()
      {
          this(DEFAULT_CAPACITY);
      }
  
      /**
       * Returns the number of elements in the buffer.
       * This is only a snapshot value, that may change
       * immediately after returning.
       *
       * @return the size.
       */
      public synchronized int size()
      {
          return usedSlots_;
      }
  
      /**
       * Returns the capacity of the buffer.
       *
       * @return the capacity.
       */
      public int capacity()
      {
          return array_.length;
      }
  
      /**
       * Peeks, but does not remove the top item from the buffer.
       *
       * @return the object or null.
       */
      public synchronized Object peek()
      {
          if (usedSlots_ > 0)
              return array_[takePtr_];
          else
              return null;
      }
  
      /**
       * Puts an item in the buffer only if there is capacity available.
       *
       * @param item the item to be inserted.
       * @return true if accepted, else false.
       */
      public synchronized boolean offer(Object x)
      {
          if (x == null)
              throw new IllegalArgumentException();
  
          if (emptySlots_ > 0)
          {
              --emptySlots_;
              array_[putPtr_] = x;
              if (++putPtr_ >= array_.length)
                  putPtr_ = 0;
              usedSlots_++;
              return true;
          }
          else
              return false;
      }
  
      /**
       * Polls and removes the top item from the buffer if one is available.
       *
       * @return the oldest item from the buffer, or null if the buffer is empty.
       */
      public synchronized Object poll()
      {
          if (usedSlots_ > 0)
          {
              --usedSlots_;
              Object old = array_[takePtr_];
              array_[takePtr_] = null;
              if (++takePtr_ >= array_.length)
                  takePtr_ = 0;
              emptySlots_++;
              return old;
          }
          else
              return null;
      }
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/impl/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0"?>
  <project>
    <extend>${basedir}/../../merlin-project.xml</extend>
    <id>fulcrum-pool-impl</id>
    <name>Fulcrum Pool Component</name>
    <currentVersion>1.0-alpha-2</currentVersion>
  
    <dependencies>
  
      <dependency>
        <groupId>fulcrum</groupId>
        <artifactId>fulcrum-pool-api</artifactId>
        <version>1.0-alpha-2</version>
      </dependency>
      <dependency>
        <groupId>fulcrum</groupId>
        <artifactId>fulcrum-factory-api</artifactId>
        <version>1.0-alpha-2</version>
      </dependency>
  
      <!--  Needed only for testing -->
  
      <dependency>
        <groupId>merlin</groupId>
        <artifactId>merlin-unit</artifactId>
        <version>3.2.2-dev</version>
      </dependency>
  
    </dependencies>
  
  </project>
  
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/impl/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="jar:jar" xmlns:maven="jelly:maven" xmlns:j="jelly:core" xmlns:util="jelly:util">
  
    <preGoal name="java:compile">
      <attainGoal name="avalon:meta"/>
    </preGoal>
  
  </project>
  
  
  1.1                  jakarta-turbine-fulcrum/pool/impl/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  target
  *.log
  .classpath
  .project
  jcoverage.ser
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/api/src/java/org/apache/fulcrum/pool/Recyclable.java
  
  Index: Recyclable.java
  ===================================================================
  package org.apache.fulcrum.pool;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   * An interface for objects that can be pooled and
   * recycled several times by different clients.
   *
   * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
   * @version $Id: Recyclable.java,v 1.1 2003/11/19 11:26:55 epugh Exp $
   */
  public interface Recyclable
  {
      /**
       * Recycles the object for a new client. Recycle methods with
       * parameters must be added to implementing object and they will be
       * automatically called by pool implementations when the object is
       * taken from the pool for a new client. The parameters must
       * correspond to the parameters of the constructors of the object.
       * For new objects, constructors can call their corresponding recycle
       * methods whenever applicable.
       * The recycle methods must call their super.
       */
      public void recycle();
  
      /**
       * Disposes the object after use. The method is called
       * when the object is returned to its pool.
       * The dispose method must call its super.
       */
      public void dispose();
  
      /**
       * Checks whether the recyclable has been disposed.
       * @return true, if the recyclable is disposed.
       */
      public boolean isDisposed();
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/api/src/java/org/apache/fulcrum/pool/PoolService.java
  
  Index: PoolService.java
  ===================================================================
  package org.apache.fulcrum.pool;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  
  /**
   * 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 object will be instantiated
   * from the specified class. If only class name is given, the request
   * to create an intance will be forwarded to the Factory Service.
   *
   * <p>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.
   *
   * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Id: PoolService.java,v 1.1 2003/11/19 11:26:55 epugh Exp $
   */
  public interface PoolService 
  {
      /** Avalon role - used to id the component within the manager */
      String ROLE = PoolService.class.getName();
  
  
      /**
       * The default pool capacity.
       */
      public static final int DEFAULT_POOL_CAPACITY = 128;
  
      /**
       * 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.
       */
      public Object getInstance(Class clazz)
          throws PoolException;
  
      /**
       * 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;
  
      /**
       * 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.
       */
      public boolean putInstance(Object instance);
  
      /**
       * Gets the capacity of the pool for a named class.
       *
       * @param className the name of the class.
       */
      public int getCapacity(String className);
  
      /**
       * 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.
       */
      public void setCapacity(String className,
                              int capacity);
  
      /**
       * Gets the current size of the pool for a named class.
       *
       * @param className the name of the class.
       */
      public int getSize(String className);
  
      /**
       * Clears instances of a named class from the pool.
       *
       * @param className the name of the class.
       */
      public void clearPool(String className);
  
      /**
       * Clears all instances from the pool.
       */
      void clearPool();
  
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/api/src/java/org/apache/fulcrum/pool/InitableRecyclable.java
  
  Index: InitableRecyclable.java
  ===================================================================
  package org.apache.fulcrum.pool;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  
  
  
  /**
   * 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
   * care of using the init method.  This is a way to avoid
   * introspection/reflection when pooling an object.
   *
   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
   * @version $Id: InitableRecyclable.java,v 1.1 2003/11/19 11:26:55 epugh Exp $
   */
  public interface InitableRecyclable extends Recyclable
  {
      /**
       * This method should be called after retrieving the object from
       * the pool.
       */
      public void init(Object initObj) throws PoolException;
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/api/src/java/org/apache/fulcrum/pool/PoolException.java
  
  Index: PoolException.java
  ===================================================================
  package org.apache.fulcrum.pool;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  /**
   * Exception thrown when there is a problem with the PoolException
   *
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: PoolException.java,v 1.1 2003/11/19 11:26:55 epugh Exp $
   */
  public class PoolException extends Exception
  {
      public PoolException(String msg)
      {
          super(msg);
      }
  	public PoolException(Exception ex)
  	  {
  		  super(ex);
  	  }
      public PoolException(String msg, Exception ex)
      {
          super(msg, ex);
      }
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/api/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <project>
  
    <extend>${basedir}/../../merlin-project.xml</extend>
    <id>fulcrum-pool-api</id>
    <name>Fulcrum Pool API</name>
    <currentVersion>1.0-alpha-2</currentVersion>
    <package>org.apache.fulcrum.pool</package>
   
  </project>
  
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/api/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  target
  *.log
  .classpath
  .project
  jcoverage.ser
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/impl/conf/block.xml
  
  Index: block.xml
  ===================================================================
  
  <container name="test">
  
     <classloader>
       <classpath>
         <repository>
           <resource id="fulcrum:fulcrum-factory-api" version="1.0-alpha-2"/>
           <resource id="fulcrum:fulcrum-factory-impl" version="1.0-alpha-2"/>
           <resource id="fulcrum:fulcrum-pool-api" version="1.0-alpha-2"/>
         </repository>
       </classpath>
     </classloader>
  
     <component name="factory" 
       class="org.apache.fulcrum.factory.DefaultFactoryService"/>
  
     <component name="pool" 
       class="org.apache.fulcrum.pool.DefaultPoolService">
       <configuration>
         <capacity default="256"/>
       </configuration>
     </component>
  
  </container>
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/impl/conf/config.xml
  
  Index: config.xml
  ===================================================================
  
  <targets>
  
    <target path="/test/factory">
      <categories priority="INFO"/>
    </target>
  
  </targets>
  
  
  
  1.1                  jakarta-turbine-fulcrum/pool/impl/src/test/org/apache/fulcrum/pool/PoolServiceTest.java
  
  Index: PoolServiceTest.java
  ===================================================================
  /*
   * Created on Aug 20, 2003
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.fulcrum.pool;
  import org.apache.avalon.merlin.unit.AbstractMerlinTestCase;
  
  /**
   * @author Eric Pugh
   * @author <a href="mailto:mcconnell@apache.org">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 AbstractMerlinTestCase
  {
      private PoolService poolService = null;
      /**
      	* Defines the testcase name for JUnit.
      	*
      	* @param name the testcase's name.
      	*/
      public PoolServiceTest(String name)
      {
          super(name);
      }
      public static void main(String[] args)
      {
          junit.textui.TestRunner.run(PoolServiceTest.class);
      }
      public void setUp() throws Exception
      {
          super.setUp();
          try
          {
              poolService = (PoolService) this.resolve( "pool" );
          }
          catch (Throwable e)
          {
              getLogger().error( "Setup failure.", e );
              fail(e.getMessage());
          }
      }
  
      /*
       * Class to test for Object getInstance(String)
       * @todo Some sort of compile error prevents this..
       */
      public void testGetInstanceString() throws PoolException
      {
          //Object object = poolService.getInstance("java.lang.StringBuffer");
          //assertTrue(object instanceof StringBuffer);
          getLogger().info( "no-impl" );
      }
      /*
       * Class to test for Object getInstance(String, ClassLoader)
       */
      public void testGetInstanceStringClassLoader()
      {
          getLogger().info( "no-impl" );
      }
      /*
       * Class to test for Object getInstance(String, Object[], String[])
       */
      public void testGetInstanceStringObjectArrayStringArray()
      {
          getLogger().info( "no-impl" );
      }
  
      /*
       * Class to test for Object getInstance(String, ClassLoader, Object[], String[])
       */
      public void testGetInstanceStringClassLoaderObjectArrayStringArray()
      {
          getLogger().info( "no-impl" );
      }
  
      public void testIsLoaderSupported()
      {
          getLogger().info( "no-impl" );
      }
  
      /*
       * Class to test for Object getInstance(Class)
       */
      public void testGetInstanceClass() throws PoolException
      {
          Object object = poolService.getInstance(StringBuffer.class);
          assertTrue(object instanceof StringBuffer);
          getLogger().info( "OK" );
      }
      /*
       * Class to test for Object getInstance(Class, Object[], String[])
       */
      public void testGetInstanceClassObjectArrayStringArray()
      {
          getLogger().info( "no-impl" );
      }
  
      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"));
          getLogger().info( "OK" );
      }
      public void testGetSetCapacity()
      {
          assertEquals(128, poolService.getCapacity("java.lang.String"));
          poolService.setCapacity("java.lang.String", 278);
          assertEquals(278, poolService.getCapacity("java.lang.String"));
          getLogger().info( "OK" );
      }
      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"));
          getLogger().info( "OK" );
      }
      /*
       * 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"));
          getLogger().info( "OK" );
      }
      /*
       * 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"));
          getLogger().info( "OK" );
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org