1 2 Previous Next 19 Replies Latest reply on Jul 30, 2010 1:56 AM by Felix Jose

    How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.

    Felix Jose Newbie

      Hi All,

       

      I am facing a big problem and my requirement I am giving below. Please anybody help me on the same.

       

      Ours is a web application.We are handling the flow of the application by using JBPM.
      In a web page we are having a result set of 3 sub users and we can select any number of them using the select button.
      If we select 3 of those sub users then it should start 3 JBPM subprocesses for them from the main JBPM process.
      And when that 3 selected users logins to the application from different web browsers  at the same time,then each JBPM subprocess's state nodes
      should be transitioned according to the actions performed by the corresponding users on their respective web sessions/pages.

       

      My doubts are:

      1. How to start/spawn 'n' subprocess depending on the selection of 'n' sub users from the result set.( For each sub user there should be a subprocess)
      2. How to map each subprocess with each selected sub user's Id. This is for transitioning the corresponding subprocess's state nodes when the respective user

       

      I will be grateful to you if you help me.

       

      Thank you and Regards,

      Felix K Jose

        • 1. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
          Felix Jose Newbie

          Hi All,

           

          Please anybody help me on this. I am sorry to disturb you all.

           

           

          Thank You and Regards,

          Felix K Jose

          • 2. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
            Felix Jose Newbie

            Hi All,

             

            I have write a JBPM main process (Request.jpdl.xml) for starting "n" subprocess depending upon the input(number of users) and is given below

             

             

             

             

             

             

             

             

             

             

             

            <java class="com.felix.poc.TestActivity" method="decreaseForkCounter"  name=

            "decreaseForkCounter" var="request" g="570,94,149,40"> 

            <arg> 

            <object expr="#{request}" /> 

            </arg>

            <transition g="-71,-18" name="sendToAssist" to="sendToAssist" />

            </java>

             

            <decision g="250,208,48,48" name="decideForkAgain">

            <handler class="com.felix.poc.ForkAgainHandler" />

            <transition g="274,113:78,-18" name="FORK_AGAIN" to="decreaseForkCounter" />

            <transition g="280,556:172,-23" name="FORK_NOT_AGAIN" to="join1" />

            </decision>

            <fork g="623,207,80,40" name="sendToAssist">

            <transition name="assist" to="assist" g="-16,-16" />

            <transition g="-39,-18" name="decideForkAgain" to="decideForkAgain" />

            </fork>

             

            <sub-process g="753,210,80,40" name="assist" sub-process-key="Assist">

            <ransition g="14,16" name="join1" to="join1" />

            </sub-process>

            <join g="777,529,80,40" name="join1">

            <transition g="-31,-18" name="end" to="theEnd" />

            </join>

             

            I have atttached the same application with this.

             

            But when I am trying to start multiple sub processes I am getting the following exception:

             

            Drecreased fork counter to:2

            2796 [main] INFO com.felix.poc.TestActivity - Drecreased fork counter to:1

            2796 [main] INFO org.hibernate.event.def.DefaultDeleteEventListener - handling transient entity in delete processing

            Fork counter is 1

            2827 [main] INFO com.felix.poc.ForkAgainHandler - Fork counter is 1

            fork again

            2827 [main] INFO com.felix.poc.ForkAgainHandler - fork again

            Drecreased fork counter to:1

            2827 [main] INFO com.felix.poc.TestActivity - Drecreased fork counter to:0

            Fork counter is 0

            2843 [main] INFO com.felix.poc.ForkAgainHandler - Fork counter is 0

            2843 [main] INFO com.felix.poc.ForkAgainHandler - fork finished

            2874 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: -104, SQLState: 23000

            2874 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Violation of unique constraint $$: duplicate value(s) for column(s) $$: SYS_CT_50 in statement [update JBPM4_EXECUTION set DBVERSION_=?, ACTIVITYNAME_=?, PROCDEFID_=?, HASVARS_=?, NAME_=?, KEY_=?, ID_=?, STATE_=?, SUSPHISTSTATE_=?, PRIORITY_=?, HISACTINST_=?, PARENT_=?, INSTANCE_=?, SUPEREXEC_=?, SUBPROCINST_=? where DBID_=? and DBVERSION_=?]

            2874 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session

            org.hibernate.exception.ConstraintViolationException

             

             

            : could not update: [org.jbpm.pvm.internal.model.ExecutionImpl#26]

            at org.hibernate.exception.SQLStateConverter.convert(

            SQLStateConverter.java:94)

            at org.hibernate.exception.JDBCExceptionHelper.convert(

            JDBCExceptionHelper.java:66)

            at org.hibernate.persister.entity.AbstractEntityPersister.update(

            AbstractEntityPersister.java:2453)

            at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(

            AbstractEntityPersister.java:2335)

            at org.hibernate.persister.entity.AbstractEntityPersister.update(

            AbstractEntityPersister.java:2635)

            at org.hibernate.action.EntityUpdateAction.execute(

            EntityUpdateAction.java:115)

            at org.hibernate.engine.ActionQueue.execute(

            ActionQueue.java:279)

            at org.hibernate.engine.ActionQueue.executeActions(

            ActionQueue.java:263)

            at org.hibernate.engine.ActionQueue.executeActions(

            ActionQueue.java:168)

            at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(

            AbstractFlushingEventListener.java:321)

            at org.hibernate.event.def.DefaultFlushEventListener.onFlush(

            DefaultFlushEventListener.java:50)

            at org.hibernate.impl.SessionImpl.flush(

            SessionImpl.java:1027)

            at org.jbpm.pvm.internal.tx.HibernateSessionResource.prepare(

            HibernateSessionResource.java:56)

            at org.jbpm.pvm.internal.tx.StandardTransaction.commit(

            StandardTransaction.java:107)

            at org.jbpm.pvm.internal.tx.StandardTransaction.complete(

            StandardTransaction.java:64)

            at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(

            StandardTransactionInterceptor.java:61)

            at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(

            EnvironmentInterceptor.java:53)

            at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(

            EnvironmentInterceptor.java:40)

            at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(

            RetryInterceptor.java:55)

            at org.jbpm.pvm.internal.svc.SkipInterceptor.execute(

            SkipInterceptor.java:43)

            at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.startProcessInstanceByKey(

            ExecutionServiceImpl.java:70)

            at com.felix.poc.Starter.main(

            Starter.java:31)

            Caused by:

            java.sql.SQLException: Violation of unique constraint $$: duplicate value(s) for column(s) $$: SYS_CT_50 in statement [update JBPM4_EXECUTION set DBVERSION_=?, ACTIVITYNAME_=?, PROCDEFID_=?, HASVARS_=?, NAME_=?, KEY_=?, ID_=?, STATE_=?, SUSPHISTSTATE_=?, PRIORITY_=?, HISACTINST_=?, PARENT_=?, INSTANCE_=?, SUPEREXEC_=?, SUBPROCINST_=? where DBID_=? and DBVERSION_=?]

            at org.hsqldb.jdbc.Util.throwError(Unknown Source)

            at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)

            at org.hibernate.persister.entity.AbstractEntityPersister.update(

            AbstractEntityPersister.java:2435)

            ... 19 more

             

             

            So how can I start the multiple suprocesses? How can I get rid from this exception.

            I am attching the test application with this. Please help me.

             

            Thank you,

            With Regards,

            Felix K Jose

             

             

            So how can I start the multiple suprocesses? How can I get rid from this exception.

            I am attching the test application with this. Please help me.

             

            Thank you,

            With Regards,

            Felix K Jose

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

            • 3. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
              Felix Jose Newbie

              Hi All,

               

              Can anybody please comment on the same? I am expecting a reply.

               

              Regards,

              Felix

              • 4. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
                Al Nadein Newbie

                Hi Felix,

                 

                You might've run into the same issue I had described in https://community.jboss.org/message/544938#544938

                 

                A simple work-around for your issue is to drop a unique constrain on ID_ field in jbpm4_execution

                In my case, I ended up patching pvm's ExecutionImpl.java

                • 5. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
                  Felix Jose Newbie

                  Hi Al Nadein,

                   

                  Thank you very much. I was waiting for a reply for 2 days. At last I got a reply. Thank you.

                   

                  And I have gone through the link you mentioned in the reply. In that you have mentioned a few workarounds and I would like to know which workaround you have used. With the workaround is there any impacts in the other functionalities? Please let me know the exact workaround you used.

                   

                  And as the reply of your discusion Huesheng mentioned a patch and whether it is part of 4.3 or do you tested the same and used. If yes please provide that and if not please send me your patch for removing the unique constraint for ID_ in the JBPM4_EXECUTION table. I have included HuieSheng's Reply below:

                   

                  HuieSheng'sReply.jpg

                  Please send me the exact workaround you have used.

                   

                  And one more doubt do you have an idea why the unique constraint is there for ID_ in the JBPM4_EXECUTION table. If we remove that, will it cause any unwanted outcomes in other functionalities?

                   

                  Once again thanks alot for your reply and help.

                   

                  With Regards,

                  Felix K Jose

                  • 6. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
                    Al Nadein Newbie

                    Hi Felix,

                     

                         A unique constrain for ID_ on JBMP4_EXECUTION is there to ensure that there don't exist more than 1 process with the same id. Since the only client of this database is the pvm (jbpm process virtual machine) and it's designed having this restriction in mind, there is really no harm to drop the constrain. Being a perfectionist, I still think there should be a code fix, rather than relaxation of the data model constrains.

                         The reason of the error is really a bug. A process is created, then a fork is hit, a child process is created. Both operations are done in memory, nothing is being recorded in a database just yet. Then either a wait state or end of a process is hit. At this moment, a system would try to persist the records: there will be 2 records created - one for the main process, another for the child process. 2 insert statements would be issued, both of them will have "ID_" set to null just because at that moment neither of ID_ values has been calculated yet. This is done with the assumption that there will be a calculation of ID_ values and the updates will be issued immediately in the same transaction. But in this setup, updates have no chance to be issued since the transaction fails to insert the second record due to a duplicate ID_ value, i.e. null. The question is why not to calculate ID_ value upfront and make a single insert instead of insert and then update.

                         I did work with HuieSheng to identify and resolve the bug, but then was pulled into some other things and didn't have a chance to follow up on her patch. In short, my project is in production with my patch. Will try to fetch it for you shortly.

                     

                    Also, wanted to say huge thanks for your process sample: creating an arbitrary number of subprocesses is something I've been trying to do for a while.

                    • 7. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
                      Al Nadein Newbie

                      One more thing: the unique constrain problem doesn't depend on the type of the database. I'm sure one can run into it using in-memory db too. It's all about the JBPM4_EXECUTION table definition, i.e. the unique constrain on ID_ field.

                      • 8. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
                        Maciej Swiderski Master

                        You are looking for something like for-each activity that is of type multi instance. It is part of 4.4 release that is coming out in few days.

                        Based on the input (given as list, array, etc) it will create new instances of the activity which is following the for-each. Below you can find a code snippet that illustrates it:

                         

                         

                           <foreach var="department" in="#{departments}" g="111,60,48,48" name="foreach">
                              <transition to="Collect data"/>
                           </foreach>
                           <task candidate-groups="#{department}" g="201,58,92,52" name="Collect data">
                              <transition to="join1"/>
                           </task>
                           <join g="343,59,48,48" multiplicity="#{quorum}" name="join">
                              <transition to="end1"/>
                           </join>
                        

                        In the example there will be a variable of type list available on runtime, let's assume that there will be four departments involved. Foreach will create 4 tasks, one for each department. At the and (join) you can use multiplicity attribute to control the flow, for instance you can say that once 3 departments did collect all data it is enough and process should not wait for the last one.

                         

                        P.S.

                        Search development forum for some details about for each activity

                         

                        HTH

                        • 9. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
                          Felix Jose Newbie

                          Hi Maciej,

                           

                          Can you please let me know when will 4.4 version release. Is there any deadline for that, like July 25th or something like that. Because we cannot use the snapshot version and I am waiting for the 4.4 stable release. Can you please provide me the information.

                           

                          Thank You,

                           

                          With Regards,

                          Felix  Jose

                          • 11. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
                            Al Nadein Newbie

                            Michael,

                             

                            Thanks! The release has been quite timely for my project.

                             

                            Regarding the pattern: foreach is indeed great to have. At the same time, are you sure it will work for subprocesses? Seems that foreach would hang to wait until a first created subprocess is complete. Also, what about the case when we need to create two different subprocesses at the same node in the graph?

                            • 12. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
                              Maciej Swiderski Master

                              In general for each will create execution for each item in the collection sequentially. It can be changed the same way as for fork activity - by introducing async continuation. So that should the trick.

                               

                              If you would like to handle different execution within for each, I must say that this is not possible, since for each supports only one out going transition.

                              • 13. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
                                Al Nadein Newbie

                                swiderski.maciejMaciej,

                                 

                                Thanks for a prompt reply. I was able to achieve what i wanted.

                                 

                                Here's my sample process:

                                {code:xml}

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

                                 

                                <process key="main" name="main" xmlns="http://jbpm.org/4.4/jpdl">
                                  
                                   <start g="-7,25,48,48" name="start">
                                      <transition g="-28,-16" name="to-open-case" to="Open Case"/>
                                   </start>
                                  
                                   <foreach g="254,18,48,48" in="#{events}" name="foreach" var="event">
                                      <transition to="Create a sub-process"/>
                                   </foreach>
                                  
                                   <custom g="96,16,126,52" name="Open Process">
                                      <transition g="-30,-34" name="to-create-subprocesses" to="foreach"/>
                                   </custom>


                                   <join g="490,18,48,48" multiplicity="#{quorum}" name="join">
                                      <transition g="-11,-14" name="to-end" to="end"/>
                                   </join>


                                   <end g="570,18,48,48" name="end"/>


                                   <sub-process g="334,16,124,52" name="Create a sub-process" sub-process-key="#{event}">
                                      <transition g="-12,-17" name="to-join" to="join"/>
                                   </sub-process>
                                    
                                </process>

                                {code}

                                 

                                Here's a client:

                                {code}
                                        Map<String, Object> variables = new HashMap<String, Object>();

                                 

                                        String[] events = new String[] { "sub1", "sub2", "sub3" };
                                        variables.put("events", events);
                                        variables.put("quorum", new Integer(events.length)); // join cardinality
                                       
                                        ProcessInstance processInstance = executionService.startProcessInstanceByKey("main", variables, "123");

                                {code}

                                 

                                The problem is - I don't seem to be able cascade delete after that - weather i start from main or any of its children, i'm falling into integrity constrains. The below fails:

                                {code}

                                List<ProcessDefinition> deployments = repositoryService
                                                .createProcessDefinitionQuery().processDefinitionKey("main").list();
                                        for (int i = 0; i < deployments.size(); i++) {
                                            ProcessDefinition pd = deployments.get(i);
                                            repositoryService.deleteDeploymentCascade(pd.getDeploymentId());
                                        }

                                {code}

                                • 14. Re: How to start/spawn 'n' subprocesses for 'n' users using JBPM-4.3.
                                  Al Nadein Newbie

                                  After a little more investigation,

                                   

                                  Cascade delete of the main process and related executions and subprocesses is passing if there are no related records in JBPM4_VARIABLES, i.e. if the process doesn't use process instance variables. Don't see how I can not have process instance variables in my case.

                                  1 2 Previous Next