use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class WorkflowProcessInstanceImpl method handleSLAViolation.
private void handleSLAViolation() {
if (slaCompliance == SLA_PENDING) {
InternalKnowledgeRuntime kruntime = getKnowledgeRuntime();
InternalProcessRuntime processRuntime = (InternalProcessRuntime) kruntime.getProcessRuntime();
processRuntime.getProcessEventSupport().fireBeforeSLAViolated(this, kruntime);
logger.debug("SLA violated on process instance {}", getId());
this.slaCompliance = SLA_VIOLATED;
this.slaTimerId = -1;
processRuntime.getProcessEventSupport().fireAfterSLAViolated(this, kruntime);
}
}
use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class WorkflowProcessInstanceImpl method setState.
public void setState(final int state, String outcome) {
super.setState(state, outcome);
// TODO move most of this to ProcessInstanceImpl
if (state == ProcessInstance.STATE_COMPLETED || state == ProcessInstance.STATE_ABORTED) {
if (this.slaCompliance == SLA_PENDING) {
if (System.currentTimeMillis() > slaDueDate.getTime()) {
// completion of the process instance is after expected SLA due date, mark it accordingly
this.slaCompliance = SLA_VIOLATED;
} else {
this.slaCompliance = state == ProcessInstance.STATE_COMPLETED ? SLA_MET : SLA_ABORTED;
}
}
InternalKnowledgeRuntime kruntime = getKnowledgeRuntime();
InternalProcessRuntime processRuntime = (InternalProcessRuntime) kruntime.getProcessRuntime();
processRuntime.getProcessEventSupport().fireBeforeProcessCompleted(this, kruntime);
// deactivate all node instances of this process instance
while (!nodeInstances.isEmpty()) {
NodeInstance nodeInstance = nodeInstances.get(0);
((org.jbpm.workflow.instance.NodeInstance) nodeInstance).cancel();
}
if (this.slaTimerId > -1) {
processRuntime.getTimerManager().cancelTimer(this.slaTimerId);
logger.debug("SLA Timer {} has been canceled", this.slaTimerId);
}
removeEventListeners();
processRuntime.getProcessInstanceManager().removeProcessInstance(this);
processRuntime.getProcessEventSupport().fireAfterProcessCompleted(this, kruntime);
if (isSignalCompletion()) {
RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER);
if (getParentProcessInstanceId() > 0 && manager != null) {
try {
org.kie.api.runtime.manager.Context<?> context = ProcessInstanceIdContext.get(getParentProcessInstanceId());
String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID);
if (caseId != null) {
context = CaseContext.get(caseId);
}
RuntimeEngine runtime = manager.getRuntimeEngine(context);
KieRuntime managedkruntime = (KieRuntime) runtime.getKieSession();
managedkruntime.signalEvent("processInstanceCompleted:" + getId(), this);
} catch (SessionNotFoundException e) {
// in case no session is found for parent process let's skip signal for process instance completion
}
} else {
processRuntime.getSignalManager().signalEvent("processInstanceCompleted:" + getId(), this);
}
}
}
}
use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class MapPersistenceTest method processWithNotNullStartDateTest.
@Test
public void processWithNotNullStartDateTest() {
String processId = "signalProcessTest";
String eventType = "myEvent";
RuleFlowProcess process = ProcessCreatorForHelp.newSimpleEventProcess(processId, eventType);
KieBase kbase = createKieBase(process);
StatefulKnowledgeSession crmPersistentSession = createSession(kbase);
RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) crmPersistentSession.startProcess(processId);
InternalKnowledgeRuntime kruntime = processInstance.getKnowledgeRuntime();
Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
ProcessInstanceInfo processInstanceInfo = new ProcessInstanceInfo(processInstance);
processInstance = (RuleFlowProcessInstance) processInstanceInfo.getProcessInstance(kruntime, crmPersistentSession.getEnvironment());
Assert.assertNotNull(processInstance.getStartDate());
Assert.assertEquals(processInstance.getStartDate(), processInstanceInfo.getStartDate());
}
Aggregations