3 Replies Latest reply on Feb 19, 2011 6:14 AM by km wen

    how to resume process

    km wen Newbie

      hi,

       

      i am newbee for jBPM. i have a qustion about how to resume a process.

       

      i difine a test process p1 as: start->A->B->end. in activity A i throw an exception, and because of WaitForSignal the process go to wait for signal.

       

      And then i start a exception handling process p2 as: start -> D->E->end. i'd like to know can i in p2 resume p1? and how?

       

      thx

       

      wen

        • 1. how to resume process
          km wen Newbie

          I define the fisrt process definition as following:

          ProcessEngine processEngine = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();

            RepositoryService repositoryService = processEngine.getRepositoryService();

            ExecutionService executionService = processEngine.getExecutionService();

            repositoryService.createDeployment().addResourceFromClasspath("testFragment.jpdl.xml").deploy();

            executionService.startProcessInstanceByKey("testFragment");

           

          The testFragment is as following;

           

          <?xml version="1.0" encoding="UTF-8"?>

          <process name="testFragment" xmlns="http://jbpm.org/4.4/jpdl">
             <start g="48,134,48,48" name="start">
                <transition name="to HelloWorld" to="HelloWorld" g="-87,-22"/>
             </start>
             <custom class="org.jbpm.testMigration.MyTest" g="359,196,92,52" name="Test">
                <transition name="to end" to="end" g="-43,-22"/>
             </custom>
             <java class="org.jbpm.testMigration.HelloWorld" g="147,194,92,52" method="printHelloWorld" name="HelloWorld">
                <transition name="to Test" to="Test" g="-45,-22"/>
             </java>
             <end g="554,146,48,48" name="end"/>
          </process>

           

          in custom node i throw an exception und catch it in catch block

           

          catch (Exception e) {  

                   

                   System.out.println("we need the exception handling");

                    activityExecution.waitForSignal();

                     

                  ProcessEngine processEngine = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();

                  RepositoryService repositoryService = processEngine.getRepositoryService();

                  ExecutionService executionService = processEngine.getExecutionService();

                  executionService.signalExecutionById("testFragment");

          }

           

          when i execute testFragment, the following execption occurres:

           

          exception in thread "main" org.jbpm.api.JbpmException: execution testFragment does not exist.

           

          how can i resume the testFragment? pleas help

          • 2. how to resume process
            Vadim Melnik Newbie

            Hi km wen,

             

            Out of curiosity why did you create two ProcessEngine instances there? First process lives/managed by  process engine A (where testFragment.jpdl.xml definition deployed), while for signaling used another process engine B. It's possible to reuse the same process engine instance inside single JVM process.

             

            Another issue is "signalExecutionById" parameter - "execution ID" is not process definition ID or key or similar. Search for "execution id" phrase in this document http://docs.jboss.com/jbpm/v4/userguide/html_single/ for better understanding.

             

            --

            Thanks,

            Vadim.

            • 3. how to resume process
              km wen Newbie

              hi, vadim

              thx for anwser

               

              because i want to use external exception handling to handle the exception, i create two process engine.

               

              i changed the definition of test fragment as following:

               

               

              private  ProcessDefinition createSimpleFragmentDefinitionStart() {

                ProcessDefinitionBuilder builder2 = ProcessDefinitionBuilder.startProcess("Second Definition");

               

                builder2.startActivity(new StartActivity()).initial().transition("A1").endActivity();

                builder2.startActivity("A1", new Display("A1")).transition("A").endActivity();

                builder2.startActivity("A", new MyTest()).transition("B1").endActivity();

                builder2.startActivity("B1", new Display("B1")).endActivity();

               

                return builder2.endProcess();

              }

               

              ClientProcessInstance getInstance(){

                ProcessDefinition pd = createSimpleFragmentDefinitionStart();

                ClientProcessInstance pi = ((ProcessDefinitionImpl) pd).startProcessInstance();

               

                return pi;

              }

               

              and then i start this test process:

               

              public static void main(String[] args) throws NullPointerException{

                TestExceptionHandling te = new TestExceptionHandling1();

               

                te.createSimpleFragmentDefinitionStart();

                te.getInstance();

              }

               

              i try to resume the test process in exception handling process, and back to the activity A, because activity A1 is complete.  I think i should get the processInstance of test process and use executionService.signalProcessById() to resume, but it doesn't  work.