views:

939

answers:

2

Hey! I'm relative new to both Java EE and Stackowerflow, please be kind :-)

I have a bunch of devices triggering Java messages to be sent on any state change. These devices are typically active for about 30-90 minute intervals. Each event message contains a device id in addition to the event details.

Central in my application is a message driven bean subscribing to those events. Every time I get an event I have to hit the database to look up some info about the device.

It would be absolutely terrific if I could associate a stateful session bean with each active device! If this had been a web application I would have used the http session to store a handle or reference to the stateful bean (I'm I right?). Is there any way that I can archive this from my message bean?

A: 

It would be nice, except it can't be done like you explained. MDBs (and SLSBs) are stateless by definition so it's safe to keep a conversation only during the invocation.

You could eventually break the spec and create a static attribute somewhere (maybe in the MDB itself) but this would certainly be not portable, neither scalable.

My suggestion is to enable caching at the JPA level (see your persistence provider of preference for details), so you can lookup whatever data you need very fast (really fast). This is portable and cluster-friendly. That's the way I use to do it in my projects and I am very happy with it.

Hope it helps.

Antonio
A: 

I'm not that comfortable recommending specific products, but isn't the Terracotta server adressing needs like this?

Magnus