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
interface SampleEventGroup { void finished(String message); } class myListener implements SampleEventGroup { public void finished(String message) { // This will be called when we 'finish'. } }
InitialContext ic = ...; EventSource es = (EventSource)ic.lookup("java:comp/websphere/ApplicationNotificationService"); myListener l = new myListener(); es.addListener(l);
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");