Search in sources :

Example 16 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class MultipleTimerServicesTest method testGlobalTimerServiceOnIndependentManager.

public void testGlobalTimerServiceOnIndependentManager() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
    NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener("timer", 3);
    // prepare listener to assert results
    final List<Long> timerExporations = new ArrayList<Long>();
    ProcessEventListener listenerM1 = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("timer")) {
                logger.debug("On manager 1");
                timerExporations.add(event.getProcessInstance().getId());
            }
        }
    };
    final List<Long> timerExporations2 = new ArrayList<Long>();
    ProcessEventListener listenerM2 = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("timer")) {
                logger.debug("On manager 2");
                timerExporations2.add(event.getProcessInstance().getId());
            }
        }
    };
    environmentM1 = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listenerM1, countDownListener)).schedulerService(globalScheduler1).get();
    environmentM2 = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf2).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listenerM2, countDownListener2)).schedulerService(globalScheduler2).get();
    managerM1 = getManager(environmentM1, "one");
    RuntimeEngine runtimeM1 = managerM1.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksessionM1 = runtimeM1.getKieSession();
    managerM2 = getManager(environmentM2, "two");
    RuntimeEngine runtimeM2 = managerM2.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksessionM2 = runtimeM2.getKieSession();
    ProcessInstance processInstanceM1 = ksessionM1.startProcess("IntermediateCatchEvent");
    assertTrue(processInstanceM1.getState() == ProcessInstance.STATE_ACTIVE);
    ProcessInstance processInstanceM2 = ksessionM2.startProcess("IntermediateCatchEvent");
    assertTrue(processInstanceM2.getState() == ProcessInstance.STATE_ACTIVE);
    // now wait for 1 second for first timer to trigger
    countDownListener.waitTillCompleted(2000);
    countDownListener2.waitTillCompleted(2000);
    // dispose session to force session to be reloaded on timer expiration
    managerM1.disposeRuntimeEngine(runtimeM1);
    managerM2.disposeRuntimeEngine(runtimeM2);
    countDownListener.waitTillCompleted();
    countDownListener2.waitTillCompleted();
    countDownListener.reset(1);
    countDownListener2.reset(1);
    try {
        runtimeM1 = managerM1.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceM1.getId()));
        ksessionM1 = runtimeM1.getKieSession();
        processInstanceM1 = ksessionM1.getProcessInstance(processInstanceM1.getId());
        assertNull(processInstanceM1);
    } catch (SessionNotFoundException e) {
    // expected in PerProcessInstance manager
    }
    try {
        runtimeM2 = managerM2.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceM2.getId()));
        ksessionM2 = runtimeM2.getKieSession();
        processInstanceM2 = ksessionM2.getProcessInstance(processInstanceM2.getId());
        assertNull(processInstanceM2);
    } catch (SessionNotFoundException e) {
    // expected in PerProcessInstance manager
    }
    // let's wait to ensure no more timers are expired and triggered
    countDownListener.waitTillCompleted(3000);
    countDownListener2.waitTillCompleted(3000);
    managerM1.disposeRuntimeEngine(runtimeM1);
    managerM2.disposeRuntimeEngine(runtimeM2);
    assertEquals(3, timerExporations.size());
    assertEquals(3, timerExporations2.size());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 17 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException 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 SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class GlobalThreadPoolTimerServiceTest method testInterediateTimerWithGlobalTestServiceWithinTransaction.

@Test(timeout = 20000)
public void testInterediateTimerWithGlobalTestServiceWithinTransaction() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
    globalScheduler = new TransactionalThreadPoolSchedulerService(3);
    // prepare listener to assert results
    final List<Long> timerExporations = new ArrayList<Long>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("timer")) {
                timerExporations.add(event.getProcessInstance().getId());
            }
        }
    };
    environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
    manager = getManager(environment, true);
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    // now wait for 1 second for first timer to trigger
    countDownListener.waitTillCompleted(2000);
    // dispose session to force session to be reloaded on timer expiration
    manager.disposeRuntimeEngine(runtime);
    countDownListener.waitTillCompleted();
    countDownListener.reset(1);
    try {
        runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtime.getKieSession();
        processInstance = ksession.getProcessInstance(processInstance.getId());
        assertNull(processInstance);
    } catch (SessionNotFoundException e) {
    // expected for PerProcessInstanceManagers since process instance is completed
    }
    // let's wait to ensure no more timers are expired and triggered
    countDownListener.waitTillCompleted(3000);
    assertEquals(3, timerExporations.size());
    manager.disposeRuntimeEngine(runtime);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ArrayList(java.util.ArrayList) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) TransactionalThreadPoolSchedulerService(org.jbpm.test.functional.timer.addon.TransactionalThreadPoolSchedulerService) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test)

Example 19 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class GlobalTimerServiceBaseTest method testInterediateTimerWithGlobalTestService.

@Test(timeout = 20000)
public void testInterediateTimerWithGlobalTestService() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
    // prepare listener to assert results
    final List<Long> timerExporations = new ArrayList<Long>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("timer")) {
                timerExporations.add(event.getProcessInstance().getId());
            }
        }
    };
    environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
    manager = getManager(environment, true);
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    // now wait for 1 second for first timer to trigger
    Thread.sleep(1500);
    // dispose session to force session to be reloaded on timer expiration
    manager.disposeRuntimeEngine(runtime);
    Thread.sleep(2000);
    try {
        runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtime.getKieSession();
        processInstance = ksession.getProcessInstance(processInstance.getId());
        assertNull(processInstance);
    } catch (SessionNotFoundException e) {
    // expected for PerProcessInstanceManagers since process instance is completed
    }
    // let's wait to ensure no more timers are expired and triggered
    countDownListener.waitTillCompleted();
    assertEquals(3, timerExporations.size());
    manager.disposeRuntimeEngine(runtime);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test)

Example 20 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class GlobalTimerServiceBaseTest method testHumanTaskDeadlineWithGlobalTimerServiceMultipleInstances.

@Test
public void testHumanTaskDeadlineWithGlobalTimerServiceMultipleInstances() throws Exception {
    environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/HumanTaskWithDeadlines.bpmn"), ResourceType.BPMN2).schedulerService(globalScheduler).get();
    manager = getManager(environment, true);
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.startProcess("htdeadlinetest");
    manager.disposeRuntimeEngine(runtime);
    RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    ProcessInstance processInstance2 = ksession2.startProcess("htdeadlinetest");
    // abort second instance to trigger unschedule of deadlines
    ksession2.abortProcessInstance(processInstance2.getId());
    manager.disposeRuntimeEngine(runtime2);
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    List<TaskSummary> krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    assertEquals(1, krisTasks.size());
    List<TaskSummary> johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(0, johnTasks.size());
    List<TaskSummary> maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(0, maryTasks.size());
    manager.disposeRuntimeEngine(runtime);
    // now wait for 2 seconds for first reassignment
    Thread.sleep(3000);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    assertEquals(0, krisTasks.size());
    johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, johnTasks.size());
    maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(0, maryTasks.size());
    runtime.getTaskService().start(johnTasks.get(0).getId(), "john");
    manager.disposeRuntimeEngine(runtime);
    // now wait for 2 more seconds for second reassignment
    Thread.sleep(2000);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    assertEquals(0, krisTasks.size());
    johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, johnTasks.size());
    maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(0, maryTasks.size());
    manager.disposeRuntimeEngine(runtime);
    // now wait for 1 seconds to make sure that reassignment did not happen any more since task was already started
    Thread.sleep(3000);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    assertEquals(0, krisTasks.size());
    johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(0, johnTasks.size());
    maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(1, maryTasks.size());
    runtime.getTaskService().start(maryTasks.get(0).getId(), "mary");
    runtime.getTaskService().complete(maryTasks.get(0).getId(), "mary", null);
    manager.disposeRuntimeEngine(runtime);
    // now wait for 2 seconds to make sure that reassignment did not happen any more since task was completed
    Thread.sleep(2000);
    try {
        runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtime.getKieSession();
        processInstance = ksession.getProcessInstance(processInstance.getId());
        assertNull(processInstance);
    } catch (SessionNotFoundException e) {
    // this can be thrown for per process instance strategy as instance has already been completed
    }
    manager.disposeRuntimeEngine(runtime);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test)

Aggregations

SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)28 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)27 KieSession (org.kie.api.runtime.KieSession)25 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)15 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)14 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)14 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)13 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)13 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)13 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)8 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)7 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)6 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)6 HashMap (java.util.HashMap)5 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 WorkItem (org.kie.api.runtime.process.WorkItem)4 Properties (java.util.Properties)3