Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java EE Servlet as container for XMPP connector

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?

like image 850
retrodev Avatar asked Mar 16 '26 02:03

retrodev


2 Answers

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.

like image 138
Tair Avatar answered Mar 19 '26 05:03

Tair


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.

like image 21
retrodev Avatar answered Mar 19 '26 04:03

retrodev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!