mcconnell    2002/12/16 20:46:34

  Modified:    merlin/src/java/org/apache/avalon/merlin/kernel
                        DefaultKernel.java
  Log:
  Updated to incorporate block and container changes.
  
  Revision  Changes    Path
  1.11      +96 -13    
avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DefaultKernel.java        16 Dec 2002 01:09:47 -0000      1.10
  +++ DefaultKernel.java        17 Dec 2002 04:46:34 -0000      1.11
  @@ -55,6 +55,11 @@
   import java.io.FileInputStream;
   import java.io.InputStream;
   import java.net.URL;
  +import java.util.List;
  +import java.util.Iterator;
  +import java.util.Map;
  +import java.util.ArrayList;
  +import java.util.Hashtable;
   import java.util.Enumeration;
   import java.util.jar.JarFile;
   import java.util.jar.Attributes;
  @@ -93,6 +98,7 @@
   import org.apache.avalon.merlin.block.Block;
   import org.apache.avalon.merlin.block.DefaultBlock;
   import org.apache.avalon.merlin.block.BlockLoader;
  +import org.apache.avalon.merlin.container.Container;
   
   /**
    * Default kernel implementation.  The implementation provides support for
  @@ -159,6 +165,16 @@
        */
       private Context m_system;
   
  +    /**
  +     * The list of blocks established by the kernel.
  +     */
  +    private List m_blocks = new ArrayList();   
  +
  +    /**
  +     * A map of root containers keyed by the block it is contained by.
  +     */
  +    private Map m_containers = new Hashtable();   
  +
       //==============================================================
       // Contextualizable
       //==============================================================
  @@ -251,9 +267,9 @@
           // announce initialization
           //
   
  -        if( getLogger().isDebugEnabled() )
  +        if( getLogger().isInfoEnabled() )
           {
  -            getLogger().debug( "initialization: " + m_home );
  +            getLogger().info( "initialization from: " + m_home );
           }
   
           //
  @@ -283,24 +299,23 @@
           // kernel configuration
           //
   
  -        if( getLogger().isDebugEnabled() )
  +        if( getLogger().isInfoEnabled() )
           {
  -            getLogger().debug( "block assembly" );
  +            getLogger().info( "commencing block construction phase" );
           }
   
  +        Block[] blocks;
           try
           {
               ClasspathDescriptor path = 
                 CREATOR.createClasspathDescriptor( m_config.getChild( "blocks" 
) );
               URL[] urls = ClasspathDescriptor.expand( m_home, path );
  -
  -            if( getLogger().isDebugEnabled() )
  +            Context system = getSystemContext();
  +            blocks = loadBlocks( m_engine, m_home, urls, system );
  +            for( int i=0; i<blocks.length; i++ )
               {
  -               getLogger().debug( "blocks: " + urls.length );
  +                m_blocks.add( blocks[i] );
               }
  -
  -            Context system = getSystemContext();
  -            Block[] blocks = loadBlocks( m_engine, m_home, urls, system );
           }
           catch( Throwable e )
           {
  @@ -312,6 +327,49 @@
               }
               throw new KernelException( error, e );
           }
  +
  +        //
  +        // Instantiate the root container in each block.
  +        //
  +
  +        if( getLogger().isInfoEnabled() )
  +        {
  +            getLogger().info( "commencing structural assembly phase" );
  +        }
  +        
  +        for( int i=0; i<blocks.length; i++ )
  +        {
  +            Block block = blocks[i];
  +            Appliance appliance = block.getAppliance();
  +            try
  +            {
  +                m_engine.assemble( appliance );
  +                Container container = (Container)appliance.access();
  +                m_containers.put( block, container );
  +            }
  +            catch( Throwable e )
  +            {
  +                final String error = 
  +                  "Unable to deploy root container: " + appliance;
  +                String log = ExceptionHelper.packException( error, e );
  +                if( getLogger().isErrorEnabled() )
  +                {
  +                    getLogger().error( log );
  +                }
  +                throw new KernelException( error, e );
  +            }
  +        }
  +
  +        //
  +        // Initiate component assembly on all blocks.
  +        //
  +
  +        for( int i=0; i<blocks.length; i++ )
  +        {
  +            Block block = blocks[i];
  +            Container container = (Container) m_containers.get( block );
  +            container.assemble();
  +        }
       }
   
       //==============================================================
  @@ -332,6 +390,17 @@
                   getLogger().debug( "startup" );
               }
           }
  +
  +        Iterator iterator = m_blocks.iterator();
  +        while( iterator.hasNext() )
  +        {
  +            Block block = (Block) iterator.next();
  +            Container container = (Container) m_containers.get( block );
  +            if( container != null )
  +            {
  +                container.startup();
  +            }
  +        }
       }
   
      /**
  @@ -348,6 +417,20 @@
                   getLogger().debug( "shutdown" );
               }
           }
  +
  +        Iterator iterator = m_blocks.iterator();
  +        while( iterator.hasNext() )
  +        {
  +            Block block = (Block) iterator.next();
  +            Container container = (Container) m_containers.get( block );
  +            if( container != null )
  +            {
  +                m_containers.remove( block );
  +                container.shutdown();
  +                block.getAppliance().release( container );
  +                block.getAppliance().terminate();
  +            }
  +        }
       }
   
       //==============================================================
  @@ -361,9 +444,9 @@
       {
           if( getLogger() != null ) 
           {
  -            if( getLogger().isDebugEnabled() )
  +            if( getLogger().isInfoEnabled() )
               {
  -                getLogger().debug( "dispose" );
  +                getLogger().info( "bye" );
               }
           }
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to