Skip to main content

developing lifecycle module(urgent pls )

3 replies [Last post]
alishacse
Offline
Joined: 2010-06-07
Points: 0

Hello.
I am trying to develop a test lifecycle module for glassfish.

In glassfish's domain.xml file the lifecycle module is configured as

...and the module

import com.sun.appserv.server.*;
public class test
{
public void handleEvent(LifecycleEvent event) throws ServerLifecycleException
{
LifecycleEventContext context = event.getLifecycleEventContext();

context.log("got event" + event.getEventType() + " event data: "
+ event.getData());

Properties props;

if (LifecycleEvent.INIT_EVENT == event.getEventType()) {
context.log("LifecycleListener: INIT_EVENT");

props = (Properties) event.getData();

// handle INIT_EVENT
return;
}

if (LifecycleEvent.STARTUP_EVENT == event.getEventType()) {
context.log("LifecycleListener: STARTUP_EVENT");

// handle STARTUP_EVENT
return;
}

if (LifecycleEvent.READY_EVENT == event.getEventType()) {

context.log("LifecycleListener: READY_EVENT");

// handle READY_EVENT
return;
}

if (LifecycleEvent.SHUTDOWN_EVENT== event.getEventType()) {
context.log("LifecycleListener: SHUTDOWN_EVENT");

// handle SHUTDOWN_EVENT
return;
}

if (LifecycleEvent.TERMINATION_EVENT == event.getEventType()) {
context.log("LifecycleListener: TERMINATE_EVENT");

// handle TERMINATION_EVENT
return;
}
}
}

above module is not writing msgs to server log file . If i am using standard module in com.sun.appserver.LifecycleListenerImpl then it start writing msgs to log,pls tell me what might be the problem as early as possible

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alishacse
Offline
Joined: 2010-06-07
Points: 0

If i am creating a life cycle module using following command then it is working then why above code is not working???

create-lifecycle-module --user admin --classname "com.sun.appserv.server.LifecycleListenerImpl" --loadorder 1 --failurefatal=true --description "this is a sample test" alisha1

Message was edited by: alishacse

hzhang_jn
Offline
Joined: 2005-07-22
Points: 0

Your lifecycle module class needs to implement the LifecycleListener interface for its methods to be called by the server at various points.

http://docs.sun.com/app/docs/doc/820-7695/beame?l=en&a=view

alishacse
Offline
Joined: 2010-06-07
Points: 0

hello hzhang_jn ,thank you very much, problem was solved by below code:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author alisha
*/
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 test_class implements LifecycleListener {
/* * receive a server lifecycle event
* @param event associated event
* @throws ServerLifecycleException for exception condition.
*
*/
public void handleEvent(LifecycleEvent event) throws ServerLifecycleException
{

LifecycleEventContext ctx=event.getLifecycleEventContext();

ctx.log("got event" + event.getEventType() + "event data:" +
event.getData());

Properties props;

if (LifecycleEvent.INIT_EVENT == event.getEventType()) {
System.out.println("LifecycleListener: INIT_EVENT");
ctx.log("LifecycleListener: INIT_EVENTalisha");
props = (Properties) event.getData();

//handle INIT_EVENT
return;
}

if (LifecycleEvent.STARTUP_EVENT == event.getEventType()) {
ctx.log("LifecycleListener: START_EVENTalisha");
System.out.println("LifecycleListener: START_EVENT");
//handle STARTUP_EVENT
return;
}
if (LifecycleEvent.READY_EVENT == event.getEventType()) {
ctx.log("LifecycleListener: READy_EVENTalisha");
System.out.println("LifecycleListener: READY_EVENT");
//handle READY_EVENT
return;
}

if (LifecycleEvent.SHUTDOWN_EVENT == event.getEventType()) {
ctx.log("LifecycleListener: SHUTDOWN_EVENTalisha");
System.out.println("LifecycleListener: SHUTDOWN_EVENT");
//handle SHUTDOWN_EVENT
return;
} if (LifecycleEvent.TERMINATION_EVENT == event.getEventType()) {
ctx.log("LifecycleListener: TERMINATE_EVENTalisha");
System.out.println("LifecycleListener: TERMINATION_EVENT");
//handle TERMINATION_EVENT
return;
}
}
}