-
1. Re: How does a sub-process work?
eaa Jun 16, 2011 8:23 AM (in response to stellina_rosa)Which editor are you using?
In jbpm5 you have 2 different types of sub-processes: embedded sub-processes and reusable sub-processes. You case is the later.
Please take a look at this test that uses reusable sub-processes:
https://github.com/esteban-aliverti/JBPM-Samples/tree/master/Simple-SubProcess-Sample
more precisely:
and
Best,
-
2. Re: How does a sub-process work?
stellina_rosa Jun 16, 2011 9:27 AM (in response to eaa)thank you! I solved the problem with your example
-
3. Re: How does a sub-process work?
eaa Jun 16, 2011 9:37 AM (in response to stellina_rosa)Great! Please mark this post as Resolved, or answered (I don't remember the right term). By doing this you will save some time to a lot of people in your same situation. Best Regards,
-
4. Re: How does a sub-process work?
stellina_rosa Jun 16, 2011 9:44 AM (in response to eaa)I can only modify the title and write SOLVED, because I can't modify the discussion in a question!
thank you
-
5. Re: How does a sub-process work?
stellina_rosa Jun 16, 2011 11:01 AM (in response to eaa)Hi! I have another question about Sub-processes;
In the sub-process I store some objects in the ksession; I would like to use the object ksession of the sub-process in the main process; in what way can I pass a parameter from sub-process to the main process?
I thought to create 2 variables: one in the main process called ksession (and type org.drools.runtime.StatefulKnowledgeSession), and the other variable in the sub-process called ksessionInternal (type org.drools.runtime.StatefulKnowledgeSession); these 2 variables are the "parameter out mapping" of the node sub-process... is right?
the problem is: in what way can I pass the ksessionInternal to the ksession variable?
thank you very much!
-
6. Re: How does a sub-process work?
eaa Jun 16, 2011 1:12 PM (in response to stellina_rosa)In JBPM5 you have two different scopes: one are process' variables and the other is ksession (shared among all the processes running in it). In the case of variables, you need to map the input and output variables of your sub-process using the editor for example. So If you want to use a variable from the main process in the sub-process, you need to define an input parameter in the sub-process and do the corresponding mapping in the reusable-subprocess node of your main process. If your sub-process modifies the variable or creates a new one and you want to use it in the main process, you need to map (again, in the reusable-subprocss node) the output variable from the sub-process to a variable in the main process. In the case of embedded sub-processes, you don't need to do these mappings, because both processes are in the same "context". If you are storing variables in you session (using insert() for example), you don need to do anything special. You don't even need to pass the ksession from the main process to the sub-process. Both processes could reach the same ksession using the "magic" variable kcontext: kcontext.getKnowledgeRuntime() Best Regards,
-
7. Re: How does a sub-process work?
stellina_rosa Jun 16, 2011 6:10 PM (in response to eaa)ok, I undestard the difference... so now I need an embedded sub process node, because I need to use the ksession(where are stored object that I must use in the main process).
on the guide there isn't any example of embedded sub-process... do you have some example??
thank you very much!
-
8. Re: How does a sub-process work?
eaa Jun 17, 2011 8:00 AM (in response to stellina_rosa)The ksession is shared among all the processes and sub-processes no matter the sub-process type. So what you get in your main process when you invoke kcontext.getKnowledgeRuntime() is the same object that you get in a (reusable or embedded) sub-process when you invoke kcontext.getKnowledgeRuntime(). If you still want to see a simple example using embedded sub-process you can take a look at the same example project I have provided.
-
9. Re: How does a sub-process work?
stellina_rosa Jun 17, 2011 8:48 AM (in response to eaa)Hi Esteban, I'm sorry to contradict you, but the ksession is not the same in main and sub-process.
I take a test with a variable and the resul is different
org.drools.runtime.process.WorkflowProcessInstance process = (org.drools.runtime.process.WorkflowProcessInstance)kcontext.getProcessInstance();
System.out.println("Risultato Processo Principale: "+process.getVariable("risultato"));
.... so this means that in the main process I can't use the ksession on the sub-process.
at this point... what is the point of using of a sub-process?? is not very useful!!!
-
10. Re: How does a sub-process work?
eaa Jun 17, 2011 9:12 AM (in response to stellina_rosa)Be careful! In your example, you are working with the process instance and not the session. So kcontext.getKnowledgeRuntime() will return the same StatefullKnowledgeSession in both of your processes. But, kcontext.getProcessInstance() will return different process instances of course (one is the main process and the other one is the sub-process).
From your tests I assume you are talking about process variables. Process variables only exist in the context of the process instance. So, if you want to usa a variable from your main process in your sub-process, you need to do the mappings in the reusable-subprocess node.
For example, in the test I have provided to you, I'm declaring a variable (messages) in the parent process:
<property id="messages" itemSubjectRef="_messagesItem"/>
Because I want to use this variable in my sub-process, I need to declare a variable of the same type in it:
<property id="internalMessages" itemSubjectRef="_internalMessagesItem"/>
Then, in the reusable-subprocess node (in the paren process) I need to copy the value from messages to internalMessages:
<dataInputAssociation>
<sourceRef>messages</sourceRef>
<targetRef>_5_internalMessagesInput</targetRef>
</dataInputAssociation>
And because I need to use the modified value of this variable in my parent process once the sub-process is finished, I also need to do an output mapping:
<dataOutputAssociation>
<sourceRef>_5_internalMessagesOutput</sourceRef>
<targetRef>messages</targetRef>
</dataOutputAssociation>
Of course you can use eclipse editor to do all these things in a more user-friendly way
Best Regards,
-
11. Re: How does a sub-process work?
stellina_rosa Jun 21, 2011 3:38 AM (in response to eaa)Thank you I used the sub-process and I solved my problem
-
12. Re: How does a sub-process work?
new-comer Nov 16, 2012 11:24 AM (in response to eaa)Esteban Aliverti, your post is very helpful, it helped me fixed my subprocess issue. thanks.