Search in sources :

Example 21 with RuleBaseConfiguration

use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.

the class TruthMaintenanceTest method testTMSWithEquivalentSubclasses.

@Test(timeout = 10000)
public void testTMSWithEquivalentSubclasses() {
    String droolsSource = "package project_java_rules2_xxx \n" + "import " + HashBrown.class.getCanonicalName() + "; \n" + "declare Foo id : int @key end \n\n" + "rule Zero \n" + "when \n" + " $s : String( this == \"go\" ) \n" + "then \n" + " insertLogical( new HashBrown(1) ); \n" + "end \n" + "rule Init \n" + "when \n" + "then \n" + " insertLogical( new HashBrown(7) ); \n" + "end \n";
    // ///////////////////////////////////
    KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kBuilder.add(new ByteArrayResource(droolsSource.getBytes()), ResourceType.DRL);
    assertFalse(kBuilder.getErrors().toString(), kBuilder.hasErrors());
    final RuleBaseConfiguration conf = new RuleBaseConfiguration();
    conf.setAssertBehaviour(RuleBaseConfiguration.AssertBehaviour.EQUALITY);
    conf.setSequentialAgenda(RuleBaseConfiguration.SequentialAgenda.SEQUENTIAL);
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(conf);
    kbase.addPackages(kBuilder.getKnowledgePackages());
    KieSession session = kbase.newKieSession();
    session.fireAllRules();
    FactHandle handle = session.insert(new HashBlack(1));
    session.insert("go");
    session.fireAllRules();
    assertNotNull(((DefaultFactHandle) handle).getEqualityKey());
    session.dispose();
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) KieSession(org.kie.api.runtime.KieSession) ByteArrayResource(org.drools.core.io.impl.ByteArrayResource) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 22 with RuleBaseConfiguration

use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.

the class ProtobufMarshaller method unmarshall.

public StatefulKnowledgeSession unmarshall(final InputStream stream, KieSessionConfiguration config, Environment environment) throws IOException, ClassNotFoundException {
    if (config == null) {
        config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    }
    if (environment == null) {
        environment = KieServices.get().newEnvironment();
    }
    MarshallerReaderContext context = new MarshallerReaderContext(stream, (KnowledgeBaseImpl) kbase, RuleBaseNodes.getNodeMap((KnowledgeBaseImpl) kbase), this.strategyStore, TIMER_READERS, this.marshallingConfig.isMarshallProcessInstances(), this.marshallingConfig.isMarshallWorkItems(), environment);
    int id = ((KnowledgeBaseImpl) this.kbase).nextWorkingMemoryCounter();
    RuleBaseConfiguration conf = ((KnowledgeBaseImpl) this.kbase).getConfiguration();
    StatefulKnowledgeSessionImpl session = ProtobufInputMarshaller.readSession(context, id, environment, (SessionConfiguration) config, initializer);
    context.close();
    if (((SessionConfiguration) config).isKeepReference()) {
        ((KnowledgeBaseImpl) this.kbase).addStatefulSession(session);
    }
    return session;
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) SessionConfiguration(org.drools.core.SessionConfiguration)

Example 23 with RuleBaseConfiguration

use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.

the class StatefulKnowledgeSessionImpl method bindRuleBase.

protected void bindRuleBase(InternalKnowledgeBase kBase, InternalAgenda agenda, boolean initInitFactHandle) {
    this.kBase = kBase;
    this.nodeMemories = new ConcurrentNodeMemories(kBase, DEFAULT_RULE_UNIT);
    this.pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
    if (agenda == null) {
        this.agenda = kBase.getConfiguration().getComponentFactory().getAgendaFactory().createAgenda(kBase);
    } else {
        this.agenda = agenda;
    }
    this.agenda.setWorkingMemory(this);
    RuleBaseConfiguration conf = kBase.getConfiguration();
    this.sequential = conf.isSequential();
    initDefaultEntryPoint();
    updateEntryPointsCache();
    if (initInitFactHandle) {
        this.initialFactHandle = initInitialFact(kBase, null);
    }
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) ConcurrentNodeMemories(org.drools.core.common.ConcurrentNodeMemories)

Example 24 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 25 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)

Aggregations

RuleBaseConfiguration (org.drools.core.RuleBaseConfiguration)28 Test (org.junit.Test)14 KieSession (org.kie.api.runtime.KieSession)8 ArrayList (java.util.ArrayList)7 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)6 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)6 List (java.util.List)5 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)5 BuildContext (org.drools.core.reteoo.builder.BuildContext)5 BetaNodeFieldConstraint (org.drools.core.spi.BetaNodeFieldConstraint)5 KieBase (org.kie.api.KieBase)5 Properties (java.util.Properties)4 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)4 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)4 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)4 StockTick (org.drools.compiler.StockTick)3 InternalFactHandle (org.drools.core.common.InternalFactHandle)3 BetaMemory (org.drools.core.reteoo.BetaMemory)3 IndexableConstraint (org.drools.core.rule.IndexableConstraint)3 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)3