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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations