use of org.drools.core.RuleBaseConfiguration.AssertBehaviour in project opennms by OpenNMS.
the class DroolsNorthbounder method initializeDroolsEngine.
/**
* Initialize drools engine.
*
* @throws Exception the exception
*/
private void initializeDroolsEngine() throws Exception {
KieServices ks = KieServices.Factory.get();
KieFileSystem kFileSystem = ks.newKieFileSystem();
for (String ruleFile : m_engine.getRuleFiles()) {
LOG.debug("Loading rules file: {}", ruleFile);
kFileSystem.write("src/main/resources/" + ruleFile, ks.getResources().newFileSystemResource(new File(ruleFile)));
}
KieBuilder kbuilder = ks.newKieBuilder(kFileSystem);
kbuilder.buildAll();
if (kbuilder.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
LOG.warn("Unable to initialize Drools engine: {}", kbuilder.getResults().getMessages(Level.ERROR));
throw new IllegalStateException("Unable to initialize Drools engine: " + kbuilder.getResults().getMessages(Level.ERROR));
}
KieContainer kContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
AssertBehaviour behaviour = AssertBehaviour.determineAssertBehaviour(m_engine.getAssertBehaviour());
RuleBaseConfiguration ruleBaseConfig = new RuleBaseConfiguration();
ruleBaseConfig.setAssertBehaviour(behaviour);
ruleBaseConfig.setEventProcessingMode(EventProcessingOption.STREAM);
m_kieBase = kContainer.newKieBase(ruleBaseConfig);
m_kieSession = m_kieBase.newKieSession();
m_kieSession.setGlobal("engine", this);
unmarshallStateFromDisk(true);
ApplicationContext ctx = m_context;
if (m_engine.getAppContext() != null) {
ctx = new FileSystemXmlApplicationContext(new String[] { m_engine.getAppContext() }, m_context);
}
for (Global global : m_engine.getGlobals()) {
m_kieSession.setGlobal(global.getName(), global.constructValue(ctx));
}
new Thread(() -> {
Logging.putPrefix(getName());
LOG.debug("Starting task thread for {}", getName());
m_kieSession.fireUntilHalt();
LOG.debug("Stopping task thread for {}", getName());
}, "FireTask-" + getName()).start();
}
use of org.drools.core.RuleBaseConfiguration.AssertBehaviour in project opennms by OpenNMS.
the class DroolsCorrelationEngine method initialize.
/**
* <p>initialize</p>
*
* @throws java.lang.Exception if any.
*/
public void initialize() throws Exception {
KieServices ks = KieServices.Factory.get();
KieFileSystem kFileSystem = ks.newKieFileSystem();
loadRules(kFileSystem);
KieBuilder kbuilder = ks.newKieBuilder(kFileSystem);
kbuilder.buildAll();
if (kbuilder.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
LOG.warn("Unable to initialize Drools engine: {}", kbuilder.getResults().getMessages(Level.ERROR));
throw new IllegalStateException("Unable to initialize Drools engine: " + kbuilder.getResults().getMessages(Level.ERROR));
}
KieContainer kContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
AssertBehaviour behaviour = AssertBehaviour.determineAssertBehaviour(m_assertBehaviour);
RuleBaseConfiguration ruleBaseConfig = new RuleBaseConfiguration();
ruleBaseConfig.setAssertBehaviour(behaviour);
EventProcessingOption eventProcessingOption = EventProcessingOption.CLOUD;
if (m_eventProcessingMode != null && m_eventProcessingMode.toLowerCase().equals("stream")) {
eventProcessingOption = EventProcessingOption.STREAM;
m_isStreaming = true;
}
ruleBaseConfig.setEventProcessingMode(eventProcessingOption);
m_kieBase = kContainer.newKieBase(ruleBaseConfig);
m_kieSession = m_kieBase.newKieSession();
m_kieSession.setGlobal("engine", this);
for (final Map.Entry<String, Object> entry : m_globals.entrySet()) {
m_kieSession.setGlobal(entry.getKey(), entry.getValue());
}
if (m_persistState != null && m_persistState) {
unmarshallStateFromDisk(true);
}
if (m_isStreaming) {
new Thread(() -> {
Logging.putPrefix(getClass().getSimpleName() + '-' + getName());
m_kieSession.fireUntilHalt();
}, "FireTask").start();
}
}
Aggregations