9 Replies Latest reply on May 31, 2010 12:30 AM by jeevdav

    Handling process state

      Hi,

       

      This is for jBPM 4.3 and I am a newbie. I have a very basic question.

       

        An application  Instantiates a process  with three states A, B and C and when it is at state B waiting for a signal the application is gracefully shutdown. Now after this is it possible to find and instantiate the same process instance again. If yes can you tell me how?

       

      I tried to do this by using the findProcessInstanceById method. But this method returms null in this scenario. Remember that I shutdown my application so i had to create the ProcessEngine again..

       

      Thanks in advance,

      Jeeves.

        • 1. Re: Handling process state

          I was using the junit tests that come with jBPM 4.3. Does this have anything to do with the way the tests are set up? I tried commenting out repositoryService.deleteDeployment() lines in the test cases but it did not help

          • 2. Re: Handling process state
            rebody

            Hi David,

             

            By default, the JbpmTestCase will clear database after each testcase.  You could restart processEngine in a method to prevent this problem.

             

            If this problem is still here.  Please provide a testcase which could reproduce the scenario.  So we could get more details to find out the reason.

            • 3. Re: Handling process state

              This is what i am running.

              testFindOne suceeds as expected, but testFindTwo and testFindThree fail unless all three are run together( when they are run together they use the same processengine and execution service)

               

              The bottom line is that findProcessInstanceById works only when the same processengine is used. But in the realworld after i recycle my application how will i be able to resume my incomplete processes?

              ========================================================================

              public class TestJBPM extends TestCase
              {
              protected static ProcessEngine processEngine = null;

                 protected static RepositoryService repositoryService;
                 protected static ExecutionService executionService;
                 protected static ManagementService managementService;
                 protected static TaskService taskService;
                 protected static HistoryService historyService;
                 protected static IdentityService identityService;

                 @Override
                protected void setUp() throws Exception {
                   super.setUp();
                    if (processEngine==null) {
                        processEngine = Configuration.getProcessEngine();
                       
                        repositoryService = processEngine.get(RepositoryService.class);
                        executionService = processEngine.getExecutionService();
                        historyService = processEngine.getHistoryService();
                        managementService = processEngine.getManagementService();
                        taskService = processEngine.getTaskService();
                        identityService = processEngine.getIdentityService();
                      }
                }
                 public void testFindOne() {
                 
                    repositoryService.createDeployment()
                       .addResourceFromClasspath("com/test/Proc.jpdl.xml")
                       .deploy();         
                   
                    ProcessInstance processInstance = executionService.startProcessInstanceByKey("Proc","t");
                    System.out.println("process id  "+processInstance.getId());
                   
                    Execution executionInA = processInstance.findActiveExecutionIn("a");
                    assertNotNull(executionInA);

                    //processInstance = executionService.signalExecutionById(executionInA.getId());
                    processInstance = executionService.findProcessInstanceById("Proc.t");
                    assertNotNull(processInstance);                 
                 }
                 public void testFindTwo() {

                    ProcessInstance processInstance = executionService.findProcessInstanceById("Proc.t");
                    assertNotNull(processInstance);     
                 
                 }
                 public void testFindThree() {
                    repositoryService.createDeployment()
                       .addResourceFromClasspath("com/test/Proc.jpdl.xml")
                       .deploy();         
                    ProcessInstance processInstance = executionService.findProcessInstanceById("Proc.t");
                    assertNotNull(processInstance);     
                 
                 }  
                   
                
               

              }

              ===========================

              The test process

              =======================

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

              <process name="Proc" xmlns="http://jbpm.org/4.3/jpdl">
                 <start name="start1" g="121,59,48,48">
                    <transition name="to a" to="a" g="-25,-20"/>
                 </start>
                 <state name="a" g="107,134,92,52">
                    <transition name="to b" to="b" g="-26,-20"/>
                 </state>
                 <state name="b" g="111,207,92,52">
                    <transition name="to c" to="c" g="-25,-20"/>
                 </state>
                 <state name="c" g="118,271,92,52">
                    <transition name="to end1" to="end1" g="-45,-20"/>
                 </state>
                 <end name="end1" g="134,344,48,48"/>
              </process>

              • 4. Re: Handling process state
                rebody

                Hi David,

                 

                There is no guaranty that method in testcase will run sequence as you expect.  So testFindTwo() and testFindThree() may be executed before testFindOne().

                 

                And You didn't re-create processEngine for each testcase.

                • 5. Re: Handling process state

                  Hi HuiSheng,

                   

                  I ran the test cases one by one by right clicking on the method I wanted to run and choosing "Run as junit test"  from eclipse. This ensured that they ran in the correct order. It aslo ensured that every time a new processengine is created.

                   

                  - Jeeves

                  • 6. Re: Handling process state
                    swiderski.maciej

                    It should run properly as soon as your process is persisted to a data base that is running regardless of your tests being executed or not. I mean that you have db server started as regular server and not in memory.

                     

                    Could you post your hibernate config file?

                    • 7. Re: Handling process state

                      sure.

                       

                      <?

                      xml version="1.0" encoding="utf-8"?>

                       

                      <!

                      DOCTYPE hibernate-configuration PUBLIC

                       

                      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

                       

                      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

                       

                      <

                      hibernate-configuration>

                       

                      <session-factory>

                       

                       

                      <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>

                       

                      <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>

                       

                      <property name="hibernate.connection.url">jdbc:hsqldb:mem:.</property>

                       

                      <property name="hibernate.connection.username">sa</property>

                       

                      <property name="hibernate.connection.password"></property>

                       

                      <property name="hibernate.hbm2ddl.auto">create-drop</property>

                       

                      <property name="hibernate.format_sql">true</property>

                       

                       

                      <mapping resource="jbpm.repository.hbm.xml" />

                       

                      <mapping resource="jbpm.execution.hbm.xml" />

                       

                      <mapping resource="jbpm.history.hbm.xml" />

                       

                      <mapping resource="jbpm.task.hbm.xml" />

                       

                      <mapping resource="jbpm.identity.hbm.xml" />

                       

                       

                      </session-factory>

                      </

                      hibernate-configuration>

                      • 8. Re: Handling process state
                        swiderski.maciej

                        Based on your description and hibernate config file, it looks like each time you call your unit test method (starting new java process it will create new instance of in memory db, meaning that it will not contain any previously created processes.

                         

                        I would suggest you to change hibernate config to point so already running db - just start hsqldb as regular server and then your process should be visible regardless of how many times you start your tests.

                        1 of 1 people found this helpful
                        • 9. Re: Handling process state

                          Maciej,

                           

                          You got it right.

                           

                          Now I have this and my test works as expected. Thank you!

                           

                           

                          <property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost:1701</property>