I have the following problem in a school project.
- Numerous cars all send their position data to a stateless webservice, which dumps it into a java message queue.
- This queue is handled by a message driven bean, which calculates some stuff and sends it to the cache.
- This cache/buffer needs to keep a set of smaller buffer objects for every car and empty every buffer periodically by sending the stuff for that car to another system.
I'm having a lot of difficulty with step 3. My first thought would be to make a stateful bean instance for every car, so that each machine in the system could hold a number of those. A singleton bean would keep track of the buffers for all cars. This would hopefully keep things scalable.
Though that is not the way things are done it seems, as everythi开发者_运维百科ng points to injection and a 1-1 relation between clients and stateful beans, while I seem to need a 1-many relation.
After some research I discovered that the online information on these kinds of scenarios is vague at best, irrelevant at worst. My book 'Begginning Java EE 6 Platform with Glassfish 3' doesn't seem to address it at all. I've contacted my techer but he hasn't responded yet, and I'm doubtful he actually knows much about it.
I'm reluctant to use a database because things don't really need (and shouldn't!) be stored longer than absolutely neccesary.
Maybe I'm missing some fundamental concept, or maybe I'm just overthinking things and need a totally different approach. My question is how would you handle this type of problem in this environment? I'm using Glassfish 3.0.1.
i think you missed something for the cache implementation. You could use a simple HashSet in order to cache your data. Or you could use an existing cache framework like memcache (google cache) which is very performant. see Memcache If you want to empty periodically the cache you can use java.util Class Timer.
Why use stateful session beans (do you have to)? I would write another StatelessSessionBean that can return values out of your cache then wrap that with another webservice.
精彩评论