![]() |
|
To create and use such hooks, the developer must do the following:
com.pramati.services.j2ee.spi.ApplicationStateListener interface.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>
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();
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.
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>
| © Pramati Technologies 2007 | Runs on Pramati Server | Feedback | Legal |