}
public void clearProcessInstancesState() {
try {
// at this point only timers are considered as state that needs to be cleared
TimerManager timerManager = ((InternalProcessRuntime)kruntime.getProcessRuntime()).getTimerManager();
for (ProcessInstance processInstance: new ArrayList<ProcessInstance>(getProcessInstances())) {
WorkflowProcessInstance pi = ((WorkflowProcessInstance) processInstance);
for (org.kie.api.runtime.process.NodeInstance nodeInstance : pi.getNodeInstances()) {
if (nodeInstance instanceof TimerNodeInstance){
if (((TimerNodeInstance)nodeInstance).getTimerInstance() != null) {
timerManager.cancelTimer(((TimerNodeInstance)nodeInstance).getTimerInstance().getId());
}
} else if (nodeInstance instanceof StateBasedNodeInstance) {
List<Long> timerIds = ((StateBasedNodeInstance) nodeInstance).getTimerInstances();
if (timerIds != null) {
for (Long id: timerIds) {
timerManager.cancelTimer(id);
}
}
}
}