2 Replies Latest reply on Nov 19, 2009 11:04 PM by Al Nadein

    End tasks in a Fork

    Al Nadein Newbie

      My process is a fork with two task nodes and a join.

      I trigger the process to start both tasks and then end each of them.
      During the execution of end() on task 1, the task is being submitted and then immediately re-instantiated. So when the token is at the join, I still have a freshly created task 1 pending in the actor's queue.

      Also, it seems like though 'task-end' is called on the child token, the root token proceeds with 'node-enter' on the same task.

      Here's the process definition:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <process-definition xmlns="" name="parallel.two.sequential.one">
      
       <swimlane name="...">
      ....
       </swimlane>
      
       <start-state name="start">
       <transition to="fork1"></transition>
       </start-state>
      
       <fork name="fork1">
       <transition to="task-node1" name="to-task-1"></transition>
       <transition to="task-node2" name="to-task-2"></transition>
       </fork>
      
       <join name="join1">
       <transition to="task-node3"></transition>
       </join>
      <task-node name="task-node1" >
       <task swimlane="..." name="Task 1" notify="true">
       <controller class="..."/>
       </task>
       <transition to="join1" name="to-the-end"></transition>
       </task-node>
      
       <task-node name="task-node2">
       <task swimlane="..." name="Task 2" notify="true">
       <controller class="..."/>
       </task>
       <transition to="join1" name="to-the-end"></transition>
       </task-node>
      
       <end-state name="end"></end-state>
      </process-definition>



      Here's the snippet of the execution:
      
      ProcessInstance processInstance = new ProcessInstance(processDefinition);
      
      Token token = processInstance.getRootToken();
      assertEquals("start", token.getNode().getName());
      
      token.signal();
      
      Map<String, Token> childTokens = token.getActiveChildren();
      assertTrue(childTokens.size() > 0);
      
      final Iterator<Token> iterator = childTokens.values().iterator();
      Token oneBranchToken = iterator.next();
      TaskMgmtInstance taskManagementInstance = oneBranchToken .getProcessInstance().getTaskMgmtInstance();
      Collection<TaskInstance> taskInstances =
       taskManagementInstance.getUnfinishedTasks(oneBranchToken );
      TaskInstance taskInstance = taskInstances.iterator().next();
      taskInstance.end();
      
      jbpmContext.save(processInstance);
      


      Here's the debug log snippet that shows task 1 being submitted and then immediately initialized again:

      08:48:11,091 DEBUG|main|: [GraphElement:fireEvent:179] event 'after-signal' on StartState(start) for Token(/)
      08:48:11,091 DEBUG|main|: [GraphElement:fireEvent:179] event 'task-end' on Task(Task 1) for Token(/to-task-1)
      08:48:11,091 DEBUG|main|: [Controller:submitTaskVariables:23] -------------current node::Task 1
      08:48:11,091 DEBUG|main|: [GraphElement:fireEvent:179] event 'before-signal' on Fork(fork1) for Token(/)
      08:48:11,091 DEBUG|main|: [GraphElement:fireEvent:179] event 'node-leave' on Fork(fork1) for Token(/)
      08:48:11,091 DEBUG|main|: [GraphElement:fireEvent:179] event 'transition' on Transition(to-task-1) for Token(/)
      08:48:11,091 DEBUG|main|: [GraphElement:fireEvent:179] event 'node-enter' on TaskNode(task-node1) for Token(/)

      08:48:11,107 DEBUG|main|: [Controller:initializeTaskVariables:17] -------------current node::Task 1
      08:48:11,107 DEBUG|main|: [GraphElement:fireEvent:179] event 'task-create' on Task(Task 1) for Token(/)
      08:48:11,107 DEBUG|main|: [TaskInstance:setActorId:258] assigning task 'Task 1' to 'analyst'
      08:48:11,107 DEBUG|main|: [GraphElement:fireEvent:179] event 'task-assign' on Task(Task 1) for Token(/)
      08:48:11,107 DEBUG|main|: [GraphElement:executeAction:271] executing Action(Task 1)
      08:48:11,107 DEBUG|main|: [Token:lock:748] token[2489] is locked by token[2489]
      08:48:11,107 DEBUG|main|: [Mail:send:189] skipping mail because there are no recipients
      08:48:11,122 DEBUG|main|: [Token:unlock:765] token[2489] is unlocked by token[2489]


        • 1. Re: End tasks in a Fork
          Santanu Saraswati Novice

          Hi Alla,
          I am not able to reproduce the problem. This is Jpdl I executed:

          <?xml version="1.0" encoding="UTF-8"?>
          
          <process-definition xmlns="" name="parallel.two.sequential.one">
          
           <swimlane name="alla" />
          
           <start-state name="start">
           <transition to="fork1"></transition>
           </start-state>
          
           <fork name="fork1">
           <transition to="task-node1" name="to-task-1"></transition>
           <transition to="task-node2" name="to-task-2"></transition>
           </fork>
          
           <task-node name="task-node1" >
           <task name="Task 1" swimlane="alla">
           </task>
           <transition to="join1" name="to-the-end"></transition>
           </task-node>
          
           <task-node name="task-node2">
           <task name="Task 2" swimlane="alla">
           </task>
           <transition to="join1" name="to-the-end"></transition>
           </task-node>
          
           <join name="join1">
           <transition to="end"></transition>
           </join>
          
           <end-state name="end"></end-state>
          </process-definition>
          


          And after execution of task1 when I ask for the current unfinished tasks I get task2 only. Below is the log I am getting:

          09:12:55,546 DEBUG GraphElement:170 - event 'task-end' on 'Task(Task 1)' for 'Token(/to-task-1)'
          09:12:55,546 DEBUG GraphElement:170 - event 'task-end' on 'Task(Task 1)' for 'Token(/to-task-1)'
          09:12:55,546 DEBUG TaskInstance:484 - completion of task 'Task 1' results in taking the default transition
          09:12:55,546 DEBUG TaskInstance:484 - completion of task 'Task 1' results in taking the default transition
          09:12:55,546 DEBUG GraphElement:170 - event 'before-signal' on 'TaskNode(task-node1)' for 'Token(/to-task-1)'
          09:12:55,546 DEBUG GraphElement:170 - event 'before-signal' on 'TaskNode(task-node1)' for 'Token(/to-task-1)'
          09:12:55,546 DEBUG GraphElement:170 - event 'node-leave' on 'TaskNode(task-node1)' for 'Token(/to-task-1)'
          09:12:55,546 DEBUG GraphElement:170 - event 'node-leave' on 'TaskNode(task-node1)' for 'Token(/to-task-1)'
          09:12:55,562 DEBUG GraphElement:170 - event 'transition' on 'Transition(to-the-end)' for 'Token(/to-task-1)'
          09:12:55,562 DEBUG GraphElement:170 - event 'transition' on 'Transition(to-the-end)' for 'Token(/to-task-1)'
          09:12:55,562 DEBUG GraphElement:170 - event 'node-enter' on 'Join(join1)' for 'Token(/to-task-1)'
          09:12:55,562 DEBUG GraphElement:170 - event 'node-enter' on 'Join(join1)' for 'Token(/to-task-1)'
          09:12:55,562 DEBUG Join:115 - forcing version increment on parent token Token(/)
          09:12:55,562 DEBUG Join:115 - forcing version increment on parent token Token(/)
          Hibernate: update JBPM_TOKEN set VERSION_=? where ID_=? and VERSION_=?
          09:12:55,578 DEBUG Join:206 - join will not yet reactivate parent: found concurrent token 'Token(/to-task-2)'
          09:12:55,578 DEBUG Join:206 - join will not yet reactivate parent: found concurrent token 'Token(/to-task-2)'
          09:12:55,578 DEBUG GraphElement:170 - event 'after-signal' on 'TaskNode(task-node1)' for 'Token(/to-task-1)'
          09:12:55,578 DEBUG GraphElement:170 - event 'after-signal' on 'TaskNode(task-node1)' for 'Token(/to-task-1)'

          I see nothing abnormal there as well.


          • 2. Re: End tasks in a Fork
            Al Nadein Newbie

            Finally have figured out the problem: dropped token.signal() from my custom controller's submitTaskVariables.

            Thanks for help, Santanu, really appreciate that.