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");
    

Related tasks
Using asynchronous beans
Related reference
Example: Event listener



Searchable topic ID:   tasb_notifications
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/asyncbns/tasks/tasb_notifications.html

Library | Support | Terms of Use | Feedback