Search in sources :

Example 1 with InternalProcessRuntime

use of org.jbpm.process.instance.InternalProcessRuntime in project jbpm by kiegroup.

the class VariableScopeInstance method setVariable.

public void setVariable(String name, Object value) {
    if (name == null) {
        throw new IllegalArgumentException("The name of a variable may not be null!");
    }
    Object oldValue = variables.get(name);
    if (oldValue == null) {
        if (value == null) {
            return;
        }
    }
    ProcessEventSupport processEventSupport = ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getProcessEventSupport();
    processEventSupport.fireBeforeVariableChanged((variableIdPrefix == null ? "" : variableIdPrefix + ":") + name, (variableInstanceIdPrefix == null ? "" : variableInstanceIdPrefix + ":") + name, oldValue, value, getProcessInstance(), getProcessInstance().getKnowledgeRuntime());
    internalSetVariable(name, value);
    processEventSupport.fireAfterVariableChanged((variableIdPrefix == null ? "" : variableIdPrefix + ":") + name, (variableInstanceIdPrefix == null ? "" : variableInstanceIdPrefix + ":") + name, oldValue, value, getProcessInstance(), getProcessInstance().getKnowledgeRuntime());
}
Also used : ProcessEventSupport(org.drools.core.event.ProcessEventSupport) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime)

Example 2 with InternalProcessRuntime

use of org.jbpm.process.instance.InternalProcessRuntime in project jbpm by kiegroup.

the class StateBasedNodeInstance method handleSLAViolation.

protected void handleSLAViolation() {
    if (slaCompliance == ProcessInstance.SLA_PENDING) {
        InternalProcessRuntime processRuntime = ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime());
        processRuntime.getProcessEventSupport().fireBeforeSLAViolated(getProcessInstance(), this, getProcessInstance().getKnowledgeRuntime());
        logger.debug("SLA violated on node instance {}", getId());
        this.slaCompliance = ProcessInstance.SLA_VIOLATED;
        this.slaTimerId = -1;
        processRuntime.getProcessEventSupport().fireAfterSLAViolated(getProcessInstance(), this, getProcessInstance().getKnowledgeRuntime());
    }
}
Also used : InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime)

Example 3 with InternalProcessRuntime

use of org.jbpm.process.instance.InternalProcessRuntime in project jbpm by kiegroup.

the class StateBasedNodeInstance method cancelSlaTimer.

private void cancelSlaTimer() {
    if (this.slaTimerId > -1) {
        TimerManager timerManager = ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getTimerManager();
        timerManager.cancelTimer(this.slaTimerId);
        logger.debug("SLA Timer {} has been canceled", this.slaTimerId);
    }
}
Also used : InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) TimerManager(org.jbpm.process.instance.timer.TimerManager)

Example 4 with InternalProcessRuntime

use of org.jbpm.process.instance.InternalProcessRuntime in project jbpm by kiegroup.

the class DynamicUtils method executeWorkItem.

private static void executeWorkItem(StatefulKnowledgeSessionImpl ksession, WorkItemImpl workItem, WorkItemNodeInstance workItemNodeInstance) {
    ProcessEventSupport eventSupport = ((InternalProcessRuntime) ksession.getProcessRuntime()).getProcessEventSupport();
    eventSupport.fireBeforeNodeTriggered(workItemNodeInstance, ksession);
    ((WorkItemManager) ksession.getWorkItemManager()).internalExecuteWorkItem(workItem);
    workItemNodeInstance.internalSetWorkItemId(workItem.getId());
    eventSupport.fireAfterNodeTriggered(workItemNodeInstance, ksession);
}
Also used : ProcessEventSupport(org.drools.core.event.ProcessEventSupport) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) WorkItemManager(org.drools.core.process.instance.WorkItemManager)

Example 5 with InternalProcessRuntime

use of org.jbpm.process.instance.InternalProcessRuntime in project jbpm by kiegroup.

the class DynamicUtils method executeSubProcess.

private static long executeSubProcess(StatefulKnowledgeSessionImpl ksession, String processId, Map<String, Object> parameters, ProcessInstance processInstance, SubProcessNodeInstance subProcessNodeInstance) {
    Process process = ksession.getKieBase().getProcess(processId);
    if (process == null) {
        logger.error("Could not find process {}", processId);
        throw new IllegalArgumentException("No process definition found with id: " + processId);
    } else {
        ProcessEventSupport eventSupport = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) ksession).getProcessRuntime()).getProcessEventSupport();
        eventSupport.fireBeforeNodeTriggered(subProcessNodeInstance, ksession);
        ProcessInstance subProcessInstance = null;
        if (((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey() != null) {
            List<String> businessKeys = new ArrayList<String>();
            businessKeys.add(((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey());
            businessKeys.add(processId);
            businessKeys.add(String.valueOf(System.currentTimeMillis()));
            CorrelationKeyFactory correlationKeyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory();
            CorrelationKey subProcessCorrelationKey = correlationKeyFactory.newCorrelationKey(businessKeys);
            subProcessInstance = (ProcessInstance) ((CorrelationAwareProcessRuntime) ksession).createProcessInstance(processId, subProcessCorrelationKey, parameters);
        } else {
            subProcessInstance = (ProcessInstance) ksession.createProcessInstance(processId, parameters);
        }
        ((ProcessInstanceImpl) subProcessInstance).setMetaData("ParentProcessInstanceId", processInstance.getId());
        ((ProcessInstanceImpl) subProcessInstance).setParentProcessInstanceId(processInstance.getId());
        subProcessInstance = (ProcessInstance) ksession.startProcessInstance(subProcessInstance.getId());
        subProcessNodeInstance.internalSetProcessInstanceId(subProcessInstance.getId());
        eventSupport.fireAfterNodeTriggered(subProcessNodeInstance, ksession);
        if (subProcessInstance.getState() == ProcessInstance.STATE_COMPLETED) {
            subProcessNodeInstance.triggerCompleted();
        } else {
            subProcessNodeInstance.addEventListeners();
        }
        return subProcessInstance.getId();
    }
}
Also used : ProcessEventSupport(org.drools.core.event.ProcessEventSupport) CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) CorrelationKey(org.kie.internal.process.CorrelationKey) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) ArrayList(java.util.ArrayList) Process(org.kie.api.definition.process.Process) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance)

Aggregations

InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)13 TimerManager (org.jbpm.process.instance.timer.TimerManager)7 TimerInstance (org.jbpm.process.instance.timer.TimerInstance)4 ArrayList (java.util.ArrayList)3 ProcessEventSupport (org.drools.core.event.ProcessEventSupport)3 Test (org.junit.Test)3 KieSession (org.kie.api.runtime.KieSession)3 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)3 Blob (java.sql.Blob)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 HashMap (java.util.HashMap)2 InternalKnowledgeRuntime (org.drools.core.common.InternalKnowledgeRuntime)2 MarshallingConfigurationImpl (org.drools.core.marshalling.impl.MarshallingConfigurationImpl)2 ProtobufMarshaller (org.drools.core.marshalling.impl.ProtobufMarshaller)2 ProtobufMessages (org.drools.core.marshalling.impl.ProtobufMessages)2 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 TaskService (org.kie.api.task.TaskService)2