6 Replies Latest reply on Dec 2, 2008 5:42 PM by judy guglielmin

    Cross-context events

    Mario Scalas Newbie

      Hi all,
        can I raise an event in application scope (context) and have it notified to active session context @Observers?

      (My problem: I have to notify logged in clients (running in session scopes) about incoming phone call events coming from a remote PBX device (facaded by a component in application scope.)

      If I'm plain wrong in my approach, could you suggest a different approach? (I've thought about message-driven beans and usage of seam-remoting but not tried it yet)

        • 1. Re: Cross-context events
          Clint Popetz Apprentice

          Indeed application scoped components can raised events which are observed by session-scoped components, but this is only true for the session-scoped components that are in the active session context when the event is fired.  In your use case, you're wanting to fire an event to be observed by components in all session scopes, and that won't work.

          My suggestion would be to have your pbx-listener component insert rows in the database representing calls, and have your web tier poll the database either on each hit or via ajax to see what calls are available. 

          • 2. Re: Cross-context events
            Mario Scalas Newbie

            Thanks for the feedback. I already store such phone information in the DB so I'm going to do this way since my today experimentation with message-driven beans have met no success (but this is another story ;)).

            • 3. Re: Cross-context events
              judy guglielmin Novice

              I have done this in ICEfaces and have found raising events and listening/Observing them in an application-scoped bean to be very effective.  My Observer method in the application-scoped bean would then do a render push.  For example, you may have an event-scoped (or whatever-scoped) bean that adds a new call record to the database and would then trigger an event.  Once a record is successfully persisted to the database, you would then trigger an event which is observed in the application-scoped bean.  Since each of your sessions is registered to the OnDemandRenderer (ICEfaces ajax-push setup which is extremely simple), then you just fire the push from the application-scoped bean and each of the views that has been registered is updated.  No MDB's required.  (if there are large numbers of calls, you might want to keep an application-scoped list available to minimize hits to the database).

              • 4. Re: Cross-context events
                Clint Popetz Apprentice

                Another aspect I failed to mention...seam events aren't cluster aware, but a database polling solution (or an MDB solution) is. 

                I never like to assume that any webapp will always be hosted on one vm.

                • 5. Re: Cross-context events
                  Vladimir Kovalyuk Apprentice

                  Interesting ... What was the problem with MDB? MDB seems the right way to go in that case.

                  • 6. Re: Cross-context events
                    judy guglielmin Novice

                    From an ICEfaces perspective, then I would use the BroadcastRenderer and push the registered views directly from the method that persisted the new Call record.  The BroadcastRenderer does the MDB work for you.  It would be interesting though to try a more EJB3 approach with Seam though.... (with the MDB's triggering a local node's push).  It's always interesting to see how others view the same tasks and solve them.