mcconnell    2002/07/03 19:26:39

  Modified:    assembly/src/java/org/apache/excalibur/merlin/kernel
                        DefaultContainer.java DefaultKernel.java
               assembly/src/java/org/apache/excalibur/merlin/registry
                        DefaultRegistry.java
  Added:       assembly/src/etc kernel.xml
  Log:
  restructing to support container hierachies
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/assembly/src/etc/kernel.xml
  
  Index: kernel.xml
  ===================================================================
  
  <!--
  Assemble a component instance.
  -->
  
  <kernel>
  
     <!--
     Declaration of the logging hierachy and constraints.
     -->
     
     <logger priority="DEBUG"/>
  
     <!--
     Declaration of installed extension directories.
     -->
  
     <extensions>
       <dirset dir=".">
         <include name="deploy"/>
       </dirset>
     </extensions>
  
     <!--
     Declaration of root kernel classpath available to all containers.
     -->
  
     <container name="root">
  
       <classpath>
         <fileset dir="dist">
           <include name="demo.jar"/>
         </fileset>
       </classpath>
  
  
       <!--
       Declaration of the services hosted by this container.  Service container here 
       will be managed relative to other provider components at the same level and 
       may be serviced by components declared in parent container.
       -->
  
       <component name="complex" 
class="org.apache.excalibur.playground.ComplexComponent">
  
          <!--
          Include the following context value in the context supplied a component 
using this 
          profile.  Context entries are normally only required in the case where the 
component
          type declares a required context type and entry values. Generally speaking, 
a component
          will normally qualify it's instantiation criteria through a configuration 
declaration.
          Any context values defined at this level will override context values 
supplied by the
          container.
          -->
  
          <context>
            <entry name="location" value="Paris"/>
          </context>
  
          <!--
          Apply the following configuration when instantiating the component.  This 
configuration
          will be applied as the primary configuration in a cascading configuration 
chain.  A 
          type may declare a default configuration under a "classname".xconfig file 
that will be 
          used to dereference any configuration requests not resolvable by the 
configuration 
          supplied here.
          -->
  
          <configuration>
            <message value="Hello"/>
          </configuration>
  
          <!--
          The parameterization criteria from this instance of the component type.
          -->
  
          <parameters/>
  
       </component>
  
       <!--
       A containers declaration will cause the creation of a new registry holding the 
       child container instances.
       -->
  
       <container name="sub-container">
  
         <classpath>
           <fileset dir="dist">
             <include name="assembly.jar"/>
           </fileset>
         </classpath>
  
         <!--
         Declaration of an embedded container.  A container will be instantiated, 
initialized
         and a validation request will be invoked.  In the container is an instance of 
Container, 
         the reference to parent container will be supplied.
         -->
  
         <component name="test" 
class="org.apache.excalibur.merlin.kernel.DefaultContainer">
           <configuration>
            <container>
             <classpath>
               <fileset dir="dist">
                 <include name="demo.jar"/>
               </fileset>
             </classpath>
            </container>
          </configuration>
        </component>
  
        <!--
        <component name="simple2" 
class="org.apache.excalibur.playground.SimpleComponent"/>
        -->
  
       </container>
  
     </container>
  
  </kernel>
  
  
  
  1.2       +77 -73    
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel/DefaultContainer.java
  
  Index: DefaultContainer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel/DefaultContainer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultContainer.java     3 Jul 2002 19:08:54 -0000       1.1
  +++ DefaultContainer.java     4 Jul 2002 02:26:39 -0000       1.2
  @@ -61,6 +61,8 @@
   import org.apache.excalibur.containerkit.metainfo.ServiceDescriptor;
   import org.apache.excalibur.containerkit.metainfo.DependencyDescriptor;
   import org.apache.excalibur.containerkit.metainfo.ServiceDesignator;
  +import org.apache.excalibur.containerkit.dependency.DependencyMap;
  +import org.apache.excalibur.containerkit.metadata.ComponentMetaData;
   import org.apache.log.Hierarchy;
   import org.apache.log.Priority;
   import org.apache.log.output.io.StreamTarget;
  @@ -75,57 +77,33 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephen McConnell</a>
    * @version $Revision$ $Date$
    */
  -public class DefaultContainer extends AbstractLogEnabled implements Container, 
Verifiable, Contextualizable, Configurable, Initializable
  +public class DefaultContainer extends DefaultRegistry implements Container
   {
       //=======================================================================
  -    // static
  -    //=======================================================================
  -
  -   /**
  -    * Context key used to locate the application classloader.
  -    */
  -    public static final String CLASSLOADER_KEY = "classloader";
  -
  -   /**
  -    * Context key used to locate the application classloader.
  -    */
  -    public static final String CONTAINER_KEY = "container";
  -
  -
  -    //=======================================================================
       // state
       //=======================================================================
   
      /**
  -    * The container context.
  -    */
  -    private Context m_context;
  -
  -   /**
       * Configuration.
       */
       private Configuration m_config;
   
      /**
  -    * The registry of components.
  -    */
  -    private DefaultRegistry m_components;
  -
  -   /**
       * The registry of embedded containers.
       */
  -    private DefaultRegistry m_containers;
  -
  -   /**
  -    * Classloader.
  -    */
  -    private ContainerClassLoader m_classloader;
  +    private List m_containers = new LinkedList();
   
      /**
       * Parent container.
       */
       private Container m_parent;
   
  +    private ContainerClassLoader m_classloader;
  +
  +    private Logger m_logger;
  +
  +    private DependencyMap m_map;
  +
       //=======================================================================
       // Contextualizable
       //=======================================================================
  @@ -136,15 +114,18 @@
       */
       public void contextualize( Context context ) throws ContextException
       {
  -        m_context = context;
           m_classloader = (ContainerClassLoader) context.get( CLASSLOADER_KEY );
           try
           {
  +            m_map = (DependencyMap) context.get( MAP_KEY );
               m_parent = (Container) context.get( CONTAINER_KEY );
  +            super.contextualize( context );
           }
           catch( ContextException e )
           {
  -            // no parent container
  +            DefaultContext c = new DefaultContext( context );
  +            c.put( CONTAINER_KEY, this );
  +            super.contextualize( c );
           }
       }
   
  @@ -158,8 +139,9 @@
       */
       public void configure( Configuration config)
       {
  +        getLogger().debug("container configuration");
  +        super.configure( config );
           m_config = config;
  -        getLogger().debug("configuration");
       }
   
       //=======================================================================
  @@ -172,8 +154,13 @@
       */
       public void initialize() throws Exception
       {
  -        m_components = createComponentRegistry( m_config.getChild( "components") );
  -        m_containers = createContainerRegistry( m_config.getChild( "containers") );
  +        getLogger().debug("container initialization (" + 
m_config.getAttribute("name","?") + ")" );
  +        super.initialize();
  +        Configuration[] containers = m_config.getChildren("container");
  +        for( int i=0; i<containers.length; i++ )
  +        {
  +            m_containers.add( createContainer( containers[i] ) );
  +        }
       }
   
       //=======================================================================
  @@ -188,56 +175,73 @@
       */
       public void verify() throws VerifyException
       {
  -        m_components.verify();
  -        m_containers.verify();
  +        super.verify();
  +        Iterator iterator = m_containers.iterator();
  +        while( iterator.hasNext() )
  +        {
  +            ((Verifiable)iterator.next()).verify();
  +        }
       }
   
       //=======================================================================
  -    // DefaultContainer
  +    // Container
       //=======================================================================
   
  -    private DefaultRegistry createComponentRegistry( Configuration config ) throws 
Exception
  -    {
  -        return createRegistry( m_classloader, config );
  -    }
  -
  -    private DefaultRegistry createContainerRegistry( Configuration config ) throws 
Exception
  +    public void startup() throws Exception
       {
  -        final ContainerClassLoader loader = new ContainerClassLoader(
  -          m_classloader, 
  -          config.getChild("classpath"), 
  -          getLogger().getChildLogger( config.getName())
  -        );
  -        return createRegistry( loader, config );
  +        ComponentMetaData[] startup = m_map.getStartupGraph();
  +        getLogger().debug("startup");
  +        for( int i=0; i<startup.length; i++ )
  +        {
  +            getLogger().debug("start: " + startup[i].getName() );
  +        }
  +        Iterator iterator = m_containers.iterator();
  +        while( iterator.hasNext() )
  +        {
  +            ((Container)iterator.next()).startup();
  +        }
       }
   
  -    private DefaultRegistry createRegistry( final ContainerClassLoader loader, 
final Configuration config ) throws Exception
  +    public void shutdown()
       {
  -        DefaultContext context = new DefaultContext();
  -        context.put( DefaultRegistry.CLASSLOADER_KEY, loader );
  -        context.put( DefaultRegistry.CONTAINER_KEY, this );
  -
  -        DefaultRegistry registry = new DefaultRegistry();
  -        registry.enableLogging( getLogger().getChildLogger( config.getName() ) );
  -        registry.contextualize( context );
  -        registry.configure( config );
  -        registry.initialize( );
  -        return registry;
  +        getLogger().debug("shutdown");
  +        ComponentMetaData[] shutdown = m_map.getShutdownGraph();
  +        for( int i=0; i<shutdown.length; i++ )
  +        {
  +            getLogger().debug("stop: " + shutdown[i].getName() );
  +        }
  +        Iterator iterator = m_containers.iterator();
  +        while( iterator.hasNext() )
  +        {
  +            ((Container)iterator.next()).shutdown();
  +        }
       }
   
       //=======================================================================
  -    // Container
  +    // private
       //=======================================================================
   
  -    public void startup() throws Exception
  +    private DefaultContainer createContainer( Configuration conf ) throws Exception
       {
  -        getLogger().debug("startup");
  -        //m_registry.execute();
  -    }
  +        Logger logger = getLogger().getChildLogger( 
conf.getAttribute("name","child") );
  +        Logger loaderLogger = logger.getChildLogger( "loader" );
   
  -    public void shutdown()
  -    {
  -        getLogger().debug("shutdown");
  -        //m_registry.dispose();
  +        final ContainerClassLoader loader = new ContainerClassLoader(
  +          m_classloader, 
  +          conf.getChild("classpath"),
  +          loaderLogger
  +        );
  +
  +        DefaultContext context = new DefaultContext();
  +        context.put( CLASSLOADER_KEY, loader );
  +        context.put( CONTAINER_KEY, this );
  +        context.put( MAP_KEY, new DependencyMap( m_map ) );
  +
  +        DefaultContainer container = new DefaultContainer();
  +        container.enableLogging( logger );
  +        container.contextualize( context );
  +        container.configure( conf );
  +        container.initialize( );
  +        return container;
       }
   }
  
  
  
  1.2       +12 -5     
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel/DefaultKernel.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultKernel.java        3 Jul 2002 19:08:54 -0000       1.1
  +++ DefaultKernel.java        4 Jul 2002 02:26:39 -0000       1.2
  @@ -62,6 +62,7 @@
   import org.apache.excalibur.containerkit.metainfo.ServiceDescriptor;
   import org.apache.excalibur.containerkit.metainfo.DependencyDescriptor;
   import org.apache.excalibur.containerkit.metainfo.ServiceDesignator;
  +import org.apache.excalibur.containerkit.dependency.DependencyMap;
   import org.apache.log.Hierarchy;
   import org.apache.log.Priority;
   import org.apache.log.output.io.StreamTarget;
  @@ -86,6 +87,8 @@
   
       private DefaultContainer m_container = new DefaultContainer();
   
  +    private boolean m_verified = false;
  +
       //=======================================================================
       // Configurable
       //=======================================================================
  @@ -97,7 +100,7 @@
       public void configure( Configuration config)
       {
           m_config = config;
  -        getLogger().debug("configuration");
  +        getLogger().debug("kernel configuration");
       }
   
       //=======================================================================
  @@ -108,19 +111,23 @@
       {
           final ContainerClassLoader loader = new ContainerClassLoader(
             new DefaultPackageRepository( 
  -            Fileset.expandExtensions( m_config.getChild( "extensions" ) ) 
  +            Fileset.expandExtensions( 
  +              m_config.getChild( "extensions" ) 
  +            ) 
             ),
             Thread.currentThread().getContextClassLoader(), 
  -          m_config.getChild("classpath"),
  +          m_config.getChild("container").getChild("classpath"),
             getLogger().getChildLogger( m_config.getName())
           );
   
           DefaultContext context = new DefaultContext();
           context.put( DefaultContainer.CLASSLOADER_KEY, loader );
  +        context.put( DefaultContainer.MAP_KEY, new DependencyMap() );
           m_container.enableLogging( getLogger().getChildLogger("container") );
           m_container.contextualize( context );
  -        m_container.configure( m_config );
  +        m_container.configure( m_config.getChild("container" ) );
           m_container.initialize( );
  +        m_container.verify();
       }
   
       //=======================================================================
  
  
  
  1.7       +33 -38    
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/registry/DefaultRegistry.java
  
  Index: DefaultRegistry.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/registry/DefaultRegistry.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultRegistry.java      3 Jul 2002 19:08:35 -0000       1.6
  +++ DefaultRegistry.java      4 Jul 2002 02:26:39 -0000       1.7
  @@ -84,27 +84,26 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephen McConnell</a>
    * @version $Revision$ $Date$
    */
  -public class DefaultRegistry extends AbstractLogEnabled implements 
Contextualizable, Configurable, Initializable, Executable, Disposable, Registry, 
Verifiable
  +public class DefaultRegistry implements LogEnabled, Contextualizable, Configurable, 
Initializable, Executable, Disposable, Registry, Verifiable
   {
       //=======================================================================
       // static
       //=======================================================================
   
      /**
  -    * Registry key used in dependency lookup for a parent registry
  -    * during servicing phase.
  +    * Context key used to locate the application classloader.
       */
  -    public static final String REGISTRY_KEY = "registry";
  +    public static final String CLASSLOADER_KEY = "classloader";
   
      /**
       * Context key used to locate the application classloader.
       */
  -    public static final String CLASSLOADER_KEY = "classloader";
  +    public static final String CONTAINER_KEY = "container";
   
      /**
       * Context key used to locate the application classloader.
       */
  -    public static final String CONTAINER_KEY = "container";
  +    public static final String MAP_KEY = "map";
   
       private static final ComponentType[] EMPTY_DEFS = new ComponentType[0];
       private static final Profile[] EMPTY_PROFILES = new Profile[0];
  @@ -154,15 +153,30 @@
   
       private Hashtable m_profiles = new Hashtable();
   
  -    private DependencyMap m_map = new DependencyMap();
  +    private DependencyMap m_map;
  +
  +    private Logger m_logger;
   
       //=======================================================================
       // LogEnabled
       //=======================================================================
  -        
  +
  +   /**
  +    * Invoked by the parent to assign the logging channel.
  +    * @param logger the logging channel
  +    */
       public void enableLogging( Logger logger )
       {
  -        super.enableLogging( logger );
  +        m_logger = logger;
  +    }
  +
  +   /**
  +    * Returns the assigned logging channel.
  +    * @return the logging channel
  +    */
  +    protected Logger getLogger()
  +    {
  +        return m_logger;
       }
   
       //=======================================================================
  @@ -178,6 +192,7 @@
           m_context = context;
           m_classloader = (ContainerClassLoader) context.get( CLASSLOADER_KEY );
           m_parent = (Container) context.get( CONTAINER_KEY );
  +        m_map = (DependencyMap) context.get( MAP_KEY );
       }
   
       //=======================================================================
  @@ -191,6 +206,8 @@
       public void configure( Configuration config)
       {
           m_config = config;
  +        getLogger().debug("registry configuration");
  +        getLogger().debug( ConfigurationUtil.list( config ) );
       }
   
       //=======================================================================
  @@ -204,7 +221,7 @@
       */
       public void initialize() throws Exception
       {
  -        getLogger().debug("initialize");
  +        getLogger().debug("registry initialization");
           m_services = new ServiceRegistry( this, m_classloader, m_config );
           m_services.enableLogging( getLogger().getChildLogger("services") );
           String[] blocks = m_classloader.getComponentClassnames();
  @@ -236,23 +253,12 @@
                   final Configuration factory = entries[i];
                   final String name = factory.getAttribute("name");
                   final String classname = factory.getAttribute("class");
  -                final String mode = factory.getName();
   
  -                if( mode.equals("component") )
  -                {
  -                    getLogger().debug("container: \n" + ConfigurationUtil.list( 
factory ));
  -                    Profile profile = m_services.install( classname, name );
  -                    populate( m_map, profile );
  -                    //listProfile( profile );
  -                }
  -                else
  -                {
  -                    // unrecognized declaration
  -                    getLogger().debug(
  -                      "bypassing unrecognized element\n" 
  -                      + ConfigurationUtil.list( factory ) 
  -                    );
  -                }
  +                getLogger().debug("component configuration");
  +                getLogger().debug( ConfigurationUtil.list( factory ) );
  +                Profile profile = m_services.install( classname, name );
  +                populate( m_map, profile );
  +                //listProfile( profile );
               }
   
               //
  @@ -303,19 +309,8 @@
       public void verify() throws VerifyException
       {
           getLogger().debug("DependencyMap listing");
  -        getLogger().debug("startup sequence");
           ComponentMetaData[] startup = m_map.getStartupGraph();
           doVerify( startup );
  -        for( int i=0; i<startup.length; i++ )
  -        {
  -            getLogger().debug("  start: " + startup[i] );
  -        }
  -        getLogger().debug("shutdown sequence");
  -        ComponentMetaData[] shutdown = m_map.getShutdownGraph();
  -        for( int i=0; i<shutdown.length; i++ )
  -        {
  -            getLogger().debug("  stop: " + shutdown[i] );
  -        }
       }
   
       //=======================================================================
  
  
  

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

Reply via email to