public static ProcessEngine getEngine(){
if (engine == null){
Database ec = JenkowBuilder.descriptor().getDatabase();
LOG.info("engineConfig="+ec);
ProcessEngineConfiguration cfg;
// context for *all* processes. available in exppressions and scripts in the process.
Map<Object,Object> ctxBeans = new HashMap<Object,Object>();
ctxBeans.put("log",LOG);
if (ec instanceof H2DemoDatabase) {
cfg = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
// we will be sharing this database with Activiti Explorer, so don't force re-creation of the whole DB
// and honor what's already there
cfg.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
} else {
cfg = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
Mailer.DescriptorImpl md = Mailer.descriptor();
System.out.println("mailer config");
System.out.println("md.getSmtpServer() -> "+md.getSmtpServer());
System.out.println("md.getDefaultSuffix() -> "+md.getDefaultSuffix());
System.out.println("md.getReplyToAddress() -> "+md.getReplyToAddress());
System.out.println("md.getSmtpPort() -> "+md.getSmtpPort());
// set database config
try {
cfg.setDataSource(ec.getDataSource());
} catch (SQLException e) {
throw new Error(e); // TODO: what's the error handling strategy in this method?
}
// set other engine config
cfg.setDatabaseSchemaUpdate("true");
}
cfg.setHistory("full"); // so that workflow variables are getting persisted in history
cfg.setJobExecutorActivate(true);
ClassLoader peCL = JenkowEngine.class.getClassLoader();
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(peCL);
// set common cfg here.
ProcessEngineConfigurationImpl peCfg = (ProcessEngineConfigurationImpl)cfg;
peCfg.setIdentityService(new IdentityServiceImpl());
peCfg.setBeans(ctxBeans);
List<BpmnParseListener> preParseListeners = peCfg.getPreParseListeners();
if (preParseListeners == null){
preParseListeners = new ArrayList<BpmnParseListener>();
peCfg.setPreParseListeners(preParseListeners);
}
preParseListeners.add(new JenkowBpmnParseListener());
cfg.setClassLoader(peCL);
// build engine
engine = cfg.buildProcessEngine();
Thread.currentThread().setContextClassLoader(oldCL);
LOG.info("created Activiti workflow engine v"+engine.VERSION);
WfUtil.deployAllToEngine();
}