@Override public Map<Long, List<TimerInstance>> execute(Context context) { Map<Long, List<TimerInstance>> result = new LinkedHashMap<>(); KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class); TimerManager timerManager = getTimerManager(kieSession); WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) kieSession.getProcessInstance(migrationSpec.getProcessInstanceId()); Collection<org.jbpm.workflow.instance.NodeInstance> activeInstances = processInstance.getNodeInstances(true); for (org.jbpm.workflow.instance.NodeInstance active : activeInstances) { if (active instanceof TimerNodeInstance) { TimerInstance timerInstance = timerManager.getTimerMap().get(((TimerNodeInstance) active).getTimerId()); timerManager.cancelTimer(timerInstance.getId()); result.put(active.getId(), Arrays.asList(timerInstance)); } else if (active instanceof StateBasedNodeInstance) { List<Long> timers = ((StateBasedNodeInstance) active).getTimerInstances(); if (timers != null && !timers.isEmpty()) { List<TimerInstance> collected = new ArrayList<>(); for (Long timerId : timers) { TimerInstance timerInstance = timerManager.getTimerMap().get(timerId); timerManager.cancelTimer(timerInstance.getId()); collected.add(timerInstance); } result.put(active.getId(), collected); } } } return result; } });
List<Long> timerList = sbni.getTimerInstances(); if ((timerList != null && timerList.contains(timerId)) || (sbni.getNodeName() != null && sbni.getNodeName().equals(timerName))) {
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>(processInstances.values())) { 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); } } } } } } catch (Exception e) { // catch everything here to make sure it will not break any following // logic to allow complete clean up } }
@Override public Map<Long, List<TimerInstance>> execute(Context context) { Map<Long, List<TimerInstance>> result = new LinkedHashMap<>(); KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class); TimerManager timerManager = getTimerManager(kieSession); WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) kieSession.getProcessInstance(migrationSpec.getProcessInstanceId()); Collection<org.jbpm.workflow.instance.NodeInstance> activeInstances = processInstance.getNodeInstances(true); for (org.jbpm.workflow.instance.NodeInstance active : activeInstances) { if (active instanceof TimerNodeInstance) { TimerInstance timerInstance = timerManager.getTimerMap().get(((TimerNodeInstance) active).getTimerId()); timerManager.cancelTimer(timerInstance.getId()); result.put(active.getId(), Arrays.asList(timerInstance)); } else if (active instanceof StateBasedNodeInstance) { List<Long> timers = ((StateBasedNodeInstance) active).getTimerInstances(); if (timers != null && !timers.isEmpty()) { List<TimerInstance> collected = new ArrayList<>(); for (Long timerId : timers) { TimerInstance timerInstance = timerManager.getTimerMap().get(timerId); timerManager.cancelTimer(timerInstance.getId()); collected.add(timerInstance); } result.put(active.getId(), collected); } } } return result; } });
List<Long> timerList = sbni.getTimerInstances(); if ((timerList != null && timerList.contains(timerId)) || (sbni.getNodeName() != null && sbni.getNodeName().equals(timerName))) {