use of org.jbpm.process.instance.InternalProcessRuntime 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.jbpm.process.instance.InternalProcessRuntime in project jbpm by kiegroup.
the class ProtobufProcessMarshaller method writeProcessTimers.
public void writeProcessTimers(MarshallerWriteContext outCtx) throws IOException {
outCtx.writersByClass.put(ProcessJobContext.class, new TimerManager.ProcessTimerOutputMarshaller());
outCtx.writersByClass.put(StartProcessJobContext.class, new TimerManager.ProcessTimerOutputMarshaller());
ProtobufMessages.ProcessData.Builder _pdata = (ProtobufMessages.ProcessData.Builder) outCtx.parameterObject;
TimerManager timerManager = ((InternalProcessRuntime) ((InternalWorkingMemory) outCtx.wm).getProcessRuntime()).getTimerManager();
long timerId = timerManager.internalGetTimerId();
_pdata.setExtension(JBPMMessages.timerId, timerId);
}
use of org.jbpm.process.instance.InternalProcessRuntime in project jbpm by kiegroup.
the class SerializedTimerRollbackTest method testSerizliableTestsWithEngineRollback.
@Test
public void testSerizliableTestsWithEngineRollback() {
try {
createRuntimeManager("org/jbpm/test/functional/timer/HumanTaskWithBoundaryTimer.bpmn");
RuntimeEngine runtimeEngine = getRuntimeEngine();
KieSession ksession = runtimeEngine.getKieSession();
logger.debug("Created knowledge session");
TaskService taskService = runtimeEngine.getTaskService();
logger.debug("Task service created");
List<Long> committedProcessInstanceIds = new ArrayList<Long>();
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("test", "john");
logger.debug("Creating process instance: {}", i);
ProcessInstance pi = ksession.startProcess("PROCESS_1", params);
committedProcessInstanceIds.add(pi.getId());
} else {
try {
Map<String, Object> params = new HashMap<String, Object>();
// set test variable to null so engine will rollback
params.put("test", null);
logger.debug("Creating process instance: {}", i);
ksession.startProcess("PROCESS_1", params);
} catch (Exception e) {
logger.debug("Process rolled back");
}
}
}
Connection c = getDs().getConnection();
Statement st = c.createStatement();
ResultSet rs = st.executeQuery("select rulesbytearray from sessioninfo");
rs.next();
Blob b = rs.getBlob("rulesbytearray");
assertNotNull(b);
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
ProtobufMarshaller marshaller = new ProtobufMarshaller(builder.newKieBase(), new MarshallingConfigurationImpl());
StatefulKnowledgeSession session = marshaller.unmarshall(b.getBinaryStream());
assertNotNull(session);
TimerManager timerManager = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) session).getProcessRuntime()).getTimerManager();
assertNotNull(timerManager);
Collection<TimerInstance> timers = timerManager.getTimers();
assertNotNull(timers);
assertEquals(5, timers.size());
for (TimerInstance timerInstance : timers) {
assertTrue(committedProcessInstanceIds.contains(timerInstance.getProcessInstanceId()));
ksession.abortProcessInstance(timerInstance.getProcessInstanceId());
}
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(0, tasks.size());
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown");
}
}
Aggregations