Search in sources :

Example 16 with InternalKnowledgeRuntime

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);
    }
}
Also used : InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime)

Example 17 with InternalKnowledgeRuntime

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);
            }
        }
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) KieRuntime(org.kie.api.runtime.KieRuntime) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) EndNodeInstance(org.jbpm.workflow.instance.node.EndNodeInstance) NodeInstance(org.jbpm.workflow.instance.NodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 18 with InternalKnowledgeRuntime

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());
}
Also used : InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) ProcessInstanceInfo(org.jbpm.persistence.processinstance.ProcessInstanceInfo) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

InternalKnowledgeRuntime (org.drools.core.common.InternalKnowledgeRuntime)18 ArrayList (java.util.ArrayList)4 Connection (org.kie.api.definition.process.Connection)4 NodeInstance (org.kie.api.runtime.process.NodeInstance)4 HashMap (java.util.HashMap)3 CompositeNodeInstance (org.jbpm.workflow.instance.node.CompositeNodeInstance)3 Node (org.kie.api.definition.process.Node)3 Map (java.util.Map)2 ExecutableCommand (org.drools.core.command.impl.ExecutableCommand)2 RegistryContext (org.drools.core.command.impl.RegistryContext)2 MarshallingConfigurationImpl (org.drools.serialization.protobuf.marshalling.MarshallingConfigurationImpl)2 InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)2 ProcessInstance (org.jbpm.process.instance.ProcessInstance)2 ConstraintEvaluator (org.jbpm.process.instance.impl.ConstraintEvaluator)2 NodeInstanceContainer (org.jbpm.workflow.instance.NodeInstanceContainer)2 WorkflowRuntimeException (org.jbpm.workflow.instance.WorkflowRuntimeException)2 ActionNodeInstance (org.jbpm.workflow.instance.node.ActionNodeInstance)2 Test (org.junit.Test)2 KieBase (org.kie.api.KieBase)2 KieRuntime (org.kie.api.runtime.KieRuntime)2