avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler AbstractComponentHandler.java FactoryComponentHandler.java PerThreadComponentHandler.java PoolableComponentHandler.java ThreadSafeComponentHandler.java
Date Thu, 07 Nov 2002 23:46:48 GMT
donaldp     2002/11/07 15:46:48

  Modified:    fortress/src/java/org/apache/excalibur/fortress/handler
                        AbstractComponentHandler.java
                        FactoryComponentHandler.java
                        PerThreadComponentHandler.java
                        PoolableComponentHandler.java
                        ThreadSafeComponentHandler.java
  Log:
  Rework how the handlers implement get so that they now overide an abstract method in AbstractComponentHandler
rather than calling parent get() method and ignoring return value.
  
  Revision  Changes    Path
  1.17      +26 -17    jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/AbstractComponentHandler.java
  
  Index: AbstractComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/AbstractComponentHandler.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AbstractComponentHandler.java	2 Oct 2002 01:52:21 -0000	1.16
  +++ AbstractComponentHandler.java	7 Nov 2002 23:46:48 -0000	1.17
  @@ -55,6 +55,7 @@
   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;
  @@ -178,31 +179,41 @@
       {
           if( !m_initialized )
           {
  -            throw new IllegalStateException(
  -                "You cannot get a component from an uninitialized holder"
  -            );
  +            final String message =
  +                "You cannot get a component from an uninitialized holder";
  +            throw new IllegalStateException( message );
           }
   
           if( m_disposed )
           {
  -            throw new IllegalStateException(
  -                "You cannot get a component from a disposed holder"
  -            );
  +            final String message =
  +                "You cannot get a component from a disposed holder";
  +            throw new IllegalStateException( message );
           }
   
  -        return null; // value not used, satisfies compiler
  +        return doGet();
       }
   
       /**
  +     * Subclasses should actually overide this to do the work
  +     * of retrieving a service.
  +     *
  +     * @return the service
  +     * @throws Exception if unable to aquire service
  +     */
  +    protected abstract Object doGet()
  +        throws Exception;
  +
  +    /**
        * Return a reference of the desired Component
        */
       public void put( final Object component )
       {
           if( !m_initialized )
           {
  -            throw new IllegalStateException(
  -                "You cannot put a component in an uninitialized holder"
  -            );
  +            final String message =
  +                "You cannot put a component in an uninitialized holder";
  +            throw new IllegalStateException( message );
           }
       }
   
  @@ -213,17 +224,15 @@
       {
           try
           {
  -            if( m_factory instanceof Disposable )
  -            {
  -                ( (Disposable)m_factory ).dispose();
  -            }
  +            ContainerUtil.dispose( m_factory );
           }
           catch( final Exception e )
           {
               if( m_logger.isWarnEnabled() )
               {
  -                m_logger.warn( "Error decommissioning component: " +
  -                               m_factory.getCreatedClass().getName(), e );
  +                final String message = "Error decommissioning component: " +
  +                    m_factory.getCreatedClass().getName();
  +                m_logger.warn( message, e );
               }
           }
   
  
  
  
  1.27      +2 -4      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/FactoryComponentHandler.java
  
  Index: FactoryComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/FactoryComponentHandler.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- FactoryComponentHandler.java	2 Oct 2002 01:47:00 -0000	1.26
  +++ FactoryComponentHandler.java	7 Nov 2002 23:46:48 -0000	1.27
  @@ -105,11 +105,9 @@
       /**
        * Get a reference of the desired Component
        */
  -    public Object get()
  +    protected Object doGet()
           throws Exception
       {
  -        super.get();
  -
           return m_factory.newInstance();
       }
   
  
  
  
  1.30      +4 -7      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PerThreadComponentHandler.java
  
  Index: PerThreadComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PerThreadComponentHandler.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- PerThreadComponentHandler.java	7 Nov 2002 23:28:59 -0000	1.29
  +++ PerThreadComponentHandler.java	7 Nov 2002 23:46:48 -0000	1.30
  @@ -119,14 +119,11 @@
       /**
        * Get a reference of the desired Component
        */
  -    public final Object get()
  +    protected Object doGet()
           throws Exception
       {
  -        super.get();
  -
  -        Object instance = m_instance.get();
  -
  -        if( instance == null )
  +        final Object instance = m_instance.get();
  +        if( null == instance )
           {
               throw new IllegalStateException( "Instance is unavailable" );
           }
  
  
  
  1.31      +2 -4      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PoolableComponentHandler.java
  
  Index: PoolableComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PoolableComponentHandler.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- PoolableComponentHandler.java	2 Oct 2002 01:47:00 -0000	1.30
  +++ PoolableComponentHandler.java	7 Nov 2002 23:46:48 -0000	1.31
  @@ -122,11 +122,9 @@
       /**
        * Get a reference of the desired Component
        */
  -    public Object get()
  +    protected Object doGet()
           throws Exception
       {
  -        super.get();
  -
           return m_pool.acquire();
       }
   
  
  
  
  1.29      +18 -21    jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ThreadSafeComponentHandler.java
  
  Index: ThreadSafeComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ThreadSafeComponentHandler.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- ThreadSafeComponentHandler.java	7 Nov 2002 23:29:42 -0000	1.28
  +++ ThreadSafeComponentHandler.java	7 Nov 2002 23:46:48 -0000	1.29
  @@ -54,6 +54,7 @@
   import org.apache.avalon.framework.configuration.Configuration;
   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;
   
   /**
  @@ -65,7 +66,8 @@
    * @version CVS $Revision$ $Date$
    * @since 4.0
    */
  -public final class ThreadSafeComponentHandler extends AbstractComponentHandler
  +public final class ThreadSafeComponentHandler
  +    extends AbstractComponentHandler
   {
       private Object m_instance;
   
  @@ -100,20 +102,22 @@
   
           if( m_instance == null )
           {
  -            m_instance = this.m_factory.newInstance();
  +            m_instance = m_factory.newInstance();
           }
   
           if( m_logger.isDebugEnabled() )
           {
  -            if( this.m_factory != null )
  +            if( null != m_factory )
               {
  -                m_logger.debug( "ComponentHandler initialized for: "
  -                                + this.m_factory.getCreatedClass().getName() );
  +                final String message = "ComponentHandler initialized for: " +
  +                    m_factory.getCreatedClass().getName();
  +                m_logger.debug( message );
               }
               else
               {
  -                m_logger.debug( "ComponentHandler initialized for: "
  -                                + this.m_instance.getClass().getName() );
  +                final String message =
  +                    "ComponentHandler initialized for: " + m_instance.getClass().getName();
  +                m_logger.debug( message );
               }
           }
   
  @@ -121,13 +125,13 @@
       }
   
       /**
  -     * Get a reference of the desired Component
  +     * Return instance for a get.
  +     *
  +     * @return the instance
        */
  -    public final Object get()
  +    protected Object doGet()
           throws Exception
       {
  -        super.get();
  -
           return m_instance;
       }
   
  @@ -144,15 +148,8 @@
               }
               else
               {
  -                if( m_instance instanceof Startable )
  -                {
  -                    ( (Startable)m_instance ).stop();
  -                }
  -
  -                if( m_instance instanceof Disposable )
  -                {
  -                    ( (Disposable)m_instance ).dispose();
  -                }
  +                ContainerUtil.stop( m_instance );
  +                ContainerUtil.dispose( m_instance );
               }
   
               m_instance = null;
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message