Search in sources :

Example 1 with SimpleRuntimeEnvironment

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);
        }
    }
}
Also used : SimpleRuntimeEnvironment(org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment) IdentityRolesSecurityManager(org.jbpm.kie.services.impl.security.IdentityRolesSecurityManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager)

Example 2 with SimpleRuntimeEnvironment

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;
}
Also used : SimpleRuntimeEnvironment(org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment) LocalTaskServiceFactory(org.jbpm.runtime.manager.impl.factory.LocalTaskServiceFactory) TaskServiceFactory(org.kie.internal.runtime.manager.TaskServiceFactory) LocalTaskServiceFactory(org.jbpm.runtime.manager.impl.factory.LocalTaskServiceFactory)

Example 3 with SimpleRuntimeEnvironment

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();
    }
}
Also used : SimpleRuntimeEnvironment(org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment) QuartzSchedulerService(org.jbpm.process.core.timer.impl.QuartzSchedulerService) EntityManagerFactory(javax.persistence.EntityManagerFactory) After(org.junit.After)

Example 4 with SimpleRuntimeEnvironment

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());
    }
}
Also used : SimpleRuntimeEnvironment(org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) PerCaseRuntimeManager(org.jbpm.runtime.manager.impl.PerCaseRuntimeManager) CaseInstanceAuditEventListener(org.jbpm.casemgmt.impl.audit.CaseInstanceAuditEventListener) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) NotifyParentCaseEventListener(org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener) CaseEventListener(org.jbpm.casemgmt.api.event.CaseEventListener) NotifyParentCaseEventListener(org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener)

Example 5 with SimpleRuntimeEnvironment

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;
    }
}
Also used : SimpleRuntimeEnvironment(org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment) HumanTaskConfigurator(org.jbpm.services.task.HumanTaskConfigurator) TaskService(org.kie.api.task.TaskService) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Aggregations

SimpleRuntimeEnvironment (org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment)5 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)2 CaseEventListener (org.jbpm.casemgmt.api.event.CaseEventListener)1 CaseInstanceAuditEventListener (org.jbpm.casemgmt.impl.audit.CaseInstanceAuditEventListener)1 NotifyParentCaseEventListener (org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener)1 IdentityRolesSecurityManager (org.jbpm.kie.services.impl.security.IdentityRolesSecurityManager)1 QuartzSchedulerService (org.jbpm.process.core.timer.impl.QuartzSchedulerService)1 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)1 PerCaseRuntimeManager (org.jbpm.runtime.manager.impl.PerCaseRuntimeManager)1 LocalTaskServiceFactory (org.jbpm.runtime.manager.impl.factory.LocalTaskServiceFactory)1 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)1 HumanTaskConfigurator (org.jbpm.services.task.HumanTaskConfigurator)1 TransactionalCommandService (org.jbpm.shared.services.impl.TransactionalCommandService)1 After (org.junit.After)1 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1 TaskService (org.kie.api.task.TaskService)1 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)1 TaskServiceFactory (org.kie.internal.runtime.manager.TaskServiceFactory)1