8 Replies Latest reply on Feb 10, 2010 7:52 AM by Adrian Mitev

    Seam scopes(raise event, get all session scoped components)

    Dumitru Ciubenco Newbie

      Hi,


      I would have two questions regarding Seam scopes(I couldn't find a good documentation about it):


      1) Events..raiseEvent raises an event on which scope/level? session? application? It is possible to isolate the scopes of raised event?For some of events I am interested in raising events to current SESSION scope and for others I would like to raise to all of them. From what I understand it is possible to raise event only for the current session components?


      2) I would like to have more access on seam components, how can I access ALL the components from ALL SESSIONS.
      I would like to have something like:


      List<Map<String, Object>> sessions = Lifecycle.getApplication().getAllSessions()



        • 1. Re: Seam scopes(raise event, get all session scoped components)
          Nikolay Elenkov Master

          Dumitru Ciubenco wrote on Feb 08, 2010 10:25:


          1) Events..raiseEvent raises an event on which scope/level? session? application? It is possible to isolate the scopes of raised event?For some of events I am interested in raising events to current SESSION scope and for others I would like to raise to all of them. From what I understand it is possible to raise event only for the current session components?


          What Seam does is: it finds a component that has an @Observe for your event,
          gets a reference to it by name (and optionally creates if it doesn't exist), calls the method.
          So if your component is application scoped, there will be only one instance. If it is session scoped, there might be multiple instances,
          but only one is available (in the current session).



          2) I would like to have more access on seam components, how can I access ALL the components from ALL SESSIONS.
          I would like to have something like:

          List<Map<String, Object>> sessions = Lifecycle.getApplication().getAllSessions()




          Seam doesn't provide support for this. You have to write it yourself. Fairly easy for a single node,
          you need a cluster-wide store if you are using a cluster. Basically, set up a session listener and
          store a reference to the session as it is created, delete it when it is destroyed.


          HTH


          • 2. Re: Seam scopes(raise event, get all session scoped components)
            Dumitru Ciubenco Newbie

            Thanks Nikolay for quickly response,


            1) Maybe it will make sense in the future to have the possibility to set the scope of the raised event to push it up in the hierarchy of scopes(E.g. for all sessions not only for the current one).


            2)Same think for my second point. It is useful not only to have access to the current session scope, it is also useful to get them all. My case of workaround would be difficult because of the clustered environment. I will try to find some of solution for this by using clustered cache, but as I already said it would be useful to have it in the Seam implementation.



            Thanks,
            Dima

            • 3. Re: Seam scopes(raise event, get all session scoped components)
              Nikolay Elenkov Master

              Dumitru Ciubenco wrote on Feb 08, 2010 13:25:


              1) Maybe it will make sense in the future to have the possibility to set the scope of the raised event to push it up in the hierarchy of scopes(E.g. for all sessions not only for the current one).


              Well, Seam 2 is not getting any more new features, so maybe in Seam 3. (I don't think the CDI specs targets such a case natively);
              There is talk of an event-JMS bridge that will allow sending events across applications, so should work for sessions as well.

              • 4. Re: Seam scopes(raise event, get all session scoped components)
                Ilya Dyoshin Novice

                Well, I guess there is a solution.


                You can create some Application-scoped bean (let's call it AllSessionBeanProvider), in which you will store the all SESSION-Scoped beans of all sessions. (i.e. implementing some common interfaces or smthng like that).


                And additionally you can extend your SESSION-Scoped beans of some abstract class with @Create method, which would be registerring the newly created bean in the AllSessionBeanProvider, and @Destroy method which would be removing the destroyed session bean from AllSessionBeanProvider)


                Regards,


                Ilya Dyoshin

                • 5. Re: Seam scopes(raise event, get all session scoped components)
                  Nikolay Elenkov Master

                  Ilya Dyoshin wrote on Feb 09, 2010 07:54:


                  You can create some Application-scoped bean (let's call it AllSessionBeanProvider), in which you will store the all SESSION-Scoped beans of all sessions. (i.e. implementing some common interfaces or smthng like that).


                  Sure, that will work. But only if you are running on a single node. For a cluster it is a bit more involved. Good news is, someone already did something similar: How do I expire sessions out Cluster wide in Seam

                  • 6. Re: Seam scopes(raise event, get all session scoped components)
                    Dumitru Ciubenco Newbie

                    In my special case I think that the approach proposed by Ilya should work,



                    Sure, that will work. But only if you are running on a single node. For a cluster it is a bit more involved...

                    I don't understand why should be a problem in a clustered environment if I'm using seam components with SESSION and APPLICATION scope. So, in my case I need only one session-scope component to be accessed from the application-scope component. @Create/@Destroy should fulfill my requirements in this case, but for something more complex this will not work, so I should try to implement custom approach in the future by really extracting the ServletSessionMap from HttpSession  and then to get the instance from the Map.
                    I'm thinking to wrap the SeamListener, and cache sessions by using infinispan in a clustered enviroment.


                    thanks,
                    Dima

                    • 7. Re: Seam scopes(raise event, get all session scoped components)
                      Nikolay Elenkov Master

                      Dumitru Ciubenco wrote on Feb 09, 2010 13:13:


                      I don't understand why should be a problem in a clustered environment if I'm using seam components with SESSION and APPLICATION scope.


                      Application scope is only visible on a single node. And your session-scoped component will be created only on the node the user is
                      actually using. So you can't be sure that you will be able to notify the users on node2 from node1. At least that is how it works on JBoss 4.2, and I don't think 5 is any different. Not sure how JBoss 6 will/is changing things.




                      • 8. Re: Seam scopes(raise event, get all session scoped components)
                        Adrian Mitev Master

                        A lot of things would be easier if this was implemented.