Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDI Events, scope of their propagation

Tags:

java

session

cdi

Here's a recurrent problem that I have and I think maybe CDI events can help me but I'm not sure.

I have two users interacting in a website, I want them to share an instance of a bean so they can both share an activity. So far the only way I know how to do this is by pushing data to the database then having two different beans, one for each user, continuosly check for changes.

My question is, if a sessionscoped bean observes an event, do every sessionbean of every user get notified when i fire it? Or only the session bean for the active user?. Because then I could use observer to keep an object syncronized for both users. However I don't really think this is the way it works because if I have a thousand sessions firing an event would incur in a 1000 method calls...

My other solution would be a huge application scoped bean that holds the activity object for both users, then any change made to it can be communicated to the users, but, I still have to be scanning this object, am I missing something?

like image 853
arg20 Avatar asked Jul 26 '11 19:07

arg20


1 Answers

You won't get it for free like that, because when the event is fired one and only one session is active for the current thread, and the actual object the observer method is called on [if non-static] is obtained from the active context.

like image 189
covener Avatar answered Sep 21 '22 14:09

covener