DevPortal

How do I Specify and Configure Application Hooks?


Table of Contents


How do I Specify Server Application Hooks?

The application developer might want to perform certain tasks on the different events in an application's lifecycle like start, stop, prepare, and remove. Pramati Server provides a way to configure multiple hooks for each application. The appropriate hook is invoked when the application is deployed, started, prepared, or stopped.

To create and use such hooks, the developer must do the following:

  1. Provide an implementation for the methods in the com.pramati.services.j2ee.spi.ApplicationStateListener interface.
  2. Register the implementation class with the Server by specifying it in the deploy-config.xml, located in the <install_dir>/server/nodes/<node_name>/config directory. For example:

    <application-hooks>
    <application-hook app-name="a.ear" async="true" class-name="com.pramati.test.AppHookTwo"/>
    <application-hooks>
    
  3. Place the implemented class in the application archive.
  4. Restart the Server.

What is the ApplicationStateListener Interface?

The Server provides an application state listener (hook) interface, found under com.pramati.services.j2ee.spi package. Methods available are shown in the table below. The implementation class of the ApplicationStateListener interface should be listed in the deploy-config.xml that is picked up by the Pramati Extension Classloader.

The following methods are available with the StartupHook interface:

/**
     *This method is called just prior to starting the
     *application. This method can use the application
     *classes because the method is called in the context of
     *the application classloader/
    public void applicationPreStart();

    /**
     * This method is called after the application has started successfully
     */
    public void applicationStarted();

    /**
     * This method is called just prior to stopping the application
     */
    public void applicationPreStop();

    /**
     * This method is called after the application has stopped.
     */
    public void applicationStopped();

    /**
     * This method is called after the application
     * has been prepared successfully.
     */
    public void applicationPrepared();

    /**
     * This method is called after the application
     * has been removed, i.e., undeployed.
     */
    public void applicationRemoved();

Sample Implementation

public class SampleApplicationHook
 implements com.pramati.services.j2ee.spi.ApplicationStateListener
{
  public void applicationStarted()
  {System.out.println(" Application Started.");}

  public void applicationStopped()
  {System.out.println(" Application Stopped.");}

  public void applicationPrepared()
  {System.out.println(" Application Prepared.");}

  public void applicationRemoved()
  {System.out.println(" Application Removed");}

  public void applicationPreStart()
  {System.out.println("Before application start");}

  public void applicationPreStop()
  {System.out.println("Before application stop");}
}

Note: To compile application hooks, make sure you have pramati_spi.jar in your classpath. This can be found in the <install_dir>/server/lib/pramati directory.

How do I Configure Application Hooks?

To configure an application hook, make the following entry in deploy-config.xml under the tag:
<deploy-config>
  <application-hooks>
    <application-hook app-name="applicationName" async="true" class-name="SampleHook"/>
  <application-hooks>
<deploy-config>
Here, app-name defines the application for which the hook or listener is to be registered. The async attribute specifies whether or not to start the hook method in a separate thread. Setting the value of the async attribute to true invokes the hook methods in a separate thread.

You can also have multiple hooks for each application. For example:

<application-hooks>
  <application-hook app-name="a.ear" async="true" class-name="com.pramati.test.AppHookTwo"/>
  <application-hook app-name="b.ear" async="true" class-name="com.pramati.test.AppHookOne"/>
<application-hooks>

Related Topics:

© Pramati Technologies 2007 Runs on Pramati Server | Feedback | Legal