XPages application events: Create your own ApplicationListener

If you want to get a handle to application events and want to know if a XPages application is created or destroyed (which means the application was destroyed because of a time out), you can implement this by creating your own own application listener.

For this you have to do the following steps:

  1. Create a class which implements the ApplicationListener interface
  2. Activate the class in XPages runtime

To realise the first part, you have to create a class that implements the interface com.ibm.xsp.application.events.ApplicationListener. This interface has two methods: applicationCreated and applicationDestroyed (the method names should be self-describing enough).

Here is an example:

package ch.hasselba.jsf.debug;

import com.ibm.xsp.application.ApplicationEx;
import com.ibm.xsp.application.events.ApplicationListener;

public class MyApplicationListener implements ApplicationListener {

    public void applicationCreated(ApplicationEx arg0) {
        System.out.println("applicationCreated()");
        System.out.println("ID: " + arg0.getApplicationId());
    }

    public void applicationDestroyed(ApplicationEx arg0) {
        System.out.println("applicationDestroyed()");
        System.out.println("ID: " + arg0.getApplicationId());  
    }

}

Now to step two, the activation of the class. To do this, you have to add a special configuration file to your application:

  1. Switch to „Java“ perspective
  2. Create a new folder „META-INF“ in the „Code/Java“ section
  3. Create a sub folder „services
  4. Create a file named „com.ibm.xsp.core.events.ApplicationListener
  5. In this file you add the full name of your MyApplicationListener class (including the package name):

The file structure should now look like this in Java perspective:

If you switch back to Domino perspective, the structure in the „Code/Java“ looks like this:

You can now verify that all works correctly by opening a XPage and have a look on your server console:

[The application timeout was set to one minute.]

Dieser Beitrag wurde unter Extensibility API, Java, JSF, XPages abgelegt und mit , , , , , , verschlagwortet. Setze ein Lesezeichen auf den Permalink.

Ein Kommentar zu XPages application events: Create your own ApplicationListener

  1. Pingback: XPages application events: Create your own ApplicationListener (2) | blog@hasselba.ch

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.


*