mcconnell 2003/12/03 16:25:03
Modified: kernel/api/src/java/org/apache/avalon/merlin
KernelCriteria.java
kernel/impl/src/java/org/apache/avalon/merlin/impl
DefaultCriteria.java DefaultFactory.java
DefaultKernel.java
kernel/test merlin.properties
kernel/test/conf hello.block
Log:
Update to properly handle the registration of dynamic children.
Revision Changes Path
1.2 +16 -1
avalon-sandbox/kernel/api/src/java/org/apache/avalon/merlin/KernelCriteria.java
Index: KernelCriteria.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/api/src/java/org/apache/avalon/merlin/KernelCriteria.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- KernelCriteria.java 2 Dec 2003 07:58:42 -0000 1.1
+++ KernelCriteria.java 4 Dec 2003 00:25:03 -0000 1.2
@@ -98,6 +98,12 @@
URL getKernelURL();
/**
+ * Return the url to the configuration override targets.
+ * @return the override url
+ */
+ URL getOverrideURL();
+
+ /**
* Return the working client directory.
* @return the working directory
*/
@@ -150,5 +156,14 @@
* @return the server execution mode
*/
boolean isServerEnabled();
+
+ /**
+ * Return the autostart policy. If TRUE (the default) the
+ * deployment of the application container will be initiated
+ * following kernel initialization.
+ *
+ * @return the autostart policy
+ */
+ boolean isAutostartEnabled();
}
1.5 +52 -11
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultCriteria.java
Index: DefaultCriteria.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultCriteria.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultCriteria.java 3 Dec 2003 04:38:02 -0000 1.4
+++ DefaultCriteria.java 4 Dec 2003 00:25:03 -0000 1.5
@@ -135,12 +135,18 @@
"merlin.deployment";
/**
- * Library path parameter descriptor.
+ * Merlin kernel url key.
*/
public static final String MERLIN_KERNEL =
"merlin.kernel";
/**
+ * Merlin target configuration override url
+ */
+ public static final String MERLIN_OVERRIDE =
+ "merlin.override";
+
+ /**
* Home directory parameter descriptor.
*/
public static final String MERLIN_DIR =
@@ -183,6 +189,11 @@
public static final String MERLIN_SERVER =
"merlin.server";
+ /**
+ * Auto start mode.
+ */
+ public static final String MERLIN_AUTOSTART =
+ "merlin.autostart";
/**
* The factory parameters template.
@@ -206,6 +217,8 @@
new Parameter(
MERLIN_KERNEL, URL.class, null ),
new Parameter(
+ MERLIN_OVERRIDE, URL.class, null ),
+ new Parameter(
MERLIN_DIR, File.class, USER_DIR ),
new Parameter(
MERLIN_TEMP, File.class, TEMP_DIR ),
@@ -219,7 +232,9 @@
new Parameter(
MERLIN_DEBUG, Boolean.class, new Boolean( false ) ),
new Parameter(
- MERLIN_SERVER, Boolean.class, new Boolean( false ) )
+ MERLIN_SERVER, Boolean.class, new Boolean( false ) ),
+ new Parameter(
+ MERLIN_AUTOSTART, Boolean.class, new Boolean( true ) )
};
private static final String [] SINGLE_KEYS =
@@ -249,10 +264,10 @@
Properties avalonWork = getLocalProperties( USER_DIR, AVALON );
Properties merlinWork = getLocalProperties( USER_DIR, MERLIN );
- printProperties( avalonStatic, "avalon" );
- printProperties( merlinStatic, "merlin" );
- printProperties( merlinWork, "merlin-work" );
- printProperties( env, "environment" );
+ //printProperties( avalonStatic, "avalon" );
+ //printProperties( merlinStatic, "merlin" );
+ //printProperties( merlinWork, "merlin-work" );
+ //printProperties( env, "environment" );
//
// Create the finder (discovery policy), construct the defaults, and
@@ -278,11 +293,14 @@
};
Defaults defaults = new Defaults( SINGLE_KEYS, MULTI_VALUE_KEYS, finders );
- printProperties( defaults, "defaults (resolved)" );
+
+ //printProperties( defaults, "defaults (resolved)" );
+
Defaults.macroExpand( defaults, new Properties[]{ system, avalonStatic, env
} );
Defaults.macroExpand( defaults, new Properties[]{ system, avalonStatic, env
} );
- printProperties( defaults, "defaults (expanded)" );
- System.out.print( "" );
+
+ //printProperties( defaults, "defaults (expanded)" );
+ //System.out.print( "" );
//
// following aquistion of the default parameters we need to assign
@@ -385,7 +403,7 @@
}
/**
- * Return the url to the kernel confiuration
+ * Return the url to the kernel configuration
* @return the kernel configuration url
*/
public URL getKernelURL()
@@ -394,6 +412,15 @@
}
/**
+ * Return the url to the configuration override targets.
+ * @return the override url
+ */
+ public URL getOverrideURL()
+ {
+ return (URL) get( MERLIN_OVERRIDE );
+ }
+
+ /**
* Return the working client directory.
* @return the working directory
*/
@@ -458,6 +485,20 @@
Boolean value = (Boolean) get( MERLIN_DEBUG );
if( null != value ) return value.booleanValue();
return false;
+ }
+
+ /**
+ * Return the autostart policy. If TRUE (the default) the
+ * deployment of the application container will be initiated
+ * following kernel initialization.
+ *
+ * @return the autostart policy
+ */
+ public boolean isAutostartEnabled()
+ {
+ Boolean value = (Boolean) get( MERLIN_AUTOSTART );
+ if( null != value ) return value.booleanValue();
+ return true;
}
/**
1.5 +119 -28
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java
Index: DefaultFactory.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultFactory.java 3 Dec 2003 20:44:26 -0000 1.4
+++ DefaultFactory.java 4 Dec 2003 00:25:03 -0000 1.5
@@ -7,6 +7,7 @@
import java.net.URL;
import java.util.Map;
import java.util.ArrayList;
+import java.util.Iterator;
import org.apache.avalon.activation.appliance.Block;
import org.apache.avalon.activation.appliance.Composite;
@@ -17,6 +18,7 @@
import org.apache.avalon.composition.data.CategoriesDirective;
import org.apache.avalon.composition.data.ContainmentProfile;
import org.apache.avalon.composition.data.TargetDirective;
+import org.apache.avalon.composition.data.builder.XMLTargetsCreator;
import org.apache.avalon.composition.data.builder.XMLDeploymentProfileCreator;
import org.apache.avalon.composition.data.builder.XMLContainmentProfileCreator;
import org.apache.avalon.composition.logging.LoggingManager;
@@ -26,6 +28,7 @@
import org.apache.avalon.composition.logging.impl.DefaultLoggingManager;
import org.apache.avalon.composition.logging.impl.FileTargetProvider;
import org.apache.avalon.composition.model.ContainmentContext;
+import org.apache.avalon.composition.model.DeploymentModel;
import org.apache.avalon.composition.model.ContainmentModel;
import org.apache.avalon.composition.model.ModelFactory;
import org.apache.avalon.composition.model.SystemContext;
@@ -47,6 +50,7 @@
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.merlin.Kernel;
import org.apache.avalon.merlin.KernelException;
import org.apache.avalon.merlin.KernelCriteria;
@@ -82,6 +86,9 @@
private static final XMLContainmentProfileCreator CONTAINER_CREATOR =
new XMLContainmentProfileCreator();
+ private static final XMLTargetsCreator TARGETS =
+ new XMLTargetsCreator();
+
//--------------------------------------------------------------------------
// state
//--------------------------------------------------------------------------
@@ -189,9 +196,23 @@
loggingDescriptor.getName() );
getLogger().debug( "logging system established" );
+ if( criteria.isInfoEnabled() )
+ {
+ StringBuffer buffer = new StringBuffer( "Merlin Kernel Environment
Listing\n");
+ Iterator keys = criteria.keySet().iterator();
+ while( keys.hasNext() )
+ {
+ String key = (String) keys.next();
+ Object value = criteria.get( key );
+ buffer.append( "\n ${" + key + "} == " + value );
+ }
+ buffer.append( "\n" );
+ getLogger().info( buffer.toString() );
+ }
+
if( criteria.isDebugEnabled() )
{
- getLogger().debug( "kernel configuration:\n\n" + listing );
+ getLogger().debug( "kernel configuration:\n" + listing );
}
//
@@ -300,25 +321,49 @@
getContainmentProfile(
kernelConfig.getChild( "container" ) ) ) );
- try
+ URL overridesURL = criteria.getOverrideURL();
+ TargetDirective[] overrides = getTargetOverrides( overridesURL );
+
+ for( int i=0; i<overrides.length; i++ )
{
- m_application = AbstractBlock.createRootBlock( services, application );
- /*
- if( m_application instanceof Composite )
+ TargetDirective target = overrides[i];
+ final String path = target.getPath();
+ Object model = application.getModel( path );
+ if( model != null )
{
- try
+ if( model instanceof DeploymentModel )
{
- getLogger().debug( "application assembly" );
- ((Composite)m_application).assemble();
+ DeploymentModel deployment = (DeploymentModel) model;
+ if( target.getConfiguration() != null )
+ {
+ deployment.setConfiguration( target.getConfiguration() );
+ }
+ if( target.getCategoriesDirective() != null )
+ {
+ deployment.setCategories( target.getCategoriesDirective() );
+ }
}
- catch( Throwable e )
+ else if( model instanceof ContainmentModel )
{
- final String error =
- "Assembly failure.";
- throw new KernelException( error, e );
+ ContainmentModel containment = (ContainmentModel) model;
+ if( target.getCategoriesDirective() != null )
+ {
+ containment.setCategories( target.getCategoriesDirective()
);
+ }
}
}
- */
+ else
+ {
+ final String warning =
+ "Ignoring target directive as the path does not refer to a known
component: "
+ + path;
+ getLogger().warn( warning );
+ }
+ }
+
+ try
+ {
+ m_application = AbstractBlock.createRootBlock( services, application );
}
catch( Throwable e )
{
@@ -326,7 +371,29 @@
"Composition failure.";
throw new KernelException( error, e );
}
+
+ Kernel kernel = createKernel( getLogger(), criteria, m_system,
m_application );
+
+ if( criteria.isAutostartEnabled() )
+ {
+ try
+ {
+ kernel.startup();
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Kernel startup failure.";
+ throw new KernelException( error, e );
+ }
+ }
+
+ return kernel;
+ }
+ private Kernel createKernel( Logger logger, KernelCriteria criteria, Block
system, Block application )
+ throws KernelException
+ {
try
{
return new DefaultKernel( getLogger(), criteria, m_system,
m_application );
@@ -346,7 +413,8 @@
* @return the containment context
*/
private ContainmentContext createContainmentContext(
- SystemContext context, Logger logger, ClassLoader parent, ContainmentProfile
profile )
+ SystemContext context, Logger logger, ClassLoader parent,
+ ContainmentProfile profile )
throws Exception
{
LoggingManager logging = context.getLoggingManager();
@@ -568,38 +636,61 @@
*/
private Configuration getKernelConfiguration( URL url ) throws Exception
{
- if( null == url )
+ if( null != url )
{
try
{
- return new DefaultConfiguration(
- "kernel",
- DefaultFactory.class.getName() );
+ DefaultConfigurationBuilder builder =
+ new DefaultConfigurationBuilder();
+ return builder.build( url.toString() );
}
catch( Throwable e )
{
final String error =
- "Unable to build kernel configuration from the supplied url: " +
url;
+ "Could not load the kernel directive: " + url;
throw new KernelException( error, e );
}
}
+ else
+ {
+
+ try
+ {
+ final InputStream stream =
+ DefaultFactory.class.getClassLoader().getResourceAsStream(
+ "kernel.xml" );
+ final InputSource source = new InputSource( stream );
+ DefaultConfigurationBuilder builder =
+ new DefaultConfigurationBuilder();
+ return builder.build( source );
+ }
+ catch( Throwable ee )
+ {
+ final String error =
+ "Internal error while attempting to build default kernel "
+ + "configuration from the kernel spec: " + url;
+ throw new KernelException( error, ee );
+ }
+ }
+ }
+
+ private TargetDirective[] getTargetOverrides( final URL url )
+ throws KernelException
+ {
+ if( null == url ) return new TargetDirective[0];
try
{
- final InputStream stream =
- DefaultFactory.class.getClassLoader().getResourceAsStream(
- "kernel.xml" );
- final InputSource source = new InputSource( stream );
DefaultConfigurationBuilder builder =
new DefaultConfigurationBuilder();
- return builder.build( source );
+ Configuration config = builder.build( url.toString() );
+ return TARGETS.createTargets( config ).getTargets();
}
- catch( Throwable ee )
+ catch( Throwable e )
{
final String error =
- "Internal error while attempting to build default kernel "
- + "configuration from the kernel spec: " + url;
- throw new KernelException( error, ee );
+ "Could not load the targets directive: " + url;
+ throw new KernelException( error, e );
}
}
1.2 +10 -42
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java
Index: DefaultKernel.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultKernel.java 2 Dec 2003 08:00:40 -0000 1.1
+++ DefaultKernel.java 4 Dec 2003 00:25:03 -0000 1.2
@@ -160,15 +160,17 @@
for( int i=0; i<urls.length; i++ )
{
URL url = urls[i];
+
if( getLogger().isInfoEnabled() )
{
getLogger().info(
"installing: "
+ StringHelper.toString( url ) );
}
+
try
{
- model.addModel( url );
+ m_application.addModel( url );
}
catch( Throwable e )
{
@@ -178,53 +180,20 @@
}
}
- //
- // apply any customization to the models using a supplied
- // targets directive
- //
-
- /*
- getLogger().debug( "customization phase" );
- TargetDirective[] targets = context.getTargetDirectives();
- for( int i=0; i<targets.length; i++ )
+ setState( INITIALIZED );
+
+ if( getLogger().isDebugEnabled() )
{
- TargetDirective target = targets[i];
- final String path = target.getPath();
- Object model = m_model.getModel( path );
- if( model != null )
+ int count = model.getModels().length;
+ if( count == 0 )
{
- if( model instanceof DeploymentModel )
- {
- DeploymentModel deployment = (DeploymentModel) model;
- if( target.getConfiguration() != null )
- {
- deployment.setConfiguration( target.getConfiguration() );
- }
- if( target.getCategoriesDirective() != null )
- {
- deployment.setCategories( target.getCategoriesDirective() );
- }
- }
- else if( model instanceof ContainmentModel )
- {
- ContainmentModel containment = (ContainmentModel) model;
- if( target.getCategoriesDirective() != null )
- {
- containment.setCategories( target.getCategoriesDirective()
);
- }
- }
+ getLogger().debug( "kernel established" );
}
else
{
- final String warning =
- "Ignoring target directive as the path does not refer to a known
component: "
- + path;
- getLogger().warn( warning );
+ getLogger().debug( "kernel established (" + count + ")" );
}
}
- */
- setState( INITIALIZED );
- getLogger().debug( "kernel established" );
}
//--------------------------------------------------------------
@@ -400,7 +369,6 @@
*/
public Appliance locate( String path ) throws KernelException
{
- if( !m_self.isEnabled() ) throw new IllegalStateException( "kernel" );
try
{
return m_application.locate( path );
1.5 +1 -1 avalon-sandbox/kernel/test/merlin.properties
Index: merlin.properties
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/test/merlin.properties,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- merlin.properties 3 Dec 2003 20:48:30 -0000 1.4
+++ merlin.properties 4 Dec 2003 00:25:03 -0000 1.5
@@ -1,4 +1,4 @@
merlin.info = true
-merlin.debug = true
+merlin.debug = false
merlin.deployment = conf/test.block,conf/test-2.block,conf/hello.block
1.2 +1 -1 avalon-sandbox/kernel/test/conf/hello.block
Index: hello.block
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/test/conf/hello.block,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- hello.block 3 Dec 2003 20:48:30 -0000 1.1
+++ hello.block 4 Dec 2003 00:25:03 -0000 1.2
@@ -9,6 +9,6 @@
</classpath>
</classloader>
- <component name="hello" class="tutorial.HelloComponent"/>
+ <component name="hello" class="tutorial.HelloComponent" activation="startup"/>
</container>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]