You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/06/18 13:28:13 UTC

cvs commit: avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl DefaultKernel.java DefaultKernelLoader.java

mcconnell    2003/06/18 04:28:13

  Modified:    merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl
                        StandardBlock.java StandardBlockLoader.java
                        XMLContainerCreator.java
               merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl
                        DefaultKernel.java DefaultKernelLoader.java
  Log:
  General housekeeping and alignment with appliance enhancements.
  
  Revision  Changes    Path
  1.12      +3 -1      avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/StandardBlock.java
  
  Index: StandardBlock.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/StandardBlock.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- StandardBlock.java	16 Jun 2003 14:25:02 -0000	1.11
  +++ StandardBlock.java	18 Jun 2003 11:28:12 -0000	1.12
  @@ -594,6 +594,8 @@
               throw new IllegalStateException( error );
           }
   
  +        super.deploy();
  +
           if( getLogger().isDebugEnabled() )
           {
               getLogger().debug( "deployment of block: " + this );
  @@ -641,7 +643,7 @@
                             + appliance;
                           getLogger().debug( message );
                       }
  -                   
  +
                       if( appliance instanceof StandardBlock )
                       {
                           StandardBlock block = (StandardBlock) appliance;
  
  
  
  1.14      +12 -146   avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/StandardBlockLoader.java
  
  Index: StandardBlockLoader.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/StandardBlockLoader.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StandardBlockLoader.java	15 Jun 2003 18:25:54 -0000	1.13
  +++ StandardBlockLoader.java	18 Jun 2003 11:28:12 -0000	1.14
  @@ -84,6 +84,7 @@
   import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.merlin.block.Block;
   import org.apache.avalon.merlin.block.BlockException;
   import org.apache.avalon.merlin.block.BlockRuntimeException;
  @@ -135,8 +136,7 @@
   
       private static final XMLProfileCreator BUILDER = new XMLProfileCreator();
   
  -    private static final XMLTypeCreator TYPE_m_creator = new XMLTypeCreator();
  -
  +    private static final XMLTypeCreator CREATOR = new XMLTypeCreator();
   
       //==============================================================
       // state
  @@ -266,6 +266,9 @@
       public Block install( final URL path, final URL overrides )
         throws Exception
       {
  +        getLogger().debug( "install: " + path );
  +        getLogger().debug( "overrides: " + overrides );
  +
           //
           // establish a URL referencing the base directory
           //
  @@ -280,7 +283,7 @@
           Targets targets = m_creator.createTargets( getTargetsConfiguration( overrides ) );
   
           //
  -        // before creating a block we need to build a classloader
  +        // before creating a block we need to build a classloader 
           // because the block implementation class may be part of 
           // the block defintion
           //
  @@ -423,7 +426,8 @@
               EngineClassLoader engine =
                 new EngineClassLoader( urls, m_system );
   
  -            engine.enableLogging( getLogger() );
  +            Logger log = m_logging.getSystemLoggerForCategory( "" );
  +            engine.enableLogging( log );
   
               DefaultLocator context = new DefaultLocator();
               context.put( LoggingManager.KEY, m_logging );
  @@ -627,8 +631,7 @@
   
           try
           {
  -            Block result = (Block) profile.getEngine().createAppliance( context, true );
  -            return result;
  +            return (Block) profile.getEngine().createAppliance( context, true );
           }
           catch( Throwable e )
           {
  @@ -708,7 +711,7 @@
               final Version version =
                 Version.getVersion( info.getChild( "version" ).getValue( "1.0" ) );
               final Properties attributes =
  -              TYPE_m_creator.buildAttributes( info.getChild( "attributes" ) );
  +              CREATOR.buildAttributes( info.getChild( "attributes" ) );
               return new InfoDescriptor( name, classname, version, attributes );
           }
           catch( ConfigurationException ce )
  @@ -731,7 +734,7 @@
       {
           try
           {
  -            return TYPE_m_creator.buildDependencies( config );
  +            return CREATOR.buildDependencies( config );
           }
           catch( ConfigurationException ce )
           {
  @@ -742,72 +745,6 @@
           }
       }
   
  -   /**
  -    * Resolve the logical services declared by this block.
  -    * @param config the dependecies configuration fragment
  -    * @return the set of declared depedency descriptors
  -    */
  -    private ServiceDescriptor[] getBlockLogicalServices( Configuration config )
  -      throws BlockException
  -    {
  -        try
  -        {
  -            return TYPE_m_creator.buildServices( config );
  -        }
  -        catch( ConfigurationException ce )
  -        {
  -            final String error =
  -              "Invalid services declaration in block specification:\n"
  -               + ConfigurationUtil.list( config );
  -            throw new BlockException( error, ce );
  -        }
  -    }
  -
  -    private void captureConfigurationTargets( String path, Configuration config )
  -      throws BlockException
  -    {
  -        Configuration[] targets = config.getChildren( "target" );
  -
  -        if( getLogger().isDebugEnabled() )
  -        {
  -            getLogger().debug("target override count: " + targets.length );
  -        }
  -
  -        for( int j=0; j<targets.length; j++ )
  -        {
  -            Configuration target = targets[j];
  -            
  -            try
  -            {
  -                String name = target.getAttribute( "name" );
  -                if( name.startsWith( "/" ) )
  -                {
  -                    name = name.substring( 1 );
  -                }
  -                String key;
  -                if( path.endsWith( "/" ) )
  -                {
  -                    key = path + name;
  -                }
  -                else
  -                {
  -                    key = path + "/" + name;
  -                }
  -                m_library.put( key, target.getChild( "configuration" ) );
  -                getLogger().debug( "registering configuration for key: " + key );
  -            }
  -            catch( Throwable e )
  -            {
  -                final String error =
  -                  "A configuration target does not declare a name in: "
  -                  + path
  -                  + ConfigurationUtil.list( target );
  -                throw new BlockException( error, e );
  -            }
  -        }
  -    }
  -
  -
       private JarFile getJarFile( URL url ) throws MalformedURLException
       {
           URL xurl;
  @@ -873,77 +810,6 @@
                 + jar.getName();
               throw new BlockException( error, e );
           }
  -    }
  -
  -    protected Profile createProfile( 
  -      String name, EngineClassLoader engine, Configuration config )
  -      throws ContainerException
  -    {
  -        String classname;
  -        try
  -        {
  -            classname = config.getAttribute( "class" );
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error =
  -              "Block directive: '" + name 
  -              + "' contains a component profile without a 'class' attribute.";
  -            throw new ContainerException( error, e );
  -        }
  -
  -        Type type;
  -        try
  -        {
  -            type = engine.getRepository().getTypeRepository().getType( classname );
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error =
  -              "Block directive: '" + name 
  -              + "' references an unknown component type: "
  -              + classname;
  -            throw new ContainerException( error, e );
  -        }
  -
  -        try
  -        {
  -            Profile profile = BUILDER.createProfile( type, config );
  -            boolean policy = getActivationPolicy( config );
  -            profile.setActivationPolicy( policy );
  -            return profile;
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error =
  -              "Block directive: '" + name
  -              + " contains a problamatic profile: "
  -              + classname;
  -            throw new ContainerException( error, e );
  -        }
  -    }
  -
  -   /**
  -    * Get the activation policy from a configuration. If no activation attribute
  -    * is present the value return defaults to FALSE (i.e. activation is deferred).
  -    *
  -    * @param config a configuration fragment holding a activation attribute
  -    * @return TRUE is the value of the activation attribute is 'true' or 'startup'
  -    *   otherwise the return value is FALSE
  -    */
  -    private boolean getActivationPolicy( Configuration config )
  -    {
  -        final String value = config.getAttribute( "activation", null );
  -        if( value == null )
  -        {
  -            return false;
  -        }
  -        final String string = value.toLowerCase().trim();
  -        if( string.equals( "startup" ) )
  -        {
  -            return true;
  -        }
  -        return string.equals( "true" );
       }
   
      /**
  
  
  
  1.5       +1 -26     avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/XMLContainerCreator.java
  
  Index: XMLContainerCreator.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/XMLContainerCreator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLContainerCreator.java	15 Jun 2003 18:25:54 -0000	1.4
  +++ XMLContainerCreator.java	18 Jun 2003 11:28:12 -0000	1.5
  @@ -733,8 +733,6 @@
               Profile profile = 
                 BUILDER.createProfile( 
                   type, config, target.getConfiguration(), target.getLoggingDirective() );
  -            boolean policy = getActivationPolicy( config );
  -            profile.setActivationPolicy( policy );
               return profile;
           }
           catch( Throwable e )
  @@ -978,29 +976,6 @@
                 "Unable to create configuration from source: " + uri;
               throw new ContainerException( error, e );
           }
  -    }
  -
  -   /**
  -    * Get the activation policy from a configuration. If no activation attribute
  -    * is present the value return defaults to FALSE (i.e. activation is deferred).
  -    *
  -    * @param config a configuration fragment holding a activation attribute
  -    * @return TRUE is the value of the activation attribute is 'true' or 'startup'
  -    *   otherwise the return value is FALSE
  -    */
  -    private boolean getActivationPolicy( Configuration config )
  -    {
  -        final String value = config.getAttribute( "activation", null );
  -        if( value == null )
  -        {
  -            return false;
  -        }
  -        final String string = value.toLowerCase().trim();
  -        if( string.equals( "startup" ) )
  -        {
  -            return true;
  -        }
  -        return string.equals( "true" );
       }
   
      /**
  
  
  
  1.22      +44 -21    avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- DefaultKernel.java	15 Jun 2003 18:25:54 -0000	1.21
  +++ DefaultKernel.java	18 Jun 2003 11:28:13 -0000	1.22
  @@ -391,15 +391,14 @@
       */
       public void initialize() throws Exception
       {
  -
  -        if( m_initialized )
  +        if( !m_contextualized )
           {
  -            throw new IllegalStateException( "initialization" );
  +             throw new IllegalStateException("context");
           }
   
  -        if( !m_contextualized )
  +        if( m_initialized )
           {
  -             throw new IllegalStateException("context");
  +            throw new IllegalStateException( "initialization" );
           }
   
           if( m_config == null )
  @@ -433,6 +432,7 @@
               }
               m_local = m_logging.getLoggerForCategory( sys );
               enableLogging( m_local );
  +
           }
           catch( Throwable e )
           {
  @@ -469,7 +469,7 @@
           m_installer = new StandardBlockLoader();
           try
           {
  -            m_installer.enableLogging( getLogger() );
  +            m_installer.enableLogging( getLogger().getChildLogger( "install" ) );
   
               DefaultLocator context = new DefaultLocator();
               context.put( Repository.KEY, m_repository );
  @@ -506,19 +506,9 @@
           // install the root block
           //
   
  -        if( getLogger().isDebugEnabled() )
  -        {
  -            getLogger().debug( "" );
  -        }
  -
           try
           {
               m_block = install( m_url, m_override );
  -            if( getLogger().isInfoEnabled() )
  -            {
  -                final String info = "Block hierarchy established.";
  -                getLogger().info( info );
  -            }
           }
           catch( Throwable e )
           {
  @@ -589,7 +579,9 @@
   
           if( getLogger().isDebugEnabled() )
           {
  -            getLogger().debug(  "installing block: " + base );
  +            getLogger().debug( "#" );
  +            getLogger().debug( "# installation phase" );
  +            getLogger().debug( "#" );
           }
   
           Block block = null;
  @@ -604,14 +596,16 @@
               throw new KernelException( error, e );
           }
   
  -        if( getLogger().isInfoEnabled() )
  +        if( getLogger().isDebugEnabled() )
           {
  -            getLogger().info( "commencing block assembly phase" );
  +            getLogger().debug( "#" );
  +            getLogger().debug( "# assembly phase" );
  +            getLogger().debug( "#" );
           }
   
           try
           {
  -            block.assemble( new DependencyGraph( m_graph ) );
  +            block.assemble( m_graph );
           }
           catch( Throwable e )
           {
  @@ -619,6 +613,35 @@
                 "Unable to assemble block.\nBlock: " 
                 + block.getName();
               throw new KernelException( error, e );
  +        }
  +
  +        Appliance[] appliances = m_graph.getStartupGraph();
  +        if( getLogger().isDebugEnabled() )
  +        {
  +            getLogger().debug( "#" );
  +            getLogger().debug( "# deployment phase" );
  +
  +            if( appliances.length > 0 )
  +            {
  +                StringBuffer buffer = new StringBuffer( "# sequence: " );
  +                for( int p=0; p<appliances.length; p++ )
  +                {
  +                    if( p == 0 )
  +                    {
  +                        buffer.append( appliances[p] );
  +                    }
  +                    else
  +                    {
  +                        buffer.append( ", " + appliances[p] );
  +                    }
  +                }
  +                getLogger().debug( buffer.toString() );
  +            }
  +            else
  +            {
  +                getLogger().debug( "# sequence: []" );
  +            }
  +            getLogger().debug( "#" );
           }
   
           try
  
  
  
  1.10      +42 -0     avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernelLoader.java
  
  Index: DefaultKernelLoader.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernelLoader.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DefaultKernelLoader.java	12 Jun 2003 18:56:20 -0000	1.9
  +++ DefaultKernelLoader.java	18 Jun 2003 11:28:13 -0000	1.10
  @@ -29,6 +29,8 @@
    */
   public class DefaultKernelLoader implements KernelLoader
   {
  +    private static final int DEFAULT_DELAY = 0;
  +
      /**
       * Creation of a new Kernel instance.  Arguments passed
       * passed to the kernel build operation are detailed in the following
  @@ -71,6 +73,14 @@
       *        the kernel will be shutdown immediately following deployment.</td>
       *   </tr>
       *   <tr>
  +    *     <td><code>urn:merlin:kernel.wait</code></td>
  +    *     <td>{@link java.lang.String}</td>
  +    *     <td>An optional int value (as a String) that will be used as the time in 
  +    *        milliseconds to wait before invoking shiutdown if the kernel is launched
  +    *        in execute mode (urn:merlin:kernel.server="false").
  +    *     </td>
  +    *   </tr>
  +    *   <tr>
       *     <td><code>urn:merlin:kernel.profile</code></td>
       *     <td>{@link java.io.File}</td>
       *     <td>Kernel configuration file that is used by the loader to configure
  @@ -111,6 +121,7 @@
                   //
                   // only set a shutdown hook if we are in server mode
                   //
  +
                   setShutdownHook( kernel );
               }
               else
  @@ -119,6 +130,16 @@
                   // force shutdown of the kernel
                   //
   
  +                int wait = getPause( map );
  +                try
  +                {
  +                    Thread.currentThread().sleep( wait );
  +                }
  +                catch( Throwable e )
  +                {
  +                    // ignore it
  +                }
  +
                   try
                   {
                       kernel.shutdown();
  @@ -146,6 +167,27 @@
               throw new KernelException( message, cause );
           }
       }
  +
  +    private int getPause( Map map )
  +    {
  +        String number = (String) map.get( "urn:merlin:kernel.wait" );
  +        if( number == null )
  +        {
  +            return DEFAULT_DELAY;
  +        }
  +        else
  +        {
  +            try
  +            {
  +                return Integer.parseInt( number );
  +            }
  +            catch( Throwable e )
  +            {
  +                return DEFAULT_DELAY;
  +            }
  +        }
  +    }
  +
   
       private boolean getServerMode( Map map )
       {
  
  
  

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