@在会话范围 bean 中观察?
以下情况可能吗?
“SessionService”是一个无状态 EJB,它会触发事件“LoggedInEvent”。调用具有观察 LoggedInEvent 的非静态方法的 SessionScoped (Weld) bean“SessionBean”,并为该特定用户初始化一些内容。
是否调用了正确的“SessionBean”实例?所有实例都被调用了吗?我在文档中找不到任何内容。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“正确的实例”是一个有点误导性的措辞。
发生的情况是这样的:
SessionService
被调用(可能由 Web 请求触发)。SessionBean
就是这种情况。当且仅当SessionBean
已在您的活动会话中实例化(对于 Web 请求,当然只有一个活动会话),那么当然会使用此实例。更多详细信息,请参见规范。
因此,回答您的问题:
是的,将调用正确的实例。为什么?因为容器有责任确保只有一个 SessionBean 实例与活动会话范围关联。
(*):如果调用是由远程 ejb 调用触发的,则您既不能假定活动会话也不能假定活动对话...
"The correct instance" is a slightly misleading wording.
What happens is this:
SessionService
is invoked (probably triggered by a web request).LoggedInEvent
, all registered observers are called in a synchronous way (meaning thatSessionService
will not terminate before all observers terminate).SessionBean
. If - and only if -SessionBean
has 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...