6 Replies Latest reply on Nov 4, 2008 10:58 AM by Coral Featherstone

    Global Event

    Damian Harvey Apprentice

      I'm using the @Event and @Observer in several places in my application, and I now have a requirement to refresh data held in Session scoped bean across different users.


      For example:
      3 different users have a Schedule (eg. train timetable) loaded into a Session scoped Bean. One user makes a change. I'd like to fire an event that is observed by all three - ie. a 'Global' Event.


      Currently the raiseEvent() method in Events uses Component.getInstance() to call any Observers, so the event is only observed by the user that fired it.


      The obvious solution is to make the observing Bean Application scoped. However this doesn't fit my use case as other groups of users have different Schedules. These users are from different companies and won't want/need their data refreshed.


      Does anyone else have a requirement to use events (or something similar) across session boundaries / between users? If so how are you handling this now?


      Cheers,


      Damian.




        • 1. Re: Global Event
          Jacob Orshalick Apprentice

          It may be a bit heavy weight for the needs of your application, but you may consider looking into jBPM with jPDL business process definitions.  A group of users can participate in a business process and a bean scoped to the business process context could observe the event.


          As another advantage, I have been using Spring Web Flow on a recent project (which has a very similar flow definition to jPDL) and have really become quite fond of these types of pageflow definitions.  The syntax feels very natural when defining flows.


          Hope it helps.

          • 2. Re: Global Event
            Damian Harvey Apprentice

            Thanks Jacob.


            I'm using jBPM elsewhere in my app (mostly for Tasks), however this situation doesn't really lend itself towards being in a business process. If I was just using the BP Context as a holder for the Bean, I can't see how users can join it when they log in. Would you envisage the process being kicked off by the first user to request the Bean? How would subsequent users join the process?


            I suppose one way to achieve what I'm  after would be something like pub-sub using JMS. I could publish a message containing the event (eg. schedule.changed) and then my subscribing MDB could just fire whatever event it receives.


            Cheers,


            Damian.

            • 3. Re: Global Event
              Jacob Orshalick Apprentice

              I'm using jBPM elsewhere in my app (mostly for Tasks), however this situation doesn't really lend itself towards being in a business process.

              Yeah, if it really does not fit a business process then you would certainly have to use some ugly work-arounds to make use of the BP context.



              I suppose one way to achieve what I'm after would be something like pub-sub using JMS.

              Seems reasonable and would certainly be less invasive than hacking into a broader scope.  I will chew on this a bit more and see if I can think of another option.  An interesting problem ;)

              • 4. Re: Global Event
                Coral Featherstone Newbie

                What was your eventual solution to this?
                I have the same requirement in that several users can work on the same set of data.


                I am trying the JMS route, but cannot find a way to get the incoming message to the individual session beans/users(in my case page scope beans.)

                • 5. Re: Global Event
                  Coral Featherstone Newbie

                  I am now trying jBPM as a possible solution to my dilemma, but have a few questions.



                  I was thinking of transitioning to an edit node on opening the modal and than to cancel or update (with the resulting global event) on closing the dialog.
                  My concern is that if the user navigates away or there is an error the workflow wont end.



                  1) Since the app doesn't really lend itself to workflow I was wondering if there was a way to always enter the worflow from the start node. Or to phrase differently can I make sure the user doesn't get stuck halfway through the process. My user would be in a modal panel and if navigating away (or and error) reentering the dialog should restart the process.



                  2) Is it possible to use jBPM without long term storage (database)


                  Would really appreciate some direction here, I don't know where to start.

                  • 6. Re: Global Event
                    Coral Featherstone Newbie

                    <process-definition 
                         name="StrategyMap"
                         xmlns="urn:jbpm.org:jpdl-3.2"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="urn:jbpm.org:jpdl-3.2 http://jbpm.org/xsd/jpdl-3.2.xsd"
                         >
                    
                        <start-state name="alterStrategyBubble">
                            <transition to="editStrategy"/>
                        </start-state>
                    
                        <task-node name="editStrategy">
                            <task name="edit" description="Prepare for changes">
                               <assignment actor-id="#{actor.id}"/>
                            </task>
                            <transition name="notify" to="notify">
                            </transition>
                            <transition name="cancel" to="cancelled"/>
                        </task-node>
                        <task-node name="notify">
                            <task name="reloadPage" description="check and update page if situation permits">
                               <assignment pooled-actors="#{identity.userGroup.name}" />
                    NEED WAY TO NOTIFY ALL USERS WITH SAME groupActorIds HERE and close task 
                            </task>
                            <transition name="complete" to="complete">
                            </transition>
                        </task-node>
                    
                        <end-state name="complete"/>
                        <end-state name="cancelled"/>
                        
                        
                    </process-definition>




                    Trying to notify a4j push component for each user in a particular group


                       @Observer("reload_requireed")
                        public void changeRequired(){
                             synchronized (listener) {
                                  List<TaskInstance> instanceList = taskInstanceList.getTaskInstanceList();
                                   if (instanceList!=null && !instanceList.isEmpty()) {
                                        //update a4j:push
                                        listener.onEvent(new EventObject(this));
                                   }
                             }
                        }
                    
                    Please anyone. Not coming right with documentation