9 Replies Latest reply on Jan 11, 2013 7:37 AM by garethed

    Process Session ID always 0 in database

    garethed

      Hello,

       

      I am starting a jbpm process using the following code:

       

       

                          KnowledgeBase kbase = readKnowledgeBase(); 

                          StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

       

       

                          AsyncHornetQHTWorkItemHandler workItemHandler = new AsyncHornetQHTWorkItemHandler(ksession);

       

                          workItemHandler.setIpAddress("10.0.0.101");

       

                          ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);

       

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

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

       

                          ksession.startProcess("defaultPackage.YesNo",params);

       

       

      The first time through the process works fine.

      Running the process again seems to log the results from the previous run through and throws an exception.

       

      8    03/01 16:13:41,694[Thread-1] ERROR service.hornetq.HornetQTaskClientConnector.run  - Client Exception with class class org.jbpm.task.service.hornetq.HornetQTaskClientConnector$1 using port 5153

      java.lang.ClassCastException: org.jbpm.process.workitem.wsht.AsyncGenericHTWorkItemHandler$TaskAddedHandler cannot be cast to org.jbpm.task.service.TaskClientHandler$GetTaskResponseHandler

                at org.jbpm.task.service.TaskClientHandler.messageReceived(TaskClientHandler.java:75)

                at org.jbpm.task.service.hornetq.HornetQTaskClientHandler.messageReceived(HornetQTaskClientHandler.java:56)

                at org.jbpm.task.service.hornetq.HornetQTaskClientConnector$1.run(HornetQTaskClientConnector.java:122)

                at java.lang.Thread.run(Thread.java:722)

      Verified

      Verified:true

       

      If I drop the jbpm5 schema and recreate it then it works fine again.

      From looking in the task table I see that the processsessionid is always 0.

      I'm using postgres as my database but I don't think that is the problem.

       

      I am creating the session on a different machine to the server that is running jBoss for development purposes if that makes a difference.

       

      Thinking about it, Surely I need to request a session from the server somehow as how will it know anything about other session ids in the database?

        • 1. Re: Process Session ID always 0 in database
          swiderski.maciej

          there are two issue with the code you use:

          1. you create session that is not persisted and thus process instances are not persisted either and if you create session for every process instance this is probably the reason of having process instance id 0

          2. when using HornetQ task client and connecting clients in parallel meaning more than one at the same time (that does not have to mean they will be active at the same time but rather they are connected) you need to ensue that each client is uniquely identified

           

          so for issue 1 you should use JPAKnowledgeService to create/load session and that will ensure you processes are stored in db too. for issue 2 you use pass unique name each time you create AsynHornetQHTWorkItemHandler.

           

          HTH

          1 of 1 people found this helpful
          • 2. Re: Process Session ID always 0 in database
            garethed

            Ahh.  I'm assuming that the jbpm-console is set up in this way.  I will be deploying another war file that will be responsible for running sessions and providing restful services for interaction with the human tasks.  Is there a way to get hold of a session from the console-server as this is already configured for persistence to the database?

             

            Gareth.

            • 3. Re: Process Session ID always 0 in database
              garethed

              Hi,

               

              I am now using the JPAKnowledgeService to create/Load sessions and they are now persisted.  As for point 2.  My application will have more than one instance of a process live at any one time. Do I need a new AsynHornetQHTWorkItemHandler for each process instance? I seem to remember there being an issue with the handler if it is not named "Human Task" does this make sense?

              I will continue reading the jBPM5 Developer Guide book but I would appreciate some guidance.  I want to make sure I can potentially have more than one knowledge base at a time, each running several instances of several processes all persisted.

               

              Thanks in advance,

               

              Gareth.

              • 4. Re: Process Session ID always 0 in database
                swiderski.maciej

                Human Task must be used when you registering handler on the work item manager that belongs to the session. I was referring to the name of the HornetQConnector that is created for AsyncHornetQHTWorkItemHandler. This class has alternative constructor that allows you to specify connector name, which might help where.

                 

                Of course you can have more than one knowledge base and knowledge session in your system.

                 

                HTH

                • 5. Re: Process Session ID always 0 in database
                  garethed

                  Thank you.

                   

                  Would this also work?

                   

                           AsyncHornetQHTWorkItemHandler workItemHandler = new AsyncHornetQHTWorkItemHandler(ksession);

                           workItemHandler.setConnectorName("Hornet" + sessionId);

                   

                  Gareth.

                  • 6. Re: Process Session ID always 0 in database
                    swiderski.maciej

                    I believe the use of setter is already too late because as part of constructor the connector is created.

                     

                    HTH

                    • 7. Re: Process Session ID always 0 in database
                      garethed

                      The other constructor

                      AsyncHornetQHTWorkItemHandler(String connectorName, AsyncTaskService client, KnowledgeRuntime session, OnErrorAction action)

                       

                      requires a client.

                       

                      Do I also need to create a client to talk to the HumanTask service?

                       

                      Gareth.

                      • 8. Re: Process Session ID always 0 in database
                        swiderski.maciej

                        you could use this:

                         

                        new AsyncHornetQHTWorkItemHandler(new AsyncHornetQTaskClient(this.connectorName), ksession, OnErrorAction.LOG)

                         

                        HTH

                        • 9. Re: Process Session ID always 0 in database
                          garethed

                          That did the trick, Thanks a lot!

                           

                          Gareth.