Lifecycle Management Specification

Lifecycle management concerns the process of incarnation, runtime management, and etherialization. Incarnation is the sequence involving instantiation and possible application of a series of lifecycle stage processes (such as configuration, contextualization, etc.). Runtime management deals with the suspension, resumption of a component. Etherialization represents the process of component end-of-life processing possibly involving the application of multiple lifecycle phases (e.g. disposal).

Incarnation

Just as objects are instantiated, the equivalent process from a component is "incarnation". Incarnation involves instantiation, a series of optional artifact delivery stages, and an optional execution phase. Component incarnation is managed exclusively by a container. Occurances of component icarnation are controlled by as associated component implementation lifestyle characteristic.

Incarnation Stage Table

instantiation

A component may declare either a null constructor, or, a single constructor with any lifecycle artifact as a parameter argument where arguments may be in any combination or order. Recognized lifecycle artificats include Logger , Context , Parameters , ServiceManager , and/or Configuration . In addition, the Context object may be substituted with a custom context interface and implementation.

NOTE: A component implementation may not duplicate constructor injection of lifecycle artifacts with the equivalent lifecycle stage.

Example:

  /**
   * Creation of a new widget.
   *
   * @param logger a logging channel
   * @avalon.dependency type="tutorial.Gizmo" key="gizmo"
   */
   public DefaultWidget( Logger logger, ServiceManager manager ) 
     throws ServiceException
   {
       m_logger = logger;
       m_logger.info( "hello" );
       m_gizmo = (Gizmo) manager.lookup( "gizmo" );
   }

logging

Optional Logger delivery strategy. A component implementation may implement the LogEnabled interface. The container will supply the component root logger via the enableLogging operation.

Example:

    /**
     * Supply of a logging channel by the container to this 
     * component.
     *
     * @param logger the logging channel
     */
     public void enableLogging( Logger logger )
     {
         m_logger = logger;
     }

contextualization

Optional context delivery strategy. A component implementation may implement the Contextualizable interface. The container will supply a component context via the contextualize operation. The context instance will be pre-populated by the container will all requested entries.

Example:

    /**
     * Supply of a context object to the component.
     *
     * @param context the component context
     * @avalon.entry key="urn:avalon:home" type="java.io.File"
     * @exception ContextException if an error occurs during 
     *   context entry resolution
     */
     public void contextualize( Context context ) 
       throws ContextException
     {
         m_home = (File) context.get( "urn:avalon:home" );
     }

service

Optional service manager delivery strategy. A component implementation may implement the Serviceable interface. The container will supply a service manager supporting all declared service dependencies.

Example:

    /**
     * Supply of the service manager to the component from which 
     * dependent services may be accessed relative to a service key.
     *
     * @param manager the supplied service manager
     * @avalon.dependency type="tutorial.Gizmo" key="gizmo"
     * @avalon.dependency type="tutorial.Widget" key="widget"
     * @exception ServiceException if an error occurs during 
     *   service resolution
     */
     public void service( ServiceManager manager ) 
       throws ServiceException
     {
         m_gizmo = (Gizmo) manager.lookup( "gizmo" );
         m_widget = (Widget) manager.lookup( "widget" );
     }

Note: the usage of the key attribute on a service dependency tag is optional. If not supplied, an implementation my request the service using the type argument (i.e. the service classname). The recommended practice is to declare a local key.

configuration

Optional configuration delivery strategy. A component implementation may implement the Configurable interface. The container will supply a component configuration via the configure operation.

Example:

    /**
     * Supply of the component configuration by the container.
     *
     * @param config the component configuration
     * @exception ConfigurationException if an error occurs during 
     *   configuration handling
     */
     public void configure( Configuration config ) 
       throws ConfigurationException
     {
         Configuration location = config.getChild( "location" );
         m_address = location.getAttribute( "address" );
     }

parameterization

Optional parameters delivery strategy. A component may implement the Parameterizable interface. The container will supply a parameters instance via the parameterize operation.

Example:

    /**
     * Supply of parameters to the component by the container
     *
     * @param params the component parameters
     * @exception ParameterException if an error occurs during 
     *   parameter handling
     */
     public void parameterize( Parameters params ) 
       throws ParameterException
     {
         m_secure = params.getParameterAsBoolean( "secure" );
         m_count = params.getParameterAsInteger( "count" );
     }

custom stage

Optional custom lifecycle stage. A component may implement zero or more custom lifecycle stages. Stages will be applied to the component in the order of avalon.stage declarations.

Example:

/**
 * Component declaring a custom stage dependency.
 *
 * @avalon.component name="demo" lifestyle="singleton" version="1.0"
 * @avalon.stage id="urn:demo:demonstratable"
 */
public class HelloComponent extends AbstractLogEnabled 
  implements Demonstratable
{
    /**
     * A custom lifecycle stage implementation.
     *
     * @param message a message from the custom lifecycle 
     *    stage handler
     */
    public void demo( String message )
    {
        getLogger().info( "extension said: " + message );
    }
}

initialization

Optional initialization stage. A component may implement the Initializable interface. The container will invoke initialization following completion of the delivery of lifecycle artifacts and any custom lifecycle stages.

Example:

    /**
     * Initialization of the component by the container.
     *
     * @exception Exception if an error occurs during 
     *   the initialization phase
     */
     public void initialize() throws Exception
     {
         ...
     }

execution

Optional execution stage. A component may implement either the Startable or Executable interfaces. If the component implements Executable the execute method will be invoked before the component instance is exposed to any other component. If the component implements the Startable interface the container will invoke the start operation. An implementation is responsible for establishing a working thread and returned from the start operation promptly.

Executable Example:

    /**
     * Execute implementation.
     */
     public void execute()
     {
         ...
     }

Startable Example:

    /**
     * Start the component.
     */
     public void start() throws Exception
     {
         ...
     }

Runtime Management

Runtime management deals with interaction with a component between the incarnation and etherialization stages. The Avalon framework defines the notion of a suspendable component. The framework also defines a number of delivery interfaces dealing with reintroduction of lifecycle artificats. None of the framework reintroduction interfaces are supported - instead, runtime management is approached as a management concern wherein any existing artifact delivery interface may be reused by a container while a component is under a suspended state. The action of resumption is equivalent to the notion of re-initialization.

Runtime Stage Table

suspension

A component implementing the the Suspendable lifecycle may be suspended by a container management system. Following suspension a container may re-apply lifecycle artifact delivery stages (logging, contextualization, service, parameterization).

Suspendable Example:

    /**
     * Suspend the component.
     */
     public void suspend()
     {
         ...
     }

suspension

A component implementing the the Suspendable lifecycle may be placed back into operation following suspension by a container management system.

Suspendable Example:

    /**
     * Resume execution.
     */
     public void resume()
     {
         ...
     }

Etherialization

The etherialization stage is the component equivalent of an object finalization. Etherialization covers the stopping of a running component and subsequent disposal. Initiation of the etherialization phase on a component instance is exclusively controlled by it's container.

Etherialization Stage Table

execution

A component implementing the the Startable lifecycle interface will be shutdown by the container.

Startable Example:

    /**
     * Stop the component.
     */
     public void stop() throws Exception
     {
         ...
     }

disposal

A component may participate in end-of-life processing by implementing the Disposable lifecycle interface. An implementation will typically released references during this stage.

Example:

    /**
     * Disposal of the component.
     */
     public void dispose()
     {
         ...
     }