1 Reply Latest reply on Aug 29, 2014 1:53 AM by Maciej Swiderski

    Catching child processes via ProcessEventListener

    Ryan Dowell Newbie

      Just started with JBPM in the last couple weeks and I have a question regarding how to handle subprocesses.


      As I understand it, when a process defines a subprocess as part of its workflow, then when that subprocess is executed, a new ProcessInstance is created but there is no externally visible state on either the parent or child referring to the other.  I understand that the parent process is able to map its variables to inputs/outputs on the subprocess but what I’d like to do is also get info on the current runtime state of the child from a class that manages the parent.  Currently I’m creating ProcessInstances inside of a wrapper class and the intention was to make the wrapper class able to reference the subprocess ProcessInstances as well.


      My question is in regards to the ProcessEventListener interface.  It is possible to catch a ‘BeforeNodeTriggered’ event and examine the event context to determine the node type and see if it is a SubProcessNode as well as the Process ID to determine the type of subprocess that is about to start.  However, this occurs before the subprocess begins execution so there is no way to get the ProcessInstance ID for the subprocess at this point.  It is also possible to catch the ‘BeforeProcessStarted’ event and get both a Process ID and ProcessInstance ID, however as noted earlier, even if the ProcessInstance for this particular event is a child of another ProcessInstance, there is nothing in the context of the event at this point that would associate it to its parent.  The question is: because the documentation states that the execution engine is single-threaded, can I safely make the assumption that if I catch a ‘BeforeNodeTriggered’ event, where the node type is a SubProcessNode with a given Process ID, then if I subsequently catch a ‘BeforeProcessStarted’ event with the same Process ID, that new ProcessInstance will always represent the child subprocess that was triggered by the parent's SubProcessNode, and it cannot be a separate instance started independently from a different source?




      -Ryan D.