use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.
the class ClassloaderKModuleDeploymentServiceTest method testDeploymentOfProcesses.
@Test
public void testDeploymentOfProcesses() throws Exception {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "defaultKieBase", "defaultKieSession");
deploymentUnit.setStrategy(RuntimeStrategy.PER_REQUEST);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployed);
assertNotNull(deployed.getDeploymentUnit());
assertNotNull(deployed.getRuntimeManager());
assertEquals("org.jbpm.test:jbpm-module:1.0:defaultKieBase:defaultKieSession", deployed.getDeploymentUnit().getIdentifier());
assertNotNull(runtimeDataService);
Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
assertNotNull(processes);
assertEquals(1, processes.size());
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Class<?> clazz = Class.forName("org.jbpm.test.Person", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
Object instance = clazz.newInstance();
Map<String, Object> params = new HashMap<String, Object>();
params.put("person", instance);
ProcessInstance processInstance = engine.getKieSession().startProcess("testkjar.src.main.resources.process", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
List<TaskSummary> tasks = engine.getTaskService().getTasksOwned("salaboy", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
Map<String, Object> content = ((InternalTaskService) engine.getTaskService()).getTaskContent(taskId);
assertTrue(content.containsKey("personIn"));
Object person = content.get("personIn");
assertEquals(clazz.getName(), person.getClass().getName());
engine.getTaskService().start(taskId, "salaboy");
Map<String, Object> data = new HashMap<String, Object>();
data.put("personOut", instance);
engine.getTaskService().complete(taskId, "salaboy", data);
processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.
the class PessimisticLockTasksServiceTest method testPessimisticLockingOnTask.
@Test
public void testPessimisticLockingOnTask() throws Exception {
final List<Exception> exceptions = new ArrayList<Exception>();
addEnvironmentEntry(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
createRuntimeManager("org/jbpm/test/functional/task/Evaluation2.bpmn");
RuntimeEngine runtimeEngine = getRuntimeEngine();
final KieSession ksession = runtimeEngine.getKieSession();
final TaskService taskService = runtimeEngine.getTaskService();
// setup another instance of task service to allow not synchronized access to cause pessimistic lock exception
RuntimeEnvironment runtimeEnv = ((InternalRuntimeManager) manager).getEnvironment();
HumanTaskConfigurator configurator = HumanTaskServiceFactory.newTaskServiceConfigurator().environment(runtimeEnv.getEnvironment()).entityManagerFactory((EntityManagerFactory) runtimeEnv.getEnvironment().get(EnvironmentName.ENTITY_MANAGER_FACTORY)).userGroupCallback(runtimeEnv.getUserGroupCallback());
// register task listeners if any
RegisterableItemsFactory itemsFactory = runtimeEnv.getRegisterableItemsFactory();
for (TaskLifeCycleEventListener taskListener : itemsFactory.getTaskListeners()) {
configurator.listener(taskListener);
}
final TaskService internalTaskService = configurator.getTaskService();
logger.info("### Starting process ###");
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("employee", "salaboy");
ProcessInstance process = ksession.startProcess("com.sample.evaluation", parameters);
// The process is in the first Human Task waiting for its completion
assertEquals(ProcessInstance.STATE_ACTIVE, process.getState());
// gets salaboy's tasks
List<TaskSummary> salaboysTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
assertEquals(1, salaboysTasks.size());
final long taskId = salaboysTasks.get(0).getId();
final CountDownLatch t2StartLockedTask = new CountDownLatch(1);
final CountDownLatch t1Continue = new CountDownLatch(1);
Thread t1 = new Thread() {
@Override
public void run() {
try {
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
logger.info("Attempting to lock task instance");
taskService.start(taskId, "salaboy");
t2StartLockedTask.countDown();
t1Continue.await();
} finally {
ut.rollback();
}
} catch (Exception e) {
logger.error("Error on thread ", e);
}
}
};
Thread t2 = new Thread() {
@Override
public void run() {
try {
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
t2StartLockedTask.await();
logger.info("Trying to start locked task instance");
try {
internalTaskService.start(taskId, "salaboy");
} catch (Exception e) {
logger.info("Abort failed with error {}", e.getMessage());
exceptions.add(e);
} finally {
t1Continue.countDown();
}
} finally {
ut.rollback();
}
} catch (Exception e) {
logger.error("Error on thread ", e);
}
}
};
t1.start();
t2.start();
t1.join();
t2.join();
assertEquals(1, exceptions.size());
assertEquals(PessimisticLockException.class.getName(), exceptions.get(0).getClass().getName());
taskService.start(salaboysTasks.get(0).getId(), "salaboy");
// complete task within user transaction to make sure no deadlock happens as both task service and ksession are under tx lock
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
taskService.complete(salaboysTasks.get(0).getId(), "salaboy", null);
ut.commit();
} catch (Exception ex) {
ut.rollback();
throw ex;
}
List<TaskSummary> pmsTasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, pmsTasks.size());
List<TaskSummary> hrsTasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(1, hrsTasks.size());
ksession.abortProcessInstance(process.getId());
assertProcessInstanceAborted(process.getId());
}
use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.
the class CaseConfigurationDeploymentListener method onDeploy.
@Override
public void onDeploy(DeploymentEvent event) {
InternalRuntimeManager runtimeManager = (InternalRuntimeManager) event.getDeployedUnit().getRuntimeManager();
if (runtimeManager instanceof PerCaseRuntimeManager) {
List<CaseEventListener> caseEventListeners = getEventListenerFromDescriptor(runtimeManager);
logger.debug("Adding following case event listeners {} for deployment {}", caseEventListeners, event.getDeploymentId());
TransactionalCommandService commandService = transactionalCommandService;
if (commandService == null) {
commandService = new TransactionalCommandService(((SimpleRuntimeEnvironment) runtimeManager.getEnvironment()).getEmf());
}
CaseInstanceAuditEventListener auditEventListener = new CaseInstanceAuditEventListener(commandService);
caseEventListeners.add(auditEventListener);
caseEventListeners.add(new NotifyParentCaseEventListener(identityProvider));
CaseEventSupport caseEventSupport = new CaseEventSupport(identityProvider, caseEventListeners);
((PerCaseRuntimeManager) runtimeManager).setCaseEventSupport(caseEventSupport);
logger.debug("CaseEventSupport configured for deployment {}", event.getDeploymentId());
}
}
use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.
the class CaseConfigurationDeploymentListener method onUnDeploy.
@Override
public void onUnDeploy(DeploymentEvent event) {
InternalRuntimeManager runtimeManager = (InternalRuntimeManager) event.getDeployedUnit().getRuntimeManager();
if (runtimeManager instanceof PerCaseRuntimeManager) {
CaseEventSupport caseEventSupport = (CaseEventSupport) ((PerCaseRuntimeManager) runtimeManager).getCaseEventSupport();
if (caseEventSupport != null) {
caseEventSupport.reset();
logger.debug("CaseEventSupport disposed for deployment {}", event.getDeploymentId());
}
}
}
use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.
the class AbstractProcessInstanceFactory method createProcessInstance.
public ProcessInstance createProcessInstance(Process process, CorrelationKey correlationKey, InternalKnowledgeRuntime kruntime, Map<String, Object> parameters) {
ProcessInstance processInstance = (ProcessInstance) createProcessInstance();
processInstance.setKnowledgeRuntime(kruntime);
processInstance.setProcess(process);
if (correlationKey != null) {
processInstance.getMetaData().put("CorrelationKey", correlationKey);
}
InternalRuntimeManager manager = (InternalRuntimeManager) kruntime.getEnvironment().get("RuntimeManager");
if (manager != null) {
processInstance.setDeploymentId(manager.getIdentifier());
}
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessInstanceManager().addProcessInstance(processInstance, correlationKey);
// set variable default values
// TODO: should be part of processInstanceImpl?
VariableScope variableScope = (VariableScope) ((ContextContainer) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
// set input parameters
if (parameters != null) {
if (variableScope != null) {
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
variableScope.validateVariable(process.getName(), entry.getKey(), entry.getValue());
variableScopeInstance.setVariable(entry.getKey(), entry.getValue());
}
} else {
throw new IllegalArgumentException("This process does not support parameters!");
}
}
return processInstance;
}
Aggregations