You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Peter Donald <pe...@apache.org> on 2002/11/08 01:14:51 UTC

Re: cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler AbstractComponentHandler.java FactoryComponentHandler.java PerThreadComponentHandler.java PoolableComponentHandler.java ThreadSafeComponentHandler.java

Hi,

Can someone take a look at this?

On Fri, 8 Nov 2002 11:06, donaldp@apache.org wrote:
> donaldp     2002/11/07 16:06:34
>
>   Modified:    fortress/src/java/org/apache/excalibur/fortress/handler
>                         AbstractComponentHandler.java
>                         FactoryComponentHandler.java
>                         PerThreadComponentHandler.java
>                         PoolableComponentHandler.java
>                         ThreadSafeComponentHandler.java
>   Log:
>   Reworked put() to be subclass friendly via a doPut() method.
>
>   Also reworked Component and Factory release. It seems that in some cases
> that factory was never disposed (ThreadSafe component) and in other cases
> the instance was never disposed (ie PerThread).
>
>   Could some one verify that these fixes are correct. ATM the Pool is not
> shut down which may mean components are not released. Needs further
> investigation?
>
>   Revision  Changes    Path
>   1.19      +32 -2    
> jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/ha
>ndler/AbstractComponentHandler.java
>
>   Index: AbstractComponentHandler.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/f
>ortress/handler/AbstractComponentHandler.java,v retrieving revision 1.18
>   retrieving revision 1.19
>   diff -u -r1.18 -r1.19
>   --- AbstractComponentHandler.java	7 Nov 2002 23:51:24 -0000	1.18
>   +++ AbstractComponentHandler.java	8 Nov 2002 00:06:34 -0000	1.19
>   @@ -53,10 +53,10 @@
>    import org.apache.avalon.framework.activity.Disposable;
>    import org.apache.avalon.framework.activity.Initializable;
>    import org.apache.avalon.framework.configuration.Configuration;
>   +import org.apache.avalon.framework.container.ContainerUtil;
>    import org.apache.avalon.framework.context.Context;
>    import org.apache.avalon.framework.logger.Logger;
>    import org.apache.avalon.framework.service.ServiceManager;
>   -import org.apache.avalon.framework.container.ContainerUtil;
>    import org.apache.excalibur.fortress.Container;
>    import
> org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager; import
> org.apache.excalibur.instrument.AbstractInstrumentable;
>   @@ -209,6 +209,36 @@
>                final String message =
>                    "You cannot put a component in an uninitialized holder";
>                throw new IllegalStateException( message );
>   +        }
>   +
>   +        doPut( component );
>   +    }
>   +
>   +    /**
>   +     * Subclasses should overide this to return component to handler.
>   +     *
>   +     * @param component the component
>   +     */
>   +    protected abstract void doPut( final Object component );
>   +
>   +
>   +    /**
>   +     * Dispose of the specified component.
>   +     *
>   +     * @param component the component
>   +     */
>   +    protected void disposeComponent( final Object component )
>   +    {
>   +        try
>   +        {
>   +            m_factory.dispose( component );
>   +        }
>   +        catch( final Exception e )
>   +        {
>   +            if( m_logger.isWarnEnabled() )
>   +            {
>   +                m_logger.warn( "Error disposing component", e );
>   +            }
>            }
>        }
>
>
>
>
>   1.28      +3 -15    
> jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/ha
>ndler/FactoryComponentHandler.java
>
>   Index: FactoryComponentHandler.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/f
>ortress/handler/FactoryComponentHandler.java,v retrieving revision 1.27
>   retrieving revision 1.28
>   diff -u -r1.27 -r1.28
>   --- FactoryComponentHandler.java	7 Nov 2002 23:46:48 -0000	1.27
>   +++ FactoryComponentHandler.java	8 Nov 2002 00:06:34 -0000	1.28
>   @@ -114,20 +114,8 @@
>        /**
>         * Return a reference of the desired Component
>         */
>   -    public void put( final Object component )
>   +    protected void doPut( final Object component )
>        {
>   -        super.put( component );
>   -
>   -        try
>   -        {
>   -            m_factory.dispose( component );
>   -        }
>   -        catch( Exception e )
>   -        {
>   -            if( m_logger.isWarnEnabled() )
>   -            {
>   -                m_logger.warn( "Error disposing component", e );
>   -            }
>   -        }
>   +        disposeComponent( component );
>        }
>    }
>
>
>
>   1.31      +8 -3     
> jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/ha
>ndler/PerThreadComponentHandler.java
>
>   Index: PerThreadComponentHandler.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/f
>ortress/handler/PerThreadComponentHandler.java,v retrieving revision 1.30
>   retrieving revision 1.31
>   diff -u -r1.30 -r1.31
>   --- PerThreadComponentHandler.java	7 Nov 2002 23:46:48 -0000	1.30
>   +++ PerThreadComponentHandler.java	8 Nov 2002 00:06:34 -0000	1.31
>   @@ -131,15 +131,20 @@
>            return instance;
>        }
>
>   +    protected void doPut( Object component )
>   +    {
>   +        //Do nothing
>   +    }
>   +
>        /**
>         * Dispose of the ComponentHandler and any associated Pools and
>         * Factories.
>         */
>        public void dispose()
>        {
>   -        super.dispose();
>   -
>   +        disposeComponent( m_instance );
>            m_instance = null;
>   +        super.dispose();
>        }
>
>        private static final class ThreadLocalComponent extends ThreadLocal
>
>
>
>   1.32      +2 -3     
> jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/ha
>ndler/PoolableComponentHandler.java
>
>   Index: PoolableComponentHandler.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/f
>ortress/handler/PoolableComponentHandler.java,v retrieving revision 1.31
>   retrieving revision 1.32
>   diff -u -r1.31 -r1.32
>   --- PoolableComponentHandler.java	7 Nov 2002 23:46:48 -0000	1.31
>   +++ PoolableComponentHandler.java	8 Nov 2002 00:06:34 -0000	1.32
>   @@ -131,9 +131,8 @@
>        /**
>         * Return a reference of the desired Component
>         */
>   -    public void put( final Object component )
>   +    protected void doPut( final Object component )
>        {
>   -        super.put( component );
>            m_pool.release( component );
>        }
>
>
>
>
>   1.30      +10 -28   
> jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/ha
>ndler/ThreadSafeComponentHandler.java
>
>   Index: ThreadSafeComponentHandler.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/f
>ortress/handler/ThreadSafeComponentHandler.java,v retrieving revision 1.29
>   retrieving revision 1.30
>   diff -u -r1.29 -r1.30
>   --- ThreadSafeComponentHandler.java	7 Nov 2002 23:46:48 -0000	1.29
>   +++ ThreadSafeComponentHandler.java	8 Nov 2002 00:06:34 -0000	1.30
>   @@ -49,12 +49,10 @@
>    */
>    package org.apache.excalibur.fortress.handler;
>
>   -import org.apache.avalon.framework.activity.Disposable;
>   -import org.apache.avalon.framework.activity.Startable;
>    import org.apache.avalon.framework.configuration.Configuration;
>   +import org.apache.avalon.framework.container.ContainerUtil;
>    import org.apache.avalon.framework.context.Context;
>    import org.apache.avalon.framework.service.ServiceManager;
>   -import org.apache.avalon.framework.container.ContainerUtil;
>    import
> org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
>
>    /**
>   @@ -135,34 +133,18 @@
>            return m_instance;
>        }
>
>   +    protected void doPut( Object component )
>   +    {
>   +        //do nothing
>   +    }
>   +
>        /**
>         * Dispose of the ComponentHandler and any associated Pools and
> Factories. */
>        public void dispose()
>        {
>   -        try
>   -        {
>   -            if( null != m_factory )
>   -            {
>   -                m_factory.dispose( m_instance );
>   -            }
>   -            else
>   -            {
>   -                ContainerUtil.stop( m_instance );
>   -                ContainerUtil.dispose( m_instance );
>   -            }
>   -
>   -            m_instance = null;
>   -        }
>   -        catch( final Exception e )
>   -        {
>   -            if( m_logger.isWarnEnabled() )
>   -            {
>   -                m_logger.warn( "Error decommissioning component: " +
>   -                               m_factory.getCreatedClass().getName(), e
> ); -            }
>   -        }
>   -
>   -        m_disposed = true;
>   +        disposeComponent( m_instance );
>   +        m_instance = null;
>   +        super.dispose();
>        }
>    }

-- 
Cheers,

Peter Donald
--------------------------------------------------
 The fact that nobody understands you doesn't 
 mean you're an artist.
--------------------------------------------------


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