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 2002/11/29 14:19:10 UTC
cvs commit: avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle package.html DeploymentService.java DeploymentException.java DefaultDeploymentService.java
mcconnell 2002/11/29 05:19:10
Added: assembly/src/java/org/apache/avalon/assembly/lifecycle
package.html DeploymentService.java
DeploymentException.java
DefaultDeploymentService.java
Log:
Seperation of deployment functionality (encapsulates lifecycle processing)
Revision Changes Path
1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/package.html
Index: package.html
===================================================================
<body>
<p>
The <code>lifecycle</code> package includes interfaces and classes supporting the lifecycle processing of a component. These stages include:
</p>
<ul>
<li>logging - including the establishment of a set of qualified logging channels for a component</li>
<li>cotext - component contextulization including support for derived context types</li>
<li>configuration - component configuration</li>
<li>parameterization - support for assignment of component parameters</li>
<li>composition - application of a service or component manager to a component</li>
<li>initialization - support for classic and extension based initialization</li>
<li>startup - support for start and stop operations o a component</li>
<li>disposal - support for component disposal</li>
</ul>
<p>
The above services are aggregated together under a single deployment service which provides general support for component deployment and decommissioning.
</p>
</body>
1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/DeploymentService.java
Index: DeploymentService.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.assembly.lifecycle;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.assembly.appliance.Appliance;
/**
* A deployment service is responsible for the deployment of a component
* in response to a request from a lifestyle manager.
*
* @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2002/11/29 13:19:09 $
*/
public interface DeploymentService
{
/**
* Deploy an appliance based on a supplied classloader, logging channel and
* containment context.
* @param classloader the classloader to use
* @param appliance the appliance to deploy
* @param logger the logging channel to assign to the component
* @param context the containment context
* @return the deployed component
*/
Object deploy( Appliance appliance, ClassLoader classloader, Logger logger, Context context )
throws DeploymentException;
/**
* Destroy an appliance.
* @param object the object to decommission
*/
void decommission( Appliance appliance, Object object );
}
1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/DeploymentException.java
Index: DeploymentException.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.assembly.lifecycle;
import org.apache.avalon.framework.CascadingException;
/**
* Exception to indicate that there was a lifecycle related error.
*
* @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2002/11/29 13:19:09 $
*/
public class DeploymentException
extends CascadingException
{
/**
* Construct a new <code>DeploymentException</code> instance.
*
* @param message The detail message for this exception.
*/
public DeploymentException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>DeploymentException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public DeploymentException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/DefaultDeploymentService.java
Index: DefaultDeploymentService.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.assembly.lifecycle;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.assembly.appliance.Appliance;
import org.apache.avalon.assembly.lifecycle.logging.LoggingService;
import org.apache.avalon.assembly.lifecycle.logging.DefaultLoggingService;
import org.apache.avalon.assembly.lifecycle.configuration.ConfigurationService;
import org.apache.avalon.assembly.lifecycle.configuration.DefaultConfigurationService;
import org.apache.avalon.assembly.lifecycle.parameters.ParameterizationService;
import org.apache.avalon.assembly.lifecycle.parameters.DefaultParameterizationService;
import org.apache.avalon.assembly.lifecycle.context.ContextualizationService;
import org.apache.avalon.assembly.lifecycle.context.DefaultContextualizationService;
import org.apache.avalon.assembly.lifecycle.composition.CompositionService;
import org.apache.avalon.assembly.lifecycle.composition.DefaultCompositionService;
import org.apache.avalon.assembly.lifecycle.initialization.InitializationService;
import org.apache.avalon.assembly.lifecycle.initialization.ExtendedInitializationService;
import org.apache.avalon.assembly.lifecycle.initialization.DefaultInitializationService;
import org.apache.avalon.assembly.lifecycle.startup.StartupService;
import org.apache.avalon.assembly.lifecycle.startup.DefaultStartupService;
import org.apache.avalon.assembly.lifecycle.disposal.DisposalService;
import org.apache.avalon.assembly.lifecycle.disposal.DefaultDisposalService;
import org.apache.avalon.assembly.lifecycle.disposal.ExtendedDisposalService;
/**
* A deployment service is responsible for the deployment of a component
* in response to a request from a lifestyle manager.
*
* @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2002/11/29 13:19:09 $
*/
public class DefaultDeploymentService extends AbstractLogEnabled implements Configurable, Serviceable, Contextualizable, Initializable, DeploymentService
{
//==============================================================
// state
//==============================================================
private Context m_context;
private ServiceManager m_manager;
private LoggingService m_logging;
private ConfigurationService m_configuration;
private ContextualizationService m_contextualization;
private ParameterizationService m_parameters;
private CompositionService m_composition;
private InitializationService m_initialization;
private StartupService m_startup;
private DisposalService m_disposal;
private boolean m_initialized = false;
private boolean m_extensionEnabled = true;
//==============================================================
// Configurable
//==============================================================
/**
* Supply of the static configuration for the deployment service.
* @param config the static configuration
*/
public void configure( Configuration config ) throws ConfigurationException
{
if( config == null )
{
throw new NullPointerException( "config" );
}
m_extensionEnabled =
config.getChild("extensions").getAttributeAsBoolean( "enabled", true );
}
//==============================================================
// Contextualizable
//==============================================================
/**
* <p>Application of a runtime context to the lifestyle service.
* The context value will be passed directly to lifestyle handlers
* established by this service.
* @param context the runtime context
*/
public void contextualize( Context context ) throws ContextException
{
if( context == null )
{
throw new NullPointerException( "context" );
}
m_context = context;
}
//==============================================================
// Serviceable
//==============================================================
/**
* <p>Application of a supporting service to the deployment service.</p>
* <table>
* <tr>
* <td>key</td><td>type</td><td>description</td>
* </tr>
* <tr>
* <td>assembly:lifecycle.logging</td>
* <td>{@link org.apache.avalon.assembly.logging.LoggingService}</td>
* <td>The logging service to use for the creation of auxiliary logging channels.</td>
* </tr>
* </table>
* @param context the runtime context
*/
public void service( ServiceManager manager ) throws ServiceException
{
if( manager == null )
{
throw new NullPointerException( "manager" );
}
m_manager = manager;
String key = "assembly:lifecycle.logging";
if( manager.hasService( key ) )
{
m_logging = (LoggingService) manager.lookup( key );
}
key = "assembly:lifecycle.configuration";
if( manager.hasService( key ) )
{
m_configuration = (ConfigurationService) manager.lookup( key );
}
key = "assembly:lifecycle.parameters";
if( manager.hasService( key ) )
{
m_parameters = (ParameterizationService) manager.lookup( key );
}
key = "assembly:lifecycle.context";
if( manager.hasService( key ) )
{
m_contextualization = (ContextualizationService) manager.lookup( key );
}
key = "assembly:lifecycle.assembly";
if( manager.hasService( key ) )
{
m_composition = (CompositionService) manager.lookup( key );
}
key = "assembly:lifecycle.initialization";
if( manager.hasService( key ) )
{
m_initialization = (InitializationService) manager.lookup( key );
}
key = "assembly:lifecycle.startup";
if( manager.hasService( key ) )
{
m_startup = (StartupService) manager.lookup( key );
}
key = "assembly:lifecycle.disposal";
if( manager.hasService( key ) )
{
m_disposal = (DisposalService) manager.lookup( key );
}
}
//==============================================================
// Initializable
//==============================================================
public void initialize() throws Exception
{
if( m_context == null )
{
throw new IllegalStateException("context");
}
if( m_manager == null )
{
throw new IllegalStateException("service");
}
if( m_logging == null )
{
m_logging = makeLoggingService();
}
if( m_configuration == null )
{
m_configuration = makeConfigurationService();
}
if( m_parameters == null )
{
m_parameters = makeParameterizationService();
}
if( m_contextualization == null )
{
m_contextualization = makeContextualizationService();
}
if( m_composition == null )
{
m_composition = makeCompositionService();
}
if( m_initialization == null )
{
m_initialization = makeInitializationService();
}
if( m_startup == null )
{
m_startup = makeStartupService();
}
if( m_disposal == null )
{
m_disposal = makeDisposalService();
}
m_initialized = true;
}
//==============================================================
// DeploymentService
//==============================================================
/**
* Deploy an appliance based ona supplied classloader, logging channel and
* containment context.
* @param classloader the classloader to use
* @param appliance the appliance to deploy
* @param logger the base logging channel to assign to the component
* @param context the containment context
* @return the deployed component
*/
public Object deploy( Appliance appliance, ClassLoader classloader, Logger logger, Context context )
throws DeploymentException
{
if( !m_initialized )
{
throw new IllegalStateException( "initialization" );
}
if( appliance == null )
{
throw new NullPointerException( "appliance" );
}
if( classloader == null )
{
throw new NullPointerException( "classloader" );
}
if( logger == null )
{
throw new NullPointerException( "logger" );
}
if( context == null )
{
throw new NullPointerException( "context" );
}
Object instance;
try
{
String classname = appliance.getProfile().getType().getInfo().getClassname();
Class clazz = classloader.loadClass( classname );
instance = clazz.newInstance();
}
catch( Throwable e )
{
final String error =
"Component implementation establishment error in appliance: "
+ appliance;
throw new DeploymentException( error, e );
}
// invoke lifecycle processing on the instance
try
{
m_logging.enableLogging( appliance, instance, logger);
m_configuration.configure( appliance, instance );
m_parameters.parameterize( appliance, instance );
m_contextualization.contextualize( appliance, instance, context );
if( instance instanceof Serviceable )
{
m_composition.service( appliance, instance );
}
else if( instance instanceof Composable )
{
m_composition.compose( appliance, instance );
}
m_initialization.initialize( appliance, instance );
m_startup.start( appliance, instance );
return instance;
}
catch( Throwable e )
{
final String error =
"Component deployment failure in appliance: "
+ appliance;
throw new DeploymentException( error, e );
}
}
/**
* Destroy an appliance.
* @param appliance the appliance to destroy
*/
public void decommission( Appliance appliance, Object instance )
{
try
{
m_startup.stop( appliance, instance );
}
catch( Throwable e )
{
// log a warning
}
m_disposal.dispose( appliance, instance );
}
private LoggingService makeLoggingService() throws DeploymentException
{
try
{
DefaultLoggingService service = new DefaultLoggingService();
service.enableLogging( getLogger().getChildLogger( "logging" ) );
return service;
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to build the bootstrap logging service.";
throw new DeploymentException( error, e );
}
}
private ConfigurationService makeConfigurationService() throws DeploymentException
{
try
{
DefaultConfigurationService service = new DefaultConfigurationService();
service.enableLogging( getLogger().getChildLogger( "config" ) );
return service;
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to build the bootstrap configuration service.";
throw new DeploymentException( error, e );
}
}
private ParameterizationService makeParameterizationService() throws DeploymentException
{
try
{
DefaultParameterizationService service = new DefaultParameterizationService();
service.enableLogging( getLogger().getChildLogger( "params" ) );
return service;
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to build the bootstrap parameterization service.";
throw new DeploymentException( error, e );
}
}
private ContextualizationService makeContextualizationService() throws DeploymentException
{
try
{
DefaultContextualizationService service = new DefaultContextualizationService();
service.enableLogging( getLogger().getChildLogger( "context" ) );
service.contextualize( m_context );
return service;
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to build the bootstrap contextualization service.";
throw new DeploymentException( error, e );
}
}
private CompositionService makeCompositionService() throws DeploymentException
{
try
{
DefaultCompositionService service = new DefaultCompositionService();
service.enableLogging( getLogger().getChildLogger( "composer" ) );
return service;
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to build the bootstrap assembly service.";
throw new DeploymentException( error, e );
}
}
private InitializationService makeInitializationService() throws DeploymentException
{
try
{
if( m_extensionEnabled )
{
ExtendedInitializationService service = new ExtendedInitializationService();
service.enableLogging( getLogger().getChildLogger( "init" ) );
service.contextualize( m_context );
return service;
}
else
{
DefaultInitializationService service = new DefaultInitializationService();
service.enableLogging( getLogger().getChildLogger( "init" ) );
return service;
}
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to build the bootstrap initialization service.";
throw new DeploymentException( error, e );
}
}
private StartupService makeStartupService() throws DeploymentException
{
try
{
DefaultStartupService service = new DefaultStartupService();
service.enableLogging( getLogger().getChildLogger( "startup" ) );
return service;
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to build the bootstrap startup service.";
throw new DeploymentException( error, e );
}
}
private DisposalService makeDisposalService() throws DeploymentException
{
try
{
if( m_extensionEnabled )
{
ExtendedDisposalService service = new ExtendedDisposalService();
service.enableLogging( getLogger().getChildLogger( "disposal" ) );
service.contextualize( m_context );
return service;
}
else
{
DefaultDisposalService service = new DefaultDisposalService();
service.enableLogging( getLogger().getChildLogger( "disposal" ) );
return service;
}
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to build the bootstrap disposal service.";
throw new DeploymentException( error, e );
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>