9 Replies Latest reply on Dec 3, 2012 5:45 AM by Thomas Setiabudi

    Create Custom Implementation for Human Task WorkItemHandler, Which class I should extend?

    Thomas Setiabudi Expert

      Hi,

       

      I use JBPM5.4 Full installer, my Human Task Server that comes with the installer is using HornetQ.

       

       

      I have a requirement where I need to get data from other application just before a human task is created. This data will be saved inside the newly created human task.

       

      Currently, my idea is to make a custom implementation for Human Task WorkItemHandler and register it to the console's CustomWorkItemHandlers.conf like this:

       

      [
        "Log": new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler(),
        "Human Task": new my.custom.human.task.CustomHTWorkItemHandler(),
      ]
      
      

       

      My questions are:

      1. By doing it this way, will the console use my custom implementation whenever a human task needs to be created?

       

      2. Because I just want to get data before task is created and add that data on the task, that means all the implementation of default Human Task Work Item Handler should be the same, I think I can just extend the existing class, but which one? I got confused to choose which class that I should extend: GenericHTWorkItemHandler? AsyncGenericHTWorkItemHandler? AbstractHTWorkItemHandler? HornetQHTWorkItemHandler? AsyncHornetQHTWorkItemHandler? or maybe some other class?

       

       

      Any help is appreciated.

       

       

      Regards,

      Thomas Setiabudi

        • 1. Re: Create Custom Implementation for Human Task WorkItemHandler, Which class I should extend?
          Newbie

          Human tasks are added through the default.session.template property file that is baked into console server.  You can override this using your own session.template file, which you need to put in an appropriate location (JBoss conf directory I think?).

           

          Human tasks need the knowledge session injected, so they added this functionality.  You can add your own human task implementations this way too.

           

          The latest implementation to look at is

          AsyncHornetQHTWorkItemHandler or AsyncMinaHTWorkItemHandler.  They keep deprecating classes so it is hard to keep up.  These use the AsyncGenericHTWorkItemHandler and AbstractHTWorkItemHandler in its type hierarchy.  Once you get what they are doing, you can write a similar one that suits your needs.

          • 2. Re: Create Custom Implementation for Human Task WorkItemHandler, Which class I should extend?
            Thomas Setiabudi Expert

            Hi Timothy Charman,

             

            Thank you for your response, I still cannot find the session.template file, where it should be?

             

            Regards,

            Thomas Setiabudi

            • 3. Re: Create Custom Implementation for Human Task WorkItemHandler, Which class I should extend?
              Newbie

              default.session.template is in console-server code in src/main/resources.  It looks like this:

              new SessionTemplate().{ 

                  businessKey = "jbpm/consolesession",

                  imported = false,

                  persistenceUnit = "org.jbpm.persistence.jpa",

                 

                  properties = ["drools.processInstanceManagerFactory":"org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory",

                                "drools.processSignalManagerFactory" : "org.jbpm.persistence.processinstance.JPASignalManagerFactory" 

                                  ],

                                 

                  workItemHandlers = ["Human Task" : "new org.jbpm.process.workitem.wsht.AsyncHornetQHTWorkItemHandler(\"jbpmConsoleHTHandler\", taskClient, ksession, org.jbpm.task.utils.OnErrorAction.LOG)",

                                      "Service Task" : "new org.jbpm.process.workitem.bpmn2.ServiceTaskHandler(ksession)"],

                                     

                  eventListeners = ["new org.jbpm.process.audit.JPAWorkingMemoryDbLogger(ksession)",

                                    "new org.jbpm.integration.console.listeners.TriggerRulesEventListener(ksession)"  ]

              };

               

              You won't find a session.template unless you create one to override this.

               

              The session template is loaded by the MVELSingleSessionManager.  The code is like this:

                          InputStream templateFile = PropertyLoader.getStreamForConfigFile("/session.template", defaultSessionTemplate);

               

              So it loads the property from the classpath - you just have to pick a place on the classpath .

               

              We gave up with this approach as we have dozens of human type tasks and didn't want to configure them all here, and we wrote our own SessionManager, but it is up to you.

              1 of 1 people found this helpful
              • 4. Re: Create Custom Implementation for Human Task WorkItemHandler, Which class I should extend?
                Thomas Setiabudi Expert

                Hi Timothy Charman,

                 

                I got the file

                jbpm-installer\jboss-as-7.1.1.Final\standalone\deployments\jbpm-gwt-console-server.war\WEB-INF\classes\default.session.template

                 

                Going to try doing my custom implementation now.

                 

                Thank you very much

                 

                Regards,

                Thomas Setiabudi

                • 5. Re: Create Custom Implementation for Human Task WorkItemHandler, Which class I should extend?
                  Thomas Setiabudi Expert

                  By writing your own session manager it means you are creating a custom implementation of jbpm-console?

                   

                  Regards,

                  Thomas Setiabudi

                  • 6. Re: Create Custom Implementation for Human Task WorkItemHandler, Which class I should extend?
                    Newbie

                    No, just the session manager.  There's a hook for contributing your own, see how the session manager instantiates a MVELSingleSessionManager if you don't give it one below.

                     

                    We give it our own so we can add them programmatically rather than using the config file.  Our session manager does what the MVEL one does but doesn't use a template, it adds the task handlers in code.

                     

                     

                     

                        @SuppressWarnings("unchecked")

                        public static SessionManager newSessionManager(KnowledgeBase kbase) {

                            String sessionManager = System.getProperty("jbpm.session.manager");

                            if (sessionManager == null) {

                                return new MVELSingleSessionManager(kbase);

                            }

                           

                            SessionManager sessionManagerInstance = null;

                            try {

                                // build session manager based on given class

                                Class<SessionManager> sessionManagerClass = (Class<SessionManager>) Class.forName(sessionManager);

                                Constructor<SessionManager> c = sessionManagerClass.getConstructor(KnowledgeBase.class);

                                sessionManagerInstance = c.newInstance(kbase);

                            } catch (Exception e) {

                                throw new RuntimeException("Cannot create SessionManager from class " + sessionManager, e);

                            }

                           

                            return sessionManagerInstance;

                        }

                    1 of 1 people found this helpful
                    • 7. Re: Create Custom Implementation for Human Task WorkItemHandler, Which class I should extend?
                      Thomas Setiabudi Expert

                      Thank you for sharing about the Custom Session Manager

                       

                      After you build your own SessionManager, how do you tell JBPM-console to use your custom session manager?

                      • 8. Re: Create Custom Implementation for Human Task WorkItemHandler, Which class I should extend?
                        Newbie

                        I use the hook in the SessionManager (which is really a session manager factory of sorts) code:

                                String sessionManager = System.getProperty("jbpm.session.manager");

                         

                        So in the java arguments I do:

                        -Djbpm.session.manager=com.me.mySessionManager

                        • 9. Re: Create Custom Implementation for Human Task WorkItemHandler, Which class I should extend?
                          Thomas Setiabudi Expert

                          Awesome,

                           

                          Thanks again Timothy Charman. I guess I will need that as my requirements keep growing.

                           

                           

                          Regards,

                          Thomas Setiabudi