2 Replies Latest reply on Dec 23, 2008 7:43 AM by romain.lamarche

    Cancelling dynamically created tasks

    redguy666

      Have such case:

      in one task-node I create few tasks for different actors (every one of them has to accept processed document). This is done in node-enter event when entering this task-node.

      I would like to cancel all pending tasks in this node when first of those actors rejects (takes "reject" transition). How to do this?

      When I write handler for task-end event that iterates through pending tasks and calls "cancel" method I get exception that the token is locked...

      simplified example of this proces:

      <process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="Proces">
      
      <start-state name="start">
       <transition to="accept" name="send"/>
      </start-state>
      
      <task-node name="accept" create-tasks="false" signal="last-wait">
       <event type="node-enter">
       <action name="create tasks" class="xxx.CreateAcceptTasks">
       <actorIds>actor1,actor2,actor3,actor4</actorIds>
       </action>
       </event>
       <event type="task-end">
       <action name="is positive?" class="xxx.AcceptTaskEnd">
       </action>
       </event>
       <task name="accept"></task>
       <transition to="accepted" name="accept"></transition>
       <transition to="rejected" name="reject"></transition>
      </task-node>
      
      ...
      
      </process-definition>
      


      xxx.CreateAcceptTasks

      just creates TaskInstances of "accept" Task and assignes them to actors provided in param.

      xxx.AcceptTaskEnd

      ???
      when I tried to fetch pending tasks with executionContext.getTaskMgmtInstance().getTaskInstances()

      and then call "cancel" on every pending tasks (that is not equal to current task of course) - I get "Token locked" exception...

      Any help would be appreciate...

        • 1. Re: Cancelling dynamically created tasks
          kukeltje

           

          when I tried to fetch pending tasks with executionContext.getTaskMgmtInstance().getTaskInstances()


          From where?

          • 2. Re: Cancelling dynamically created tasks
            romain.lamarche

            Hi,

            Try to call setSignaling(false) before call cancel() and it should works.
            The problem is that you call "cancel()" in an event (i think) and the token is locked. And calling cancel make the task to signal the token, which is not what you want, and you can't do this from an event.


            Another way is to add end-task="true" in the task-node (XML definition).
            This will make all tasks not ended to be canceled when the token leave the task-node. So it may not do what you want, because you want to cancel all tasks only when the "reject" transition is taken.