Search in sources :

Example 31 with InternalRuntimeManager

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

the class AbstractAvailableJobsExecutor method getClassLoader.

protected ClassLoader getClassLoader(String deploymentId) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (deploymentId == null) {
        return cl;
    }
    InternalRuntimeManager manager = ((InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(deploymentId));
    if (manager != null && manager.getEnvironment().getClassLoader() != null) {
        cl = manager.getEnvironment().getClassLoader();
    }
    return cl;
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager)

Example 32 with InternalRuntimeManager

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

the class JPAProcessInstanceManager method getProcessInstance.

public ProcessInstance getProcessInstance(long id, boolean readOnly) {
    InternalRuntimeManager manager = (InternalRuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER);
    if (manager != null) {
        manager.validate((KieSession) kruntime, ProcessInstanceIdContext.get(id));
    }
    TransactionManager txm = (TransactionManager) this.kruntime.getEnvironment().get(EnvironmentName.TRANSACTION_MANAGER);
    org.jbpm.process.instance.ProcessInstance processInstance = null;
    processInstance = (org.jbpm.process.instance.ProcessInstance) this.processInstances.get(id);
    if (processInstance != null) {
        if (((WorkflowProcessInstanceImpl) processInstance).isPersisted() && !readOnly) {
            ProcessPersistenceContextManager ppcm = (ProcessPersistenceContextManager) this.kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
            ppcm.beginCommandScopedEntityManager();
            ProcessPersistenceContext context = ppcm.getProcessPersistenceContext();
            ProcessInstanceInfo processInstanceInfo = (ProcessInstanceInfo) context.findProcessInstanceInfo(id);
            if (processInstanceInfo == null) {
                return null;
            }
            TransactionManagerHelper.addToUpdatableSet(txm, processInstanceInfo);
            processInstanceInfo.updateLastReadDate();
            EventManagerProvider.getInstance().get().update(new ProcessInstanceView(processInstance));
        }
        return processInstance;
    }
    // Make sure that the cmd scoped entity manager has started
    ProcessPersistenceContextManager ppcm = (ProcessPersistenceContextManager) this.kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
    ppcm.beginCommandScopedEntityManager();
    ProcessPersistenceContext context = ppcm.getProcessPersistenceContext();
    ProcessInstanceInfo processInstanceInfo = (ProcessInstanceInfo) context.findProcessInstanceInfo(id);
    if (processInstanceInfo == null) {
        return null;
    }
    processInstance = (org.jbpm.process.instance.ProcessInstance) processInstanceInfo.getProcessInstance(kruntime, this.kruntime.getEnvironment(), readOnly);
    if (!readOnly) {
        processInstanceInfo.updateLastReadDate();
        TransactionManagerHelper.addToUpdatableSet(txm, processInstanceInfo);
        EventManagerProvider.getInstance().get().update(new ProcessInstanceView(processInstance));
    }
    if (((ProcessInstanceImpl) processInstance).getProcessXml() == null) {
        Process process = kruntime.getKieBase().getProcess(processInstance.getProcessId());
        if (process == null) {
            throw new IllegalArgumentException("Could not find process " + processInstance.getProcessId());
        }
        processInstance.setProcess(process);
    }
    if (processInstance.getKnowledgeRuntime() == null) {
        Long parentProcessInstanceId = (Long) ((ProcessInstanceImpl) processInstance).getMetaData().get("ParentProcessInstanceId");
        if (parentProcessInstanceId != null) {
            kruntime.getProcessInstance(parentProcessInstanceId);
        }
        processInstance.setKnowledgeRuntime(kruntime);
        ((ProcessInstanceImpl) processInstance).reconnect();
        if (readOnly) {
            internalRemoveProcessInstance(processInstance);
        }
    }
    return processInstance;
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) Process(org.kie.api.definition.process.Process) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) ProcessInstanceView(org.jbpm.persistence.api.integration.model.ProcessInstanceView) TransactionManager(org.drools.persistence.api.TransactionManager) ProcessPersistenceContextManager(org.jbpm.persistence.api.ProcessPersistenceContextManager)

Example 33 with InternalRuntimeManager

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

the class PerCaseRuntimeManagerTest method testTimerStartWithDeactivate.

@Test(timeout = 10000)
public void testTimerStartWithDeactivate() {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Hello", 1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-TimerStart.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(countDownListener);
            return listeners;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
    assertNotNull(manager);
    countDownListener.waitTillCompleted();
    RuntimeEngine runtime1 = manager.getRuntimeEngine(CaseContext.get("Case-1"));
    List<? extends ProcessInstanceLog> logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(1, logs.size());
    manager.disposeRuntimeEngine(runtime1);
    ((InternalRuntimeManager) manager).deactivate();
    countDownListener.reset(1);
    countDownListener.waitTillCompleted(2000);
    runtime1 = manager.getRuntimeEngine(CaseContext.get("Case-1"));
    logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(1, logs.size());
    manager.disposeRuntimeEngine(runtime1);
    ((InternalRuntimeManager) manager).activate();
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    runtime1 = manager.getRuntimeEngine(CaseContext.get("Case-1"));
    logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(2, logs.size());
    manager.disposeRuntimeEngine(runtime1);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 34 with InternalRuntimeManager

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

the class PerProcessInstanceRuntimeManagerTest method testSignalEventWithDeactivate.

@Test
public void testSignalEventWithDeactivate() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    ksession1.signalEvent("SampleEvent", null);
    List<? extends ProcessInstanceLog> logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(1, logs.size());
    manager.disposeRuntimeEngine(runtime1);
    ((InternalRuntimeManager) manager).deactivate();
    runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    ksession1 = runtime1.getKieSession();
    ksession1.signalEvent("SampleEvent", null);
    logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(1, logs.size());
    manager.disposeRuntimeEngine(runtime1);
    ((InternalRuntimeManager) manager).activate();
    runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    ksession1 = runtime1.getKieSession();
    ksession1.signalEvent("SampleEvent", null);
    logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(2, logs.size());
    manager.disposeRuntimeEngine(runtime1);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 35 with InternalRuntimeManager

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

the class SingletonRuntimeManagerTest method testSignalEventWithDeactivate.

@Test
public void testSignalEventWithDeactivate() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime1 = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    ksession1.signalEvent("SampleEvent", null);
    List<? extends ProcessInstanceLog> logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(1, logs.size());
    manager.disposeRuntimeEngine(runtime1);
    ((InternalRuntimeManager) manager).deactivate();
    runtime1 = manager.getRuntimeEngine(EmptyContext.get());
    ksession1 = runtime1.getKieSession();
    ksession1.signalEvent("SampleEvent", null);
    logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(1, logs.size());
    manager.disposeRuntimeEngine(runtime1);
    ((InternalRuntimeManager) manager).activate();
    runtime1 = manager.getRuntimeEngine(EmptyContext.get());
    ksession1 = runtime1.getKieSession();
    ksession1.signalEvent("SampleEvent", null);
    logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(2, logs.size());
    manager.disposeRuntimeEngine(runtime1);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)51 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)29 Test (org.junit.Test)23 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)23 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)17 HashMap (java.util.HashMap)14 KieSession (org.kie.api.runtime.KieSession)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)14 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)12 ArrayList (java.util.ArrayList)9 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)9 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)9 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)8 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)7 KieServices (org.kie.api.KieServices)7 ReleaseId (org.kie.api.builder.ReleaseId)7 TaskService (org.kie.api.task.TaskService)7 InternalTaskService (org.kie.internal.task.api.InternalTaskService)7 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)6