3 Replies Latest reply on Mar 10, 2014 5:49 AM by salaboy21

    Async workitem handler not working in jbpm 6.0.1?

    eilagar

      I need to verify a use case where the manaul task is completed asyncronously. As suggested in the documentation and several posts I have done the following. However when the completeWorkItem is called in the inner thread an IlleagelState exception is thrown. Seems like the runtime of the orignal process and the runtime of the thread in which the task is trying to be completed are different which is not acceptable to JBPM.

       

      Help? I have attached the complete project which has a junit for async as well as sync workhandler. Also attached is the exception trace.

       

      Thanks

      /Munish

       

       

      com.top.benchmark.test;

      org.kie.api.runtime.manager.RuntimeEngine;

      org.kie.api.runtime.process.WorkItem;

      org.kie.api.runtime.process.WorkItemHandler;

      org.kie.api.runtime.process.WorkItemManager;

       

      class AsyncMockManualTaskHandler implements WorkItemHandler {

      private RuntimeEngine runtime;

      public AsyncMockManualTaskHandler(RuntimeEngine runtime) {

      this.runtime = runtime;

      @Override

      public void abortWorkItem(WorkItem arg0, WorkItemManager arg1) {

      // We do not need to do this.}

      public static final String EXECUTION_ID = "executionId";

      @Override

      public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

      new AsyncTaskCompleter(workItem, runtime).start();

      }

       

      class AsyncTaskCompleter extends Thread {

      private RuntimeEngine runtime;

      workItem = null;

      public AsyncTaskCompleter(WorkItem workItem, RuntimeEngine runtime) {

      this.runtime = runtime;

      this.workItem = workItem;


       

      @Override


      public void run() {

         runtime.getKieSession().getWorkItemManager().completeWorkItem(workItem.getId(), null);

      }

       

       


       







        • 1. Re: Async workitem handler not working in jbpm 6.0.1?
          salaboy21

          Hi Munish,

          If you are planning to work with Manual tasks, why are you involving a thread into the mix?

          If it is a manual task you can just create an application that loads the right workItemId and then complete it when the manual task is ready.

          HTH

          • 2. Re: Async workitem handler not working in jbpm 6.0.1?
            eilagar

            Hi Mauricio,

             

            Thanks for the prompt rely. Can you point me to an example how I can do it propery?

             

            /Munish

            • 3. Re: Async workitem handler not working in jbpm 6.0.1?
              salaboy21

              Well it really works as human tasks are working just simpler.

              Try to create an example of the following:

              1) A process with a manual task in it

              2) register the ManualTaskWorkItemHandler to the kie session

              3) the ManualTaskWorkItemHandler in the execute method it needs to register somewhere (probably your own data storage/db/file/etc) that a manual task is pending and inside it needs to store the workItemId that is associated with that task

              4) when the manual task is completed just pick the workItemId that you have stored and using the kiesession.getWorkItemManager().completeWorkItem method complete the work item with the correspondent outputs.

               

              No threads involved.. keep it as simple as possible and share your problems if you find them

               

               

              HTH