Use the application notification service
During the application lifetime, individual J2EE components (servlets or enterprise beans) within a single EAR file might need to signal each other. There is an event source in the java:comp namespace that is bound into all components within an EAR file that can be used for notification.
Overview
The JNDI name for this event source, in the java:comp namespace that is bound into all components within an EAR file, is:java:comp/websphere/ApplicationNotificationServiceComponents within the same application can fire asynchronous events and register event listeners using this application notification service. Startup beans can be used to register these event listeners at application startup or they can be registered dynamically at run time.
Procedure
To have your enterprise bean or servlet use the application notification service, write code similar to the following example:InitialContext ic = new InitialContext(); EventSource appES = (EventSource) ic.lookup("java:comp/websphere/ApplicationNotificationService"); // now, the application can add a listener using the EventSource.addListener method. // MyEventType is an interface. MyEventType myListener = ...; AppES.addListener(myListener); // later another component can fire events as follows InitialContext ic = new InitialContext(); EventSource appES = (EventSource) ic.lookup("java:comp/websphere/ApplicationNotificationService"); // This highlights a constant string on the EventSource interface which // specifies the 'java:comp/websphere/ApplicationNotificationService' string. ic.lookup(appES.APPLICATION_NOTIFICATION_EVENT_SOURCE) // now, the application can add a listener using the EventSource.addListener method. MyEventType proxy = appES.getEventTrigger(MyEventType.class, false); proxy.someEvent(someArguments);
Example
Developing event listeners