10 Replies Latest reply on Nov 14, 2012 3:36 AM by joploya

    Have a good CDI architecture to use JBPM5

    joploya

      Hello all,

       

      I would be very interested to have your inputs about how you have implemented jbpm5 in a JEE 6 web application using CDI. Wich optimization you made, etc...

       

      For my part I have started to migrate from JBPM3 to JBPM5 and I have done something like this to be abble to use the human task web service :

      UML_Project_Jbpm-Architecture.png

      If you understand well jbpm5.3, please have a look to my diagram and tell me if I am on a wrong way.

       

      Best Regards to all.

        • 1. Re: Have a good CDI architecture to use JBPM5
          salaboy21

          Hi there is already a module that provides a CDI Human Task service: you can find it in the master branch of jBPM:

           

          https://github.com/droolsjbpm/jbpm/tree/master/jbpm-services/jbpm-human-task-services

           

          That will make your life easier.

           

          Cheers

          • 2. Re: Have a good CDI architecture to use JBPM5
            joploya

            Hello Mauricio,

             

            Thank you very much for this information.

            I take a look to your link, download the zip of the master branch and build the jbpm-human-task-service, so I obtain jars. I import them to my project but I am not sure about how to use it, because for what I see a lot of functions are not yet implemented. Is it really usable from now?

            But it will be very usefull, espacially the adminTaskService.

             

            You make a very good job with jbpm.

             

            Regards

            • 3. Re: Have a good CDI architecture to use JBPM5
              salaboy21

              Are you running inside a CDI container?

              If that's true you will be able to inject the services provided by the jars.

              Don't worry about the unimplemented methods. Most of the services are complete and all the unimplemented functionality will come in the next few months. If you need something that is not implemented yet, drop me a line and I will implement that functionality for you.

               

              Cheers

              • 4. Re: Have a good CDI architecture to use JBPM5
                joploya

                Yes I use a CDI container : WELD.

                 

                I inject the TaskServiceEntryPoint to manage tasks without problem. But I don't understand where the link with the web service is done. I haven't found a HornetQ client.

                 

                Also, to check if I understand, I always have to manage by my own the loading of the knowledgeBase and KnowledgeSession to start a new processInstance like below :

                ProcessInstance process = ksession.startProcess("com.st.ams.flow.npl", params);
                

                Then the process go to the next wait step wich is my first humanTask. To complete it I have to retrieve it. This is what I done before :

                                             

                                              BlockingTaskSummaryResponseHandler taskSummaryResponseHandler = new BlockingTaskSummaryResponseHandler();
                                              taskClientProducer.getClient()
                                                                                                .getTasksAssignedAsPotentialOwner(requestor.getName(), groups, "en-UK", taskSummaryResponseHandler);
                                              List<TaskSummary> potentialTasks = taskSummaryResponseHandler.getResults();
                                              TaskSummary requestorTask = null;
                                              for(TaskSummary task : potentialTasks){
                                                        System.out.println("PM_PL can execute task " + task.getName() + " (" + task.getId() + " : " + task.getDescription() + ")");
                                                        if(process.getId() == task.getProcessInstanceId()){
                                                                  System.out.println("The task "+task.getId()+" "+task.getName()+" is the one the requestor have to take");
                                                                  requestorTask = task;;
                                                        }
                                              }
                                              BlockingTaskOperationResponseHandler taskOperationResponseHandler = new BlockingTaskOperationResponseHandler();
                                              taskClientProducer.getClient().claim(requestorTask.getId(), requestor.getName(), groups, taskOperationResponseHandler);
                                              taskClientProducer.getClient().start(requestorTask.getId(), requestor.getName(), taskOperationResponseHandler);
                //                              Thread.sleep(60000);
                                              System.out.println("The PM_PL has well finish his task : call to complete");
                                              taskClientProducer.getClient().complete(requestorTask.getId(), requestor.getName(), null, taskOperationResponseHandler);
                

                And with your API I can do the same with the code below right?                    

                  private @Inject TaskServiceEntryPoint taskService;
                
                                              TaskSummary requestorTask = null;
                                              List<TaskSummary> potentialTasks = taskService.getTasksAssignedAsPotentialOwner(requestor.getName(), groups, "en-UK");
                                              for(TaskSummary task : potentialTasks){
                                                        System.out.println("PM_PL can execute task " + task.getName() + " (" + task.getId() + " : " + task.getDescription() + ")");
                                                        if(process.getId() == task.getProcessInstanceId()){
                                                                  System.out.println("The task "+task.getId()+" "+task.getName()+" is the one the requestor have to take");
                                                                  requestorTask = task;;
                                                        }
                                              }
                                              taskService.claim(requestorTask.getId(), requestor.getName(), groups);
                                              taskService.start(requestorTask.getId(), requestor.getName());
                //                                        Thread.sleep(60000);
                                              System.out.println("The PM_PL has well finish his task : call to complete");
                                              taskService.complete(requestorTask.getId(), requestor.getName(), null);
                

                 

                Is this method getTasksAssignedAsPotentialOwner use the TaskOrm file in the Human-Task-Service jar? Because this TaskOrm use jpa1 instead of jpa2.

                 

                Many thanks in advance for your reply.

                • 5. Re: Have a good CDI architecture to use JBPM5
                  salaboy21

                  Well it depends, how many sessions do you have in your application?

                  We are refactoring some of the services to use CDI, and you can find a couple of examples in the droolsjbpm-knowledge-services project right behind the jbpm-human-task-services inside jbpm-services.

                  One of the tests is doing exactly that, creating a process, attaching a ht work item handler injected by CDI and then executing the process.

                   

                  https://github.com/droolsjbpm/jbpm/blob/master/jbpm-services/droolsjbpm-knowledge-services/src/test/java/org/droolsjbpm/services/test/DomainKnowledgeServiceBaseTest.java#L56

                   

                  There is no need for a transport because everything is running inside weld, do you need to have an external component for running the human tasks? Is that a requirement for your application?

                   

                   

                  All the CDI services can be exposed using Switchyard/Camel, so we are planning to provide support for that in later stages, but it's not there yet.

                  Cheers

                  • 6. Re: Have a good CDI architecture to use JBPM5
                    joploya

                    By "external component for running human task", you means the web service human task? I am not sure to understand your question. I have no requierement for the underlying implementation of human task. My only requierement is to deploy all I need in a single instance of Jboss. But if you don't use the the webservice where is the persistence.xml file to configure to use the good datasource please?

                     

                    In my application I have one session per user and about one hundred users, is it possible to use a unique default StatefullKnowledgeSession regarding this information?

                     

                    Regards,

                    • 7. Re: Have a good CDI architecture to use JBPM5
                      joploya

                      For the persistence.xlm, I was confused between jbpm-human-task-service and the example. I see you configure the persistence in the persistence.xml of the application. It is not my prefered solution because it makes me have multiple persistence units in the same persistence.xml and the web service removed this "problem". But it is not blocking of course.

                       

                      Can I ask why are you still using jpa1? You don't deploy your test on jboss7?

                      • 8. Re: Have a good CDI architecture to use JBPM5
                        salaboy21

                        Instead of having multiple Persistence Unit just have one for your app and the human task services as it is in the example.

                        If you have multiple Persistence Units you will need to use JTA, and if you use the web services option you will not have transaction support for that services. Using one single Persistence Unit will make it easy to run everything in the same transaction without using two phase commits.

                         

                        Cheers

                        • 9. Re: Have a good CDI architecture to use JBPM5
                          salaboy21

                          About JPA2, it should be using JPA2 and Hibernate 4 now, can you check that please? where did you see JPA1 inside jbpm-services?

                           

                          Cheers

                          • 10. Re: Have a good CDI architecture to use JBPM5
                            joploya

                            Hello Mauricio,

                             

                            About jpa1, I should make an error,but I say you use jpa1 because of the file : jbpm-services\jbpm-human-task-services\src\main\resources\META-INF\Taskorm.xml

                            wich start with :

                            <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
                                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
                                           version="1.0">
                            

                             

                            And the file jbpm-services\jbpm-human-task-services\src\test\resources\META-INF\persistence.xml

                            <persistence version="1.0"
                                         xmlns="http://java.sun.com/xml/ns/persistence" 
                                         xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
                            

                             

                            About the persistence units :

                             

                            I can't have a unique persistence unit, if human task persistence is manage inside my application. Indeed, I have a lot of mapping objects dedicated to the application that are saved in a database. And I have another database dedicated to jbpm mapping. I don't know for the moment how I will do that without the web service.

                             

                            Regards,