Search in sources :

Example 1 with ProcessEngineLookup

use of org.activiti.cdi.spi.ProcessEngineLookup 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)

Aggregations

ArrayList (java.util.ArrayList)1 ActivitiServices (org.activiti.cdi.impl.util.ActivitiServices)1 ProcessEngineLookup (org.activiti.cdi.spi.ProcessEngineLookup)1 ActivitiException (org.activiti.engine.ActivitiException)1 ProcessEngine (org.activiti.engine.ProcessEngine)1