8 Replies Latest reply on Nov 30, 2009 5:27 AM by neshap

    How to signal subprocess?

    olivierl

      Hi,

      I have a subprocess in my workfow, and a state node within. I can execute it, and it wait as expected in the state node. Until here, everything is ok.

      Now I want to signal the state node with : executionService.signalExecutionById(executionId). But the problem is : I don't know the executionId of the subprocess! I can't use : executionService.startProcessInstanceById(processDefinitionId).getId() either because I don't know the processDefinitionId since jBPM generates custom keys for subprocess!

      I have also tried to find the subprocess execution id from its parent process, but it doesn't seem possible to access child process from parent process.

      Did I miss something?

      I'm using v4.2
      Thanks

        • 1. Re: How to signal subprocess?
          rmoskal

          Something like this works for me:

          ExecutionImpl tp = (ExecutionImpl) executionService.findProcessInstanceById(topPop.getProcessExecutionId());
          
          ExecutionImpl subProc = tp.findActiveExecutionIn(activityName).getSubProcessInstance();
          
          executionService.signalExecutionById(subProc.getId(),"to Rework");


          • 2. Re: How to signal subprocess?
            olivierl

            Waaouu It works perfectly!! Thanks

            • 3. Re: How to signal subprocess?

              Instead of casting it to implementation class, you can try something like

              Execution parentExecution=instance.findActiveExecutionIn("SubProcessParent");
              OpenExecution subProcessExecution=((OpenExecution)parentExecution).getSubProcessInstance();


              After that you can access state and signal it with something like:

              Execution subProcessState=subProcessExecution.findActiveExecutionIn("SubProcess");


              Regards
              Nenad

              • 4. Re: How to signal subprocess?
                olivierl

                Thanks for your response, but you have a cast too : Execution into OpenExecution.

                Does someone know the diffrence between Execution, ExecutionImpl, OpenExecution, ProcessInstance? I'm a bit confused with all these concepts.

                • 5. Re: How to signal subprocess?

                  Hi

                  I have a state that has an event that is consumed until the flag reaches a certain value. When you reach this value need to turn to another task. As I do this, some examples in java

                  <state g="438,14,92,52" name="verificar repo">
                   <on event="start">
                   <timer duedate="1 minutes" repeat="10 seconds"/>
                   <event-listener class="com.configuracion.eventos.VerificarReposicion">
                   <field name="documento"><object expr="#{resReposicion}"/></field>
                   <field name="caf"><object expr="#{txtCaf}"/></field>
                   </event-listener>
                   </on>
                   <transition to="enviar email"/>
                   </state>
                  
                   <mail g="562,14,107,54" name="enviar email">
                   <to addresses="carlosj@audifarma.com.co"/>
                   <subject>Prueba</subject>
                   <text>Prueba</text>
                   <transition to="fin_1"/>
                   </mail>
                  


                   public void notify(EventListenerExecution execution) throws Exception {
                   ProcessInstance processInstance = executionService.findProcessInstanceById("Pendientes-1");
                   String respuesta = execution.getVariable("respuesta")+"";
                   if (respuesta.equals(null)) {
                   respuesta = new String();
                   execution.setVariable("respuesta", respuesta);
                   }
                   ReposicionDao reposicion = new ReposicionDao();
                   respuesta = reposicion.verificarCarguePorReposicion(documento, caf);
                   execution.setVariable("respuesta", respuesta);
                  
                  if(execution.getVariable("respuesta").toString().equals("N")){
                  executionService.signalExecutionById(processInstance.getId(),"enviar email");
                   }
                   }
                  


                  Thanks

                  • 6. Re: How to signal subprocess?
                    kukeltje

                    @cmjhingeniero

                    What is the relation of your post with this topic?

                    • 7. Re: How to signal subprocess?

                      sorry

                      • 8. Re: How to signal subprocess?

                         

                        Thanks for your response, but you have a cast too : Execution into OpenExecution.

                        Does someone know the diffrence between Execution, ExecutionImpl, OpenExecution, ProcessInstance? I'm a bit confused with all these concepts.


                        I'm a bit new to JBPM, but I'll try to give it a go.
                        It seems that casting has to be done (my opinion is better to cast it to interface than implementation). Judging from the javadoc, state of the Execution can be either active or locked. OpenExecution is Execution in active state only, and it gives you access to related objects in execution. ProcessInstance is one execution of a process definition, and it can have many concurrent executions (forks, subprocess).