Search in sources :

Example 36 with RuleBaseConfiguration

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();
    }
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) EventProcessingOption(org.kie.api.conf.EventProcessingOption) RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) AssertBehaviour(org.drools.core.RuleBaseConfiguration.AssertBehaviour) KieBuilder(org.kie.api.builder.KieBuilder) HashMap(java.util.HashMap) Map(java.util.Map) KieContainer(org.kie.api.runtime.KieContainer)

Example 37 with RuleBaseConfiguration

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");
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 38 with RuleBaseConfiguration

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");
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) Test(org.junit.Test)

Example 39 with RuleBaseConfiguration

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);
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) PriorityQueueAgendaGroupFactory(org.drools.core.common.PriorityQueueAgendaGroupFactory) Properties(java.util.Properties) Test(org.junit.Test)

Example 40 with RuleBaseConfiguration

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;
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) BuildContext(org.drools.core.reteoo.builder.BuildContext) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) JavaDialectRuntimeData(org.drools.core.rule.JavaDialectRuntimeData) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Aggregations

RuleBaseConfiguration (org.drools.core.RuleBaseConfiguration)43 Test (org.junit.Test)19 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)11 BuildContext (org.drools.core.reteoo.builder.BuildContext)10 ArrayList (java.util.ArrayList)8 Properties (java.util.Properties)8 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)8 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)8 BetaNodeFieldConstraint (org.drools.core.spi.BetaNodeFieldConstraint)8 KieSession (org.kie.api.runtime.KieSession)8 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)6 BetaMemory (org.drools.core.reteoo.BetaMemory)6 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)6 TupleList (org.drools.core.util.index.TupleList)6 List (java.util.List)5 BetaConstraints (org.drools.core.common.BetaConstraints)5 InternalFactHandle (org.drools.core.common.InternalFactHandle)5 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)5 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)5 SingleBetaConstraints (org.drools.core.common.SingleBetaConstraints)4