8 Replies Latest reply on Apr 9, 2008 10:42 AM by kukeltje

    taskInstance.cancel() still fires events

    dleerob

      Hi,

      When I call taskInstance.cancel(), it still fires any task-end events etc.
      When cancelling a task instance, I would assume that any task instance events should not be fired. But I see in the code that the cancel() method still calls end(), which in turn fires the events.

      I dont want these events to be fired if I cancel a task instance.
      Is there any way I can stop these events from being fired when cancelling? Perhaps temporarily remove events for that task instance before calling cancel() ?

      Any ideas?

        • 1. Re: taskInstance.cancel() still fires events
          olivier_debels

          We extended taskInstance with an abort(), which does the same as cancel() but doesn't fire events and doesn't signal the token.

          We use this in a number of use cases. For example we have situations where user want to merge two task instance in different process instances. The use initially thought he would do the job in two separate tasks, but decides afterwards to do it in a single one. In this case we want to abort the second process instance and all task instances it contains.

          • 2. Re: taskInstance.cancel() still fires events
            dleerob

            Thanks Olivier...you always come back with useful info/ideas.

            How do you get Jbpm to make use of your extended TaskInstance class, instead of using the original TaskInstance class?

            • 3. Re: taskInstance.cancel() still fires events
              olivier_debels

              Our custom task instance subclasses the jbpm task instance, we also provide a custom hibernate mapping (again extending the one of jbpm).

              We created a custom TaskInstanceFactory (which creates our custom task instance) and made sure jbpm is using this one. You can set override this setting in jbpm.cfg.xml.


              <bean name="jbpm.task.instance.factory" class="???.task.factory.CustomTaskInstanceFactory" singleton="true" />
              


              This is also described somewhere in the jbpm documentation.

              • 4. Re: taskInstance.cancel() still fires events
                dleerob

                Thanks for your time.

                Hopefully an "abort" method will be added to JBPM in a future release. :)

                • 5. Re: taskInstance.cancel() still fires events
                  dleerob

                  I found quite a simple way to make sure a "task-end" event does not get fired when cancelling a task instance. I remove the event, cancel the task instance, and then add the event back.
                  Simply use code similair to the following:

                  taskInstance.setSignalling(false);
                   Task task = taskInstance.getTask();
                   Event endTaskEvent = task.getEvent(Event.EVENTTYPE_TASK_END);
                   if (endTaskEvent != null) {
                   task.removeEvent(endTaskEvent);
                   }
                   taskInstance.cancel();
                   if (endTaskEvent != null) {
                   task.addEvent(endTaskEvent);
                   }


                  It seems to work fine for me. Can anyone see anything wrong with doing it this way? It doesn't seem to update the database with new events or actions or anything, as you are adding back the same event object.

                  • 6. Re: taskInstance.cancel() still fires events
                    olivier_debels

                    Depends what you want.

                    In your case task-end event will not get fired, but the task instance will end and process instance will continue (token will signal). The task-end event will never fire again (since task instance was already added), so adding it again is not needed.

                    If you want your process instance to continue and if you want your task instance to complete, but without events, then this is ok.

                    If you want your process instance to 'abort', and your task instance to 'abort' where you can make a distinction between completed task instances and aborted ones, then this is not ok.

                    • 7. Re: taskInstance.cancel() still fires events
                      jdriver

                      Any possibility of sharing the code for CustomTaskInstanceFactory and extended TaskInstance class?

                      • 8. Re: taskInstance.cancel() still fires events
                        kukeltje

                        if willing to share, please put in on the wiki... would be a nice addition/example