avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle AbstractLifestyleHandler.java SingletonLifestyleHandler.java
Date Sat, 30 Nov 2002 18:12:07 GMT
mcconnell    2002/11/30 10:12:07

  Modified:    assembly/src/java/org/apache/avalon/assembly/appliance
                        DefaultAppliance.java
               assembly/src/java/org/apache/avalon/assembly/lifecycle/composition
                        DefaultCompositionService.java
                        DefaultServiceManager.java
               assembly/src/java/org/apache/avalon/assembly/lifecycle/configuration
                        DefaultConfigurationService.java
               assembly/src/java/org/apache/avalon/assembly/lifecycle/context
                        DefaultContextualizationService.java
               assembly/src/java/org/apache/avalon/assembly/lifecycle/disposal
                        DefaultDisposalService.java
                        ExtendedDisposalService.java
               assembly/src/java/org/apache/avalon/assembly/lifecycle/initialization
                        DefaultInitializationService.java
                        ExtendedInitializationService.java
               assembly/src/java/org/apache/avalon/assembly/lifecycle/logging
                        DefaultLoggingService.java
               assembly/src/java/org/apache/avalon/assembly/lifecycle/parameters
                        DefaultParameterizationService.java
               assembly/src/java/org/apache/avalon/assembly/lifecycle/startup
                        DefaultStartupService.java
               assembly/src/java/org/apache/avalon/assembly/lifestyle
                        AbstractLifestyleHandler.java
                        SingletonLifestyleHandler.java
  Log:
  Fixed a bug in the service manager release logic where release of an object
  was been redirected to appliance of the principal component and not the
  appliance of the provider.
  
  Revision  Changes    Path
  1.3       +11 -2     avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultAppliance.java
  
  Index: DefaultAppliance.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultAppliance.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultAppliance.java	29 Nov 2002 13:04:54 -0000	1.2
  +++ DefaultAppliance.java	30 Nov 2002 18:12:06 -0000	1.3
  @@ -393,7 +393,16 @@
       */
       public void release( Object object )
       {
  -        m_handler.release( object );
  +        try
  +        {
  +            m_handler.release( object );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Lifestyle handler raised a release error in appliance: " + getProfile().getName();
  +            throw new ApplianceRuntimeException( error, e );
  +        }
       }
   
       public String toString()
  
  
  
  1.2       +8 -6      avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/composition/DefaultCompositionService.java
  
  Index: DefaultCompositionService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/composition/DefaultCompositionService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultCompositionService.java	29 Nov 2002 13:04:54 -0000	1.1
  +++ DefaultCompositionService.java	30 Nov 2002 18:12:06 -0000	1.2
  @@ -94,15 +94,16 @@
   
           if( object instanceof Serviceable )
           {
  -            ServiceManager manager = new DefaultServiceManager( appliance );
  -            ((Serviceable)object).service( manager );
  -
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
                     "[" + appliance.getProfile().getName() + "]";
                   getLogger().debug( message );
               }
  +            DefaultServiceManager manager = new DefaultServiceManager( appliance );
  +            manager.enableLogging( getLogger().getChildLogger( "manager" ) );
  +            ((Serviceable)object).service( manager );
  +
           }
       }
   
  @@ -124,14 +125,15 @@
   
           if( object instanceof Composable )
           {
  -            ServiceManager manager = new DefaultServiceManager( appliance );
  -            ((Composable)object).compose( new WrapperComponentManager( manager ) );
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
                     "[" + appliance.getProfile().getName() + "]";
                   getLogger().debug( message );
               }
  +            DefaultServiceManager manager = new DefaultServiceManager( appliance );
  +            manager.enableLogging( getLogger().getChildLogger( "manager" ) );
  +            ((Composable)object).compose( new WrapperComponentManager( manager ) );
           }
       }
   }
  
  
  
  1.3       +32 -3     avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/composition/DefaultServiceManager.java
  
  Index: DefaultServiceManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/composition/DefaultServiceManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultServiceManager.java	29 Nov 2002 16:05:34 -0000	1.2
  +++ DefaultServiceManager.java	30 Nov 2002 18:12:06 -0000	1.3
  @@ -54,6 +54,9 @@
    */ 
   package org.apache.avalon.assembly.lifecycle.composition;
   
  +import java.util.Hashtable;
  +
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.assembly.appliance.Appliance;
  @@ -64,7 +67,7 @@
    * is supplied to componets during lifecyle processing.
    * @author Stephen McConnell <mcconnell@osm.net>
    */
  -public class DefaultServiceManager implements ServiceManager
  +public class DefaultServiceManager extends AbstractLogEnabled implements ServiceManager
   {
   
       //========================================================================
  @@ -76,6 +79,13 @@
        */
       private Appliance m_appliance;
   
  +    /**
  +     * A table of appliance instances keyed by the object that was provided
  +     * by the appliance so that we can locate the correct appliance when 
  +     * releasing the object.
  +     */
  +    private Hashtable m_table = new Hashtable();
  +
       //========================================================================
       // constructor
       //========================================================================
  @@ -129,7 +139,9 @@
   
           try
           {
  -            return provider.access( dependency );
  +            Object object = provider.access( dependency );
  +            m_table.put( object, provider );
  +            return object;
           }
           catch( Throwable e )
           {
  @@ -147,6 +159,23 @@
        */
       public void release( Object object )
       {
  -        m_appliance.release( object );
  +        Appliance provider = (Appliance) m_table.get( object );
  +        if( provider == null )
  +        {
  +            if( getLogger().isWarnEnabled() )
  +            {
  +                final String warning =
  +                  "Inconsistent release request - the object: "
  +                  + object.getClass().getName() 
  +                  + "/" + System.identityHashCode( object )
  +                  + " was not provided by this manager.";
  +                getLogger().warn( warning );
  +            }
  +        }
  +        else
  +        {
  +            provider.release( object );
  +            m_table.remove( object );
  +        }
       }
   }
  
  
  
  1.2       +7 -7      avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/configuration/DefaultConfigurationService.java
  
  Index: DefaultConfigurationService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/configuration/DefaultConfigurationService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultConfigurationService.java	29 Nov 2002 13:04:55 -0000	1.1
  +++ DefaultConfigurationService.java	30 Nov 2002 18:12:06 -0000	1.2
  @@ -87,18 +87,18 @@
   
           if( object instanceof Configurable )
           {
  -            Configuration config = appliance.getProfile().getConfiguration();
  -            if( config == null )
  -            {
  -                config = new DefaultConfiguration( "configuration", null );
  -            }
  -            ((Configurable)object).configure( config );
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
                     "[" + appliance.getProfile().getName() + "]";
                   getLogger().debug( message );
               }
  +            Configuration config = appliance.getProfile().getConfiguration();
  +            if( config == null )
  +            {
  +                config = new DefaultConfiguration( "configuration", null );
  +            }
  +            ((Configurable)object).configure( config );
           }
       }
   }
  
  
  
  1.3       +4 -4      avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/DefaultContextualizationService.java
  
  Index: DefaultContextualizationService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/DefaultContextualizationService.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultContextualizationService.java	29 Nov 2002 16:06:35 -0000	1.2
  +++ DefaultContextualizationService.java	30 Nov 2002 18:12:06 -0000	1.3
  @@ -127,15 +127,15 @@
   
           if( object instanceof Contextualizable )
           {
  -            Context standard =
  -              createStandardContext( appliance.getProfile(), context );
  -            ((Contextualizable)object).contextualize( standard );
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
                     "[" + appliance.getProfile().getName() + "]";
                   getLogger().debug( message );
               }
  +            Context standard =
  +              createStandardContext( appliance.getProfile(), context );
  +            ((Contextualizable)object).contextualize( standard );
           }
       }
   
  
  
  
  1.2       +8 -6      avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/disposal/DefaultDisposalService.java
  
  Index: DefaultDisposalService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/disposal/DefaultDisposalService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultDisposalService.java	29 Nov 2002 13:04:55 -0000	1.1
  +++ DefaultDisposalService.java	30 Nov 2002 18:12:06 -0000	1.2
  @@ -83,14 +83,16 @@
   
           if( object instanceof Disposable )
           {
  +            if( getLogger().isDebugEnabled() )
  +            {
  +                final String message = 
  +                  "Appliance disposal: " 
  +                  + appliance.getProfile().getName();
  +                getLogger().debug( message );
  +            }
               try
               {
                   ((Disposable)object).dispose();
  -                if( getLogger().isDebugEnabled() )
  -                {
  -                    final String message = "Appliance disposal: " + appliance.getProfile().getName();
  -                    getLogger().debug( message );
  -                }
               }
               catch( Throwable e )
               {
  
  
  
  1.4       +9 -3      avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/disposal/ExtendedDisposalService.java
  
  Index: ExtendedDisposalService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/disposal/ExtendedDisposalService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ExtendedDisposalService.java	29 Nov 2002 16:06:35 -0000	1.3
  +++ ExtendedDisposalService.java	30 Nov 2002 18:12:06 -0000	1.4
  @@ -123,6 +123,12 @@
           StageDescriptor[] stages = appliance.getProfile().getType().getStages();
           if( stages.length > 0 )
           {
  +            if( getLogger().isDebugEnabled() )
  +            {
  +                final String message =  
  +                  "[" + appliance.getProfile().getName() + "] destroy stage extension handling"
;
  +                getLogger().debug( message );
  +            }
               for( int i = 0; i < stages.length; i++ )
               {
                   StageDescriptor stage = stages[i];
  @@ -136,13 +142,13 @@
   
           if( object instanceof Disposable )
           {
  -            ((Disposable)object).dispose();
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
  -                  "[" + appliance.getProfile().getName() + "]";
  +                  "[" + appliance.getProfile().getName() + "] disposal";
                   getLogger().debug( message );
               }
  +            ((Disposable)object).dispose();
           }
       }
   
  
  
  
  1.2       +2 -2      avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/initialization/DefaultInitializationService.java
  
  Index: DefaultInitializationService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/initialization/DefaultInitializationService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultInitializationService.java	29 Nov 2002 13:04:55 -0000	1.1
  +++ DefaultInitializationService.java	30 Nov 2002 18:12:06 -0000	1.2
  @@ -75,13 +75,13 @@
       {
          if( object instanceof Initializable )
          {
  -           ((Initializable)object).initialize();
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
                     "[" + appliance.getProfile().getName() + "]";
                   getLogger().debug( message );
               }
  +           ((Initializable)object).initialize();
          }
       }
   }
  
  
  
  1.4       +11 -3     avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/initialization/ExtendedInitializationService.java
  
  Index: ExtendedInitializationService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/initialization/ExtendedInitializationService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ExtendedInitializationService.java	29 Nov 2002 16:06:35 -0000	1.3
  +++ ExtendedInitializationService.java	30 Nov 2002 18:12:06 -0000	1.4
  @@ -129,6 +129,14 @@
               {
                   StageDescriptor stage = stages[ i ];
   
  +                if( getLogger().isDebugEnabled() )
  +                {
  +                    final String message =  
  +                      "[" + appliance.getProfile().getName() 
  +                      + "] extension:" + stage;
  +                    getLogger().debug( message );
  +                }
  +
                   Appliance provider;
                   try
                   {
  @@ -206,13 +214,13 @@
   
           if( object instanceof Initializable )
           {
  -            ((Initializable)object).initialize();
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
  -                  "[" + appliance.getProfile().getName() + "]";
  +                  "[" + appliance.getProfile().getName() + "] initialization";
                   getLogger().debug( message );
               }
  +            ((Initializable)object).initialize();
           }
       }
   }
  
  
  
  1.2       +6 -6      avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/logging/DefaultLoggingService.java
  
  Index: DefaultLoggingService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/logging/DefaultLoggingService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultLoggingService.java	29 Nov 2002 13:04:55 -0000	1.1
  +++ DefaultLoggingService.java	30 Nov 2002 18:12:06 -0000	1.2
  @@ -84,17 +84,17 @@
   
           if( object instanceof LogEnabled )
           {
  -            if( logger == null )
  -            {
  -                throw new NullPointerException( "logger" );
  -            }
  -            ((LogEnabled)object).enableLogging( logger );
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
                     "[" + appliance.getProfile().getName() + "]";
                   getLogger().debug( message );
               }
  +            if( logger == null )
  +            {
  +                throw new NullPointerException( "logger" );
  +            }
  +            ((LogEnabled)object).enableLogging( logger );
           }
       }
   }
  
  
  
  1.2       +7 -7      avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/parameters/DefaultParameterizationService.java
  
  Index: DefaultParameterizationService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/parameters/DefaultParameterizationService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultParameterizationService.java	29 Nov 2002 13:04:55 -0000	1.1
  +++ DefaultParameterizationService.java	30 Nov 2002 18:12:06 -0000	1.2
  @@ -87,18 +87,18 @@
   
           if( object instanceof Parameterizable )
           {
  -            Parameters params = appliance.getProfile().getParameters();
  -            if( params == null )
  -            {
  -                params = Parameters.EMPTY_PARAMETERS;
  -            }
  -            ((Parameterizable)object).parameterize( params );
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
                     "[" + appliance.getProfile().getName() + "]";
                   getLogger().debug( message );
               }
  +            Parameters params = appliance.getProfile().getParameters();
  +            if( params == null )
  +            {
  +                params = Parameters.EMPTY_PARAMETERS;
  +            }
  +            ((Parameterizable)object).parameterize( params );
           }
       }
   }
  
  
  
  1.2       +3 -3      avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/startup/DefaultStartupService.java
  
  Index: DefaultStartupService.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/startup/DefaultStartupService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultStartupService.java	29 Nov 2002 13:04:55 -0000	1.1
  +++ DefaultStartupService.java	30 Nov 2002 18:12:06 -0000	1.2
  @@ -83,13 +83,13 @@
   
           if( object instanceof Startable )
           {
  -            ((Startable)object).start();
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
                     "[" + appliance.getProfile().getName() + "]";
                   getLogger().debug( message );
               }
  +            ((Startable)object).start();
           }
       }
   
  @@ -112,13 +112,13 @@
   
           if( object instanceof Startable )
           {
  -            ((Startable)object).stop();
               if( getLogger().isDebugEnabled() )
               {
                   final String message =  
                     "[" + appliance.getProfile().getName() + "]";
                   getLogger().debug( message );
               }
  +            ((Startable)object).stop();
           }
       }
   }
  
  
  
  1.5       +13 -0     avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/AbstractLifestyleHandler.java
  
  Index: AbstractLifestyleHandler.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/AbstractLifestyleHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractLifestyleHandler.java	29 Nov 2002 17:37:30 -0000	1.4
  +++ AbstractLifestyleHandler.java	30 Nov 2002 18:12:06 -0000	1.5
  @@ -249,6 +249,19 @@
       //==============================================================
   
      /**
  +    * Return the appliance that this handler is handling.
  +    * @return the appliance
  +    */
  +    protected Appliance getAppliance()
  +    {
  +        if( m_appliance == null )
  +        {
  +            throw new IllegalStateException("appliance");
  +        }
  +        return m_appliance;
  +    }
  +
  +   /**
       * Creation of a new intance of the class declared by the profile backing the 
       * appliance assigned to this handler.
       * @return Object a new instance of the component class
  
  
  
  1.3       +50 -1     avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/SingletonLifestyleHandler.java
  
  Index: SingletonLifestyleHandler.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/SingletonLifestyleHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SingletonLifestyleHandler.java	29 Nov 2002 17:37:30 -0000	1.2
  +++ SingletonLifestyleHandler.java	30 Nov 2002 18:12:07 -0000	1.3
  @@ -106,6 +106,13 @@
       */
       private Object access() throws LifestyleException
       {
  +        if( getLogger().isDebugEnabled() )
  +        {
  +            final String debug =
  +              "access in appliance: " 
  +              + getAppliance().getProfile().getName();
  +            getLogger().debug( debug );
  +        }
           Object object = newInstance();
           try
           {
  @@ -113,6 +120,15 @@
           }
           catch( Throwable e )
           {
  +            if( getLogger().isWarnEnabled() )
  +            {
  +                final String warning =
  +                  "access stage processing failure in appliance: " 
  +                  + getAppliance().getProfile().getName()
  +                  + " - reverting singletone instance to null.";
  +                getLogger().warn( warning );
  +            }
  +
               //
               // We really should be putting more effort into cleaning up
               // the created instance - i.e. shoudown, disposal etc. Also, 
  @@ -130,6 +146,17 @@
       */
       public void release( Object object )
       {
  +        if( m_instance == null )
  +        {
  +            final String error = 
  +              "Singleton instance has not been established for appliance: "
  +              + getAppliance().getProfile().getName();
  +            throw new IllegalStateException( error );
  +        }
  +        if( object == null )
  +        {
  +            return;
  +        }
           if( object.equals( m_instance ) )
           {
               super.processReleaseStage( m_instance );
  @@ -137,7 +164,12 @@
           else
           {
               final String warning =
  -                "Illegal attempt to release an object that was not provided by this handler.";
  +              "Illegal attempt to release an object [" 
  +                 + object.getClass() 
  +                 + "] that does not correspond to the singleton: ]"
  +                 + m_instance.getClass()
  +                 + "] in appliance: "
  +                 + getAppliance();
               getLogger().warn( warning );
           }
       }
  @@ -168,7 +200,24 @@
       {
           if( m_instance == null )
           {
  +            if( getLogger().isDebugEnabled() )
  +            {
  +                final String debug =
  +                  "creating new instance in appliance: "
  +                    + getAppliance().getProfile().getName();
  +                getLogger().debug( debug );
  +            }
  +
               m_instance = super.newInstance();
  +
  +            if( getLogger().isDebugEnabled() )
  +            {
  +                final String debug =
  +                  "new instance in appliance: "
  +                    + getAppliance().getProfile().getName()
  +                    + " established: " + m_instance.getClass().getName();
  +                getLogger().debug( debug );
  +            }
           }
           return m_instance;
       }
  
  
  

--
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