AnsweredAssumed Answered

Custom Multi-instance Service Task

Question asked by jcoveron on Aug 5, 2017

Greetings,

Activiti version: 6.0

 

I am creating a Service Task that extends TaskActivityBehavior class. This is because I need to do a long running job outside Activiti. This works fine.

 

The doubt I have is when configuring this Service Task as a sequential multi instance task. I see that Activiti enters class MultiInstanceActivityBehavior prior to entering my service task, but my service task is only executed once.

 

I also saw that the variables nrOfInstances, nrOfActiveInstances, nrOfCompletedInstances and loopCounter are correctly set. But still, the execute method of my service task is only executed once.

 

Here is the code of the execute method.

 

<code>

@Override
public void execute(DelegateExecution execution) {
   try {
      FileHandler fh = new FileHandler("name", "filename", new FolderHandler());
      execution.setVariable(fh.getName(), fh);
      

      GenericTaskEntity task = new GenericTaskEntity();
      task.setDetails(this.setDetails(fh.getName()));
      task.setExecutionId(execution.getId());
      task.setPriority((int) counter.incrementAndGet());
      task.setProcessDefinitionId(execution.getProcessDefinitionId());
      task.setProcessInstanceId(execution.getProcessInstanceId());
      task.setTenantId(1L);
      task.setType(BehaviorTaskType.TASK1.getType());
      this.tasksQueueService.submit(task);
   } catch (Exception e) {
      this.throwException(execution,
         "There was a problem when trying to execute task '" + BehaviorTaskType.TASK1.toString() + "' "
      );
   }
}

</code>

 

And here is the trigger method:

 

<code>

public void trigger(DelegateExecution execution, String signalName, Object signalData) {
   this.checkSignal(execution);
   leave(execution);
}

</code>

 

And finally, this is how the XML part for the service task looks like:

 

<code>

<serviceTask id="servicetask1" name="Service Task" activiti:delegateExpression="${task1}">
   <multiInstanceLoopCharacteristics isSequential="true">
      <loopCardinality>3</loopCardinality>
   </multiInstanceLoopCharacteristics>
</serviceTask>

</code>

 

Many thanks in advance for your help.

 

Regardas,

José

Outcomes