use of org.drools.core.RuleBaseConfiguration 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();
}
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class RuleBaseConfigurationTest method testProgrammaticPropertiesFile.
@Test
public void testProgrammaticPropertiesFile() {
RuleBaseConfiguration cfg = new RuleBaseConfiguration();
assertEquals(true, cfg.isIndexLeftBetaMemory());
Properties properties = new Properties();
properties.setProperty("drools.indexLeftBetaMemory", "false");
cfg = new RuleBaseConfiguration(properties);
assertEquals(false, cfg.isIndexLeftBetaMemory());
System.getProperties().remove("drools.indexLeftBetaMemory");
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class RuleBaseConfigurationTest method testSystemProperties.
@Test
public void testSystemProperties() {
RuleBaseConfiguration cfg = new RuleBaseConfiguration();
assertEquals(AssertBehaviour.IDENTITY, cfg.getAssertBehaviour());
System.setProperty("drools.equalityBehavior", "EQUALITY");
cfg = new RuleBaseConfiguration();
assertEquals(AssertBehaviour.EQUALITY, cfg.getAssertBehaviour());
System.getProperties().remove("drools.equalityBehavior");
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class RuleBaseConfigurationTest method testSequential.
@Test
public void testSequential() {
Properties properties = new Properties();
properties.setProperty("drools.sequential", "false");
RuleBaseConfiguration cfg = new RuleBaseConfiguration(properties);
assertFalse(cfg.isSequential());
assertTrue(cfg.getAgendaGroupFactory() instanceof PriorityQueueAgendaGroupFactory);
properties = new Properties();
properties.setProperty("drools.sequential.agenda", "sequential");
properties.setProperty("drools.sequential", "true");
cfg = new RuleBaseConfiguration(properties);
assertTrue(cfg.isSequential());
assertEquals(SequentialAgenda.SEQUENTIAL, cfg.getSequentialAgenda());
properties = new Properties();
properties.setProperty("drools.sequential.agenda", "dynamic");
properties.setProperty("drools.sequential", "true");
cfg = new RuleBaseConfiguration(properties);
assertTrue(cfg.isSequential());
assertEquals(SequentialAgenda.DYNAMIC, cfg.getSequentialAgenda());
assertTrue(cfg.getAgendaGroupFactory() instanceof PriorityQueueAgendaGroupFactory);
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class ScenarioTest method createContext.
public BuildContext createContext() {
RuleBaseConfiguration conf = new RuleBaseConfiguration();
KnowledgeBaseImpl rbase = new KnowledgeBaseImpl("ID", conf);
BuildContext buildContext = new BuildContext(rbase, Collections.emptyList());
RuleImpl rule = new RuleImpl("rule1").setPackage("org.pkg1");
InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("org.pkg1");
pkg.getDialectRuntimeRegistry().setDialectData("java", new JavaDialectRuntimeData());
pkg.addRule(rule);
buildContext.setRule(rule);
return buildContext;
}
Aggregations