use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class AbstractDeploymentService method commonDeploy.
public void commonDeploy(DeploymentUnit unit, DeployedUnitImpl deployedUnit, RuntimeEnvironment environemnt, KieContainer kieContainer) {
synchronized (this) {
if (deploymentsMap.containsKey(unit.getIdentifier())) {
DeployedUnit deployed = deploymentsMap.remove(unit.getIdentifier());
RuntimeManager manager = deployed.getRuntimeManager();
manager.close();
}
RuntimeManager manager = null;
deploymentsMap.put(unit.getIdentifier(), deployedUnit);
((SimpleRuntimeEnvironment) environemnt).addToEnvironment("IdentityProvider", identityProvider);
((SimpleRuntimeEnvironment) environemnt).addToEnvironment("Active", deployedUnit.isActive());
try {
switch(unit.getStrategy()) {
case SINGLETON:
manager = managerFactory.newSingletonRuntimeManager(environemnt, unit.getIdentifier());
break;
case PER_REQUEST:
manager = managerFactory.newPerRequestRuntimeManager(environemnt, unit.getIdentifier());
break;
case PER_PROCESS_INSTANCE:
manager = managerFactory.newPerProcessInstanceRuntimeManager(environemnt, unit.getIdentifier());
break;
case PER_CASE:
manager = managerFactory.newPerCaseRuntimeManager(environemnt, unit.getIdentifier());
break;
default:
throw new IllegalArgumentException("Invalid strategy " + unit.getStrategy());
}
if (!deployedUnit.isActive()) {
((InternalRuntimeManager) manager).deactivate();
}
((InternalRuntimeManager) manager).setKieContainer(kieContainer);
deployedUnit.setRuntimeManager(manager);
DeploymentDescriptor descriptor = ((InternalRuntimeManager) manager).getDeploymentDescriptor();
List<String> requiredRoles = descriptor.getRequiredRoles(DeploymentDescriptor.TYPE_EXECUTE);
if (requiredRoles != null && !requiredRoles.isEmpty()) {
((InternalRuntimeManager) manager).setSecurityManager(new IdentityRolesSecurityManager(identityProvider, requiredRoles));
}
notifyOnDeploy(unit, deployedUnit);
} catch (Throwable e) {
deploymentsMap.remove(unit.getIdentifier());
if (manager != null) {
manager.close();
}
notifyOnUnDeploy(unit, deployedUnit);
throw new RuntimeException(e);
}
}
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class CancelCaseCommand method execute.
@Override
public Void execute(Context context) {
CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
Collection<ProcessInstanceDesc> caseProcesses = runtimeDataService.getProcessInstancesByCorrelationKey(correlationKey, new QueryContext(0, 1000));
if (caseProcesses.isEmpty()) {
throw new CaseNotFoundException("Case with id " + caseId + " was not found");
}
List<Long> processInstanceIds = caseProcesses.stream().filter(pi -> pi.getState().equals(ProcessInstance.STATE_ACTIVE)).sorted((ProcessInstanceDesc o1, ProcessInstanceDesc o2) -> {
return Long.valueOf(o2.getParentId()).compareTo(Long.valueOf(o1.getParentId()));
}).map(pi -> pi.getId()).collect(toList());
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
CaseFileInstance caseFile = getCaseFile(ksession, caseId);
caseEventSupport.fireBeforeCaseCancelled(caseId, caseFile, processInstanceIds);
logger.debug("Case {} consists of following process instances (ids) {}", caseId, processInstanceIds);
processService.abortProcessInstances(processInstanceIds);
caseEventSupport.fireAfterCaseCancelled(caseId, caseFile, processInstanceIds);
if (destroy) {
RuntimeManager runtimeManager = getRuntimeManager(context);
if (runtimeManager instanceof PerCaseRuntimeManager) {
caseEventSupport.fireBeforeCaseDestroyed(caseId, caseFile, processInstanceIds);
logger.debug("Case {} aborted, destroying case data including per case runtime engine (including working memory)", caseId);
((PerCaseRuntimeManager) runtimeManager).destroyCase(CaseContext.get(caseId));
caseEventSupport.fireAfterCaseDestroyed(caseId, caseFile, processInstanceIds);
}
}
return null;
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class CaseCommand method getRuntimeManager.
protected RuntimeManager getRuntimeManager(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
RuntimeManager runtimeManager = (RuntimeManager) ksession.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER);
return runtimeManager;
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class RuntimeManagerFactoryImpl method newPerProcessInstanceRuntimeManager.
public RuntimeManager newPerProcessInstanceRuntimeManager(RuntimeEnvironment environment, String identifier) {
SessionFactory factory = getSessionFactory(environment, identifier);
TaskServiceFactory taskServiceFactory = getTaskServiceFactory(environment);
RuntimeManager manager = new PerProcessInstanceRuntimeManager(environment, factory, taskServiceFactory, identifier);
initTimerService(environment, manager);
((AbstractRuntimeManager) manager).init();
return manager;
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class RuntimeManagerFactoryImpl method newPerRequestRuntimeManager.
public RuntimeManager newPerRequestRuntimeManager(RuntimeEnvironment environment, String identifier) {
SessionFactory factory = getSessionFactory(environment, identifier);
TaskServiceFactory taskServiceFactory = getTaskServiceFactory(environment);
RuntimeManager manager = new PerRequestRuntimeManager(environment, factory, taskServiceFactory, identifier);
initTimerService(environment, manager);
((AbstractRuntimeManager) manager).init();
return manager;
}
Aggregations