I'm writing my first Java EE 5 app on WebLogic 10.3.5. and need some architectural advice.
When the app starts I need to open a persistent connection to an XMPP server to send Instant Messages. Messages will be constantly pulled from a table, which will be populated by another part of the app.
As I see it I can't use container managed objects for this, such as EJB, because I would then have no control over the object and socket connection lifecycle.
Is a Servlet an appropriate candidate for a process that starts with the app and holds a persistent socket connection?
Looks like you are going to use one of the options listed by Markus Eisele in his blogpost. There is a mention of Weblogic-specific mechanism (which is not pure Java EE however) for application lifecycle listeners.
I solved this by creating a ServletContextListener that instantiates and EJB 3.0 stateless session bean.
The session bean then instantiates an XMPP connection using a @PostConstruct method and closes the connection using a @PreDestroy method.
I made the session bean use an EJB 3.0 Timer to poll the message queue table every couple of minutes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With