You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/09/25 17:47:58 UTC

cvs commit: jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool PoolUtil.java FixedSizePool.java VariableSizePool.java BlockingFixedSizePool.java

bloritsch    2002/09/25 08:47:58

  Modified:    event/src/java/org/apache/excalibur/mpool FixedSizePool.java
                        VariableSizePool.java BlockingFixedSizePool.java
  Added:       event/src/java/org/apache/excalibur/mpool PoolUtil.java
  Log:
  Add support for resetting objects (with the Recycle method)
  
  Revision  Changes    Path
  1.6       +5 -2      jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/FixedSizePool.java
  
  Index: FixedSizePool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/FixedSizePool.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FixedSizePool.java	13 Aug 2002 08:15:20 -0000	1.5
  +++ FixedSizePool.java	25 Sep 2002 15:47:57 -0000	1.6
  @@ -54,6 +54,9 @@
   import org.apache.avalon.excalibur.collections.FixedSizeBuffer;
   import org.apache.avalon.framework.activity.Disposable;
   
  +import java.lang.reflect.Method;
  +import java.lang.reflect.Modifier;
  +
   /**
    * This is an <code>Pool</code> that caches Poolable objects for reuse.
    * Please note that this pool offers no resource limiting whatsoever.
  @@ -115,7 +118,7 @@
           {
               synchronized( m_buffer )
               {
  -                m_buffer.add( object );
  +                m_buffer.add( PoolUtil.reset( object ) );
                   m_buffer.notifyAll();
               }
           }
  
  
  
  1.3       +2 -2      jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/VariableSizePool.java
  
  Index: VariableSizePool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/VariableSizePool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- VariableSizePool.java	13 Aug 2002 08:15:20 -0000	1.2
  +++ VariableSizePool.java	25 Sep 2002 15:47:57 -0000	1.3
  @@ -145,7 +145,7 @@
           {
               synchronized( m_buffer )
               {
  -                m_buffer.add( pooledObject );
  +                m_buffer.add( PoolUtil.reset( pooledObject ) );
               }
           }
       }
  
  
  
  1.4       +2 -3      jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/BlockingFixedSizePool.java
  
  Index: BlockingFixedSizePool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/BlockingFixedSizePool.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BlockingFixedSizePool.java	14 Aug 2002 17:04:11 -0000	1.3
  +++ BlockingFixedSizePool.java	25 Sep 2002 15:47:57 -0000	1.4
  @@ -49,7 +49,6 @@
   */
   package org.apache.excalibur.mpool;
   
  -import org.apache.avalon.excalibur.concurrent.Mutex;
   import org.apache.avalon.excalibur.collections.Buffer;
   import org.apache.avalon.excalibur.collections.BufferUnderflowException;
   import org.apache.avalon.excalibur.collections.FixedSizeBuffer;
  @@ -196,7 +195,7 @@
               {
                   if ( m_buffer.size() < m_maxSize )
                   {
  -                    m_buffer.add( object );
  +                    m_buffer.add( PoolUtil.reset( object ) );
                       m_semaphore.notify();
                   }
                   else
  
  
  
  1.1                  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/PoolUtil.java
  
  Index: PoolUtil.java
  ===================================================================
  /*
   * Created by IntelliJ IDEA.
   * User: bloritsch
   * Date: Sep 25, 2002
   * Time: 11:47:49 AM
   * To change template for new class use 
   * Code Style | Class Templates options (Tools | IDE Options).
   */
  package org.apache.excalibur.mpool;
  
  import java.lang.reflect.Method;
  import java.lang.reflect.Modifier;
  
  public final class PoolUtil
  {
      private final static Object[] EMPTY = new Object[] {};
      private final static Class[] EMPTY_ARGS = new Class[] {};
  
      private PoolUtil() {}
  
      public static Object reset( final Object obj )
      {
          try
          {
              Class klass = obj.getClass();
              Method recycle = klass.getMethod( "recycle", EMPTY_ARGS );
  
              if ( Modifier.isPublic( recycle.getModifiers() ) &&
                      recycle.getReturnType().equals( void.class ) )
              {
                  recycle.invoke( obj, EMPTY );
              }
          }
          catch (Exception e)
          {
              // Not a recyclable object--don't worry about it
          }
  
          return obj;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Mpool support for Recyclable (was RE: cvs commit: jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool PoolUtil.java FixedSizePool.java VariableSizePool.java BlockingFixedSizePool.java)

Posted by Berin Loritsch <bl...@apache.org>.
Fixed.

I have the Recyclable/Resettable set up this way:

if the Object implements Resettable, it will call the "reset()"
method.

If the "org.apache.avalon.excalibur.pool.Recyclable" class
is assignable from the Object's class we invoke the "recycle()"
method.

Otherwise we leave the class alone.

> -----Original Message-----
> From: Berin Loritsch [mailto:bloritsch@apache.org] 
> Sent: Wednesday, September 25, 2002 7:42 PM
> To: 'Avalon Developers List'
> Subject: RE: cvs commit: 
> jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/m
> pool PoolUtil.java FixedSizePool.java VariableSizePool.java 
> BlockingFixedSizePool.java
> 
> 
> > From: Peter Donald [mailto:peter@apache.org] 
> > 
> > On Thu, 26 Sep 2002 01:47, bloritsch@apache.org wrote:
> > >   1.1                 
> > > 
> > jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/m
> > pool/PoolUtil
> > >.java
> > >
> > >   Index: PoolUtil.java
> > >   
> > ===================================================================
> > >   /*
> > >    * Created by IntelliJ IDEA.
> > >    * User: bloritsch
> > >    * Date: Sep 25, 2002
> > >    * Time: 11:47:49 AM
> > >    * To change template for new class use
> > >    * Code Style | Class Templates options (Tools | IDE Options).
> > >    */
> > 
> > LICENSE!
> 
> Oops.  (As you can see I have an early adopters version of IDEA)
> 
> Will fix ASAP.
> 
> > 
> > 
> > I would prefer that you checked if it implemented Recyclable 
> > class (also by 
> > reflection). The reason being that I have classes that have a 
> > recycle method 
> > that are not Recyclable.
> 
> Hmm.  We need to support the Recyclable interface from the old Pool
> package
> without an artificial dependency for one class....
> 
> So we can choose to use a particular "recycle" method even if it is
> "reset" or whatever using pure reflection.  Any thoughts on how to
> satisfy it without crazy dependency checks?
> 
> I can add the check for the "Recycle" interface as well.  How do you
> feel about a "Resettable" interface for MPool, which will allow
> PoolUtil to check for the Resettable interface or the old Recyclable
> interface.  That way we can make them both work....
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:avalon-dev-> unsubscribe@jakarta.apache.org>
> For 
> additional commands, 
> e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: cvs commit: jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool PoolUtil.java FixedSizePool.java VariableSizePool.java BlockingFixedSizePool.java

Posted by Berin Loritsch <bl...@apache.org>.
> From: Peter Donald [mailto:peter@apache.org] 
> 
> On Thu, 26 Sep 2002 01:47, bloritsch@apache.org wrote:
> >   1.1                 
> > 
> jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/m
> pool/PoolUtil
> >.java
> >
> >   Index: PoolUtil.java
> >   
> ===================================================================
> >   /*
> >    * Created by IntelliJ IDEA.
> >    * User: bloritsch
> >    * Date: Sep 25, 2002
> >    * Time: 11:47:49 AM
> >    * To change template for new class use
> >    * Code Style | Class Templates options (Tools | IDE Options).
> >    */
> 
> LICENSE!

Oops.  (As you can see I have an early adopters version of IDEA)

Will fix ASAP.

> 
> 
> I would prefer that you checked if it implemented Recyclable 
> class (also by 
> reflection). The reason being that I have classes that have a 
> recycle method 
> that are not Recyclable.

Hmm.  We need to support the Recyclable interface from the old Pool
package
without an artificial dependency for one class....

So we can choose to use a particular "recycle" method even if it is
"reset" or whatever using pure reflection.  Any thoughts on how to
satisfy it without crazy dependency checks?

I can add the check for the "Recycle" interface as well.  How do you
feel about a "Resettable" interface for MPool, which will allow
PoolUtil to check for the Resettable interface or the old Recyclable
interface.  That way we can make them both work....


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool PoolUtil.java FixedSizePool.java VariableSizePool.java BlockingFixedSizePool.java

Posted by Peter Donald <pe...@apache.org>.
On Thu, 26 Sep 2002 01:47, bloritsch@apache.org wrote:
>   1.1                 
> jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/PoolUtil
>.java
>
>   Index: PoolUtil.java
>   ===================================================================
>   /*
>    * Created by IntelliJ IDEA.
>    * User: bloritsch
>    * Date: Sep 25, 2002
>    * Time: 11:47:49 AM
>    * To change template for new class use
>    * Code Style | Class Templates options (Tools | IDE Options).
>    */

LICENSE!

>   package org.apache.excalibur.mpool;
>
>   import java.lang.reflect.Method;
>   import java.lang.reflect.Modifier;
>
>   public final class PoolUtil
>   {
>       private final static Object[] EMPTY = new Object[] {};
>       private final static Class[] EMPTY_ARGS = new Class[] {};
>
>       private PoolUtil() {}
>
>       public static Object reset( final Object obj )
>       {
>           try
>           {
>               Class klass = obj.getClass();
>               Method recycle = klass.getMethod( "recycle", EMPTY_ARGS );
>
>               if ( Modifier.isPublic( recycle.getModifiers() ) &&
>                       recycle.getReturnType().equals( void.class ) )
>               {
>                   recycle.invoke( obj, EMPTY );
>               }


I would prefer that you checked if it implemented Recyclable class (also by 
reflection). The reason being that I have classes that have a recycle method 
that are not Recyclable.

>           }
>           catch (Exception e)
>           {
>               // Not a recyclable object--don't worry about it
>           }
>
>           return obj;
>       }
>   }

-- 
Cheers,

Peter Donald
--------------------------------
 These aren't the droids you're 
 looking for. Move along. 
-------------------------------- 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>