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:
- Create a class which implements the ApplicationListener interface
- 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:
- Switch to „Java“ perspective
- Create a new folder „META-INF“ in the „Code/Java“ section
- Create a sub folder „services„
- Create a file named „com.ibm.xsp.core.events.ApplicationListener„
- 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.]
Pingback: XPages application events: Create your own ApplicationListener (2) | blog@hasselba.ch