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