link
Avalon
Avalon Central
Home PlanetProductsCentral
Lifecycle Tools Example
Creating 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 your 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 either 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 definition of your extension handler you need to prepare the meta-info that will be used by Merlin to identify the extension and the stage interface it 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 your 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 type="Exploitable"/>
   </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 it requires a handler for. The following <type/> declaration includes a <stage/> tag that contains a <reference/> element that includes a 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 type="Exploitable"/>
   </stages>

</type>

Execution

To execute the example you simply need to include a reference to your 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.


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