8 Replies Latest reply on Oct 18, 2009 9:49 AM by aapthorp

    sub process event propagation

    aapthorp

      Are events propagated from sub-processes to parent processes?

      I have a sub-process where I want to detect certain events at the parent process level without interrupting the flow of the sub-process. I've tested this with a simple sub-process within a process state and the sub-process events don't seem to be propagated.

      Also, I noticed that the parent process doesn't get set when a sub-process is created by a process state.

        • 1. Re: sub process event propagation
          aapthorp

          Hmm, having looked at the code and a few entries in this forum relating to visibility of parent process from the sub-process this appears to be a current limitation in 3.3

          Before I raise a feature request, a question; is this also an issue in 4.0?

          • 2. Re: sub process event propagation
            kukeltje

            The parent process does not get set in 4.0 either, but there is a relation to the parent execution (the execution that started the subprocess). So I'm not sure events bubble up to the parent execution or not. Testing is the quickest you can do or wait until I get a response from the devs (have not worked with that part myself yet)

            • 3. Re: sub process event propagation
              aapthorp

              Just thinking through the behaviour I'm looking for I realise that once the event is propagated up it needs to be detected / signal a particular node in the super-process. Is there an obvious way of doing this in jBPM?

              • 4. Re: sub process event propagation
                kukeltje

                the <on event="...." makes it directional in 4, the <event type="..." in 3

                • 5. Re: sub process event propagation
                  aapthorp

                  Ronald,

                  Maybe I've missed something but if the event is propagated to the super-process level then I need to write an actionhandler/eventlistener to direct it at the node in question or is it visible to all nodes in the process?

                  Another question - can events be filtered by source node?

                  • 6. Re: sub process event propagation
                    kukeltje

                    you just need an eventhandler ON the node

                    • 7. Re: sub process event propagation
                      aapthorp

                      I have rather belatedly come back to this one, having not made the switch to jBPM4 - I find the jbpm-console more friendly for trying things out thanks to the ability to signal tokens.

                      I still don't see how this works in JBPM3, may be it works in 4. What I'm trying to achieve is similar to signal events as described in the following (section New Signal Event):

                      http://www.brsilver.com/wordpress/2008/09/15/concepts-and-terminology-in-bpmn-20/

                      In order to implement this behaviour I have an actionhandler in the subprocess which propagates the event to the superprocess. Question is do I use another handler at the superprocess level and "wire" it to the target node, or do I get the actionhandler to find a handler for the event on the target node?

                      • 8. Re: sub process event propagation
                        aapthorp

                        So my final (JBPM 3) solution for this requirement is as follows.

                        An actionhandler in the subprocess which propagates the event to the superprocess.

                        public void execute(ExecutionContext executionContext) throws Exception {
                        
                         if (eventType == null) {
                         eventType = executionContext.getEvent().getEventType();
                         }
                         Token superToken = executionContext.getProcessInstance()
                         .getSuperProcessToken();
                         ExecutionContext superContext = new ExecutionContext(superToken);
                         superToken.getProcessInstance().getProcessDefinition().fireEvent(eventType, superContext);
                        }


                        and another action handler to handle the propogated event in the superprocess:

                        
                        String nodeName=null;
                        String transitionName=null;
                        
                        public void execute(ExecutionContext executionContext) throws Exception {
                        
                         List tokenList = executionContext.getProcessInstance().findAllTokens();
                         for (Iterator it = tokenList.iterator(); it.hasNext();) {
                         Token token = (Token) it.next();
                         if (token.getNode().getName().equals(nodeName)) {
                         token.signal(transitionName);
                         }
                         }
                        }


                        The propagated event can then be sent to a state that transitions to a join to control the main flow of the superprocess. I'm sure there are some other ways of getting the same effect but this seems to work quite well. I have also refined it further to consolidate events of the same type from multiple instances of the same subprocess.

                        Now need to see how this is achieved in JBPM4.