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/04/29 02:49:00 UTC
cvs commit: avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl DefaultDeploymentService.java
mcconnell 2003/04/28 17:49:00
Modified: merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl
DefaultDeploymentService.java
Log:
Updating to incorporate intialization internally.
Revision Changes Path
1.3 +179 -59 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/DefaultDeploymentService.java
Index: DefaultDeploymentService.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifecycle/impl/DefaultDeploymentService.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultDeploymentService.java 28 Apr 2003 21:19:43 -0000 1.2
+++ DefaultDeploymentService.java 29 Apr 2003 00:49:00 -0000 1.3
@@ -55,15 +55,16 @@
import org.apache.avalon.assembly.lifecycle.DeploymentService;
import org.apache.avalon.assembly.lifecycle.context.ContextualizationService;
import org.apache.avalon.assembly.lifecycle.context.DefaultCompositionService;
-import org.apache.avalon.assembly.lifecycle.initialization.DefaultInitializationService;
-import org.apache.avalon.assembly.lifecycle.initialization.ExtendedInitializationService;
-import org.apache.avalon.assembly.lifecycle.initialization.InitializationService;
+//import org.apache.avalon.assembly.lifecycle.initialization.DefaultInitializationService;
+//import org.apache.avalon.assembly.lifecycle.initialization.ExtendedInitializationService;
+//import org.apache.avalon.assembly.lifecycle.initialization.InitializationService;
import org.apache.avalon.assembly.locator.Contextualizable;
import org.apache.avalon.assembly.locator.Locator;
import org.apache.avalon.assembly.locator.impl.DefaultLocator;
import org.apache.avalon.assembly.logging.LoggingManager;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.activity.Startable;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
@@ -95,7 +96,7 @@
private Locator m_context;
private LoggingManager m_logging;
private ContextualizationService m_contextualization;
- private InitializationService m_initialization;
+ //private InitializationService m_initialization;
private boolean m_initialized = false;
@@ -140,14 +141,14 @@
m_contextualization = makeContextualizationService();
}
- if( m_context.hasEntry( InitializationService.KEY ) )
- {
- m_initialization =
- (InitializationService) m_context.get( InitializationService.KEY );
- } else
- {
- m_initialization = makeInitializationService();
- }
+ //if( m_context.hasEntry( InitializationService.KEY ) )
+ //{
+ // m_initialization =
+ // (InitializationService) m_context.get( InitializationService.KEY );
+ //} else
+ //{
+ // m_initialization = makeInitializationService();
+ //}
m_initialized = true;
@@ -181,14 +182,13 @@
throw new NullPointerException( "classloader" );
}
+ Object instance;
try
{
-
//
// commence deployment
//
- Object instance;
try
{
final String classname = appliance.getType().getInfo().getClassname();
@@ -203,27 +203,84 @@
throw new DeploymentException( error, e );
}
- // invoke lifecycle processing on the instance
+ //
+ // invoke lifecycle processing on the instance commencing with
+ // logging channel assignment
+ //
if( instance instanceof LogEnabled )
{
handleLogging( appliance, ((LogEnabled)instance) );
}
+ //
+ // contextualize the component
+ //
+
m_contextualization.contextualize( classloader, appliance, instance );
+ //
+ // configure the component
+ //
+
if( instance instanceof Configurable )
{
handleConfiguration( appliance, ((Configurable)instance) );
}
+
+ //
+ // parameterize the component
+ //
+
if( instance instanceof Parameterizable )
{
handleParameterization( appliance, ((Parameterizable)instance) );
}
- m_initialization.initialize( appliance, instance );
+ //
+ // invoke create state lifecycle extensions
+ //
+
+ StageDescriptor[] stages = appliance.getType().getStages();
+ if( stages.length > 0 )
+ {
+ for( int i = 0; i < stages.length; i++ )
+ {
+ StageDescriptor stage = stages[i];
+ processCreateStage( appliance, stage, instance );
+ }
+ }
+
+ //
+ // initialize the instance
+ //
+
+ if( instance instanceof Initializable )
+ {
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message = "initializing " + appliance;
+ getLogger().debug( message );
+ }
+ ((Initializable)instance).initialize();
+ }
+
+ //
+ // start the instance
+ //
+
+ if( instance instanceof Startable )
+ {
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message = "starting " + appliance;
+ getLogger().debug( message );
+ }
+ ((Startable)instance).start();
+ }
+
return instance;
- }
+ }
catch( Throwable e )
{
final String error =
@@ -251,7 +308,17 @@
*/
public void decommission( Appliance appliance, Object instance, boolean disassemble )
{
- //
+ if( appliance == null )
+ {
+ throw new NullPointerException( "appliance" );
+ }
+
+ if( instance == null )
+ {
+ throw new NullPointerException( "instance" );
+ }
+
+ // ## need to review this
// make sure all dependent components are decommissioned
//
@@ -260,22 +327,66 @@
appliance.disassemble();
}
- try
+ //
+ // stop the component
+ //
+
+ if( instance instanceof Startable )
{
- m_initialization.deinitialize( appliance, instance );
- }
- catch( Throwable e )
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message = "stopping " + appliance;
+ getLogger().debug( message );
+ }
+ try
+ {
+ ((Startable)instance).stop();
+ }
+ catch( Throwable se )
+ {
+ final String warning =
+ "Component related error while process stop phase - appliance: "
+ + appliance.toString();
+ getLogger().warn( warning );
+ }
+ }
+
+ //
+ // handle the destroy stage lifecyle extensions
+ //
+
+ StageDescriptor[] stages = appliance.getType().getStages();
+ if( stages.length > 0 )
{
- final String warning =
- "Ignoring shutdown error raised by component: " + appliance;
- getLogger().warn( warning, e );
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message =
+ "destroy stage extension handling for appliance:"
+ + appliance;
+ getLogger().debug( message );
+ }
+
+ for( int i = 0; i < stages.length; i++ )
+ {
+ StageDescriptor stage = stages[i];
+ processDestroyStage( appliance, stage, instance );
+ }
}
- if( instance != null )
+ //
+ // dispose of the component
+ //
+
+ if( instance instanceof Disposable )
{
- handleDisposal( appliance, instance );
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message = "disposal " + appliance;
+ getLogger().debug( message );
+ }
+
+ ((Disposable)instance).dispose();
}
- //m_disposal.dispose( appliance, instance );
}
//----------------------------------------------------------------------------
@@ -349,47 +460,53 @@
object.parameterize( params );
}
- /**
- * Dispose of the supplied object. The implementation uses the
- * supplied appliance to get any destroy stage lifecycle extension
- * handlers prior to disposing of the object.
- *
- * @param appliance the appliance
- * @param object the object to dispose
- */
- public void handleDisposal( Appliance appliance, Object object )
+ /**
+ * Processing of a stage handler for the create stage in the component
+ * lifecyle.
+ *
+ * @param appliance the appliance
+ * @param stage the lifecycle extension stage
+ * @param the object to which the stage extension is to be applied
+ */
+ private void processCreateStage(
+ Appliance appliance, StageDescriptor stage, Object object )
{
- StageDescriptor[] stages = appliance.getType().getStages();
- if( stages.length > 0 )
+ try
{
- if( getLogger().isDebugEnabled() )
+ Appliance provider = appliance.getExtensionProvider( stage );
+ if( provider == null )
{
- final String message =
- "destroy stage extension handling for appliance:"
- + appliance;
- getLogger().debug( message );
+ final String error =
+ "Missing extension provider in appliance: '" + appliance
+ + "' for the stage: " + stage;
+ throw new DeploymentException( error );
}
- for( int i = 0; i < stages.length; i++ )
+ try
{
- StageDescriptor stage = stages[i];
- processDestroyStage( appliance, stage, object );
+ Creator handler = (Creator) provider.resolve( this );
+ handler.create(
+ object, new DefaultLocator( appliance.getContextMap() ) );
+ provider.release( handler, this );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Extension handler execution error in appliance: '"
+ + appliance
+ + "' under stage: '" + stage
+ + "' for target: '" + object + "'";
+ throw new DeploymentException( error, e );
}
}
-
- //
- // and finally, dispose of the component
- //
-
- if( object instanceof Disposable )
+ catch( Throwable e )
{
- if( getLogger().isDebugEnabled() )
+ if( getLogger().isWarnEnabled() )
{
- final String message = "disposal " + appliance;
- getLogger().debug( message );
+ final String warning =
+ "Ignoring extension related error during destroy stage.";
+ getLogger().warn( warning, e );
}
-
- ((Disposable) object).dispose();
}
}
@@ -443,6 +560,7 @@
}
}
+
//----------------------------------------------------------------------------
// internal services
//----------------------------------------------------------------------------
@@ -462,6 +580,7 @@
}
}
+ /*
private InitializationService makeInitializationService() throws DeploymentException
{
try
@@ -477,6 +596,7 @@
throw new DeploymentException( error, e );
}
}
+ */
//private DisposalService makeDisposalService() throws DeploymentException
//{
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org