mcconnell 2003/08/30 11:36:55
Modified: merlin maven.xml
merlin/activation/src/java/org/apache/avalon/activation/appliance/impl
DefaultAppliance.java DefaultBlock.java
DefaultServiceManager.java
merlin/composition/src/java/org/apache/avalon/composition/data/builder
XMLContainmentProfileCreator.java
XMLDeploymentProfileCreator.java
merlin/composition/src/java/org/apache/avalon/composition/data/writer
XMLDeploymentProfileWriter.java
merlin/composition/src/java/org/apache/avalon/composition/model/impl
DefaultContainmentModel.java
DefaultDeploymentModel.java
Log:
Update to the appliance disposal logic to catch the case where a component is
released by a consuming component and the manager has already released the resource.
Revision Changes Path
1.48 +4 -0 avalon-sandbox/merlin/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/maven.xml,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- maven.xml 28 Aug 2003 12:06:54 -0000 1.47
+++ maven.xml 30 Aug 2003 18:36:54 -0000 1.48
@@ -18,6 +18,10 @@
<attainGoal name="merlin:dist"/>
<attainGoal name="merlin:site"/>
<attainGoal name="merlin:package"/>
+ <attainGoal name="merlin:replicate"/>
+ </goal>
+
+ <goal name="merlin:replicate">
<copy toDir="${merlin.home}">
<fileset dir="${merlin.build.inst.dir}"/>
</copy>
1.8 +6 -3
avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultAppliance.java
Index: DefaultAppliance.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultAppliance.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultAppliance.java 28 Aug 2003 12:06:54 -0000 1.7
+++ DefaultAppliance.java 30 Aug 2003 18:36:54 -0000 1.8
@@ -544,7 +544,6 @@
{
((Disposable)m_lifestyle).dispose();
}
- m_lifestyle = null;
}
if( m_contextProvider != null )
{
@@ -552,6 +551,7 @@
m_contextualization = null;
}
m_deployment.setEnabled( false );
+ m_lifestyle = null;
}
}
@@ -595,6 +595,9 @@
*/
public void release( Object source, Object instance )
{
+ if( instance == null ) return;
+ if( !m_deployment.isEnabled() ) return;
+
try
{
applyAccessStages( instance, false );
@@ -788,7 +791,7 @@
int id = System.identityHashCode( instance );
getLogger().debug( "applying service manager to: " + id );
}
- ServiceManager manager = new DefaultServiceManager( m_providers );
+ ServiceManager manager = new DefaultServiceManager( getLogger(),
m_providers );
((Serviceable)instance).service( manager );
}
}
1.11 +27 -47
avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultBlock.java
Index: DefaultBlock.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultBlock.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DefaultBlock.java 28 Aug 2003 12:06:54 -0000 1.10
+++ DefaultBlock.java 30 Aug 2003 18:36:54 -0000 1.11
@@ -56,6 +56,7 @@
import java.util.Hashtable;
import java.util.ArrayList;
import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@@ -992,14 +993,15 @@
if( method.getDeclaringClass().equals( java.lang.Object.class ) )
{
m_logger.debug( "invocation: " + method.getName() );
- m_logger.debug( "object invocation" );
- if( args == null )
+ try
{
- return method.invoke( m_block, new Object[0] );
+ return method.invoke( m_block, args );
}
- else
+ catch( InvocationTargetException e )
{
- return method.invoke( m_block, args );
+ final String error =
+ "Unexpected delegation error on java.lang.Object";
+ throw new ApplianceException( error, e.getTargetException() );
}
}
@@ -1007,50 +1009,28 @@
// otherwise we are delegating to an implementation component
//
- try
- {
- //
- // get the appliance we delegate to
- //
-
- ServiceDirective service =
- m_model.getExportDirective( method.getDeclaringClass() );
+ ServiceDirective service =
+ m_model.getExportDirective( method.getDeclaringClass() );
- String path = service.getPath();
- Appliance provider =
- (Appliance) m_block.resolveAppliance( path );
- m_logger.debug(
- "delegating: " + method.getName() );
+ String path = service.getPath();
+ Appliance provider = (Appliance) m_block.resolveAppliance( path );
+ m_logger.debug( "delegating: " + method.getName() );
- //
- // resolve the service object from the appliance
- // and delegate the invocation to that provider
- //
+ //
+ // resolve the service object from the appliance
+ // and delegate the invocation to that provider
+ //
- Object object = null;
- try
- {
- object = provider.resolve( this );
- if( args == null )
- {
- return method.invoke( object, new Object[0] );
- }
- else
- {
- return method.invoke( object, args );
- }
- }
- catch( Throwable e )
- {
- final String error =
- "Delegation error raised by provider: "
- + object.getClass();
- throw new ApplianceException( error, e );
- }
- finally
- {
- if( object != null ) provider.release( this, object );
- }
+ try
+ {
+ Object object = provider.resolve( this );
+ return method.invoke( object, args );
+ }
+ catch( InvocationTargetException e )
+ {
+ final String error =
+ "Delegation error raised by provider: " + provider;
+ throw new ApplianceException( error, e.getTargetException() );
}
catch( Throwable e )
{
1.2 +43 -15
avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultServiceManager.java
Index: DefaultServiceManager.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/activation/src/java/org/apache/avalon/activation/appliance/impl/DefaultServiceManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultServiceManager.java 7 Aug 2003 17:11:17 -0000 1.1
+++ DefaultServiceManager.java 30 Aug 2003 18:36:54 -0000 1.2
@@ -59,6 +59,9 @@
import org.apache.avalon.activation.appliance.Appliance;
import org.apache.avalon.activation.appliance.Home;
+import org.apache.avalon.composition.util.ExceptionHelper;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.meta.info.DependencyDescriptor;
@@ -67,7 +70,7 @@
* Default implementation of the framework [EMAIL PROTECTED] ServiceManager}
interface.
* @author Stephen McConnell <[EMAIL PROTECTED]>
*/
-class DefaultServiceManager implements ServiceManager
+class DefaultServiceManager extends AbstractLogEnabled implements ServiceManager
{
//========================================================================
// immutable state
@@ -95,8 +98,9 @@
* @param appliance the appliance handling the component
* to be serviced
*/
- public DefaultServiceManager( Map map )
+ public DefaultServiceManager( Logger logger, Map map )
{
+ super.enableLogging( logger );
m_map = map;
}
@@ -146,10 +150,11 @@
{
//
// TODO: framework states that ServiceException is thrown
- // if the service is noit found - and in this case that isn't
+ // if the service is not found - and in this case that isn't
// the issue - in effect we have a good key, but we simply
- // have not been able to go go from key to instance -
- // should look into some more concrete subtypes of ServiceException
+ // have not been able to go from key to instance -
+ // should look into some more concrete subtypes of
+ // ServiceException
final String error =
"Unexpected runtime error while attempting to resolve service for
key: " + key;
@@ -159,28 +164,51 @@
/**
* Release a service back to the manager.
- * @param object a pooled object
+ * @param object the object to release
*/
public void release( Object object )
{
- if( object == null )
+ if( object == null ) return;
+
+ int id = System.identityHashCode( object );
+ Integer link = new Integer( id );
+ final String key = (String) m_table.get( link );
+ if( key == null )
{
+ final String warning =
+ "Ignoring attempt to release an object ["
+ + id
+ + "] that was not established by this service manager.";
+ getLogger().warn( warning );
return;
}
- Integer link = new Integer( System.identityHashCode( object ) );
- final String key = (String) m_table.get( link );
final Home provider = (Home) m_map.get( key );
- if( provider != null )
+ if( provider == null )
+ {
+ final String warning =
+ "Internal inconsistency. "
+ + "Unable to release component as no provider could be found for the
key ["
+ + key
+ + "].";
+ getLogger().warn( warning );
+ return;
+ }
+
+ try
{
provider.release( this, object );
- m_table.remove( link );
}
- else
+ catch( Throwable e )
{
- // TODO: should this be ignored as we are currently doing
- // or should we get brutal and throw an
- // IllegalArgumentException ?
+ final String error =
+ "Internal error while attempting to release object from provider: " +
provider;
+ final String warning = ExceptionHelper.packException( error, e, true );
+ getLogger().warn( warning );
+ }
+ finally
+ {
+ m_table.remove( link );
}
}
}
1.12 +4 -2
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/XMLContainmentProfileCreator.java
Index: XMLContainmentProfileCreator.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/XMLContainmentProfileCreator.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- XMLContainmentProfileCreator.java 26 Aug 2003 22:45:24 -0000 1.11
+++ XMLContainmentProfileCreator.java 30 Aug 2003 18:36:54 -0000 1.12
@@ -398,7 +398,9 @@
}
else if( child.getName().equals( "component" ) )
{
- list.add( DEPLOYMENT_CREATOR.createDeploymentProfile( child ) );
+ DeploymentProfile profile =
+ DEPLOYMENT_CREATOR.createDeploymentProfile( child );
+ list.add( profile );
}
else if( child.getName().equals( "include" ) )
{
1.8 +2 -2
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/XMLDeploymentProfileCreator.java
Index: XMLDeploymentProfileCreator.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/XMLDeploymentProfileCreator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XMLDeploymentProfileCreator.java 26 Aug 2003 22:45:24 -0000 1.7
+++ XMLDeploymentProfileCreator.java 30 Aug 2003 18:36:54 -0000 1.8
@@ -118,7 +118,7 @@
final Parameters params =
getParameters( config.getChild( "parameters", false ) );
final Configuration configuration =
- config.getChild( "configuration", false );
+ config.getChild( "configuration", true );
return new DeploymentProfile(
name, activation, classname, categories, context, dependencies,
1.5 +10 -3
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/writer/XMLDeploymentProfileWriter.java
Index: XMLDeploymentProfileWriter.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/writer/XMLDeploymentProfileWriter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLDeploymentProfileWriter.java 26 Aug 2003 22:45:24 -0000 1.4
+++ XMLDeploymentProfileWriter.java 30 Aug 2003 18:36:54 -0000 1.5
@@ -104,7 +104,7 @@
}
if(( profile.getCategories() == null ) && ( profile.getContext() == null )
- && ( profile.getConfiguration() == null ) && (profile.getParameters() ==
null ))
+ && ( isEmptyConfiguration( profile.getConfiguration() ) ) &&
(profile.getParameters() == null ))
{
writer.write( "/>");
}
@@ -117,6 +117,13 @@
}
}
+ private boolean isEmptyConfiguration( Configuration config )
+ {
+ if( config == null ) return true;
+ if( config.getChildren().length > 0 ) return false;
+ return config.getAttributeNames().length == 0;
+ }
+
/**
* Write out a containment deployment content.
* @param writer the writer
@@ -350,7 +357,7 @@
final Writer writer, final Configuration config, String pad )
throws IOException
{
- if( config != null )
+ if( !isEmptyConfiguration( config ) )
{
StringBuffer buffer = new StringBuffer();
ConfigurationUtil.list( buffer, pad, config );
1.31 +20 -19
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
Index: DefaultContainmentModel.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- DefaultContainmentModel.java 26 Aug 2003 22:45:24 -0000 1.30
+++ DefaultContainmentModel.java 30 Aug 2003 18:36:54 -0000 1.31
@@ -451,6 +451,10 @@
return new DefaultContainmentModel( context );
}
+ catch( ModelException e )
+ {
+ throw e;
+ }
catch( Throwable e )
{
final String error =
@@ -623,25 +627,22 @@
}
else if( path.endsWith( "/" ) )
{
- final URL blockURL = new URL( url.toString() +
"BLOCK-INF/block.xml" );
- final InputStream stream = blockURL.openStream();
+ final URL blockURL =
+ new URL( url.toString() + "BLOCK-INF/block.xml" );
- try
- {
- final ContainmentProfile profile =
- BUILDER.createContainmentProfile( stream );
- return createContainmentModel(
- getName( name, profile ), profile, new URL[]{ url } );
- }
- catch( Throwable e )
- {
- final String error =
- "Unable to create local block [" + blockURL.toString()
- + "] in the containmment model ["
- + getQualifiedName()
- + "] due to a build related error.";
- throw new ModelException( error, e );
- }
+ DefaultConfigurationBuilder builder =
+ new DefaultConfigurationBuilder();
+ Configuration config =
+ builder.build( blockURL.toString() );
+
+ final ContainmentProfile profile =
+ CREATOR.createContainmentProfile( config );
+
+ final String message =
+ "including composite block: " + blockURL.toString();
+ getLogger().debug( message );
+
+ return createContainmentModel( getName( name, profile ), profile,
new URL[]{ url } );
}
else
{
1.23 +3 -6
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java
Index: DefaultDeploymentModel.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- DefaultDeploymentModel.java 23 Aug 2003 02:23:30 -0000 1.22
+++ DefaultDeploymentModel.java 30 Aug 2003 18:36:54 -0000 1.23
@@ -454,12 +454,9 @@
}
/**
- * Return the configuration to be applied to the component.
- * The implementation returns the current configuration state.
- * If the the component type does not implementation the
- * Configurable interface, the implementation returns null.
+ * Return the parameters to be applied to the component.
*
- * @return the qualified configuration
+ * @return the parameters
*/
public Parameters getParameters()
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]