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 2004/02/12 06:59:42 UTC
cvs commit: avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/impl SimpleDeploymentModel.java
mcconnell 2004/02/11 21:59:42
Modified: merlin/activation/csi/src/java/org/apache/avalon/activation/csi
Resources.properties SecureAppliance.java
SecureInvocationHandler.java
SecureServiceManager.java
merlin/activation/csi/src/test/conf playground.xml
merlin/activation/impl/src/java/org/apache/avalon/activation/impl
AbstractLifestyleManager.java
ApplianceInvocationHandler.java
DefaultAppliance.java DefaultServiceManager.java
Resources.properties
merlin/composition/api/src/java/org/apache/avalon/composition/model
ContainmentModel.java DeploymentModel.java
merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
DefaultComponentModel.java
DefaultContainmentModel.java
DefaultContainmentModelAssemblyHelper.java
DefaultDeploymentModel.java
merlin/composition/impl/src/test/org/apache/avalon/composition/model/impl
SimpleDeploymentModel.java
Added: merlin/composition/api/src/java/org/apache/avalon/composition/model
FatalServiceException.java
TransientServiceException.java
Log:
Updates to remove circular dependency loop.
Revision Changes Path
1.2 +1 -0 avalon/merlin/activation/csi/src/java/org/apache/avalon/activation/csi/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/avalon/merlin/activation/csi/src/java/org/apache/avalon/activation/csi/Resources.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Resources.properties 10 Feb 2004 16:14:11 -0000 1.1
+++ Resources.properties 12 Feb 2004 05:59:41 -0000 1.2
@@ -30,4 +30,5 @@
# DefaultAppliance
# -----
appliance.error.resolve.non-commission-state=Cannot respond to resolve request as the appliance {0} is in a non-commissioned state.
+appliance.error.resolve.transient=Service managed by [{0}] return a transient non-availability status. Projected delay before service resumption is [{1}] milliseconds.
1.2 +45 -12 avalon/merlin/activation/csi/src/java/org/apache/avalon/activation/csi/SecureAppliance.java
Index: SecureAppliance.java
===================================================================
RCS file: /home/cvs/avalon/merlin/activation/csi/src/java/org/apache/avalon/activation/csi/SecureAppliance.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SecureAppliance.java 10 Feb 2004 16:14:12 -0000 1.1
+++ SecureAppliance.java 12 Feb 2004 05:59:41 -0000 1.2
@@ -20,9 +20,11 @@
import java.lang.reflect.Proxy;
import org.apache.avalon.activation.ApplianceException;
+import org.apache.avalon.activation.TransientApplianceException;
import org.apache.avalon.activation.LifestyleManager;
import org.apache.avalon.composition.model.ComponentModel;
+import org.apache.avalon.composition.model.TransientRuntimeException;
import org.apache.avalon.composition.util.DefaultState;
import org.apache.avalon.excalibur.i18n.ResourceManager;
@@ -56,6 +58,8 @@
private final DefaultState m_commissioned = new DefaultState();
+ private long m_delay = 0;
+
//-------------------------------------------------------------------
// constructor
//-------------------------------------------------------------------
@@ -112,26 +116,55 @@
*/
public Object resolve() throws Exception
{
- if( !m_commissioned.isEnabled() )
- {
- final String error =
- REZ.getString(
- "appliance.error.resolve.non-commission-state",
- this.toString() );
- throw new IllegalStateException( error );
- }
-
if( getComponentModel().getType().getInfo().
getAttribute( "urn:activation:proxy", "true" ).equals( "false" ) )
{
- return m_lifestyle.resolve();
+ return resolve( false );
}
else
{
+ return resolve( true );
+ }
+ }
+
+ /**
+ * Resolve a object to a value.
+ *
+ * @return the resolved object
+ * @throws Exception if an error occurs
+ */
+ protected Object resolve( boolean proxy ) throws Exception
+ {
+ if( !proxy )
+ {
+ if( m_delay > 0 )
+ {
+ final String error =
+ REZ.getString(
+ "appliance.error.resolve.transient",
+ this.toString(),
+ "" + m_delay );
+ throw new TransientRuntimeException( error, m_delay );
+ }
+ else if( !m_commissioned.isEnabled() )
+ {
+ final String error =
+ REZ.getString(
+ "appliance.error.resolve.non-commission-state",
+ this.toString() );
+ throw new IllegalStateException( error );
+ }
+ else
+ {
+ return m_lifestyle.resolve();
+ }
+ }
+ else
+ {
ComponentModel model = getComponentModel();
Logger logger = model.getLogger().getChildLogger( "proxy" );
SecureInvocationHandler handler =
- new SecureInvocationHandler( this, logger, m_lifestyle.resolve() );
+ new SecureInvocationHandler( this, logger );
try
{
1.2 +21 -9 avalon/merlin/activation/csi/src/java/org/apache/avalon/activation/csi/SecureInvocationHandler.java
Index: SecureInvocationHandler.java
===================================================================
RCS file: /home/cvs/avalon/merlin/activation/csi/src/java/org/apache/avalon/activation/csi/SecureInvocationHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SecureInvocationHandler.java 10 Feb 2004 16:14:14 -0000 1.1
+++ SecureInvocationHandler.java 12 Feb 2004 05:59:41 -0000 1.2
@@ -27,8 +27,10 @@
import org.apache.avalon.activation.Appliance;
import org.apache.avalon.activation.ApplianceException;
import org.apache.avalon.activation.LifestyleManager;
+import org.apache.avalon.activation.TransientApplianceException;
import org.apache.avalon.composition.model.ComponentModel;
+import org.apache.avalon.composition.model.TransientRuntimeException;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.logger.Logger;
@@ -46,7 +48,7 @@
// immutable state
//-------------------------------------------------------------------
- private final Appliance m_appliance;
+ private final SecureAppliance m_appliance;
private final Logger m_logger;
//-------------------------------------------------------------------
@@ -65,11 +67,10 @@
*
* @param instance the underlying provider
*/
- protected SecureInvocationHandler( Appliance appliance, Logger logger, Object instance )
+ protected SecureInvocationHandler( SecureAppliance appliance, Logger logger )
{
m_appliance = appliance;
m_logger = logger;
- m_instance = instance;
}
//-------------------------------------------------------------------
@@ -100,7 +101,7 @@
try
{
- return secureInvocation( method, m_instance, args );
+ return secureInvocation( method, args );
}
catch( Throwable e )
{
@@ -144,16 +145,20 @@
private Object getInstance() throws Exception
{
+ if( m_instance == null )
+ m_instance = m_appliance.resolve( false );
return m_instance;
}
private Object secureInvocation(
- final Method method, final Object object, final Object[] args )
+ final Method method, final Object[] args )
throws Exception
{
+ Object instance = getInstance();
+
//if( ! m_secured )
//{
- return method.invoke( object, args );
+ return method.invoke( instance, args );
//}
//else
//{
@@ -162,7 +167,7 @@
// {
// public Object run() throws Exception
// {
- // return method.invoke( object, args );
+ // return method.invoke( instance, args );
// }
// }, m_accessControlContext );
// return result;
@@ -176,7 +181,14 @@
+ m_appliance.toString();
while( true )
{
- if( e instanceof UndeclaredThrowableException )
+ if( e instanceof TransientApplianceException )
+ {
+ TransientApplianceException t =
+ (TransientApplianceException) e;
+ return new TransientRuntimeException(
+ t.getMessage(), t.getDelay() );
+ }
+ else if( e instanceof UndeclaredThrowableException )
{
Throwable cause =
((UndeclaredThrowableException) e).getUndeclaredThrowable();
1.2 +39 -1 avalon/merlin/activation/csi/src/java/org/apache/avalon/activation/csi/SecureServiceManager.java
Index: SecureServiceManager.java
===================================================================
RCS file: /home/cvs/avalon/merlin/activation/csi/src/java/org/apache/avalon/activation/csi/SecureServiceManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SecureServiceManager.java 10 Feb 2004 16:14:16 -0000 1.1
+++ SecureServiceManager.java 12 Feb 2004 05:59:41 -0000 1.2
@@ -21,10 +21,14 @@
import java.util.Hashtable;
import java.lang.reflect.Proxy;
+import org.apache.avalon.activation.TransientApplianceException;
+
import org.apache.avalon.composition.model.ComponentModel;
import org.apache.avalon.composition.model.DeploymentModel;
import org.apache.avalon.composition.model.DependencyModel;
import org.apache.avalon.composition.model.Resolver;
+import org.apache.avalon.composition.model.TransientServiceException;
+import org.apache.avalon.composition.model.FatalServiceException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
@@ -125,6 +129,18 @@
*/
public Object lookup( String key ) throws ServiceException
{
+ return lookup( key, -1 );
+ }
+
+ /**
+ * Retrieve Object by key.
+ * @param key the role
+ * @return the Object
+ * @throws ServiceException if an error occurs
+ * @throws NullPointerException if the supplied key is null
+ */
+ public Object lookup( String key, long timeout ) throws ServiceException
+ {
if( key == null )
{
throw new NullPointerException( "key" );
@@ -187,6 +203,28 @@
return instance;
}
+ catch( TransientApplianceException e )
+ {
+ long delay = e.getDelay();
+ if(( timeout == -1 ) || (( delay < timeout ) && ( delay > 0 )) )
+ {
+ try
+ {
+ Thread.currentThread().sleep( delay );
+ }
+ catch( Throwable interrupted )
+ {
+ // ignore
+ }
+ return lookup( key, delay );
+ }
+ else
+ {
+ final String error =
+ "Requested service is not responding.";
+ throw new TransientServiceException( key, error, delay );
+ }
+ }
catch( Throwable e )
{
//
@@ -200,7 +238,7 @@
final String error =
"Unexpected runtime error while attempting to resolve service for key: "
+ key;
- throw new ServiceException( key, error, e );
+ throw new FatalServiceException( key, error, e );
}
}
1.2 +2 -2 avalon/merlin/activation/csi/src/test/conf/playground.xml
Index: playground.xml
===================================================================
RCS file: /home/cvs/avalon/merlin/activation/csi/src/test/conf/playground.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- playground.xml 10 Feb 2004 16:14:22 -0000 1.1
+++ playground.xml 12 Feb 2004 05:59:41 -0000 1.2
@@ -5,7 +5,7 @@
<container name="playground">
- <categories priority="INFO"/>
+ <categories priority="DEBUG"/>
<classloader>
<classpath>
@@ -21,7 +21,7 @@
<component name="complex"
class="org.apache.avalon.playground.ComplexComponent">
- <categories priority="INFO"/>
+ <!--<categories priority="INFO"/>-->
</component>
<container name="test">
1.2 +2 -2 avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/AbstractLifestyleManager.java
Index: AbstractLifestyleManager.java
===================================================================
RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/AbstractLifestyleManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractLifestyleManager.java 10 Feb 2004 16:19:15 -0000 1.1
+++ AbstractLifestyleManager.java 12 Feb 2004 05:59:41 -0000 1.2
@@ -26,6 +26,7 @@
import org.apache.avalon.activation.ComponentFactory;
import org.apache.avalon.composition.model.ComponentModel;
+
import org.apache.avalon.meta.info.InfoDescriptor;
import org.apache.avalon.framework.logger.Logger;
@@ -62,7 +63,6 @@
{
m_factory = factory;
m_model = model;
-
m_logger = model.getLogger();
}
1.2 +19 -23 avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/ApplianceInvocationHandler.java
Index: ApplianceInvocationHandler.java
===================================================================
RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/ApplianceInvocationHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ApplianceInvocationHandler.java 10 Feb 2004 16:19:15 -0000 1.1
+++ ApplianceInvocationHandler.java 12 Feb 2004 05:59:41 -0000 1.2
@@ -27,8 +27,10 @@
import org.apache.avalon.activation.Appliance;
import org.apache.avalon.activation.ApplianceException;
import org.apache.avalon.activation.LifestyleManager;
+import org.apache.avalon.activation.TransientApplianceException;
import org.apache.avalon.composition.model.ComponentModel;
+import org.apache.avalon.composition.model.TransientRuntimeException;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.logger.Logger;
@@ -46,7 +48,7 @@
// immutable state
//-------------------------------------------------------------------
- private final Appliance m_appliance;
+ private final DefaultAppliance m_appliance;
private final Logger m_logger;
//-------------------------------------------------------------------
@@ -65,11 +67,10 @@
*
* @param instance the underlying provider
*/
- protected ApplianceInvocationHandler( Appliance appliance, Logger logger, Object instance )
+ protected ApplianceInvocationHandler( DefaultAppliance appliance, Logger logger )
{
m_appliance = appliance;
m_logger = logger;
- m_instance = instance;
}
//-------------------------------------------------------------------
@@ -100,7 +101,7 @@
try
{
- return secureInvocation( method, m_instance, args );
+ return secureInvocation( method, args );
}
catch( Throwable e )
{
@@ -144,29 +145,17 @@
private Object getInstance() throws Exception
{
+ if( m_instance == null )
+ m_instance = m_appliance.resolve( false );
return m_instance;
}
private Object secureInvocation(
- final Method method, final Object object, final Object[] args )
+ final Method method, final Object[] args )
throws Exception
{
- //if( ! m_secured )
- //{
- return method.invoke( object, args );
- //}
- //else
- //{
- // Object result = AccessController.doPrivileged(
- // new PrivilegedExceptionAction()
- // {
- // public Object run() throws Exception
- // {
- // return method.invoke( object, args );
- // }
- // }, m_accessControlContext );
- // return result;
- //}
+ Object instance = getInstance();
+ return method.invoke( instance, args );
}
private Throwable handleInvocationThrowable( Throwable e )
@@ -176,7 +165,14 @@
+ m_appliance.toString();
while( true )
{
- if( e instanceof UndeclaredThrowableException )
+ if( e instanceof TransientApplianceException )
+ {
+ TransientApplianceException t =
+ (TransientApplianceException) e;
+ return new TransientRuntimeException(
+ t.getMessage(), t.getDelay() );
+ }
+ else if( e instanceof UndeclaredThrowableException )
{
Throwable cause =
((UndeclaredThrowableException) e).getUndeclaredThrowable();
1.2 +52 -14 avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultAppliance.java
Index: DefaultAppliance.java
===================================================================
RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultAppliance.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultAppliance.java 10 Feb 2004 16:19:15 -0000 1.1
+++ DefaultAppliance.java 12 Feb 2004 05:59:41 -0000 1.2
@@ -20,9 +20,11 @@
import java.lang.reflect.Proxy;
import org.apache.avalon.activation.ApplianceException;
+import org.apache.avalon.activation.TransientApplianceException;
import org.apache.avalon.activation.LifestyleManager;
import org.apache.avalon.composition.model.ComponentModel;
+import org.apache.avalon.composition.model.TransientRuntimeException;
import org.apache.avalon.composition.util.DefaultState;
import org.apache.avalon.excalibur.i18n.ResourceManager;
@@ -56,6 +58,8 @@
private final DefaultState m_commissioned = new DefaultState();
+ private long m_delay = 0;
+
//-------------------------------------------------------------------
// constructor
//-------------------------------------------------------------------
@@ -81,8 +85,18 @@
synchronized( m_commissioned )
{
if( m_commissioned.isEnabled() ) return;
- m_lifestyle.commission();
- m_commissioned.setEnabled( true );
+
+ try
+ {
+ m_delay = m_model.getDeploymentTimeout();
+ m_lifestyle.commission();
+ m_delay = 0;
+ m_commissioned.setEnabled( true );
+ }
+ finally
+ {
+ m_delay = 0;
+ }
}
}
@@ -104,6 +118,7 @@
// Resolver
//-------------------------------------------------------------------
+
/**
* Resolve a object to a value.
*
@@ -112,26 +127,49 @@
*/
public Object resolve() throws Exception
{
- if( !m_commissioned.isEnabled() )
- {
- final String error =
- REZ.getString(
- "appliance.error.resolve.non-commission-state",
- this.toString() );
- throw new IllegalStateException( error );
- }
-
if( getComponentModel().getType().getInfo().
getAttribute( "urn:activation:proxy", "true" ).equals( "false" ) )
{
- return m_lifestyle.resolve();
+ return resolve( false );
}
else
{
+ return resolve( true );
+ }
+ }
+
+ public Object resolve( boolean proxy ) throws Exception
+ {
+ if( !proxy )
+ {
+ if( m_delay > 0 )
+ {
+ final String error =
+ REZ.getString(
+ "appliance.error.resolve.transient",
+ this.toString(),
+ "" + m_delay );
+ throw new TransientRuntimeException( error, m_delay );
+ }
+ else if( !m_commissioned.isEnabled() )
+ {
+ final String error =
+ REZ.getString(
+ "appliance.error.resolve.non-commission-state",
+ this.toString() );
+ throw new IllegalStateException( error );
+ }
+ else
+ {
+ return m_lifestyle.resolve();
+ }
+ }
+ else
+ {
ComponentModel model = getComponentModel();
Logger logger = model.getLogger().getChildLogger( "proxy" );
ApplianceInvocationHandler handler =
- new ApplianceInvocationHandler( this, logger, m_lifestyle.resolve() );
+ new ApplianceInvocationHandler( this, logger );
try
{
1.2 +42 -2 avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultServiceManager.java
Index: DefaultServiceManager.java
===================================================================
RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultServiceManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultServiceManager.java 10 Feb 2004 16:19:15 -0000 1.1
+++ DefaultServiceManager.java 12 Feb 2004 05:59:41 -0000 1.2
@@ -21,10 +21,14 @@
import java.util.Hashtable;
import java.lang.reflect.Proxy;
+import org.apache.avalon.activation.TransientApplianceException;
+
import org.apache.avalon.composition.model.ComponentModel;
import org.apache.avalon.composition.model.DeploymentModel;
import org.apache.avalon.composition.model.DependencyModel;
import org.apache.avalon.composition.model.Resolver;
+import org.apache.avalon.composition.model.TransientServiceException;
+import org.apache.avalon.composition.model.FatalServiceException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
@@ -125,6 +129,18 @@
*/
public Object lookup( String key ) throws ServiceException
{
+ return lookup( key, -1 );
+ }
+
+ /**
+ * Retrieve Object by key.
+ * @param key the role
+ * @return the Object
+ * @throws ServiceException if an error occurs
+ * @throws NullPointerException if the supplied key is null
+ */
+ public Object lookup( String key, long timeout ) throws ServiceException
+ {
if( key == null )
{
throw new NullPointerException( "key" );
@@ -172,7 +188,7 @@
// object with the source provider
//
- String id = "" + System.identityHashCode( instance );
+ String id = "" + System.identityHashCode( instance );
m_table.put( id, key );
if( getLogger().isDebugEnabled() )
{
@@ -187,6 +203,30 @@
return instance;
}
+ /*
+ catch( TransientApplianceException e )
+ {
+ long delay = e.getDelay();
+ if(( timeout == -1 ) || (( delay < timeout ) && ( delay > 0 )) )
+ {
+ try
+ {
+ Thread.currentThread().sleep( delay );
+ }
+ catch( Throwable interrupted )
+ {
+ // ignore
+ }
+ return lookup( key, delay );
+ }
+ else
+ {
+ final String error =
+ "Requested service is not responding.";
+ throw new TransientServiceException( key, error, delay );
+ }
+ }
+ */
catch( Throwable e )
{
//
@@ -200,7 +240,7 @@
final String error =
"Unexpected runtime error while attempting to resolve service for key: "
+ key;
- throw new ServiceException( key, error, e );
+ throw new FatalServiceException( key, error, e );
}
}
1.2 +1 -0 avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/Resources.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Resources.properties 10 Feb 2004 16:19:15 -0000 1.1
+++ Resources.properties 12 Feb 2004 05:59:41 -0000 1.2
@@ -30,4 +30,5 @@
# DefaultAppliance
# -----
appliance.error.resolve.non-commission-state=Cannot respond to resolve request as the appliance {0} is in a non-commissioned state.
+appliance.error.resolve.transient=Service managed by [{0}] return a transient non-availability status. Projected delay before service resumption is [{1}] milliseconds.
1.18 +16 -1 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ContainmentModel.java
Index: ContainmentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/ContainmentModel.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ContainmentModel.java 7 Feb 2004 20:23:32 -0000 1.17
+++ ContainmentModel.java 12 Feb 2004 05:59:41 -0000 1.18
@@ -98,6 +98,12 @@
*/
long getDeploymentTimeout();
+ /**
+ * Assemble the containment model.
+ * @exception Exception if an error occurs during model assembly
+ */
+ void assemble() throws AssemblyException;
+
/**
* Return the set of models nested within this model.
* @return the classloader model
@@ -144,6 +150,15 @@
* @exception ModelException if an error occurs during model establishment
*/
DeploymentModel addModel( DeploymentProfile profile ) throws ModelException;
+
+ /**
+ * Addition of a new subsidiary model within
+ * the containment context.
+ *
+ * @param model the model to add
+ * @return the model
+ */
+ DeploymentModel addModel( DeploymentModel model );
/**
* Remove a named model from this model.
1.14 +5 -2 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/DeploymentModel.java
Index: DeploymentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/DeploymentModel.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DeploymentModel.java 10 Feb 2004 16:23:33 -0000 1.13
+++ DeploymentModel.java 12 Feb 2004 05:59:41 -0000 1.14
@@ -17,6 +17,8 @@
package org.apache.avalon.composition.model;
+import java.util.List;
+
import org.apache.avalon.composition.data.Mode;
import org.apache.avalon.composition.model.Commissionable;
import org.apache.avalon.composition.model.Resolver;
@@ -105,9 +107,10 @@
/**
* Assemble the model.
+ * @param subjects a list of deployment models that make up the assembly chain
* @exception Exception if an error occurs during model assembly
*/
- void assemble() throws AssemblyException;
+ void assemble( List subjects ) throws AssemblyException;
/**
* Return the set of models consuming this model.
1.1 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/FatalServiceException.java
Index: FatalServiceException.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.composition.model;
import org.apache.avalon.framework.service.ServiceException;
/**
* Exception to indicate that there was a transient service error. The
* exception exposes a delay value which is the anticipated delay in
* service availability. A delay value of 0 indicates an unknown delay.
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2004/02/12 05:59:41 $
*/
public class FatalServiceException
extends ServiceException
{
/**
* Construct a new <code>FatalServiceException</code> instance.
*
* @param key the lookup key
* @param message The detail message for this exception.
* @param cause expected service availability delay in milliseconds
*/
public FatalServiceException(
final String key, final String message, Throwable cause )
{
super( key, message, cause );
}
}
1.1 avalon/merlin/composition/api/src/java/org/apache/avalon/composition/model/TransientServiceException.java
Index: TransientServiceException.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.composition.model;
import org.apache.avalon.framework.service.ServiceException;
/**
* Exception to indicate that there was a transient service error. The
* exception exposes a delay value which is the anticipated delay in
* service availability. A delay value of 0 indicates an unknown delay.
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2004/02/12 05:59:41 $
*/
public class TransientServiceException
extends ServiceException
{
private final long m_delay;
/**
* Construct a new <code>TransientServiceException</code> instance.
*
* @param key the lookup key
* @param message The detail message for this exception.
* @param delay expected service availability delay in milliseconds
*/
public TransientServiceException(
final String key, final String message, long delay )
{
super( key, message );
m_delay = delay;
}
/**
* Returns the expected duration of service non-availability.
* @return the non-availability duration
*/
public long getDelay()
{
return m_delay;
}
}
1.7 +4 -4 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultComponentModel.java
Index: DefaultComponentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultComponentModel.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultComponentModel.java 10 Feb 2004 16:23:33 -0000 1.6
+++ DefaultComponentModel.java 12 Feb 2004 05:59:41 -0000 1.7
@@ -17,6 +17,7 @@
package org.apache.avalon.composition.model.impl;
+import java.util.List;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
@@ -236,7 +237,6 @@
*/
public boolean isAssembled()
{
- //return m_assembly.isEnabled();
return ( isContextAssembled()
&& isStageAssembled()
&& isServiceAssembled() );
@@ -276,9 +276,9 @@
* Assemble the model.
* @exception Exception if an error occurs during model assembly
*/
- public void assemble() throws AssemblyException
+ public void assemble( List subjects ) throws AssemblyException
{
- // nothing to do
+ getLogger().warn( "## component assembly request in : " + this + " with " + subjects );
}
/**
1.32 +61 -5 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
Index: DefaultContainmentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- DefaultContainmentModel.java 10 Feb 2004 16:23:33 -0000 1.31
+++ DefaultContainmentModel.java 12 Feb 2004 05:59:41 -0000 1.32
@@ -26,6 +26,7 @@
import java.util.LinkedList;
import java.util.Iterator;
import java.util.Hashtable;
+import java.util.List;
import java.util.ArrayList;
import java.util.Map;
@@ -397,6 +398,17 @@
*/
public void assemble() throws AssemblyException
{
+ List list = new ArrayList();
+ assemble( list );
+ }
+
+ /**
+ * Assemble the model.
+ * @param subjects the list of deployment targets making up the assembly chain
+ * @exception Exception if an error occurs during model assembly
+ */
+ public void assemble( List subjects ) throws AssemblyException
+ {
synchronized( m_assembly )
{
if( isAssembled() )
@@ -413,7 +425,7 @@
for( int i=0; i<models.length; i++ )
{
DeploymentModel model = models[i];
- helper.assembleModel( model );
+ helper.assembleModel( model, subjects );
}
m_assembly.setEnabled( true );
@@ -591,6 +603,20 @@
/**
* Addition of a new subsidiary model within
+ * the containment context.
+ *
+ * @param profile a containment or deployment profile
+ * @return the model based on the supplied profile
+ * @exception ModelException if an error occurs during model establishment
+ */
+ public DeploymentModel addModel( DeploymentModel model )
+ {
+ final String name = model.getName();
+ return addModel( name, model );
+ }
+
+ /**
+ * Addition of a new subsidiary model within
* the containment context using a supplied profile.
*
* @param profile a containment or deployment profile
@@ -599,11 +625,40 @@
*/
public DeploymentModel addModel( DeploymentProfile profile ) throws ModelException
{
+ final String name = profile.getName();
+ DeploymentModel model = createDeploymentModel( name, profile );
+ addModel( name, model );
+ return model;
+ }
+
+ /**
+ * Addition of a new subsidiary model within
+ * the containment context using a supplied profile.
+ *
+ * @param profile a containment or deployment profile
+ * @return the model based on the supplied profile
+ * @exception ModelException if an error occurs during model establishment
+ */
+ DeploymentModel createDeploymentModel( DeploymentProfile profile ) throws ModelException
+ {
+ final String name = profile.getName();
+ return createDeploymentModel( name, profile );
+ }
+
+ /**
+ * Addition of a new subsidiary model within
+ * the containment context using a supplied profile.
+ *
+ * @param profile a containment or deployment profile
+ * @return the model based on the supplied profile
+ * @exception ModelException if an error occurs during model establishment
+ */
+ DeploymentModel createDeploymentModel( String name, DeploymentProfile profile ) throws ModelException
+ {
if( null == profile )
throw new NullPointerException( "profile" );
DeploymentModel model = null;
- final String name = profile.getName();
if( profile instanceof ContainmentProfile )
{
ContainmentProfile containment = (ContainmentProfile) profile;
@@ -644,7 +699,7 @@
profile.getClass().getName() );
throw new ModelException( error );
}
- return addModel( name, model );
+ return model;
}
/**
@@ -777,8 +832,9 @@
//--------------------------------------------------------------
private DeploymentModel addModel(
- String name, DeploymentModel model ) throws ModelException
+ String name, DeploymentModel model )
{
+ if( model.equals( this ) ) return model;
ModelRepository repository = m_context.getModelRepository();
synchronized( repository )
{
1.3 +62 -33 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModelAssemblyHelper.java
Index: DefaultContainmentModelAssemblyHelper.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModelAssemblyHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultContainmentModelAssemblyHelper.java 10 Feb 2004 16:23:33 -0000 1.2
+++ DefaultContainmentModelAssemblyHelper.java 12 Feb 2004 05:59:41 -0000 1.3
@@ -17,6 +17,7 @@
package org.apache.avalon.composition.model.impl;
+import java.util.List;
import java.util.ArrayList;
import org.apache.avalon.composition.data.DeploymentProfile;
@@ -66,14 +67,14 @@
//-------------------------------------------------------------------
private final ContainmentContext m_context;
- private final ContainmentModel m_model;
+ private final DefaultContainmentModel m_model;
//-------------------------------------------------------------------
// constructor
//-------------------------------------------------------------------
public DefaultContainmentModelAssemblyHelper(
- ContainmentContext context, ContainmentModel model )
+ ContainmentContext context, DefaultContainmentModel model )
{
m_context = context;
m_model = model;
@@ -83,32 +84,44 @@
// implementation
//-------------------------------------------------------------------
- public void assembleModel( DeploymentModel model )
+ /**
+ * Assemble a target model during which all deployment and runtime
+ * dependencies are assigned a provider model.
+ *
+ * @param model the target model to be assembled
+ * @param subject the model requesting the assembly
+ */
+ public void assembleModel( DeploymentModel model, List subjects )
throws AssemblyException
{
if( null == model )
{
throw new NullPointerException( "model" );
}
-
+ if( null == subjects )
+ {
+ throw new NullPointerException( "subjects" );
+ }
+ if( subjects.contains( model ) )
+ {
+ return;
+ }
if( model.isAssembled() )
{
return;
}
+
+ if( model instanceof ComponentModel )
+ {
+ assembleComponent( (ComponentModel) model, subjects );
+ }
else
{
- if( model instanceof ComponentModel )
- {
- assembleComponent( (ComponentModel) model );
- }
- else
- {
- model.assemble();
- }
- }
+ model.assemble( subjects );
+ }
}
- private void assembleComponent( ComponentModel model ) throws AssemblyException
+ private void assembleComponent( ComponentModel model, List subjects ) throws AssemblyException
{
ModelRepository repository = m_context.getModelRepository();
@@ -127,10 +140,11 @@
{
try
{
+ subjects.add( model );
StageDescriptor stage =
new StageDescriptor( clazz.getName() );
DeploymentModel provider =
- findExtensionProvider( repository, stage );
+ findExtensionProvider( repository, stage, subjects );
context.setProvider( provider );
}
catch( Throwable e )
@@ -141,6 +155,10 @@
+ " due to a component context phase handler establishment failure.";
throw new AssemblyException( error, e );
}
+ finally
+ {
+ subjects.remove( model );
+ }
}
}
}
@@ -157,8 +175,9 @@
{
try
{
+ subjects.add( model );
DeploymentModel provider =
- findExtensionProvider( repository, stage );
+ findExtensionProvider( repository, stage, subjects );
stage.setProvider( provider );
}
catch( Throwable e )
@@ -169,6 +188,10 @@
+ " due to a component extension handler establishment failure.";
throw new AssemblyException( error, e );
}
+ finally
+ {
+ subjects.remove( model );
+ }
}
}
@@ -184,8 +207,9 @@
{
try
{
+ subjects.add( model );
DeploymentModel provider =
- findDependencyProvider( repository, dependency );
+ findDependencyProvider( repository, dependency, subjects );
dependency.setProvider( provider );
}
catch( Throwable e )
@@ -195,12 +219,16 @@
+ " due to a service provider establishment failure.";
throw new AssemblyException( error, e );
}
+ finally
+ {
+ subjects.remove( model );
+ }
}
}
}
private DeploymentModel findDependencyProvider(
- ModelRepository repository, DependencyModel dependency )
+ ModelRepository repository, DependencyModel dependency, List subjects )
throws AssemblyException
{
String path = dependency.getPath();
@@ -214,18 +242,18 @@
+ path + "] in " + this + ".";
throw new AssemblyException( error );
}
- assembleModel( model );
+ assembleModel( model, subjects );
return model;
}
else
{
return findDependencyProvider(
- repository, dependency.getDependency() );
+ repository, dependency.getDependency(), subjects );
}
}
private DeploymentModel findDependencyProvider(
- ModelRepository repository, DependencyDescriptor dependency )
+ ModelRepository repository, DependencyDescriptor dependency, List subjects )
throws AssemblyException
{
DeploymentModel[] candidates =
@@ -234,7 +262,7 @@
DeploymentModel model = selector.select( candidates, dependency );
if( model != null )
{
- assembleModel( model );
+ assembleModel( model, subjects );
return model;
}
@@ -250,8 +278,9 @@
{
try
{
- DeploymentModel solution = m_model.addModel( profile );
- assembleModel( solution );
+ DeploymentModel solution = m_model.createDeploymentModel( profile );
+ assembleModel( solution, subjects );
+ m_model.addModel( solution );
return solution;
}
catch( AssemblyException ae )
@@ -281,7 +310,7 @@
}
private DeploymentModel findExtensionProvider(
- ModelRepository repository, StageModel stage )
+ ModelRepository repository, StageModel stage, List subjects )
throws AssemblyException
{
String path = stage.getPath();
@@ -295,17 +324,17 @@
+ path + "] in " + this + ".";
throw new AssemblyException( error );
}
- assembleModel( model );
+ assembleModel( model, subjects );
return model;
}
else
{
- return findExtensionProvider( repository, stage.getStage() );
+ return findExtensionProvider( repository, stage.getStage(), subjects );
}
}
private DeploymentModel findExtensionProvider(
- ModelRepository repository, StageDescriptor stage )
+ ModelRepository repository, StageDescriptor stage, List subjects )
throws AssemblyException
{
DeploymentModel[] candidates =
@@ -314,7 +343,7 @@
DeploymentModel model = selector.select( candidates, stage );
if( model != null )
{
- assembleModel( model );
+ assembleModel( model, subjects );
return model;
}
@@ -330,8 +359,9 @@
{
try
{
- DeploymentModel solution = m_model.addModel( profile );
- assembleModel( solution );
+ DeploymentModel solution = m_model.createDeploymentModel( profile );
+ assembleModel( solution, subjects );
+ m_model.addModel( solution );
return solution;
}
catch( AssemblyException ae )
@@ -409,5 +439,4 @@
}
return (DeploymentProfile[]) list.toArray( new DeploymentProfile[0] );
}
-
}
1.16 +1 -23 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java
Index: DefaultDeploymentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- DefaultDeploymentModel.java 10 Feb 2004 16:23:33 -0000 1.15
+++ DefaultDeploymentModel.java 12 Feb 2004 05:59:41 -0000 1.16
@@ -90,7 +90,6 @@
public void commission() throws Exception
{
m_context.getSystemContext().commission( this );
- //getRuntime().commission();
}
/**
@@ -100,7 +99,6 @@
public void decommission()
{
m_context.getSystemContext().decommission( this );
- //getRuntime().decommission();
}
//--------------------------------------------------------------
@@ -116,7 +114,6 @@
public Object resolve() throws Exception
{
return m_context.getSystemContext().resolve( this );
- //return getRuntime().resolve();
}
/**
@@ -127,7 +124,6 @@
public void release( Object instance )
{
m_context.getSystemContext().release( this, instance );
- //getRuntime().release( this );
}
//--------------------------------------------------------------
@@ -190,24 +186,6 @@
public DeploymentModel[] getProviderGraph()
{
return m_context.getDependencyGraph().getProviderGraph( this );
- }
-
- /**
- * Set the runtime handler for the model.
- * @param handler the runtime handler
- */
- public void setHandler( Commissionable handler )
- {
- m_handler = handler;
- }
-
- /**
- * Get the assigned runtime handler for the model.
- * @return the runtime handler
- */
- public Commissionable getHandler()
- {
- return m_handler;
}
/**
1.2 +2 -1 avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/impl/SimpleDeploymentModel.java
Index: SimpleDeploymentModel.java
===================================================================
RCS file: /home/cvs/avalon/merlin/composition/impl/src/test/org/apache/avalon/composition/model/impl/SimpleDeploymentModel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SimpleDeploymentModel.java 10 Feb 2004 16:23:35 -0000 1.1
+++ SimpleDeploymentModel.java 12 Feb 2004 05:59:42 -0000 1.2
@@ -17,6 +17,7 @@
package org.apache.avalon.composition.model.impl;
+import java.util.List;
import org.apache.avalon.composition.data.Mode;
import org.apache.avalon.composition.model.DeploymentModel;
@@ -137,7 +138,7 @@
* Assemble the model.
* @exception Exception if an error occurs during model assembly
*/
- public void assemble() throws AssemblyException
+ public void assemble( List subjects ) throws AssemblyException
{
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org