WebSphere Application Server - Express, Version 6.0.x     Operating Systems: AIX, HP-UX, Linux, Solaris, Windows

Developing event listeners

Why and when to perform this task

Application components that listen for events can use the EventSource.addListener() method to register an event listener object (a type of asynchronous bean) with the event source to which the events will be published. An event source also can fire events in a type-safe manner using any interface.

Notifications between components within a single EAR file are handled by a special event source. See the topic, Using the application notification service.

Steps for this task

  1. Create an event listener object, which can be any type. For example, see the following interface code:
    interface SampleEventGroup
    {
    
    void finished(String message);
    }
    
    class myListener implements SampleEventGroup
    {
    
    public void finished(String message)
    
    {
    
    // This will be called when we 'finish'.
    
    }
    }
    
  2. Register the event listener object with the event source. For example, see the following code:
    InitialContext ic = ...;
    EventSource es = (EventSource)ic.lookup("java:comp/websphere/ApplicationNotificationService");
    myListener l = new myListener();
    es.addListener(l);
    
    This enables the myListener.finished() method to be called whenever the event is fired. The following code example shows how this event might be fired:
    InitialContext ic = ...;
    EventSource es = (EventSource)ic.lookup("java:comp/websphere/ApplicationNotificationService");
    myListener proxy = es.getEventTrigger(myListener.class);
    // fire the 'event' by calling the method 
    // representing the event on the proxy
    proxy.finished("done");
    



Sub-topics
Using the application notification service
Example: Event listener

Related tasks
Using asynchronous beans

Task topic    

Terms of Use | Feedback

Last updated: Jun 8, 2005 12:45:23 PM EDT
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/asyncbns/tasks/tasb_notifications.html

© Copyright IBM Corporation 2004, 2005. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)