The following example shows a portion of the server.xml that defines a lifecycle listener.
<lifecycle-module> <class-name>com.sun.ias.server.LifecycleListenerImpl</class-name> <is-failure-fatal>false</is-failure-fatal> <description>Sample lifecycle module</description> <property> <name>foo</name> <value>fooval</value> <property> </lifecycle-module>
The following example shows a sample LifecycleListener implementation
/** *PROPERITARY/CONFIDENTIAL. Use of this product is subject to license terms * *Copyright 2006-2007 by SunMicrosystems, Inc., *4150 Network Circle, Santa Clara, California, 95054, U.S.A *All rights reserved. package com.sun.ias.server; import java.util.Properties; import java.util.logging.Level; import com.sun.appserv.server.LifecycleEventContext; import com.sun.appserv.server.ServerLifecycleException; import com.sun.appserv.server.LifecycleEvent; import com.sun.appserv.server.LifecycleListener; /** * LifecycleListenerImpl is a dummy implementation for the LifecycleListener * interface. * This implementation stubs out various lifecycle interface methods. */ public class LifecycleListenerImpl implements LifecycleListener { /** receive a server lifecycle event * @param event associated event * @throws <code>ServerLifecycleException</code> for exception condition. * * / public void handleEvent(LifecycleEvent event) throws ServerLifecycleException { LifecycleEventContex ctx=event.getLifecycleEventContext(); ctx.log(level.INFO, "got event" + event.getEventType() + "event data:" + event.getData()); Properties props; if (Lifecycleevent.INIT_EVENT == event.getEventType()) { System.out.println("LifecycleListener: INIT_EVENT"); props = (Properties) event.getData(); //handle INIT_EVENT return; } if (LifecycleEvent.STARTUP_EVENT == event.getEventType()) { System.out.println("LifecycleListener: START_EVENT"); //handle STARTUP_EVENT return; } if (LifecycleEvent.READY_EVENT == event.getEventType()) { System.out.println("LifecycleListener: READY_EVENT"); //handle READY_EVENT return; } if (LifecycleEvent.SHUTDOWN_EVENT == event.getEventType()) { System.out.println("LifecycleListener: SHUTDOWN_EVENT"); //handle SHUTDOWN_EVENT return; } if (LifecycleEven.TERMINATION_EVENT == event.getEventType()) { System.out.println("LifecycleListener: TERMINATION_EVENT"); //handle TERMINATION_EVENT return; } } }