5 Dec, 2006

What is ServiceLifeCycle and How to Use it?

  • Deepal Jayasingha
  • - WSO2

Do not confuse service life cycle with session management. A session itself has its own life cycle but the service life cycle is different from that.

Session management is something to do with context like OperationContext , ServiceContext etc (You can learn more about session manegment here). However, service life cycle is something to do with AxisService. There will be different number of instances of the above contexts depending on the session scope, but there will be only one instance of AxisService for a particular a service.

To have service life cycle management support you need to implement org.apache.axis2.engine.ServiceLifeCycle interface. And need to specify the implementation class name in the services.xml.

The above interface has only two methods. One will be called at the service deployment time, while other will be called at the system shutdown time.

package org.apache.myservice;

public class MyServiceLifeCycle implements ServiceLifeCycle {

public void startUp(ConfigurationContext configctx, AxisService service) {
// Open up the DB connection
// Store the connection as a parameter in AxisService

public void shutDown(ConfigurationContext configctx, AxisService service){
// retrieve the parameter from AxisService and close the connection.

In the above case your services.xml is as follows;

<service name="MyService"
class="org.apache.myservice.MyServiceLifeCycle" >
<!--Rest of the elements goes here-->

Applies To:

Apache Axis2/Java 1.1 or later


About Author

  • Deepal Jayasingha
  • WSO2 Inc.