You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jv...@apache.org on 2001/07/14 07:01:58 UTC

cvs commit: jakarta-turbine/src/java/org/apache/turbine/services/pool ArrayCtorRecyclable.java BoundedBuffer.java InitableRecyclable.java ObjectInputStreamForContext.java Recyclable.java RecyclableSupport.java PoolService.java TurbinePoolService.java

jvanzyl     01/07/13 22:01:58

  Modified:    src/java/org/apache/turbine/services/pool PoolService.java
                        TurbinePoolService.java
  Added:       src/java/org/apache/turbine/services/pool
                        ArrayCtorRecyclable.java BoundedBuffer.java
                        InitableRecyclable.java
                        ObjectInputStreamForContext.java Recyclable.java
                        RecyclableSupport.java
  Log:
  - new location for pooling classes.
  
  Revision  Changes    Path
  1.7       +1 -2      jakarta-turbine/src/java/org/apache/turbine/services/pool/PoolService.java
  
  Index: PoolService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/pool/PoolService.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PoolService.java	2001/07/13 19:21:20	1.6
  +++ PoolService.java	2001/07/14 05:01:57	1.7
  @@ -55,7 +55,6 @@
    */
   
   import org.apache.turbine.TurbineException;
  -import org.apache.turbine.util.pool.Recyclable;
   import org.apache.turbine.services.factory.FactoryService;
   
   /**
  @@ -71,7 +70,7 @@
    * a dispose method, when they are returned to the pool.
    *
    * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
  - * @version $Id: PoolService.java,v 1.6 2001/07/13 19:21:20 jvanzyl Exp $
  + * @version $Id: PoolService.java,v 1.7 2001/07/14 05:01:57 jvanzyl Exp $
    */
   public interface PoolService extends FactoryService
   {
  
  
  
  1.14      +1 -6      jakarta-turbine/src/java/org/apache/turbine/services/pool/TurbinePoolService.java
  
  Index: TurbinePoolService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/pool/TurbinePoolService.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TurbinePoolService.java	2001/07/13 19:21:23	1.13
  +++ TurbinePoolService.java	2001/07/14 05:01:58	1.14
  @@ -58,12 +58,7 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.lang.reflect.Method;
  -
   import org.apache.turbine.TurbineException;
  -import org.apache.turbine.util.pool.Recyclable;
  -import org.apache.turbine.util.pool.ArrayCtorRecyclable;
  -import org.apache.turbine.util.pool.BoundedBuffer;
  -import org.apache.turbine.util.pool.ObjectInputStreamForContext;
   import org.apache.turbine.services.TurbineServices;
   import org.apache.turbine.services.BaseService;
   import org.apache.turbine.services.InitializationException;
  @@ -82,7 +77,7 @@
    * a dispose method, when they are returned to the pool.
    *
    * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
  - * @version $Id: TurbinePoolService.java,v 1.13 2001/07/13 19:21:23 jvanzyl Exp $
  + * @version $Id: TurbinePoolService.java,v 1.14 2001/07/14 05:01:58 jvanzyl Exp $
    */
   public class TurbinePoolService 
       extends TurbineFactoryService
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/pool/ArrayCtorRecyclable.java
  
  Index: ArrayCtorRecyclable.java
  ===================================================================
  package org.apache.turbine.services.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 2001/07/14 05:01:57 jvanzyl 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/src/java/org/apache/turbine/services/pool/BoundedBuffer.java
  
  Index: BoundedBuffer.java
  ===================================================================
  package org.apache.turbine.services.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 2001/07/14 05:01:57 jvanzyl 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/src/java/org/apache/turbine/services/pool/InitableRecyclable.java
  
  Index: InitableRecyclable.java
  ===================================================================
  package org.apache.turbine.services.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 org.apache.turbine.TurbineException;
  
  
  /**
   * 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 2001/07/14 05:01:57 jvanzyl Exp $
   */
  public interface InitableRecyclable extends Recyclable
  {
      /**
       * This method should be called after retrieving the object from
       * the pool.
       */
      public void init(Object initObj) throws TurbineException;
  }
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/pool/ObjectInputStreamForContext.java
  
  Index: ObjectInputStreamForContext.java
  ===================================================================
  package org.apache.turbine.services.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 2001/07/14 05:01:57 jvanzyl 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/src/java/org/apache/turbine/services/pool/Recyclable.java
  
  Index: Recyclable.java
  ===================================================================
  package org.apache.turbine.services.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 2001/07/14 05:01:57 jvanzyl 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/src/java/org/apache/turbine/services/pool/RecyclableSupport.java
  
  Index: RecyclableSupport.java
  ===================================================================
  package org.apache.turbine.services.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 org.apache.turbine.services.pool.TurbinePool;
  
  /**
   * A support class for recyclable objects implementing default methods.
   *
   * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
   * @version $Id: RecyclableSupport.java,v 1.1 2001/07/14 05:01:58 jvanzyl Exp $
   */
  public class RecyclableSupport implements Recyclable
  {
      /**
       * The disposed flag.
       */
      private boolean disposed;
  
      /**
       * Constructs a new recyclable support and calls the default recycle method.
       */
      public void Recyclable()
      {
          recycle();
      }
  
      /**
       * Recycles the object by removing its disposed flag.
       */
      public void recycle()
      {
          disposed = false;
      }
  
      /**
       * Disposes the object by setting its disposed flag.
       */
      public void dispose()
      {
          disposed = true;
      }
  
      /**
       * Checks whether the object is disposed.
       *
       * @return true, if the object is disposed.
       */
      public boolean isDisposed()
      {
          return disposed;
      }
      
      /**
       * A convenience method allowing a clever recyclable object 
       * to put itself into a pool for recycling.
       * 
       * @return true, if disposal was accepted by the pool.
       */
      protected boolean doDispose()
      {
          try
          {
              return TurbinePool.putInstance(this);
          }
          catch (RuntimeException x)
          {
              return false;
          }
      }
  }
  
  
  

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