2010/12/15 - Apache Excalibur has been retired.

For more information, please explore the Attic.

Outdated content

Merlin no longer uses the excalibur-lifecycle package.

Example

Create your lifestyle stage interface

The following interface is your domain specific lifecycle stage interface. It is the interface that an extension handler will use to interact with your component during deployment and decommissioning.

 public interface Exploitable
 {
    /**
     * Operation invoked by an exploitation manager.
     * @param message a message to be displayed
     */
     void exploit( String message );
 }
                

Create the lifestyle extension handler

An extension handler is the implementation class that will be activated by the Merlin container to handle domain specific tasks during the deployment and decommissioning phases. The extension can implement etier or both of the Creator and Accessor interfaces depeding on the particular extension requirements. IN this example we are defining a simple creation stage handler that supplies a message to an instance of Exploitable.

 public class ExploitationManager implements Creator
 {
    /**
     * Operation invoked by a container to request creation
     * stage extension interception.
     * @param object a component to manager
     * @param context the context
     */
     public void create( Object object, Context context )
     {
         if( object instanceof Exploitable )
         {
             ((Expoitable)object).exploit( "hello" );
         }
     }

    /**
     * Operation invoked by a container to request destroy
     * stage extension interception.
     * @param object a component to manager
     * @param context the context
     */
     public void destroy( Object object, Context context )
     {
     }
 }
                

To complete the defintion of you extension handler you need to prepare the meta-info that will be used by Merlin to identify the extension and the stage interface is supports. The following <type/> declaration includes an <extensions/> tag that contains a <reference/> element that includes the reference to the Exploitable lifecycle stage interface. This is the key that Merlin uses to associate a handler with a component. If you extension class requires any specific context values, they should be declared in a context element within the extension element.

                    <type>

                    <info>
                    <name>my-extension-handler</name>
                    </info>

                    <extensions>
                    <extension>
                    <name>exploitation</name>
                    <reference type="Exploitable" version="1.0"/>
                    </extension>
                    </extensions>

                    </type>

                

Create a component implementing the stage interface

 public class MyComponent extends AbstractLogEnabled implements Exploitable
 {
    /**
     * Operation invoked by an exploitation manager.
     * @param message a message to be displayed
     */
     public void exploit( String message )
     {
         getLogger().info( message );
     }
 }
                

To complete the defintion of your component you need to prepare the meta-info that will be used by Merlin to identify the stage interface is requires a handler for. The following <type/> declaration includes an <stage/> tag that contains a <reference/> element that includes the reference to the Exploitable lifecycle stage interface. This is the key that Merlin uses to associate the component with a handler capable of handling the Exploitable interface.

                    <type>

                    <info>
                    <name>my-component</name>
                    </info>

                    <stages>
                    <stage>
                    <name>exploit-me</name>
                    <reference type="Exploitable" version="1.0"/>
                    </stage>
                    </stages>

                    </type>

                

Register you component and the extension

To complete the process you need to declare your handler and component in a jar manifest file. The following entries show the declaration of the component and the extension handler.

  Manifest-Version: 1.0
  Created-By: Ant 1.5

  Name: MyComponent.class
  Avalon: Type

  Name: ExploitationManager.class
  Avalon: Type
                

Execute the example

To execute the example you simply need to include a reference to you component within a Merlin container declaration. The following XML source declares a Merlin kernel, container, and component. You don't need to include the handler because Merlin can sort that out itself based on the information supplied in the meta-info declarations.

                    <kernel>

                    <container name="my-container>

                    <classpath>
                    <fileset dir="lib">
                    <include name="my-domo.jar"/>
                    </fileset>
                    </classpath>

                    <component name="demo" class="MyComponent" activation="startup"/>

                    <container>

                    </kernel>