cancel
Showing results for 
Search instead for 
Did you mean: 

How to persist process state between 2 JavaDelegates?

seb2013
Champ in-the-making
Champ in-the-making
Dear community,

I hava a simple setup with 2 JavaDelegates in sequence. If an exception is thrown in the 2nd class, the workflow stops as expected. If I start the excecution with the same business-key again, the 1st and 2nd task will be executed. So Activiti starts from beginning again. What I need is that Activity resumes at the 2nd step because the first step was already processed successfully previously. Somehow the context/state is not going to be persisted after the 1st step finished. Hope that somebody can help me with the right setup. I could not find anything about that in the forum. Below I attached the simplified java and deployment code.

Thanks,
Sebastian



  <process id="seq-exception" name="seq-exception">
    <startEvent id="startevent1" name="Start"></startEvent>
    <serviceTask id="servicetask2" name="Sucess" activiti:delegateExpression="#{MyJavaDelegate}"></serviceTask>
    <serviceTask id="servicetask1" name="Exception" activiti:delegateExpression="#{MyJavaDelegateWithException}"></serviceTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="servicetask2"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="servicetask2" targetRef="servicetask1"></sequenceFlow>
    <sequenceFlow id="flow3" name="" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
  </process>

@Component(value = "MyJavaDelegate")
public class MyJavaDelegate implements JavaDelegate {

    private static final Logger logger = LoggerFactory.getLogger(MyJavaDelegate.class);

    @Override
    @Transactional
    public void execute(DelegateExecution execution) throws Exception {
        logger.info("MyJavaDelegate");
    }

}

@Component(value = "MyJavaDelegateWithException")
public class MyJavaDelegateWithException implements JavaDelegate {

    private static final Logger logger = LoggerFactory.getLogger(MyJavaDelegateWithException.class);

    @Override
    @Transactional
    public void execute(DelegateExecution execution) throws Exception {
        logger.info("MyJavaDelegateWithException");
        throw new Exception("Dummy Exception");
    }
}

public class MainBean {
    @Autowired
    private RuntimeService runtimeService;

    public void execute(String processDefinitionKey, String businessKey) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey,
                businessKey);
    }
}
3 REPLIES 3

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
you either have to include a (non-functional) waitstate for this e.g. with a timeout on it of 1 second, or wait for the 'async' functionality (http://jira.codehaus.org/browse/ACT-126) to be implemented.

seb2013
Champ in-the-making
Champ in-the-making
Thanks for your answer, Roland. Do you mean by waitstate the Java receive task? (http://www.activiti.org/userguide/index.html#bpmnReceiveTask)
I don't see a way to specify a timeout there. Or are you refering to a Timer Boundary Event?

trademak
Star Contributor
Star Contributor
Hi,

Yes a Java receive task would do the trick. But you'll have to signal it before it completes the task.
You can add a boundary timer event to do this for you, but it clutters the process diagram a bit.
The Timer intermediate catching event is also a possibility, and probably the cleanest way to do this.

Best regards,