How Can I Get Notified When There are Changes to Contexts?

The information model within Axis2 contains a hierarchy of contexts. These contexts contain information about various levels within Axis2. Sometimes it is important to know when these contexts are created and removed. In this knowledge base item, we will discuss how we can get notified when new context is created and deleted.

Date: Sun, 30th Nov, 2008
Level: Introductory
Reads: 1197 Comments: 0 | Login or register to post comments
Eran Chinthaka
Software Engineer
WSO2 Inc.
chinthaka's picture

Configuration Context, the parent of all the contexts within Axis2, acts as the central point for the operation of the Axis2 engine. Whenever there is a creation or deletion of a message context, service context or service group context, the configuration context will be notified about this creation or deletion. We can register a listener with the configuration context, so that we can also be notified about these changes within Axis2. This is very handy if you are implementing a monitoring service or a management functionality on top of Axis2.

Let's see how we can do this.

Step 1 : Implement org.apache.axis2.context.ContextListener interface

public interface ContextListener {

    /**
     * A context has been added
     *
     * @param context
     */
    void contextCreated(AbstractContext context);

    /**
     * A context has been removed
     *
     * @param context
     */
    void contextRemoved(AbstractContext context);
}

First implement the org.apache.axis2.context.ContextListener interface. This interface contains two methods to be notified during a context creation and context deletion. You will get the created or removed context as an input to this method, so that you can extract the relevant information or perform some operation on top of them.

Step 2 : Register the implementation of ContextListener

Then you need to register your implementation of ContextListener interface with the configuration context, using the provided

public void addContextListener(ContextListener contextListener)

method.

 

ContextListener listener = new MyContextListener();

// get access to the configuration context. 
ConfigurationContext configContext = MessageContext.getCurrentMessageContext().getConfigurationContext();

configContext.addContextListener(listener);

Now whenever there is a creation or deletion of a context, the configuration context will notify your context listener.

 

Applies To

1. Apache Axis2

 

More Information

 

  • More information about various contexts can be found here.

 

 

library project main code
Learn Cloud
Learn
Cloud

The WSO2 Application Server is a reliable application server that can host your enterprise web applications. The WSO2 Application Server as a Service is offered in StratosLive, the WSO2 Platform as a Service. This article explains how a simple web application can be developed and deployed from Carbon Studio to the WSO2 Application Server...

Latest Webinar
KeellsSuper is a leading supermarket chain with 50-plus outlets in Sri Lanka, and it offers the only online supermarket in the country. In 2005, JKH implemented SAP ERP across it’s 70 subsidiaries...
Thursday, February 16th 2012, 09.00 AM (PST)

Thursday, February 16th 2012, 10.00 AM (GMT)