1 Reply Latest reply on Oct 1, 2012 5:20 AM by swiderski.maciej

    Waiting for events to occur in a flow?

      I'm a flow noob (...obviously) using 5.3.

       

      I have a few examples working and am trying to integrate some rules.  I think I have a fundamental misunderstanding of rule tasks (maybe flow).   Basically, I want to have a more complicated process and I want to only advance to the next node when a certain set of conditions are met. 

       

      To set up a simple test, I have a flow, start node->rule task->script task (writes "Done")-> end node.  I don't want to get to the script task until the process receives a message with text='hi' or text='yo'.  I set up the following ruleflow group (I have a Message and MessageB class):

       

        rule "waitforit rule"

             ruleflow-group "waitforMessage"

             dialect "mvel"

        when

            not ($m : Message())

        then

            System.out.println("no message yet");

        end;

       

        rule "dotone"

             ruleflow-group "waitforMessage"

             dialect "mvel"

        when

            $m : Message(text=='hi' || text=='yo')

        then

            System.out.println("got message:"+$m.text);

        end;

       

      I tried:

       

      1) I start the process and insert a MessageB object (i see hibernate update the session).  I expected the first rule to fire, but it does not.  Then I insert a Message object and the process/app just exits (WITHOUT) giving me the "Done" message (i have a thread.sleep after the insert - and no dispose).

       

      2) So, I start the process and do a fireallrules, wait 10 seconds then insert a Message object.  But, as soon as I fireallrules, I get the "no message yet" message AND the "Done" message.  Nothing happens for 10 seconds and then the process ends.

       

      So, I have just one question....in 6 parts:

       

          a) in #1, why doesn't the first rule fire? 

          b)   and Why/How does the process exit without a "Done" message?  (I don't dispose of the ksession in my code)

          c) in #2, why does the fireallrules immediatly trigger the "Done" message?

          d) as I read it in the documentation, the rule task should keep the process from advancing until all of the rules are no longer active.  However, I thought the first rule would ensure that the group was active until a Message arives.  Is that wrong?

          e) what is the right way to do this sort of thing?

          f)  Can someone clue me into what I am doing wrong?  Am I thinking about this in the wrong way?

        

      Thanks very much for your thoughts/comments.

        • 1. Re: Waiting for events to occur in a flow?
          swiderski.maciej

          First of all, how do you run the process - jbpm-console, unit test, custom application?

           

          In general, to activate a rule you need to insert/update/retract facts to/from the session. Once rule is activated you can fire it using firellRules.

          Jim Beam wrote:

              a) in #1, why doesn't the first rule fire? 


          I believe nothing was added to session so no activation took place so nothing to fire

          Jim Beam wrote:

              b)   and Why/How does the process exit without a "Done" message?  (I don't dispose of the ksession in my code)

           

          That depends on how you run the process - are you sure that process is completed? I think it resides in business rule task...

           

           

          Jim Beam wrote:

              c) in #2, why does the fireallrules immediatly trigger the "Done" message?

          This is the answer to part 2, as soon as you fire rules it will trigger business rule task to continue

           

           

          Jim Beam wrote:

              d) as I read it in the documentation, the rule task should keep the process from advancing until all of the rules are no longer active.  However, I thought the first rule would ensure that the group was active until a Message arives.  Is that wrong?

          As far as I know business rule task does not wait for a condition to be met, it simply executes rules that are active at the time when rule task was executed.

           

           

          Jim Beam wrote:

              e) what is the right way to do this sort of thing?

              f)  Can someone clue me into what I am doing wrong?  Am I thinking about this in the wrong way?

            

          If you are looking for way of putting process instance into wait state until condition is met you should use intermediate conditional event instead of rule task. Conditional event will wait until defined condition is met and move on only when that condition is met. Take a look at the example here.

           

          HTH

          1 of 1 people found this helpful