is following scenario possible?
“SessionService” which is a stateless EJB fires an event “LoggedInEvent”. A SessionScoped (Weld) bean “SessionBean” having a non static method observing the LoggedInEvent is called and initializes some things for that specific user.
Is the correct instance of “SessionBean” called? Are all instances called? I can not find anything in the documentation.
“The correct instance” is a slightly misleading wording.
What happens is this:
SessionServiceis invoked (probably triggered by a web request).LoggedInEvent, all registered observers are called in a synchronous way (meaning thatSessionServicewill not terminate before all observers terminate).SessionBean. If – and only if –SessionBeanhas already been instantiated in your active session (there’s certainly only one session active regarding the web request), then this instance will of course be used.More details in the spec.
So, to answer you question:
Yes, the correct instance will be called. Why? Because it’s the responsibility of the container to make sure that only one
SessionBean-instance is associated with the active session scope.(*): If an invocation is for example triggered by a remote ejb call, you can neither assume an active session nor an active conversation…