@Bean public DmnEngine dmnEngine(@SuppressWarnings("unused") ProcessEngine processEngine) { // The process engine needs to be injected, as otherwise it won't be initialized, which means that the DmnEngine is not initialized yet if (!DmnEngines.isInitialized()) { throw new IllegalStateException("DMN engine has not been initialized"); } return DmnEngines.getDefaultDmnEngine(); } }
public static DmnEngine getDefaultDmnEngine() { return getDmnEngine(NAME_DEFAULT); }
@Override protected void initializeDmnEngine() { if (cachedDmnEngine == null) { LOGGER.info("No cached dmn engine found for test. Retrieving the default engine."); DmnEngines.destroy(); // Just to be sure we're not getting any previously cached version cachedDmnEngine = DmnEngines.getDefaultDmnEngine(); if (cachedDmnEngine == null) { throw new FlowableException("no default dmn engine available"); } } dmnEngine = cachedDmnEngine; dmnEngineConfiguration = ((DmnEngineImpl) dmnEngine).getDmnEngineConfiguration(); }
/** * obtain a dmn engine by name. * * @param dmnEngineName * is the name of the dmn engine or null for the default dmn engine. */ public static DmnEngine getDmnEngine(String dmnEngineName) { if (!isInitialized()) { init(); } return dmnEngines.get(dmnEngineName); }
if (!isInitialized()) { if (dmnEngines == null) { URL resource = iterator.next(); LOGGER.info("Initializing dmn engine using configuration '{}'", resource.toString()); initDmnEngineFromResource(resource); URL resource = resources.nextElement(); LOGGER.info("Initializing dmn engine using Spring configuration '{}'", resource.toString()); initDmnEngineFromSpringResource(resource); setInitialized(true); } else { LOGGER.info("DMN engines already initialized");
/** * closes all dmn engines. This method should be called when the server shuts down. */ public static synchronized void destroy() { if (isInitialized()) { Map<String, DmnEngine> engines = new HashMap<>(dmnEngines); dmnEngines = new HashMap<>(); for (String dmnEngineName : engines.keySet()) { DmnEngine dmnEngine = engines.get(dmnEngineName); try { dmnEngine.close(); } catch (Exception e) { LOGGER.error("exception while closing {}", (dmnEngineName == null ? "the default dmn engine" : "dmn engine " + dmnEngineName), e); } } dmnEngineInfosByName.clear(); dmnEngineInfosByResourceUrl.clear(); dmnEngineInfos.clear(); setInitialized(false); } }
@Override public DmnEngine buildDmnEngine() { DmnEngine dmnEngine = super.buildDmnEngine(); DmnEngines.setInitialized(true); enginesBuild.add(dmnEngine.getName()); return dmnEngine; }
public static void main(String[] args) { try { DmnEngine dmnEngine = DmnEngines.getDefaultDmnEngine(); DataSource dataSource = dmnEngine.getDmnEngineConfiguration().getDataSource(); DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName()); if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema())) { database.setDefaultSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema()); database.setLiquibaseSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema()); } if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog())) { database.setDefaultCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog()); database.setLiquibaseCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog()); } Liquibase liquibase = new Liquibase("org/flowable/dmn/db/liquibase/flowable-dmn-db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); liquibase.getDatabase().close(); } catch (Exception e) { e.printStackTrace(); } } }
/** * retries to initialize a dmn engine that previously failed. */ public static EngineInfo retry(String resourceUrl) { LOGGER.debug("retying initializing of resource {}", resourceUrl); try { return initDmnEngineFromResource(new URL(resourceUrl)); } catch (MalformedURLException e) { throw new FlowableException("invalid url: " + resourceUrl, e); } }
private static EngineInfo initDmnEngineFromResource(URL resourceUrl) { EngineInfo dmnEngineInfo = dmnEngineInfosByResourceUrl.get(resourceUrl.toString()); // if there is an existing dmn engine info if (dmnEngineInfo != null) { // remove that dmn engine from the member fields dmnEngineInfos.remove(dmnEngineInfo); if (dmnEngineInfo.getException() == null) { String dmnEngineName = dmnEngineInfo.getName(); dmnEngines.remove(dmnEngineName); dmnEngineInfosByName.remove(dmnEngineName); } dmnEngineInfosByResourceUrl.remove(dmnEngineInfo.getResourceUrl()); } String resourceUrlString = resourceUrl.toString(); try { LOGGER.info("initializing dmn engine for resource {}", resourceUrl); DmnEngine dmnEngine = buildDmnEngine(resourceUrl); String dmnEngineName = dmnEngine.getName(); LOGGER.info("initialised dmn engine {}", dmnEngineName); dmnEngineInfo = new EngineInfo(dmnEngineName, resourceUrlString, null); dmnEngines.put(dmnEngineName, dmnEngine); dmnEngineInfosByName.put(dmnEngineName, dmnEngineInfo); } catch (Throwable e) { LOGGER.error("Exception while initializing dmn engine: {}", e.getMessage(), e); dmnEngineInfo = new EngineInfo(null, resourceUrlString, ExceptionUtils.getStackTrace(e)); } dmnEngineInfosByResourceUrl.put(resourceUrlString, dmnEngineInfo); dmnEngineInfos.add(dmnEngineInfo); return dmnEngineInfo; }
public DmnEngineImpl(DmnEngineConfiguration dmnEngineConfiguration) { this.dmnEngineConfiguration = dmnEngineConfiguration; this.name = dmnEngineConfiguration.getEngineName(); this.dmnManagementService = dmnEngineConfiguration.getDmnManagementService(); this.dmnRepositoryService = dmnEngineConfiguration.getDmnRepositoryService(); this.dmnRuleService = dmnEngineConfiguration.getDmnRuleService(); this.dmnHistoryService = dmnEngineConfiguration.getDmnHistoryService(); if (dmnEngineConfiguration.getSchemaManagementCmd() != null) { dmnEngineConfiguration.getCommandExecutor().execute(dmnEngineConfiguration.getSchemaCommandConfig(), dmnEngineConfiguration.getSchemaManagementCmd()); } if (name == null) { LOGGER.info("default flowable DmnEngine created"); } else { LOGGER.info("DmnEngine {} created", name); } DmnEngines.registerDmnEngine(this); }
@Bean public DmnEngine dmnEngine(@SuppressWarnings("unused") AppEngine appEngine) { // The app engine needs to be injected, as otherwise it won't be initialized, which means that the DmnEngine is not initialized yet if (!DmnEngines.isInitialized()) { throw new IllegalStateException("DMN engine has not been initialized"); } return DmnEngines.getDefaultDmnEngine(); } }
@Override public void start() { synchronized (lifeCycleMonitor) { if (!isRunning()) { enginesBuild.forEach(name -> autoDeployResources(DmnEngines.getDmnEngine(name))); running = true; } } }