7 Replies Latest reply on Dec 8, 2015 7:23 PM by Rajiv Dadhich

    JBPM 6.1.0.Final custom human task event listener is not working

    Soumya Bose Newbie

      In JBPM 6.1.0.Final I am trying to put a custom task event listener, so that I can write some of my code on create / complete of a task. I am doing the following -

       

      In my kie project's 'java/src/main' source directory I have created a custom listener class 'CustomBAMTaskEventListener' which extends 'BAMTaskEventListener' class. I have overriten some methods like 'afterTaskActivatedEvent', 'afterTaskAddedEvent', 'afterTaskCompletedEvent' with some print statement. And within kie project's META-INF/kie-deployment-descriptor.xml I have defined this task listener -

       

      <task-event-listeners>

              <task-event-listener>

                  <identifier>new com.cordistech.task.listener.CustomBAMTaskEventListener()</identifier>

              </task-event-listener>

          </task-event-listeners>

       

      But in jbpm while a new task is getting created, this listener class is not picked up. Cant see the print statements in jbpm console log.

       

      Can you please advise how to use my custom HT event listener in jbpm to achieve my requirement ? Any help will be really appreciated.

        • 1. Re: JBPM 6.1.0.Final custom human task event listener is not working
          Maciej Swiderski Master

          there was an issue with task event listeners in 6.1 defined in deployment descriptor that is now solved in 6.2. So best to upgrade. If not possible you can still register event listeners using CDI producers, see docs for details.

           

          HTH

          • 2. Re: JBPM 6.1.0.Final custom human task event listener is not working
            Soumya Bose Newbie

            Thanks for your reply Maciej. Can you please give an example on how to use CDI producers for Task event Listener ? I have seen there are some listeners within jbpm-audit-6.1.0.Final.jar like 'JPATaskLifeCycleEventListener', 'BAMTaskEventListener' e.t.c. which are getting called when a new task is created. Like that listeners If I create a listener class 'CustomTaskLifeCycleEventListener' which implements TaskLifeCycleEventListener interface, then where and how I need to register this class, so that it is also getting called when a new task is created ?

            • 3. Re: JBPM 6.1.0.Final custom human task event listener is not working
              Soumya Bose Newbie

              I have tried to use a producer for Task event listener. I have done the following -

               

              Created a producer class 'EibpTaskEventListenerProducer',

               

              @ApplicationScoped

              @Alternative

              @Selectable

              public class EibpTaskEventListenerProducer implements EventListenerProducer<TaskLifeCycleEventListener> {

               

                  @Override

                  @Produces

                  public List<TaskLifeCycleEventListener> getEventListeners(String identifier, Map<String, Object> params) {

               

                      List<TaskLifeCycleEventListener> taskEventListeners = new ArrayList<TaskLifeCycleEventListener>();

                      taskEventListeners.add(new EibpTaskLifeCycleEventListener());

               

                      return taskEventListeners;

                  }

               

              }

               

              This producer class producing list of listeners with my custom event listener class 'EibpTaskLifeCycleEventListener' which is implementing 'TaskLifeCycleEventListener' interface, where I will be notified when a new task will be created.

               

              I have deployed this producer & listener class as a jar and kept the jar file within jbpm-console's WEB-INF/lib directory. But after server startup, when a new task is created my listener is not picked up.

               

              Can you please advise if I am missing any necessary steps to achieve my requirement ?

              • 4. Re: JBPM 6.1.0.Final custom human task event listener is not working
                Maciej Swiderski Master

                few things:

                • make sure you use org.kie.api.task.TaskLifeCycleEventListener as interface of the events listeners
                • your jar that is placed in WEB-INF/lib must be a bean archive, meaning it must include marker file META-INF/beans.xml
                • @Alternative is not needed as if you use that you must explicitly enable it in beans.xml so I would recommend to remove it
                • @Selectable is not needed at all here

                 

                HTH

                1 of 1 people found this helpful
                • 7. Re: JBPM 6.1.0.Final custom human task event listener is not working
                  Rajiv Dadhich Newbie

                  Just to help others.

                  In case, if you wish to not use CDI, you can extend DefaultRegisterableItemsFactory and override getTaskListeners method to return list with added custom listener.

                       @Override

                      public List<TaskLifeCycleEventListener> getTaskListeners() {

                          List<TaskLifeCycleEventListener> taskListeners = super.getTaskListeners();

                          taskListeners.add(new CustomTaskEventListener());

                          return taskListeners;

                      }

                   

                  Also make sure, you register you new registrableItemsFactory while creating runtime environment.

                  RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault()

                                      .userGroupCallback(userGroupCallback)

                                      .knowledgeBase(kbase)

                                      .addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER,txManager)

                                      .registerableItemsFactory(<customItemsFactory>)

                   

                  Hope this helps!!

                  Thanks.