@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; } });
TimerNodeInstance tni = (TimerNodeInstance) nodeInstance; if (tni.getTimerId() == timerId || (tni.getNodeName() != null && tni.getNodeName().equals(timerName))) { TimerInstance timer = tm.getTimerMap().get(tni.getTimerId()); TimerInstance timer = tm.getTimerMap().get(timerList.get(0));
public void deserialize(MarshallerReaderContext inCtx, Timer timer) throws ClassNotFoundException { JBPMMessages.ProcessTimer ptimer = timer.getExtension(JBPMMessages.procTimer); TimerService ts = inCtx.wm.getTimerService(); long processInstanceId = ptimer.getTimer().getProcessInstanceId(); Trigger trigger = ProtobufInputMarshaller.readTrigger(inCtx, ptimer.getTrigger()); TimerInstance timerInstance = ProtobufProcessMarshaller.readTimer(inCtx, ptimer.getTimer()); TimerManager tm = ((InternalProcessRuntime) inCtx.wm.getProcessRuntime()).getTimerManager(); // check if the timer instance is not already registered to avoid duplicated timers if (!tm.getTimerMap().containsKey(timerInstance.getId())) { ProcessJobContext pctx = new ProcessJobContext(timerInstance, trigger, processInstanceId, inCtx.wm.getKnowledgeRuntime(), false); Date date = trigger.hasNextFireTime(); if (date != null) { long then = date.getTime(); long now = pctx.getKnowledgeRuntime().getSessionClock().getCurrentTime(); // overdue timer if (then < now) { trigger = new OverdueTrigger(trigger, pctx.getKnowledgeRuntime()); } } JobHandle jobHandle = ts.scheduleJob(processJob, pctx, trigger); timerInstance.setJobHandle(jobHandle); pctx.setJobHandle(jobHandle); tm.getTimerMap().put(timerInstance.getId(), timerInstance); } } }
tm.getTimerMap().remove(ctx.getTimer().getId()); tm.getTimerService().removeJob(ctx.getJobHandle()); tm.getTimerMap().remove(ctx.getTimer().getId()); tm.getTimerService().removeJob(ctx.getJobHandle());
tm.getTimerMap().remove(ctx.getTimer().getId()); tm.getTimerService().removeJob(ctx.getJobHandle());
@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; } });
TimerNodeInstance tni = (TimerNodeInstance) nodeInstance; if (tni.getTimerId() == timerId || (tni.getNodeName() != null && tni.getNodeName().equals(timerName))) { TimerInstance timer = tm.getTimerMap().get(tni.getTimerId()); TimerInstance timer = tm.getTimerMap().get(timerList.get(0));
public void deserialize(MarshallerReaderContext inCtx, Timer timer) throws ClassNotFoundException { JBPMMessages.ProcessTimer ptimer = timer.getExtension(JBPMMessages.procTimer); TimerService ts = inCtx.wm.getTimerService(); long processInstanceId = ptimer.getTimer().getProcessInstanceId(); Trigger trigger = ProtobufInputMarshaller.readTrigger(inCtx, ptimer.getTrigger()); TimerInstance timerInstance = ProtobufProcessMarshaller.readTimer(inCtx, ptimer.getTimer()); TimerManager tm = ((InternalProcessRuntime) inCtx.wm.getProcessRuntime()).getTimerManager(); // check if the timer instance is not already registered to avoid duplicated timers if (!tm.getTimerMap().containsKey(timerInstance.getId())) { ProcessJobContext pctx = new ProcessJobContext(timerInstance, trigger, processInstanceId, inCtx.wm.getKnowledgeRuntime(), false); Date date = trigger.hasNextFireTime(); if (date != null) { long then = date.getTime(); long now = pctx.getKnowledgeRuntime().getSessionClock().getCurrentTime(); // overdue timer if (then < now) { trigger = new OverdueTrigger(trigger, pctx.getKnowledgeRuntime()); } } JobHandle jobHandle = ts.scheduleJob(processJob, pctx, trigger); timerInstance.setJobHandle(jobHandle); pctx.setJobHandle(jobHandle); tm.getTimerMap().put(timerInstance.getId(), timerInstance); } } }
tm.getTimerMap().remove(ctx.getTimer().getId()); tm.getTimerService().removeJob(ctx.getJobHandle()); tm.getTimerMap().remove(ctx.getTimer().getId()); tm.getTimerService().removeJob(ctx.getJobHandle());
tm.getTimerMap().remove(ctx.getTimer().getId()); tm.getTimerService().removeJob(ctx.getJobHandle());