I have created an application that listens to incomming messages from an AS400 DataQueue. The application is running in a Java application server (Glassfish).
I am using the jt400 library to connect and read from the Dataqueue. Reading from a dataqueue is very similar to reading from a socket. You call read and it blocks untill something is writen from the other end of the connection. The API provides an overloaded read method that allows the programmer to set a timeout period.
Since read is a blocking call and must be called from my application, I had to figure out a way to make it start when the application starts starts and keep it running for as long as Glassfish is up.
I created an EJB, added the @Startup annotation and set a @Scheduled method. In that method I am calling read with a timeout in a while loop, allowing me to check properties of the class and maybe shut it down.
I was wondering if there is a better way to implement something like this. I am not talking specifically about connecting to an AS400 DataQueue. What I have in mind is an event mechanism running inside a Java application server where you can hook custom event message providers.
Could this be defined as a custom resource on Glassfish like a JDBC resource? Does the J2EE specification provide some mechanism to build on?