Search in sources :

Example 21 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class MultiSchemaMultiTenantProcessEngineConfiguration method buildProcessEngine.

@Override
public ProcessEngine buildProcessEngine() {
    if (databaseType == null) {
        throw new ActivitiException("Setting the databaseType is mandatory when using MultiSchemaMultiTenantProcessEngineConfiguration");
    }
    // Disable schema creation/validation by setting it to null.
    // We'll do it manually, see buildProcessEngine() method (hence why it's copied first)
    String originalDatabaseSchemaUpdate = this.databaseSchemaUpdate;
    this.databaseSchemaUpdate = null;
    // Using a cache / tenant to avoid process definition id conflicts
    this.processDefinitionCache = new MultiSchemaMultiTenantProcessDefinitionCache(tenantInfoHolder, this.processDefinitionCacheLimit);
    // Also, we shouldn't start the async executor until *after* the schema's have been created
    boolean originalIsAutoActivateAsyncExecutor = this.asyncExecutorActivate;
    this.asyncExecutorActivate = false;
    ProcessEngine processEngine = super.buildProcessEngine();
    // Reset to original values
    this.databaseSchemaUpdate = originalDatabaseSchemaUpdate;
    this.asyncExecutorActivate = originalIsAutoActivateAsyncExecutor;
    // Create tenant schema
    for (String tenantId : tenantInfoHolder.getAllTenants()) {
        createTenantSchema(tenantId);
    }
    // Start async executor
    if (asyncExecutor != null && originalIsAutoActivateAsyncExecutor) {
        asyncExecutor.start();
    }
    booted = true;
    return processEngine;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) MultiSchemaMultiTenantProcessDefinitionCache(org.activiti.engine.impl.persistence.deploy.MultiSchemaMultiTenantProcessDefinitionCache) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 22 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class ActivitiExtension method lookupProcessEngine.

protected ProcessEngine lookupProcessEngine(BeanManager beanManager) {
    ServiceLoader<ProcessEngineLookup> processEngineServiceLoader = ServiceLoader.load(ProcessEngineLookup.class);
    Iterator<ProcessEngineLookup> serviceIterator = processEngineServiceLoader.iterator();
    List<ProcessEngineLookup> discoveredLookups = new ArrayList<ProcessEngineLookup>();
    while (serviceIterator.hasNext()) {
        ProcessEngineLookup serviceInstance = (ProcessEngineLookup) serviceIterator.next();
        discoveredLookups.add(serviceInstance);
    }
    Collections.sort(discoveredLookups, new Comparator<ProcessEngineLookup>() {

        public int compare(ProcessEngineLookup o1, ProcessEngineLookup o2) {
            return (-1) * ((Integer) o1.getPrecedence()).compareTo(o2.getPrecedence());
        }
    });
    ProcessEngine processEngine = null;
    for (ProcessEngineLookup processEngineLookup : discoveredLookups) {
        processEngine = processEngineLookup.getProcessEngine();
        if (processEngine != null) {
            this.processEngineLookup = processEngineLookup;
            logger.debug("ProcessEngineLookup service {} returned process engine.", processEngineLookup.getClass());
            break;
        } else {
            logger.debug("ProcessEngineLookup service {} retuned 'null' value.", processEngineLookup.getClass());
        }
    }
    if (processEngineLookup == null) {
        throw new ActivitiException("Could not find an implementation of the org.activiti.cdi.spi.ProcessEngineLookup service " + "returning a non-null processEngine. Giving up.");
    }
    ActivitiServices activitiServices = ProgrammaticBeanLookup.lookup(ActivitiServices.class, beanManager);
    activitiServices.setProcessEngine(processEngine);
    return processEngine;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessEngineLookup(org.activiti.cdi.spi.ProcessEngineLookup) ActivitiServices(org.activiti.cdi.impl.util.ActivitiServices) ArrayList(java.util.ArrayList) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 23 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class ActivitiExtension method afterDeploymentValidation.

public void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanManager beanManager) {
    try {
        logger.info("Initializing activiti-cdi.");
        // initialize the process engine
        ProcessEngine processEngine = lookupProcessEngine(beanManager);
        // deploy the processes if engine was set up correctly
        deployProcesses(processEngine);
    } catch (Exception e) {
        // interpret engine initialization problems as definition errors
        event.addDeploymentProblem(e);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 24 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class ActivitiServletContextListener method contextInitialized.

public void contextInitialized(ServletContextEvent event) {
    LOGGER.info("Booting Activiti Process Engine");
    ProcessEngine processEngine = null;
    try {
        processEngine = ProcessEngines.getDefaultProcessEngine();
    } catch (Exception e) {
        LOGGER.error("Error starting the Activiti REST API", e);
    }
    if (processEngine == null) {
        LOGGER.error("Could not start the Activiti REST API");
    }
}
Also used : ProcessEngine(org.activiti.engine.ProcessEngine)

Example 25 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class AsyncExecutorTest method testAsyncScriptExecutionOnTwoEngines.

@Test
public void testAsyncScriptExecutionOnTwoEngines() {
    ProcessEngine firstProcessEngine = null;
    ProcessEngine secondProcessEngine = null;
    try {
        // Deploy
        firstProcessEngine = createProcessEngine(false);
        Date now = setClockToCurrentTime(firstProcessEngine);
        deploy(firstProcessEngine, "AsyncExecutorTest.testAsyncScriptExecution.bpmn20.xml");
        // Start process instance. Nothing should happen
        firstProcessEngine.getRuntimeService().startProcessInstanceByKey("asyncScript");
        Assert.assertEquals(0, firstProcessEngine.getTaskService().createTaskQuery().taskName("Task after script").count());
        Assert.assertEquals(1, firstProcessEngine.getManagementService().createJobQuery().count());
        // Start second engine, with async executor enabled
        // Same timestamp as first engine
        secondProcessEngine = createProcessEngine(true, now);
        Assert.assertEquals(0, firstProcessEngine.getTaskService().createTaskQuery().taskName("Task after script").count());
        Assert.assertEquals(1, firstProcessEngine.getManagementService().createJobQuery().count());
        // Move the clock 1 second. Should be executed now by second engine
        addSecondsToCurrentTime(secondProcessEngine, 1);
        waitForAllJobsBeingExecuted(secondProcessEngine, 10000L);
        // Verify if all is as expected
        Assert.assertEquals(1, firstProcessEngine.getTaskService().createTaskQuery().taskName("Task after script").count());
        Assert.assertEquals(0, firstProcessEngine.getManagementService().createJobQuery().count());
        Assert.assertEquals(0, getAsyncExecutorJobCount(firstProcessEngine));
        Assert.assertEquals(1, getAsyncExecutorJobCount(secondProcessEngine));
    } finally {
        // Clean up
        cleanup(firstProcessEngine);
        cleanup(secondProcessEngine);
    }
}
Also used : Date(java.util.Date) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Aggregations

ProcessEngine (org.activiti.engine.ProcessEngine)31 Test (org.junit.Test)13 RepositoryService (org.activiti.engine.RepositoryService)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 ActivitiException (org.activiti.engine.ActivitiException)6 RuntimeService (org.activiti.engine.RuntimeService)6 TaskService (org.activiti.engine.TaskService)4 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)4 StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 Task (org.activiti.engine.task.Task)4 StandaloneInMemProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration)3 Deployment (org.activiti.engine.repository.Deployment)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1