users@glassfish.java.net

Question on design: Servlet or LifecycleListener to implement a service?

From: <glassfish_at_javadesktop.org>
Date: Tue, 11 Sep 2007 15:13:38 PDT

I a service that needs to be implemented as part of a J2EE application that we are developing on Glassfish. This service interacts with devices in a network by communicating with them over UDP and receiving performance management data from these devices. It uses a proprietary message protocol based on RDP (Reliable Datagram Protocol). It is similar to TCP with windows, timers, etc. but is datagram based instead of stream based.

The service must retrieve a list of devices to communicate with at initialization and then it must be also possible to add, delete, and check the status of the connections at runtime via other interfaces.

In a previous life, this service was implemented as a Servlet that basically spawned of a new service thread and an I/O thread that received the UDP datagrams and then updated a database with the performance data. It use RMI by being an RMI server to allow other interfaces to add, remove, and check status of other devices to be monitored.

Now in our new application, I am looking for a good way to do this. I know that I can probably still do this with a Servlet but I also see that I can probably do this with a LifecycleListener. Either case is a little "out of the world" of the standard J2EE application. The rest of the application uses JSF, EJB, JPA, and JMS as its basic building blocks. I'm thinking that instead of directly accessing the database, that it would be probably better to use JMS to pass the received data off to a MDB that perform the processing of the data. This seems to get back into the "J2EE World" at an early point.

I had also thought of using a JCA Connector and I have already developed another for communicating with these network devices in a request/response fashion. The Connector architecture fit pretty well. In this case, however, I have to have an active process that is listening for messages and also is maintaining the RDP protocol timers, etc. The thought of using an inbound connector piques my interest as this somewhat models what I need to do but two things worry me.

First is that a JCA Connector is typically statically configured with its connection information. In this case, however, I need to have the connector retrieve the list of devices to communicate with at startup and also be able to dynamically added and remove and check status of these devices. I'm not sure how I would do that with a JCA Connector.

The second is having the JCA Connector manage it's own threads. I know that the JCA architecture has the ability to have work tasks, but I need a little more control on when these tasks run. So I think I would need to manage my communications threads myself.

So if anyone has any comments or suggestions which path would be best, it will be much appreciated.
[Message sent by forum member 'bbergquist' (bbergquist)]

http://forums.java.net/jive/thread.jspa?messageID=234942