سؤال

We have a Java EE application running on Glassfish 3.1 that needs to accept notifications from a legacy system written in Java. This legacy system provides a JAR file that should be used by any external applications wishing to subscribe to the system's notifications.

When used in a Java SE application, the library works like this:

  1. The library is initialized with connection parameters to the legacy system
  2. The library connects to the system and listens for notifications
  3. Our application registers for notifications by implementing an interface
  4. Whenever a notification comes, a method in the implementing class is called

We would like to reproduce the same in Java EE in a way that an EJB method is called whenever a notification is sent by the system.

Is JCA the way to go? How about a singleton EJB initializing the library and registering itself as a listener?

Good examples about this topic are hard to find, so if you have any guidance, I'd be grateful.

هل كانت مفيدة؟

المحلول

Theoretically JCA would indeed be the dedicated API to use for this.

If the application is an EAR and the EJB classes live in a pure EJB module, there are quite some restrictions on what an EJB is allowed to do. JCA can do specifically those things that EJBs are not allowed to do (reflection, static fields, create threads, load native libraries, etc).

The downside is that JCA is a 'carefully' under-documented API, that's more intended to be used by vendors of such legacy systems as you describe than by 'ordinary' application programmers. If you want to go the JCA way, one source of information is perhaps the Quartz sourcecode, which contains an inbound JCA resource adapter for Quartz.

Directly registering the Singleton as a listener should be done carefully. The legacy library should get a reference to the proxy class of the Singleton, not the actual implementation (i.e. don't pass this to the legacy library).

Another option could be to provide a regular class that implements the required interface and registers with the legacy library. Upon receiving a notification it can look up a JMS connection factory and Queue from JNDI and then sends a JMS message to which a Message Driven Bean is listening.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top