I'm having trouble getting sessionscoped beans and ejb stateful beans to communicate between user sessions, within the same java-ee container. Through trial and error I have settled on using a database to pass messages between the user sessions. But now I have a problem, how do I notify a user's session that the DB has changed Can I start a background polling thread in each user's session context to poll the database for changes? If this would work, what is the best method to avoid blocking, but to make sure the polling bean "wakes up" in their own user's session context?
I'm using Glassfish 3.1.2, and user sessions are CDI sessionscoped beans, with some stateful EJBs for JPA database access. I'm using the CDI event-bus to pass messages around the beans in the user's session.
I have tried to use Singletons to communicate between user sessions. But that doesn't work because once the message originating from user 1 is passed to user 2's beans, and those beans fire off a CDI event, the CDI event is handled by the session context of user 1. Which makes sense, since the message was created while in User 1's session.
Any help would be appreciated!!