[ 
https://issues.apache.org/jira/browse/OWB-1246?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16530326#comment-16530326
 ] 

Mark Struberg commented on OWB-1246:
------------------------------------

Hi Jo!
 OpenWebBeans behaves exactly as defined by the spec. So this is not a bug. 
 The event will only be received by beans within 'currently active Contexts'.
 That is only the one single active Session (if any) of your current Thread 
will get notified.

Imagine that Sessions might not even be held locally in memory but on a 
memcached, a file, some database or somewhere on another node on a cluster. So 
it's really ok that not all the Sessions are re-loaded into memory. Especially 
since the Servlet spec requires that Sessions must be rather treated as kind of 
'private' storage.
 Once Session passivation and re-activation comes into play it gets even more 
complicated.

Probably you could explain to us what problem you want to solve? 
 It seems like CDI events are not the 'right hammer' for your problem ;)
 Either here, but probably it's more interactive to ping us on the 
[email protected] mailing list or on IRC.

> CDI Event are not observed across SessionScoped beans
> -----------------------------------------------------
>
>                 Key: OWB-1246
>                 URL: https://issues.apache.org/jira/browse/OWB-1246
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Core, Events
>    Affects Versions: 1.7.3
>            Reporter: Jo Desmet
>            Priority: Major
>
> I have a simple setup with just one single Session that backs a JSF xhtml 
> file. Within that I fire an event, expeting that both the same session, and 
> any other session will receive the event on submitting.
> However, oddly enough, I can see that during the firing of the event, only 
> the current session receives it, not any other sessions. I am making sure I 
> have two different sessions by using two different browsers (Safari and 
> Firefox in this case).
> See also https://stackoverflow.com/q/51027804/744133
>  
> {code:java}
> package testevent;
> import java.io.Serializable;
> import javax.enterprise.context.SessionScoped;
> import javax.enterprise.event.Event;
> import javax.enterprise.event.Observes;
> import javax.enterprise.event.Reception;
> import javax.inject.Inject;
> import javax.inject.Named;
> import org.apache.logging.log4j.LogManager;
> import org.apache.logging.log4j.Logger;
> @Named
> @SessionScoped
> public class TestEventSession implements Serializable {
> private String message = "Start Message";
> private String receivedMessage = "";
> @Inject
> @ForTest Event<String> messageEvent;
> Logger LOG = LogManager.getLogger();
> public void messageChanged(@Observes(notifyObserver = Reception.IF_EXISTS) 
> @ForTest String message) {
> LOG.info("messageChanged <-- "+message);
> this.receivedMessage = message;
> }
> public String getReceivedMessage() {
> return receivedMessage;
> }
> public String getMessage() {
> LOG.info("getMessage --> "+message);
> return message;
> }
> public void setMessage(String message) {
> LOG.info("setMessage <-- "+message);
> this.message = message;
> LOG.info("Firing Message Change");
> messageEvent.fire(message);
> LOG.info("Done Firing Message Change");
> }
> }
> {code}
> {code:java}
> <?xml version='1.0' encoding='UTF-8' ?> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html 
> xmlns="http://www.w3.org/1999/xhtml";
> xmlns:h="http://xmlns.jcp.org/jsf/html";
> xmlns:f="http://java.sun.com/jsf/core";
> >
> <f:view transient="false">
> <h:body>
> <h:form>
> <h:inputText value="#{testEventSession.message}" />
> <h:outputText value="#{testEventSession.receivedMessage}" />
> <h:commandButton value="Submit"/>
> <h:button value="Refresh" />
> </h:form>
> </h:body>
> </f:view>
> </html>
> {code}
> {code:java}
>  
> package testevent; 
> import static java.lang.annotation.ElementType.FIELD; 
> import static java.lang.annotation.ElementType.METHOD; 
> import static java.lang.annotation.ElementType.PARAMETER; 
> import static java.lang.annotation.ElementType.TYPE; 
> import static java.lang.annotation.RetentionPolicy.RUNTIME; 
> import java.lang.annotation.Retention; import java.lang.annotation.Target; 
> import javax.inject.Qualifier; 
> @Qualifier @Retention(RUNTIME) @Target({METHOD, FIELD, PARAMETER, TYPE}) 
> public @interface ForTest { }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to