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/merlin/activation/src/java/org/apache/avalon/activation/lifestyle/impl SingletonLifestyleHandler.java
Date Mon, 08 Sep 2003 06:12:21 GMT
mcconnell    2003/09/07 23:12:21

  Modified:    merlin/activation/src/java/org/apache/avalon/activation/appliance/impl
                        DefaultAppliance.java DefaultServiceManager.java
               merlin/activation/src/java/org/apache/avalon/activation/lifestyle/impl
                        SingletonLifestyleHandler.java
  Log:
  Improved state checking related to service resolution.
  
  Revision  Changes    Path
  1.14      +16 -38    avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultAppliance.java
  
  Index: DefaultAppliance.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultAppliance.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DefaultAppliance.java	6 Sep 2003 13:58:03 -0000	1.13
  +++ DefaultAppliance.java	8 Sep 2003 06:12:21 -0000	1.14
  @@ -215,46 +215,24 @@
       }
   
       /**
  -     * Return the dependency associations for component type with specified role.
  -     *
  -     * @param role the dependency role name
  -     * @return the appliance mapped as a provider of the role
  -     */
  -    private Appliance getServiceProvider( final String role )
  -    {
  -        return (Appliance) m_providers.get( role );
  -    }
  -
  -    /**
  -     * Return the assigned service providers.
  -     * @return the set of service provider appliances.
  -     */
  -    private Appliance[] getServiceProviders()
  -    {
  -        return (Appliance[]) m_providers.values().toArray( new Appliance[0] );        
  -    }
  -
  -    /**
        * Returns the appliace assigned to handle the components lifecycle stage.
        * @param stage the lifecycle stage specification
        * @return the stage extension
  -     * @exception LifecycleException
  +     * @exception IllegalStateException if the stage provider is unresolvable
        */
  -    private Appliance getStageProvider( StageDescriptor stage ) 
  +    private Appliance getStageProvider( StageDescriptor stage ) throws IllegalArgumentException
       {
  -        Appliance appliance = (Appliance) m_stages.get( stage.getKey() );
  -        if( appliance != null )
  -        {
  -            return appliance;
  -        }
  -        else
  -        {
  -            final String error = 
  -              REZ.getString( 
  -                "lifecycle.stage.key.unknown.error",
  -                m_model.getQualifiedName(), stage.getKey() );
  -             throw new IllegalArgumentException( error );
  -        }
  +        final String key = stage.getKey();
  +        Appliance appliance = (Appliance) m_stages.get( key );
  +        if( appliance != null ) return appliance;
  +
  +        final String error = 
  +          REZ.getString( 
  +            "lifecycle.stage.key.unknown.error",
  +            m_model.getQualifiedName(), key );
  +        getLogger().error( error );
  +
  +        throw new IllegalStateException( error );
       }
   
       /**
  @@ -582,11 +560,11 @@
       public Object resolve( final Object source, final Class[] ref ) throws Exception
       {
           if( source == null ) throw new NullPointerException( "source" );
  +        if( m_lifestyle == null ) throw new IllegalStateException( "lifestyle" );
   
           Class[] refs = ref;
           if( refs == null ) refs = new Class[0];
  -
  -        Object instance = m_lifestyle.resolve( source, ref );
  +        Object instance = m_lifestyle.resolve( source, refs );
           return applyAccessStages( instance, true );
       }
   
  
  
  
  1.4       +2 -0      avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultServiceManager.java
  
  Index: DefaultServiceManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultServiceManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultServiceManager.java	1 Sep 2003 19:32:02 -0000	1.3
  +++ DefaultServiceManager.java	8 Sep 2003 06:12:21 -0000	1.4
  @@ -100,6 +100,8 @@
        */
       public DefaultServiceManager( Logger logger, Map map )
       {
  +        if( logger == null ) throw new NullPointerException( "logger" );
  +        if( map == null ) throw new NullPointerException( "map" );
           super.enableLogging( logger );
           m_map = map;
       }
  
  
  
  1.3       +7 -5      avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/lifestyle/impl/SingletonLifestyleHandler.java
  
  Index: SingletonLifestyleHandler.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/lifestyle/impl/SingletonLifestyleHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SingletonLifestyleHandler.java	22 Aug 2003 18:00:07 -0000	1.2
  +++ SingletonLifestyleHandler.java	8 Sep 2003 06:12:21 -0000	1.3
  @@ -68,6 +68,7 @@
       public SingletonLifestyleHandler( Logger logger, Factory factory )
       {
           super( logger );
  +        if( factory == null ) throw new IllegalStateException( "factory" );
           m_factory = factory;
       }
   
  @@ -89,11 +90,12 @@
           // using the ref array.
           //
   
  -        if( m_instance == null )
  +        if( m_instance != null ) return m_instance;
  +        synchronized( m_factory )
           {
               m_instance = m_factory.newInstance();
  +            return m_instance;
           }
  -        return m_instance;
       }
   
       /**
  @@ -111,9 +113,9 @@
       */
       public void dispose()
       {
  -        if( m_instance != null )
  +        synchronized( m_factory )
           {
  -            m_factory.destroy( m_instance );
  +            if( m_instance != null ) m_factory.destroy( m_instance );
           }
       }
   }
  
  
  

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


Mime
View raw message