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;
}
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;
}
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);
}
}
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");
}
}
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);
}
}
Aggregations