if (nodeInstance instanceof TimerNodeInstance) { TimerNodeInstance tni = (TimerNodeInstance) nodeInstance; if (tni.getTimerId() == timerId || (tni.getNodeName() != null && tni.getNodeName().equals(timerName))) { TimerInstance timer = tm.getTimerMap().get(tni.getTimerId()); tni.internalSetTimerId(newTimer.getId()); logger.debug("New timer {} successfully registered", newTimer);
nodeInstance = new TimerNodeInstance(); ((TimerNodeInstance) nodeInstance).internalSetTimerId(stream.readLong()); break; case PersisterEnums.EVENT_NODE_INSTANCE:
public void internalTrigger(NodeInstance from, String type) { if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) { throw new IllegalArgumentException( "A TimerNode only accepts default incoming connections!"); } InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); timerInstance = createTimerInstance(kruntime); if (getTimerInstances() == null) { addTimerListener(); } ((InternalProcessRuntime)kruntime.getProcessRuntime()) .getTimerManager().registerTimer(timerInstance, (ProcessInstance) getProcessInstance()); timerId = timerInstance.getId(); }
public void addEventListeners() { super.addEventListeners(); if (getTimerInstances() == null) { addTimerListener(); } }
@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; } });
protected TimerInstance createTimerInstance(InternalKnowledgeRuntime kruntime) { Timer timer = getTimerNode().getTimer(); TimerInstance timerInstance = new TimerInstance(); if (kruntime != null && kruntime.getEnvironment().get("jbpm.business.calendar") != null){ BusinessCalendar businessCalendar = (BusinessCalendar) kruntime.getEnvironment().get("jbpm.business.calendar"); String delay = resolveVariable(timer.getDelay()); timerInstance.setDelay(businessCalendar.calculateBusinessTimeAsDuration(delay)); if (timer.getPeriod() == null) { timerInstance.setPeriod(0); } else { String period = resolveVariable(timer.getPeriod()); timerInstance.setPeriod(businessCalendar.calculateBusinessTimeAsDuration(period)); } } else { configureTimerInstance(timer, timerInstance); } timerInstance.setTimerId(timer.getId()); return timerInstance; }
((TimerNodeInstance) active).internalSetTimerId(timerInstance.getId()); } else if (active instanceof StateBasedNodeInstance) {
public void removeEventListeners() { super.removeEventListeners(); ((WorkflowProcessInstance) getProcessInstance()).removeEventListener("timerTriggered", this, false); }
public TimerNode getTimerNode() { return (TimerNode) getNode(); }
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 } }
} else if (nodeInstance instanceof TimerNodeInstance) { stream.writeShort(PersisterEnums.TIMER_NODE_INSTANCE); stream.writeLong(((TimerNodeInstance) nodeInstance).getTimerId()); } else if (nodeInstance instanceof JoinInstance) { stream.writeShort(PersisterEnums.JOIN_NODE_INSTANCE);
protected TimerInstance createTimerInstance(InternalKnowledgeRuntime kruntime) { Timer timer = getTimerNode().getTimer(); TimerInstance timerInstance = new TimerInstance(); if (kruntime != null && kruntime.getEnvironment().get("jbpm.business.calendar") != null){ BusinessCalendar businessCalendar = (BusinessCalendar) kruntime.getEnvironment().get("jbpm.business.calendar"); String delay = resolveVariable(timer.getDelay()); timerInstance.setDelay(businessCalendar.calculateBusinessTimeAsDuration(delay)); if (timer.getPeriod() == null) { timerInstance.setPeriod(0); } else { String period = resolveVariable(timer.getPeriod()); timerInstance.setPeriod(businessCalendar.calculateBusinessTimeAsDuration(period)); } } else { configureTimerInstance(timer, timerInstance); } timerInstance.setTimerId(timer.getId()); return timerInstance; }
public void addEventListeners() { super.addEventListeners(); if (getTimerInstances() == null) { addTimerListener(); } }
((TimerNodeInstance) active).internalSetTimerId(timerInstance.getId()); } else if (active instanceof StateBasedNodeInstance) {
public void cancel() { ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime() .getProcessRuntime()).getTimerManager().cancelTimer(timerId); super.cancel(); }
public TimerNode getTimerNode() { return (TimerNode) getNode(); }
if (nodeInstance instanceof TimerNodeInstance) { TimerNodeInstance tni = (TimerNodeInstance) nodeInstance; if (tni.getTimerId() == timerId || (tni.getNodeName() != null && tni.getNodeName().equals(timerName))) { TimerInstance timer = tm.getTimerMap().get(tni.getTimerId()); tni.internalSetTimerId(newTimer.getId()); logger.debug("New timer {} successfully registered", newTimer);
nodeInstance = new TimerNodeInstance(); ((TimerNodeInstance) nodeInstance).internalSetTimerId( _content.getTimer().getTimerId() ); break; case ASYNC_EVENT_NODE :
public void internalTrigger(NodeInstance from, String type) { if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) { throw new IllegalArgumentException( "A TimerNode only accepts default incoming connections!"); } InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); timerInstance = createTimerInstance(kruntime); if (getTimerInstances() == null) { addTimerListener(); } ((InternalProcessRuntime)kruntime.getProcessRuntime()) .getTimerManager().registerTimer(timerInstance, (ProcessInstance) getProcessInstance()); timerId = timerInstance.getId(); }
.setType( NodeInstanceType.TIMER_NODE ) .setTimer( JBPMMessages.ProcessInstance.NodeInstanceContent.TimerNode.newBuilder() .setTimerId( ((TimerNodeInstance) nodeInstance).getTimerId() ) .build() ); } else if ( nodeInstance instanceof JoinInstance ) {