use of org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment 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.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment in project jbpm by kiegroup.
the class RuntimeManagerFactoryCDIImpl method getTaskServiceFactory.
@Override
protected TaskServiceFactory getTaskServiceFactory(RuntimeEnvironment environment) {
// if there is an implementation of TaskServiceFactory in the environment then use it
TaskServiceFactory taskServiceFactory = (TaskServiceFactory) ((SimpleRuntimeEnvironment) environment).getEnvironmentTemplate().get("org.kie.internal.runtime.manager.TaskServiceFactory");
if (taskServiceFactory != null) {
return taskServiceFactory;
}
try {
taskServiceFactory = taskServiceFactoryInjected.get();
// since this is CDI let's make sure it has all dependencies met
taskServiceFactory.newTaskService().toString();
} catch (Exception e) {
taskServiceFactory = new LocalTaskServiceFactory(environment);
}
return taskServiceFactory;
}
use of org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment in project jbpm by kiegroup.
the class MultipleTimerServicesTest method cleanup.
@After
public void cleanup() {
System.clearProperty("org.quartz.properties");
((QuartzSchedulerService) globalScheduler1).forceShutdown();
((QuartzSchedulerService) globalScheduler2).forceShutdown();
managerM1.close();
managerM2.close();
EntityManagerFactory emf = ((SimpleRuntimeEnvironment) environmentM1).getEmf();
if (emf != null) {
emf.close();
}
emf = ((SimpleRuntimeEnvironment) environmentM2).getEmf();
if (emf != null && emf.isOpen()) {
emf.close();
}
}
use of org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment 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.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment in project jbpm by kiegroup.
the class LocalTaskServiceFactory method newTaskService.
@Override
public TaskService newTaskService() {
// all to reuse an already given instance of task service instead of producing new one
TaskService providedTaskService = (TaskService) ((SimpleRuntimeEnvironment) runtimeEnvironment).getEnvironmentTemplate().get("org.kie.api.task.TaskService");
if (providedTaskService != null) {
return providedTaskService;
}
EntityManagerFactory emf = ((SimpleRuntimeEnvironment) runtimeEnvironment).getEmf();
if (emf != null) {
HumanTaskConfigurator configurator = HumanTaskServiceFactory.newTaskServiceConfigurator().environment(runtimeEnvironment.getEnvironment()).entityManagerFactory(emf).userGroupCallback(runtimeEnvironment.getUserGroupCallback()).userInfo(UserDataServiceProvider.getUserInfo());
TaskService internalTaskService = configurator.getTaskService();
return internalTaskService;
} else {
return null;
}
}
Aggregations