List<Long> timerList = sbni.getTimerInstances(); if ((timerList != null && timerList.contains(timerId)) || (sbni.getNodeName() != null && sbni.getNodeName().equals(timerName))) { timerList.add(newTimer.getId()); sbni.internalSetTimerInstances(timerList); logger.debug("New timer {} successfully registered", newTimer);
public void internalTrigger(NodeInstance from, String type) { super.internalTrigger(from, type); if (getNodeInstanceContainer().getNodeInstance(getId()) == null) { return; Map<Timer, DroolsAction> timers = getEventBasedNode().getTimers(); if (timers != null) { addTimerListener(); timerInstances = new ArrayList<Long>(timers.size()); TimerManager timerManager = ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getTimerManager(); for (Timer timer: timers.keySet()) { TimerInstance timerInstance = createTimerInstance(timer); timerManager.registerTimer(timerInstance, (ProcessInstance) getProcessInstance()); timerInstances.add(timerInstance.getId()); if (getEventBasedNode().getBoundaryEvents() != null) { for (String name : getEventBasedNode().getBoundaryEvents()) { boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()) .isRuleActiveInRuleFlowGroup("DROOLS_SYSTEM", name, getProcessInstance().getId()); if (isActive) { getProcessInstance().getKnowledgeRuntime().signalEvent(name, null); } else { addActivationListener(); ((WorkflowProcessInstanceImpl) getProcessInstance()).addActivatingNodeId((String) getNode().getMetaData().get("UniqueId"));
public void addEventListeners() { super.addEventListeners(); for (NodeInstance nodeInstance: nodeInstances) { if (nodeInstance instanceof EventBasedNodeInstanceInterface) { ((EventBasedNodeInstanceInterface) nodeInstance).addEventListeners(); } } }
public void addEventListeners() { if (timerInstances != null && timerInstances.size() > 0 || slaTimerId > -1) { addTimerListener(); } if (slaCompliance == ProcessInstance.SLA_PENDING) { ((WorkflowProcessInstance) getProcessInstance()).addEventListener("slaViolation:" + getId(), this, true); } }
public void cancel() { if (this.slaCompliance == ProcessInstance.SLA_PENDING) { if (System.currentTimeMillis() > slaDueDate.getTime()) { // completion of the process instance is after expected SLA due date, mark it accordingly this.slaCompliance = ProcessInstance.SLA_VIOLATED; } else { this.slaCompliance = ProcessInstance.SLA_ABORTED; } } cancelSlaTimer(); cancelTimers(); removeEventListeners(); removeActivationListener(); super.cancel(); }
protected void triggerCompleted(String type, boolean remove) { if (this.slaCompliance == ProcessInstance.SLA_PENDING) { if (System.currentTimeMillis() > slaDueDate.getTime()) { // completion of the node instance is after expected SLA due date, mark it accordingly this.slaCompliance = ProcessInstance.SLA_VIOLATED; } else { this.slaCompliance = ProcessInstance.STATE_COMPLETED; } } cancelSlaTimer(); ((org.jbpm.workflow.instance.NodeInstanceContainer)getNodeInstanceContainer()).setCurrentLevel(getLevel()); cancelTimers(); removeActivationListener(); super.triggerCompleted(type, remove); }
@Override public void signalEvent(String type, Object event) { if ("timerTriggered".equals(type)) { TimerInstance timerInstance = (TimerInstance) event; if (timerInstances != null && timerInstances.contains(timerInstance.getId())) { triggerTimer(timerInstance); } else if (timerInstance.getId() == slaTimerId) { handleSLAViolation(); } } else if (("slaViolation:" + getId()).equals(type)) { handleSLAViolation(); } else if (type.equals(getActivationType())) { if (event instanceof MatchCreatedEvent) { String name = ((MatchCreatedEvent)event).getMatch().getRule().getName(); if (checkProcessInstance((Activation) ((MatchCreatedEvent)event).getMatch())) { ((MatchCreatedEvent)event).getKieRuntime().signalEvent(name, null); } } } }
protected void configureSla() { String slaDueDateExpression = (String) getNode().getMetaData().get("customSLADueDate"); if (slaDueDateExpression != null) { TimerInstance timer = ((WorkflowProcessInstanceImpl)getProcessInstance()).configureSLATimer(slaDueDateExpression); if (timer != null) { this.slaTimerId = timer.getId(); this.slaDueDate = new Date(System.currentTimeMillis() + timer.getDelay()); this.slaCompliance = ProcessInstance.SLA_PENDING; logger.debug("SLA for node instance {} is PENDING with due date {}", this.getId(), this.slaDueDate); 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; } });
public void cancel() { while (!nodeInstances.isEmpty()) { NodeInstance nodeInstance = (NodeInstance) nodeInstances.get(0); ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).cancel(); } super.cancel(); }
timers.add(timerInstance.getId()); ((StateBasedNodeInstance) active).internalSetTimerInstances(timers);
protected void triggerCompleted(String type, boolean remove) { if (this.slaCompliance == ProcessInstance.SLA_PENDING) { if (System.currentTimeMillis() > slaDueDate.getTime()) { // completion of the node instance is after expected SLA due date, mark it accordingly this.slaCompliance = ProcessInstance.SLA_VIOLATED; } else { this.slaCompliance = ProcessInstance.STATE_COMPLETED; } } cancelSlaTimer(); ((org.jbpm.workflow.instance.NodeInstanceContainer)getNodeInstanceContainer()).setCurrentLevel(getLevel()); cancelTimers(); removeActivationListener(); super.triggerCompleted(type, remove); }
@Override public void signalEvent(String type, Object event) { if ("timerTriggered".equals(type)) { TimerInstance timerInstance = (TimerInstance) event; if (timerInstances != null && timerInstances.contains(timerInstance.getId())) { triggerTimer(timerInstance); } else if (timerInstance.getId() == slaTimerId) { handleSLAViolation(); } } else if (("slaViolation:" + getId()).equals(type)) { handleSLAViolation(); } else if (type.equals(getActivationType())) { if (event instanceof MatchCreatedEvent) { String name = ((MatchCreatedEvent)event).getMatch().getRule().getName(); if (checkProcessInstance((Activation) ((MatchCreatedEvent)event).getMatch())) { ((MatchCreatedEvent)event).getKieRuntime().signalEvent(name, null); } } } }
protected void configureSla() { String slaDueDateExpression = (String) getNode().getMetaData().get("customSLADueDate"); if (slaDueDateExpression != null) { TimerInstance timer = ((WorkflowProcessInstanceImpl)getProcessInstance()).configureSLATimer(slaDueDateExpression); if (timer != null) { this.slaTimerId = timer.getId(); this.slaDueDate = new Date(System.currentTimeMillis() + timer.getDelay()); this.slaCompliance = ProcessInstance.SLA_PENDING; logger.debug("SLA for node instance {} is PENDING with due date {}", this.getId(), this.slaDueDate); addTimerListener(); } } }
public void cancel() { if (this.slaCompliance == ProcessInstance.SLA_PENDING) { if (System.currentTimeMillis() > slaDueDate.getTime()) { // completion of the process instance is after expected SLA due date, mark it accordingly this.slaCompliance = ProcessInstance.SLA_VIOLATED; } else { this.slaCompliance = ProcessInstance.SLA_ABORTED; } } cancelSlaTimer(); cancelTimers(); removeEventListeners(); removeActivationListener(); super.cancel(); }
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 } }
public void addEventListeners() { if (timerInstances != null && timerInstances.size() > 0 || slaTimerId > -1) { addTimerListener(); } if (slaCompliance == ProcessInstance.SLA_PENDING) { ((WorkflowProcessInstance) getProcessInstance()).addEventListener("slaViolation:" + getId(), this, true); } }
public void cancel() { ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime() .getProcessRuntime()).getTimerManager().cancelTimer(timerId); super.cancel(); }
timers.add(timerInstance.getId()); ((StateBasedNodeInstance) active).internalSetTimerInstances(timers);
public void internalTrigger(NodeInstance from, String type) { super.internalTrigger(from, type); if (getNodeInstanceContainer().getNodeInstance(getId()) == null) { return; Map<Timer, DroolsAction> timers = getEventBasedNode().getTimers(); if (timers != null) { addTimerListener(); timerInstances = new ArrayList<Long>(timers.size()); TimerManager timerManager = ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getTimerManager(); for (Timer timer: timers.keySet()) { TimerInstance timerInstance = createTimerInstance(timer); timerManager.registerTimer(timerInstance, (ProcessInstance) getProcessInstance()); timerInstances.add(timerInstance.getId()); if (getEventBasedNode().getBoundaryEvents() != null) { for (String name : getEventBasedNode().getBoundaryEvents()) { boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()) .isRuleActiveInRuleFlowGroup("DROOLS_SYSTEM", name, getProcessInstance().getId()); if (isActive) { getProcessInstance().getKnowledgeRuntime().signalEvent(name, null); } else { addActivationListener(); ((WorkflowProcessInstanceImpl) getProcessInstance()).addActivatingNodeId((String) getNode().getMetaData().get("UniqueId"));