0

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?

  • Have a look at the CDI event system (not sure if that's what you're actually after). It would allow you to define custom event handlers ass well as fire custom events in the server. Or are you after listeners that observe server/container events? – Thomas Sep 04 '15 at 14:33
  • I am trying to figure out what is the best way to implement something that fires events/triggers code it in a separate thread. The event is fired when the code returns from a blocking call. – user1533878 Sep 07 '15 at 09:37
  • Well, as I said that might be doable with the CDI event system. You'd define observers as CDI beans or EJBs and fire the event manually. Then you'd have to decide whether to inform the observers immediately or at the end of the transaction (if there is any). – Thomas Sep 07 '15 at 12:01
  • I think that the use of the word "event" is creating confusion. In order for the event to be fired some code has to be running in the background listening to the DataQueue or whatever I need to be listening to. I am interested in the best way to implement this. What is the best way to launch a "server thread" listening on something? My initial approach was to use a Timer. – user1533878 Sep 08 '15 at 08:24

0 Answers0