9 Replies Latest reply on May 28, 2012 1:52 AM by gigazhang

    0 With jBPM5,the process can not continue successful

    houxiaojun

        In jBPM5,when i start several process in one StatefulKnowledgeSession,the process and the task in it will be successfully continued.however,if i start several processinstance with different StatefulKnowledgeSession,when i complete task,the tasks behind it will not be created.

             So i want to know if i need to create process instances in one session even different user want to create processinstance in different time and different place.Does someone know?HELP!!!

        • 1. Re: 0 With jBPM5,the process can not continue successful
          wwweeii

          I met the same problem too! Is there anyone knows it?

          • 2. Re: 0 With jBPM5,the process can not continue successful
            houxiaojun

            Here is the code,hoping this can help you :

            public static final void main(String[] args) {

                    try {

             

                        // load up the knowledge base

                        KnowledgeBase kbase = readKnowledgeBase();

                        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                        StatefulKnowledgeSession ksession2 = kbase.newStatefulKnowledgeSession();

                        KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);

                        ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());

                        ksession2.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());

                        // start a new process instance

                        Map<String, Object> params = new HashMap<String, Object>();

                        params.put("employee", "krisv");

                        ksession.startProcess("com.sample.evaluation", params);

                        ksession2.startProcess("com.sample.evaluation", params);

                        //logger.close();

                    } catch (Throwable t) {

                        t.printStackTrace();

                    }

                }

             

                private static KnowledgeBase readKnowledgeBase() throws Exception {

                    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

                    kbuilder.add(ResourceFactory.newClassPathResource("Evaluation.bpmn"), ResourceType.BPMN2);

                    return kbuilder.newKnowledgeBase();

                }

            I created two session here,when i run it ,two processinstance was created,and there are two tasks for user "krisv"未命名.jpg

            i can complete the first task successfully,and the continued tasks was created too like this:

             

            [2011:05:149 14:05:344:debug] Arguments : [org.jbpm.task.Task@b1e211a8]

            [2011:05:149 14:05:423:debug] Message receieved on client : AddTaskResponse

            [2011:05:149 14:05:423:debug] Arguments : [3]

            [2011:05:149 14:05:423:debug] Message receieved on client : AddTaskResponse

            [2011:05:149 14:05:423:debug] Arguments : [4]

             

            however,when i complete the second task in the above picture,the result is like this:

            [2011:05:149 14:05:357:debug] Message receieved on client : GetTaskResponse

            [2011:05:149 14:05:357:debug] Arguments : [org.jbpm.task.Task@ce8b1e7d]

            [2011:05:149 14:05:420:debug] Message receieved on client : GetTaskResponse

            [2011:05:149 14:05:420:debug] Arguments : [org.jbpm.task.Task@ce8b1e7d]

            [2011:05:149 14:05:421:debug] Message receieved on client : GetTaskResponse

            [2011:05:149 14:05:421:debug] Arguments : [org.jbpm.task.Task@ce8b1e7d]

            [2011:05:149 14:05:421:debug] Message receieved on client : GetTaskResponse

            [2011:05:149 14:05:421:debug] Arguments : [org.jbpm.task.Task@ce8b1e7d]

             

            there are no AddTaskResponse,and the continued tasks can not be created.

            • 3. Re: 0 With jBPM5,the process can not continue successful
              salaboy21

              HI Xiaojun,

              In this case both tasks wil be created, That's fine. The problem is that your main() method will die along with the sessions right?

              The sessions will not be notified about the task completion, for that reason your process will not continue to the next steps.

              For this reason we usually configure the session with a persistence mechanism that allows us to restore the status of the session from a different thread and notify it when a task was completed. You should also need to consider using CommandBasedWSHumanTaskHandler instead of WSHumanTaskHandler if you are planing to use persistence.

              By the way who is starting the Human Task Server? are you getting some error?

              Cheers

              • 4. Re: 0 With jBPM5,the process can not continue successful
                houxiaojun

                Thank you very much for your response!The human task server is started in another class ,so i didn't get errors in this part.

                Can you give me more advice if i want to achive that different users start their own process instance of one process in different place and different time,or i can say in different class.

                • 5. Re: 0 With jBPM5,the process can not continue successful
                  salaboy21

                  You have different options, please take a look at the persistence configurations inside the official documentation to understand how to work with it.

                  You need to think how to maintain your session live in a global scope or how to restore it before interacting with a human task. Doing that you will be sure that your session will be notified by the human task server when the task is completed.

                  You can also take a look at the examples provided here:

                  https://github.com/Salaboy/Drools_jBPM5-Training-Examples

                  and here

                  https://github.com/esteban-aliverti/JBPM-Samples

                  Both repositories are part of a community training about jBPM that we are creating and improving here:

                  http://salaboy.wordpress.com/2011/01/24/announcing-jbpm5-community-training/

                  Cheers

                  • 6. Re: 0 With jBPM5,the process can not continue successful
                    houxiaojun

                    So in order to achive the requirement above,different session will be ok,or i have to use the same session to start different processinstance?

                     

                    By the way,when you say the session persistence configurations do you mean the sessioninfo table in the database?

                    • 7. Re: 0 With jBPM5,the process can not continue successful
                      salaboy21

                      You can use both approaches, both should work:

                      1) One Session -> Multiple Processes

                      2) Multi Sessions -> One process

                       

                      By Persistence Configurations I mean sessions and processes persistence configurations
                      http://docs.jboss.org/jbpm/v5.0/userguide/ch08.html

                      http://docs.jboss.org/drools/release/5.2.0.CR1/drools-expert-docs/html_single/index.html#d0e2697

                       

                      Cheers

                      • 8. Re: 0 With jBPM5,the process can not continue successful
                        houxiaojun

                        I finished the persistence configurations according to the user guide of jbpm5.And my database has the sessioninfo,processinstanceinfo tables ,etc.Below is my test code:

                        public static void main(String[] args){

                               

                               

                                try {

                                    PoolingDataSource ds = new PoolingDataSource();

                                    ds.setUniqueName("jdbc/testDS");

                                    ds.setClassName("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");

                                    ds.setMaxPoolSize(3);

                                    ds.setAllowLocalTransactions(true);

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

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

                                    ds.getDriverProperties().put("URL", "jdbc:mysql://localhost:3306/jbpm5");

                                    ds.init();

                                   

                         

                                    // load up the knowledge base

                                    KnowledgeBase kbase = readKnowledgeBase();

                                    // start a new process instance

                                    EntityManagerFactory emf = Persistence

                                            .createEntityManagerFactory("org.jbpm.persistence.jpa");

                                    Environment env = KnowledgeBaseFactory.newEnvironment();

                                    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY,

                                            emf);

                                    env.set(EnvironmentName.TRANSACTION_MANAGER,

                                            TransactionManagerServices.getTransactionManager());

                                    // create a new knowledge session that uses JPA to store the runtime

                                    // state

                                    StatefulKnowledgeSession ksession=null;

                                    ksession= JPAKnowledgeService.newStatefulKnowledgeSession(

                                            kbase,

                                            null,

                                            env);

                                   

                                    JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger(ksession);

                                    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());

                                    // start a new process instance

                                    Map<String, Object> params = new HashMap<String, Object>();

                                    params.put("employee", "krisv");

                                    ksession.startProcess("com.sample.evaluation", params);

                                   

                                   

                                   logger.dispose();

                               

                                } catch (Throwable t) {

                                    t.printStackTrace();

                                }

                            }

                         

                            private static KnowledgeBase readKnowledgeBase() throws Exception {

                                KnowledgeBuilder kbuilder = KnowledgeBuilderFactory

                                        .newKnowledgeBuilder();

                                kbuilder.add(ResourceFactory.newClassPathResource("Evaluation.bpmn"),

                                        ResourceType.BPMN2);

                                return kbuilder.newKnowledgeBase();

                            }

                        The first time i run the code,the processinstance and the tasks are created successfully.But when i run it second time ,exception was occured just like this:

                        javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.persistence.jpa] Unable to build EntityManagerFactory

                            at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)

                            at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)

                            at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)

                            at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)

                            at com.sample.ProcessTest.main(ProcessTest.java:67)

                        Caused by: org.hibernate.HibernateException: Could not obtain BTM transaction manager instance

                            at org.hibernate.transaction.BTMTransactionManagerLookup.getTransactionManager(BTMTransactionManagerLookup.java:50)

                            at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:357)

                            at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)

                            at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)

                            at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)

                            ... 4 more

                        Caused by: java.lang.reflect.InvocationTargetException

                            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                            at java.lang.reflect.Method.invoke(Method.java:597)

                            at org.hibernate.transaction.BTMTransactionManagerLookup.getTransactionManager(BTMTransactionManagerLookup.java:47)

                            ... 8 more

                        Caused by: bitronix.tm.utils.InitializationException: cannot open disk journal

                            at bitronix.tm.BitronixTransactionManager.<init>(BitronixTransactionManager.java:59)

                            at bitronix.tm.TransactionManagerServices.getTransactionManager(TransactionManagerServices.java:43)

                            ... 13 more

                        Caused by: java.io.IOException:The process cannot access the file because another process has locked a portion of the file

                            at java.io.RandomAccessFile.read(Native Method)

                            at java.io.RandomAccessFile.readInt(RandomAccessFile.java:720)

                            at bitronix.tm.journal.TransactionLogHeader.<init>(TransactionLogHeader.java:77)

                            at bitronix.tm.journal.TransactionLogAppender.<init>(TransactionLogAppender.java:50)

                            at bitronix.tm.journal.DiskJournal.open(DiskJournal.java:132)

                            at bitronix.tm.BitronixTransactionManager.<init>(BitronixTransactionManager.java:46)

                            ... 14 more

                         

                         

                        I do not know what happened above,can you help me out?Waiting for your response,thank you!!

                        • 9. Re: 0 With jBPM5,the process can not continue successful
                          gigazhang

                          there's much more masses...