6 Replies Latest reply on Sep 10, 2014 3:15 AM by Maciej Swiderski

    How to complete a signalled process ?

    James Yu Newbie

      Hi all,

       

      I have two processes defined as the following screenshots:

      P1

      2014-09-08_075513.png

      P2

      2014-09-08_075526.png

      The only difference between P1 and P2 is that P1 is blocked and waiting for external event to continue.

      Before persistence is enabled, both P1 and P2 works totally fine.  For example,

      I start P1 with startProcess(), continue P1 with signalEvent(), and I get P1's state as complete (2) with getState() when P1 finish running.

      Same for P2 except I don't need to signalEvent().

       

      After I enable persistence, P2 still works fine but the behavior of P1 got changed.

      I start P1 with startProcess(), continue P1 with signalEvent(), but this time I get P1's state as active (1) with getState() when P1 finish running.

      When I try to confirm which node P1 is on with getNode(), I get "Process instance ##[xxxxxxxxxx] is disconnected." exception.

       

      How do I put P1 into complete state with persistence enabled and how to make getNode() work ?

        • 1. Re: How to complete a signalled process ?
          Maciej Swiderski Master

          with persistence enabled the ProcessInstance returned from startProcess will reflect only the state of the process instance until last wait state. Then when you signal process instance you will need to fetch the instance vie ksession.getProcessInstance to see any updates to it and I believe then you will get null as process instance has been completed.

           

          HTH

          • 2. Re: Re: How to complete a signalled process ?
            James Yu Newbie

            Hi Maciej,

             

            I think process state is the side effect of that process does not complete properly or at least been marked as complete.

             

            Following is the database records for P1 and P2 mentioned in previous post.

            P1 has processInstanceId of 16 while P2 has 15.

             

            In processinstancelog table, we can see P2 is in complete state (status = 2) and P1 is in active state (status = 1 + both duration and end_date are null)

            2014-09-08_175049.png

            In processinstanceinfo table, I cannot find any record with InstanceId of 15 or 16, so I recon both P1 and P2 finish running.

            2014-09-08_175131.png

            and this is the code snippet (important part is highlight in blue) I used to fire signalEvent() and getState() on P1.

            ds = new PoolingDataSource();

            ds.setUniqueName("jdbc/testDS");

            ds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");

            ds.setAllowLocalTransactions(true);

            ds.setMaxPoolSize(3);

            ds.getDriverProperties().put("driverClassName", "com.mysql.jdbc.Driver");

            ds.getDriverProperties().put("Url", "jdbc:mysql://localhost:3306/jbpm");

            ds.getDriverProperties().put("password", "jbpm");

            ds.getDriverProperties().put("user", "jbpm");

            ds.init();

            kservices = KieServices.Factory.get();

            kstore = kservices.getStoreServices();

            environment = kservices.newEnvironment();

            EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");

            TransactionManager tm = TransactionManagerServices.getTransactionManager();

            environment.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

            environment.set(EnvironmentName.TRANSACTION_MANAGER, tm);

            ksconf = kservices.newKieSessionConfiguration();

            kbase = kservices.getKieClasspathContainer().getKieBase();

            ksession = kstore.loadKieSession(sessionId, kbase, ksconf, environment);

            ProcessInstance processInstance = ksession.getProcessInstance(pid);

            ksession.signalEvent(signal, data, pid);

            System.out.println(processInstance.getState());

             

            I just don't know why signalEvent() can put process into complete state when persistence is disabled and leave process in active state when persistence is enabled.

            Is there any extra steps to be taken when persistence is enabled?

            • 3. Re: Re: Re: How to complete a signalled process ?
              James Yu Newbie

              I take one further step by examining nodeinstancelog table.

              Please refer to the following observation in case you need more information.

               

              for process instance #15 that completes properly, the node instance id is in perfect mirror.

              eg. 0 -> 1 -> 2 -> 3 -> 3 -> 2 -> 1 -> 0

              where node id #3 appears twice

               

              for process instance #16 that remains active but is actually completed, the node instance id has one node id missing.

              eg. 0 -> 1 -> 2 -> 3 -> 2 -> 1 -> 0

              where node id #3 only appears once

              2014-09-09_162313.png

              • 4. Re: How to complete a signalled process ?
                Maciej Swiderski Master

                the problem with your code is that you don't register logger on your ksession and that's why processinstancelog table does not have log records while processinstance is actually completed.

                 

                I would recommend using RuntimeManager based code to avoid such issues. See jbpm docs for details about both JPA db logger on ksession and runtime manager.

                 

                HTH

                1 of 1 people found this helpful
                • 5. Re: How to complete a signalled process ?
                  James Yu Newbie

                  Thank you Maciej,

                   

                  In jbpm docs, I see there is a JPAWorkingMemoryDbLogger. (Chapter 8. Core Engine: Persistence and transactions)

                  When I try to find a logger for real DB (not in memory DB), I cannot find one.

                  Do you mind to provide an example or relative document link?

                  • 6. Re: How to complete a signalled process ?
                    Maciej Swiderski Master

                    same logger shall be used regardless of the data base type. The name is WorkingMemory and not MemoryDB

                     

                    HTH