Skip to content
Browse files

DROOLS-7 Phreak now works better for subnetworks, and non reactive su…

…bnetworks
  • Loading branch information...
1 parent 015dd2e commit 1cee9793317b9ddaccbb132665574670034bdf48 @mdproctor mdproctor committed Mar 14, 2013
Showing with 1,023 additions and 814 deletions.
  1. +931 −24 drools-compiler/src/test/java/org/drools/integrationtests/LinkingTest.java
  2. +3 −3 drools-compiler/src/test/java/org/drools/integrationtests/SegmentCreationTest.java
  3. +0 −713 drools-compiler/src/test/java/org/drools/integrationtests/SubNetworkLinkingTest.java
  4. +1 −1 drools-compiler/src/test/java/org/drools/reteoo/MockLeftTupleSink.java
  5. +1 −1 drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
  6. +5 −4 drools-core/src/main/java/org/drools/common/ConcurrentNodeMemories.java
  7. +1 −1 drools-core/src/main/java/org/drools/common/MemoryFactory.java
  8. +1 −1 drools-core/src/main/java/org/drools/common/NodeMemories.java
  9. +46 −38 drools-core/src/main/java/org/drools/phreak/SegmentUtilities.java
  10. +17 −4 drools-core/src/main/java/org/drools/reteoo/AbstractTerminalNode.java
  11. +1 −2 drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
  12. +1 −3 drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
  13. +1 −3 drools-core/src/main/java/org/drools/reteoo/BetaNode.java
  14. +1 −1 drools-core/src/main/java/org/drools/reteoo/ConditionalBranchNode.java
  15. +1 −1 drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
  16. +1 −1 drools-core/src/main/java/org/drools/reteoo/FromNode.java
  17. +1 −2 drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
  18. +1 −1 drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
  19. +1 −1 drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java
  20. +1 −1 drools-core/src/main/java/org/drools/reteoo/QueryElementNode.java
  21. +1 −1 drools-core/src/main/java/org/drools/reteoo/RiaPathMemory.java
  22. +2 −2 drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
  23. +1 −2 drools-core/src/main/java/org/drools/reteoo/WindowNode.java
  24. +2 −2 drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
  25. +1 −1 drools-core/src/test/java/org/drools/reteoo/MockLeftTupleSink.java
View
955 drools-compiler/src/test/java/org/drools/integrationtests/LinkingTest.java
@@ -1,36 +1,17 @@
package org.drools.integrationtests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.util.ArrayList;
import java.util.List;
import org.drools.FactHandle;
import org.drools.base.ClassObjectType;
-import org.drools.common.AgendaItem;
-import org.drools.common.DefaultAgenda;
-import org.drools.common.InternalAgendaGroup;
-import org.drools.common.InternalRuleBase;
+import org.drools.common.*;
import org.drools.impl.KnowledgeBaseImpl;
import org.drools.impl.StatefulKnowledgeSessionImpl;
-import org.drools.integrationtests.SubNetworkLinkingTest.A;
-import org.drools.integrationtests.SubNetworkLinkingTest.B;
-import org.drools.integrationtests.SubNetworkLinkingTest.C;
-import org.drools.integrationtests.SubNetworkLinkingTest.D;
-import org.drools.integrationtests.SubNetworkLinkingTest.E;
-import org.drools.integrationtests.SubNetworkLinkingTest.F;
-import org.drools.integrationtests.SubNetworkLinkingTest.G;
import org.drools.phreak.RuleNetworkEvaluatorActivation;
import org.drools.phreak.SegmentUtilities;
-import org.drools.reteoo.BetaMemory;
-import org.drools.reteoo.JoinNode;
-import org.drools.reteoo.LeftInputAdapterNode;
+import org.drools.reteoo.*;
import org.drools.reteoo.LeftInputAdapterNode.LiaNodeMemory;
-import org.drools.reteoo.NotNode;
-import org.drools.reteoo.ObjectTypeNode;
-import org.drools.reteoo.ReteooWorkingMemoryInterface;
import org.junit.Ignore;
import org.junit.Test;
import org.kie.KnowledgeBase;
@@ -42,8 +23,810 @@
import org.kie.io.ResourceFactory;
import org.kie.io.ResourceType;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
public class LinkingTest {
-
+ public static class A {
+ private int value;
+
+ public A() {
+
+ }
+
+ public A(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+ }
+
+ public static class B {
+ private int value;
+
+ public B() {
+
+ }
+
+ public B(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+ }
+
+ public static class C {
+ private int value;
+
+ public C() {
+
+ }
+
+ public C(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+ }
+
+ public static class D {
+ private int value;
+
+ public D() {
+
+ }
+
+ public D(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+ }
+
+ public static class E {
+ private int value;
+
+ public E() {
+
+ }
+
+ public E(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+ }
+
+ public static class F {
+ private int value;
+
+ public F() {
+
+ }
+
+ public F(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+ }
+
+ public static class G {
+ private int value;
+
+ public G() {
+
+ }
+
+ public G(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+ }
+
+ @Test
+ public void testSubNetworkSharing() throws Exception {
+ // Checks the network is correctly formed, with sharing
+ String str = "";
+ str += "package org.kie \n";
+ str += "import " + A.class.getCanonicalName() + "\n" ;
+ str += "import " + B.class.getCanonicalName() + "\n" ;
+ str += "import " + C.class.getCanonicalName() + "\n" ;
+ str += "import " + D.class.getCanonicalName() + "\n" ;
+ str += "import " + E.class.getCanonicalName() + "\n" ;
+ str += "global java.util.List list \n";
+
+ str += "rule rule1 when \n";
+ str += " A() \n";
+ str += " B() \n";
+ str += " C() \n";
+ str += " D() \n";
+ str += "then \n";
+ str += "end \n";
+
+ str += "rule rule2 when \n";
+ str += " A() \n";
+ str += " exists( B() and C() ) \n";
+ str += " D() \n";
+ str += "then \n";
+ str += "end \n";
+
+ str += "rule rule3 when \n";
+ str += " A() \n";
+ str += " exists( B() and C() and D() ) \n";
+ str += " E() \n";
+ str += "then \n";
+ str += "end \n";
+
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+
+ kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL );
+
+ assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
+
+ KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( LRUnlinkingOption.ENABLED );
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
+ assertEquals( 3, liaNode.getSinkPropagator().size() );
+
+ ExistsNode existsNode2 = ( ExistsNode) liaNode.getSinkPropagator().getSinks()[1];
+
+ ExistsNode existsNode3 = ( ExistsNode) liaNode.getSinkPropagator().getSinks()[2];
+
+ JoinNode joinNodeB = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0];
+ assertSame( joinNodeB.getRightInput(), getObjectTypeNode(kbase, B.class ) );
+
+ JoinNode joinNodeC = ( JoinNode) joinNodeB.getSinkPropagator().getSinks()[0];
+ assertSame( joinNodeC.getRightInput(), getObjectTypeNode(kbase, C.class ) );
+ assertEquals( 2, joinNodeC.getSinkPropagator().size() );
+
+ JoinNode joinNodeD = ( JoinNode) joinNodeC.getSinkPropagator().getSinks()[0];
+ assertSame( joinNodeD.getRightInput(), getObjectTypeNode(kbase, D.class ) );
+ assertEquals( 2, joinNodeD.getSinkPropagator().size() );
+
+
+ assertSame( existsNode2, (( RightInputAdapterNode) joinNodeC.getSinkPropagator().getSinks()[1]).getSinkPropagator().getSinks()[0] );
+
+ assertSame( existsNode3, (( RightInputAdapterNode) joinNodeD.getSinkPropagator().getSinks()[1]).getSinkPropagator().getSinks()[0] );
+ }
+
+ @Test
+ public void testSubNetworkSharingMemories() throws Exception {
+ // checks the memory sharing works, and linking, uses the already checked network from testSubNetworkSharing
+ String str = "";
+ str += "package org.kie \n";
+ str += "import " + A.class.getCanonicalName() + "\n" ;
+ str += "import " + B.class.getCanonicalName() + "\n" ;
+ str += "import " + C.class.getCanonicalName() + "\n" ;
+ str += "import " + D.class.getCanonicalName() + "\n" ;
+ str += "import " + E.class.getCanonicalName() + "\n" ;
+ str += "global java.util.List list \n";
+
+ str += "rule rule1 when \n";
+ str += " A() \n";
+ str += " B() \n";
+ str += " C() \n";
+ str += " D() \n";
+ str += "then \n";
+ str += "end \n";
+
+ str += "rule rule2 when \n";
+ str += " A() \n";
+ str += " exists( B() and C() ) \n";
+ str += " D() \n";
+ str += "then \n";
+ str += "end \n";
+
+ str += "rule rule3 when \n";
+ str += " A() \n";
+ str += " exists( B() and C() and D() ) \n";
+ str += " E() \n";
+ str += "then \n";
+ str += "end \n";
+
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+
+ kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL );
+
+ assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
+
+ KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( LRUnlinkingOption.ENABLED );
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ LeftInputAdapterNode liaNodeA = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
+ ExistsNode existsNode2 = ( ExistsNode) liaNodeA.getSinkPropagator().getSinks()[1];
+ ExistsNode existsNode3 = ( ExistsNode) liaNodeA.getSinkPropagator().getSinks()[2];
+ JoinNode joinNodeB = ( JoinNode) liaNodeA.getSinkPropagator().getSinks()[0];
+ JoinNode joinNodeC = ( JoinNode) joinNodeB.getSinkPropagator().getSinks()[0];
+
+ JoinNode joinNodeD1 = ( JoinNode) joinNodeC.getSinkPropagator().getSinks()[0];
+ JoinNode joinNodeD2 = ( JoinNode) existsNode2.getSinkPropagator().getSinks()[0];
+
+ JoinNode joinNodeE = ( JoinNode) existsNode3.getSinkPropagator().getSinks()[0];
+
+ RuleTerminalNode rtn1 = ( RuleTerminalNode ) joinNodeD1.getSinkPropagator().getSinks()[0];
+ RuleTerminalNode rtn2 = ( RuleTerminalNode ) joinNodeD2.getSinkPropagator().getSinks()[0];
+ RuleTerminalNode rtn3 = ( RuleTerminalNode ) joinNodeE.getSinkPropagator().getSinks()[0];
+
+ FactHandle fha = wm.insert( new A() );
+ wm.insert( new B() );
+ wm.insert( new C() );
+ wm.insert( new D() );
+
+ BetaMemory bm = null;
+
+ LiaNodeMemory liam = ( LiaNodeMemory ) wm.getNodeMemory( liaNodeA );
+
+ BetaMemory bm1 = ( BetaMemory ) wm.getNodeMemory( joinNodeB );
+ BetaMemory bm2 = ( BetaMemory ) wm.getNodeMemory( joinNodeC );
+ BetaMemory bm3 = ( BetaMemory ) wm.getNodeMemory( joinNodeD1 );
+ assertEquals(1, liam.getNodePosMaskBit() );
+ assertEquals(1, bm1.getNodePosMaskBit() );
+ assertEquals(2, bm2.getNodePosMaskBit() );
+ assertEquals(1, bm3.getNodePosMaskBit() );
+
+ assertNotSame( liam.getSegmentMemory(), bm1.getSegmentMemory() );
+ assertSame( bm1.getSegmentMemory(), bm2.getSegmentMemory() );
+ assertNotSame( bm2.getSegmentMemory(), bm3.getSegmentMemory() );
+
+ BetaMemory bm4 = ( BetaMemory ) wm.getNodeMemory( existsNode2 );
+ BetaMemory bm5 = ( BetaMemory ) wm.getNodeMemory( joinNodeD2 );
+ assertEquals(1, bm4.getNodePosMaskBit() );
+ assertEquals(2, bm5.getNodePosMaskBit() );
+ assertSame( bm4.getSegmentMemory(), bm5.getSegmentMemory() );
+
+ PathMemory rs1 = (PathMemory) wm.getNodeMemory( rtn1 );
+ PathMemory rs2 = (PathMemory) wm.getNodeMemory( rtn2 );
+ PathMemory rs3 = (PathMemory) wm.getNodeMemory( rtn3 );
+
+ assertTrue( rs1.isRuleLinked() );
+ assertTrue( rs2.isRuleLinked() );
+ assertFalse( rs3.isRuleLinked() ); // no E yet
+
+
+ wm.insert( new E() );
+ BetaMemory bm6 = ( BetaMemory ) wm.getNodeMemory( existsNode3 );
+ BetaMemory bm7 = ( BetaMemory ) wm.getNodeMemory( joinNodeE );
+ assertEquals(1, bm6.getNodePosMaskBit() );
+ assertEquals(2, bm7.getNodePosMaskBit() );
+ assertSame( bm6.getSegmentMemory(), bm7.getSegmentMemory() );
+
+ assertTrue( rs1.isRuleLinked() );
+ assertTrue( rs2.isRuleLinked() );
+ assertTrue( rs3.isRuleLinked() );
+
+ wm.retract( fha );
+ wm.fireAllRules(); // need to have rules evalulated, for unlinking to happen
+ assertFalse( rs1.isRuleLinked() );
+ assertFalse( rs2.isRuleLinked() );
+ assertFalse( rs3.isRuleLinked() );
+ }
+
+ @Test
+ public void testSubNetworkRiaLinking() throws Exception {
+ String str = "";
+ str += "package org.kie \n";
+ str += "import " + A.class.getCanonicalName() + "\n" ;
+ str += "import " + B.class.getCanonicalName() + "\n" ;
+ str += "import " + C.class.getCanonicalName() + "\n" ;
+ str += "import " + D.class.getCanonicalName() + "\n" ;
+ str += "import " + E.class.getCanonicalName() + "\n" ;
+ str += "global java.util.List list \n";
+
+ str += "rule rule1 when \n";
+ str += " A() \n";
+ str += " B() \n";
+ str += " exists( C() and D() ) \n";
+ str += " E() \n";
+ str += "then \n";
+ str += "end \n";
+
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+
+ kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL );
+
+ assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
+
+ KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( LRUnlinkingOption.ENABLED );
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
+ assertEquals( 1, liaNode.getSinkPropagator().size() );
+
+ JoinNode bNode = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0];
+ assertEquals( 2, bNode.getSinkPropagator().size() );
+
+ ExistsNode exists1n = ( ExistsNode) bNode.getSinkPropagator().getSinks()[1];
+
+ JoinNode cNode = ( JoinNode) bNode.getSinkPropagator().getSinks()[0];
+ JoinNode dNode = ( JoinNode) cNode.getSinkPropagator().getSinks()[0];
+ assertEquals( 1, dNode.getSinkPropagator().size() );
+
+ RightInputAdapterNode riaNode1 = ( RightInputAdapterNode ) dNode.getSinkPropagator().getSinks()[0];
+
+
+ JoinNode eNode = ( JoinNode ) exists1n.getSinkPropagator().getSinks()[0];
+ RuleTerminalNode rtn = ( RuleTerminalNode ) eNode.getSinkPropagator().getSinks()[0];
+
+ SegmentUtilities.createSegmentMemory( exists1n, wm );
+ BetaMemory existsBm = ( BetaMemory ) wm.getNodeMemory( exists1n );
+
+ assertEquals( 0, existsBm.getSegmentMemory().getLinkedNodeMask() );
+
+ FactHandle fhc = wm.insert( new C() );
+ FactHandle fhd = wm.insert( new D() );
+
+ assertEquals( 1, existsBm.getSegmentMemory().getLinkedNodeMask() ); // exists is start of new segment
+
+ wm.retract( fhd );
+ assertEquals( 0, existsBm.getSegmentMemory().getLinkedNodeMask() );
+
+ PathMemory rs = (PathMemory) wm.getNodeMemory( rtn );
+ assertFalse( rs.isRuleLinked() );
+
+ wm.insert( new A() );
+ wm.insert( new B() );
+ wm.insert( new E() );
+ assertFalse( rs.isRuleLinked() );
+
+
+ wm.insert( new D() );
+ assertTrue( rs.isRuleLinked() );
+
+ wm.retract( fhc );
+ assertFalse( rs.isRuleLinked() );
+
+ wm.insert( new C() );
+ assertTrue( rs.isRuleLinked() );
+ }
+ @Test
+ public void testNonReactiveSubNetworkInShareMasks() throws Exception {
+ String str = "";
+ str += "package org.kie \n";
+ str += "import " + A.class.getCanonicalName() + "\n" ;
+ str += "import " + B.class.getCanonicalName() + "\n" ;
+ str += "import " + C.class.getCanonicalName() + "\n" ;
+ str += "import " + D.class.getCanonicalName() + "\n" ;
+ str += "import " + E.class.getCanonicalName() + "\n" ;
+ str += "import " + F.class.getCanonicalName() + "\n" ;
+ str += "import " + G.class.getCanonicalName() + "\n" ;
+ str += "global java.util.List list \n";
+
+ str += "rule rule1 when \n";
+ str += " A() \n";
+ str += " exists( B() and C() ) \n";
+ str += " exists( eval(1==1) ) \n";
+ str += " D() \n";
+ str += "then \n";
+ str += "end \n";
+
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+
+ kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL );
+
+ assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
+
+ KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( LRUnlinkingOption.ENABLED );
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
+ assertEquals( 2, liaNode.getSinkPropagator().size() );
+
+ JoinNode bNode = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0];
+ JoinNode cNode = ( JoinNode) bNode.getSinkPropagator().getSinks()[0];
+ ExistsNode exists1n = ( ExistsNode) liaNode.getSinkPropagator().getSinks()[1];
+ EvalConditionNode evalNode = ( EvalConditionNode) exists1n.getSinkPropagator().getSinks()[0];
+ ExistsNode exists2n = ( ExistsNode) exists1n.getSinkPropagator().getSinks()[1];
+ JoinNode dNode = ( JoinNode) exists2n.getSinkPropagator().getSinks()[0];
+ RuleTerminalNode rtn = ( RuleTerminalNode) dNode.getSinkPropagator().getSinks()[0];
+
+ wm.insert( new A() );
+
+ PathMemory pmem = ( PathMemory ) wm.getNodeMemory(rtn);
+ assertEquals( 3, pmem.getSegmentMemories().length );
+ assertEquals( 7, pmem.getAllLinkedMaskTest() ); // D is in the exists segment
+
+
+ BetaMemory bm = ( BetaMemory ) wm.getNodeMemory(dNode);
+ assertNull(bm.getSegmentMemory()); // check lazy initialization
+ wm.insert( new D() );
+ assertEquals(2, bm.getSegmentMemory().getAllLinkedMaskTest()); // only D can be linked in
+ }
+
+ @Test
+ public void testNonReactiveSubNetworkOwnSegmentMasks() throws Exception {
+ String str = "";
+ str += "package org.kie \n";
+ str += "import " + A.class.getCanonicalName() + "\n" ;
+ str += "import " + B.class.getCanonicalName() + "\n" ;
+ str += "import " + C.class.getCanonicalName() + "\n" ;
+ str += "import " + D.class.getCanonicalName() + "\n" ;
+ str += "import " + E.class.getCanonicalName() + "\n" ;
+ str += "import " + F.class.getCanonicalName() + "\n" ;
+ str += "import " + G.class.getCanonicalName() + "\n" ;
+ str += "global java.util.List list \n";
+
+ str += "rule rule1 when \n";
+ str += " A() \n";
+ str += " exists( B() and C() ) \n";
+ str += " exists( eval(1==1) ) \n";
+ str += " D() \n";
+ str += "then \n";
+ str += "end \n";
+ str += "rule rule2 when \n";
+ str += " A() \n";
+ str += " exists( B() and C() ) \n";
+ str += " exists( eval(1==1) ) \n";
+ str += " E() \n";
+ str += "then \n";
+ str += "end \n";
+
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+
+ kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL );
+
+ assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
+
+ KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( LRUnlinkingOption.ENABLED );
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
+ assertEquals( 2, liaNode.getSinkPropagator().size() );
+
+ JoinNode bNode = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0];
+ JoinNode cNode = ( JoinNode) bNode.getSinkPropagator().getSinks()[0];
+ ExistsNode exists1n = ( ExistsNode) liaNode.getSinkPropagator().getSinks()[1];
+ EvalConditionNode evalNode = ( EvalConditionNode) exists1n.getSinkPropagator().getSinks()[0];
+ ExistsNode exists2n = ( ExistsNode) exists1n.getSinkPropagator().getSinks()[1];
+ JoinNode dNode = ( JoinNode) exists2n.getSinkPropagator().getSinks()[0];
+ RuleTerminalNode rtn = ( RuleTerminalNode) dNode.getSinkPropagator().getSinks()[0];
+
+ wm.insert( new A() );
+
+ PathMemory pmem = ( PathMemory ) wm.getNodeMemory(rtn);
+ assertEquals( 4, pmem.getSegmentMemories().length );
+ assertEquals( 11, pmem.getAllLinkedMaskTest() ); // the exists eval segment does not need to be linked in
+
+ RightInputAdapterNode.RiaNodeMemory riaMem = (RightInputAdapterNode.RiaNodeMemory) wm.getNodeMemory((MemoryFactory) exists1n.getRightInput());
+ assertEquals( 2, riaMem.getRiaPathMemory().getAllLinkedMaskTest() ); // second segment must be linked in
+
+ wm.insert( new B() );
+ wm.insert( new C() );
+ assertEquals( 2, riaMem.getRiaPathMemory().getSegmentMemories().length );
+
+ riaMem = (RightInputAdapterNode.RiaNodeMemory) wm.getNodeMemory((MemoryFactory) exists2n.getRightInput());
+ assertEquals( 0, riaMem.getRiaPathMemory().getAllLinkedMaskTest() ); // no segments to be linked in
+ }
+
+ @Test
+ public void testNestedSubNetwork() throws Exception {
+ String str = "";
+ str += "package org.kie \n";
+ str += "import " + A.class.getCanonicalName() + "\n" ;
+ str += "import " + B.class.getCanonicalName() + "\n" ;
+ str += "import " + C.class.getCanonicalName() + "\n" ;
+ str += "import " + D.class.getCanonicalName() + "\n" ;
+ str += "import " + E.class.getCanonicalName() + "\n" ;
+ str += "import " + F.class.getCanonicalName() + "\n" ;
+ str += "import " + G.class.getCanonicalName() + "\n" ;
+ str += "global java.util.List list \n";
+
+ str += "rule rule1 when \n";
+ str += " A() \n";
+ str += " B() \n";
+ str += " exists( C() and D() and exists( E() and F() ) ) \n";
+ str += " G() \n";
+ str += "then \n";
+ str += "end \n";
+
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+
+ kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL );
+
+ assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
+
+ KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( LRUnlinkingOption.ENABLED );
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
+ assertEquals( 1, liaNode.getSinkPropagator().size() );
+
+ JoinNode bNode = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0];
+ assertEquals( 2, bNode.getSinkPropagator().size() );
+
+ ExistsNode exists1n = ( ExistsNode) bNode.getSinkPropagator().getSinks()[1];
+
+ JoinNode cNode = ( JoinNode) bNode.getSinkPropagator().getSinks()[0];
+ JoinNode dNode = ( JoinNode) cNode.getSinkPropagator().getSinks()[0];
+ assertEquals( 2, dNode.getSinkPropagator().size() );
+
+ ExistsNode exists2n = ( ExistsNode) dNode.getSinkPropagator().getSinks()[1];
+
+ JoinNode eNode = ( JoinNode) dNode.getSinkPropagator().getSinks()[0];
+ JoinNode fNode = ( JoinNode) eNode.getSinkPropagator().getSinks()[0];
+
+ RightInputAdapterNode riaNode2 = ( RightInputAdapterNode ) fNode.getSinkPropagator().getSinks()[0];
+ assertEquals( exists2n, riaNode2.getSinkPropagator().getSinks()[0] );
+
+ RightInputAdapterNode riaNode1 = ( RightInputAdapterNode ) exists2n.getSinkPropagator().getSinks()[0];
+ assertEquals( exists1n, riaNode1.getSinkPropagator().getSinks()[0] );
+
+ JoinNode gNode = ( JoinNode) exists1n.getSinkPropagator().getSinks()[0];
+ RuleTerminalNode rtn = ( RuleTerminalNode) gNode.getSinkPropagator().getSinks()[0];
+
+ wm.insert( new A() );
+ wm.insert( new B() );
+ wm.insert( new C() );
+ wm.insert( new D() );
+ wm.insert( new F() );
+ wm.insert( new G() );
+
+ PathMemory rs = (PathMemory) wm.getNodeMemory( rtn );
+ assertFalse( rs.isRuleLinked() );
+
+ FactHandle fhE1 = wm.insert( new E() );
+ FactHandle fhE2 = wm.insert( new E() );
+ assertTrue( rs.isRuleLinked() );
+
+ wm.retract( fhE1 );
+ assertTrue( rs.isRuleLinked() );
+
+ wm.retract( fhE2 );
+ assertFalse( rs.isRuleLinked() );
+ }
+
+ @Test
+ public void testNestedSubNetworkMasks() throws Exception {
+ String str = "";
+ str += "package org.kie \n";
+ str += "import " + A.class.getCanonicalName() + "\n" ;
+ str += "import " + B.class.getCanonicalName() + "\n" ;
+ str += "import " + C.class.getCanonicalName() + "\n" ;
+ str += "import " + D.class.getCanonicalName() + "\n" ;
+ str += "import " + E.class.getCanonicalName() + "\n" ;
+ str += "import " + F.class.getCanonicalName() + "\n" ;
+ str += "import " + G.class.getCanonicalName() + "\n" ;
+ str += "global java.util.List list \n";
+
+ str += "rule rule1 when \n";
+ str += " A() \n";
+ str += " B() \n";
+ str += " exists( C() and D() and exists( E() and F() ) ) \n";
+ str += " G() \n";
+ str += "then \n";
+ str += "end \n";
+
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+
+ kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL );
+
+ assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
+
+ KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( LRUnlinkingOption.ENABLED );
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
+ JoinNode bNode = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0];
+
+ ExistsNode exists1n = ( ExistsNode) bNode.getSinkPropagator().getSinks()[1];
+
+ JoinNode cNode = ( JoinNode) bNode.getSinkPropagator().getSinks()[0];
+ JoinNode dNode = ( JoinNode) cNode.getSinkPropagator().getSinks()[0];
+
+ ExistsNode exists2n = ( ExistsNode) dNode.getSinkPropagator().getSinks()[1];
+
+ JoinNode eNode = ( JoinNode) dNode.getSinkPropagator().getSinks()[0];
+ JoinNode fNode = ( JoinNode) eNode.getSinkPropagator().getSinks()[0];
+
+ RightInputAdapterNode riaNode2 = ( RightInputAdapterNode ) fNode.getSinkPropagator().getSinks()[0];
+ RightInputAdapterNode riaNode1 = ( RightInputAdapterNode ) exists2n.getSinkPropagator().getSinks()[0];
+
+ JoinNode gNode = ( JoinNode) exists1n.getSinkPropagator().getSinks()[0];
+ RuleTerminalNode rtn = ( RuleTerminalNode) gNode.getSinkPropagator().getSinks()[0];
+
+ wm.insert( new A() );
+ wm.insert( new B() );
+ wm.insert( new C() );
+ wm.insert( new D() );
+ wm.insert( new G() );
+
+ LiaNodeMemory liaMem = ( LiaNodeMemory ) wm.getNodeMemory( liaNode );
+ BetaMemory bMem = ( BetaMemory ) wm.getNodeMemory( bNode );
+ BetaMemory exists1Mem = ( BetaMemory ) wm.getNodeMemory( exists1n );
+ BetaMemory cMem = ( BetaMemory ) wm.getNodeMemory( cNode );
+ BetaMemory dMem = ( BetaMemory ) wm.getNodeMemory( dNode );
+ BetaMemory exists2Mem = ( BetaMemory ) wm.getNodeMemory( exists2n );
+ BetaMemory eMem = ( BetaMemory ) wm.getNodeMemory( eNode );
+ BetaMemory fMem = ( BetaMemory ) wm.getNodeMemory( fNode );
+ BetaMemory gMem = ( BetaMemory ) wm.getNodeMemory( gNode );
+
+ RightInputAdapterNode.RiaNodeMemory riaMem1 = (RightInputAdapterNode.RiaNodeMemory) wm.getNodeMemory( riaNode1 );
+ RightInputAdapterNode.RiaNodeMemory riaMem2 = (RightInputAdapterNode.RiaNodeMemory) wm.getNodeMemory( riaNode2 );
+
+ PathMemory rs = (PathMemory) wm.getNodeMemory( rtn );
+
+ assertFalse( rs.isRuleLinked() ); //E and F are not inserted yet, so rule is unlinked
+
+ //---
+ // assert a and b in same segment
+ assertSame( liaMem.getSegmentMemory(), bMem.getSegmentMemory() );
+
+ // exists1 and b not in same segment
+ assertNotSame( bMem.getSegmentMemory(), exists1Mem.getSegmentMemory() );
+
+ // exists1 and b are in same segment
+ assertSame( exists1Mem.getSegmentMemory(), gMem.getSegmentMemory() );
+
+ // check segment masks
+ assertEquals( 2, rs.getSegmentMemories().length );
+ assertEquals( 3, rs.getAllLinkedMaskTest() );
+ assertEquals( 1, rs.getLinkedSegmentMask() );
+
+ assertEquals( 3, liaMem.getSegmentMemory().getAllLinkedMaskTest() );
+ assertEquals( 1, liaMem.getNodePosMaskBit() );
+ assertEquals( 2, bMem.getNodePosMaskBit() );
+
+ assertEquals( 3, exists1Mem.getSegmentMemory().getAllLinkedMaskTest() );
+ assertEquals( 1, exists1Mem.getNodePosMaskBit() );
+ assertEquals( 2, gMem.getNodePosMaskBit() );
+
+
+ // assert c, d are in the same segment, and that this is the only segment in ria1 memory
+ assertSame( dMem.getSegmentMemory(), cMem.getSegmentMemory() );
+
+ // assert d and exists are not in the same segment
+ assertNotSame( exists2Mem.getSegmentMemory(), dMem.getSegmentMemory() );
+ assertEquals( 3, riaMem1.getRiaPathMemory().getSegmentMemories().length );
+ assertEquals( null, riaMem1.getRiaPathMemory().getSegmentMemories()[0] ); // only needs to know about segments in the subnetwork
+ assertEquals( dMem.getSegmentMemory(), riaMem1.getRiaPathMemory().getSegmentMemories()[1] );
+ assertEquals( 1, dMem.getSegmentMemory().getPathMemories().size() );
+ assertSame( riaMem1.getRiaPathMemory(), cMem.getSegmentMemory().getPathMemories().get(0) );
+
+ assertEquals( 3, cMem.getSegmentMemory().getAllLinkedMaskTest() );
+ assertEquals( 3, cMem.getSegmentMemory().getLinkedNodeMask() ); // E and F is not yet inserted, so bit is not set
+ assertEquals( 1, cMem.getNodePosMaskBit() );
+ assertEquals( 2, dMem.getNodePosMaskBit() );
+
+ assertEquals( 0, exists2Mem.getNodePosMaskBit() );
+ FactHandle fhE1 = wm.insert( new E() ); // insert to lazy initialize exists2Mem segment
+ FactHandle fhF1 = wm.insert( new F() );
+ assertEquals( 1, exists2Mem.getNodePosMaskBit() );
+ assertEquals( 6, riaMem1.getRiaPathMemory().getAllLinkedMaskTest() ); // only cares that the segment for c, E and exists1 are set, ignores the outer first segment
+ assertEquals( 6, riaMem1.getRiaPathMemory().getLinkedSegmentMask() ); // E and F are inerted, so 6
+ wm.delete(fhE1);
+ wm.delete(fhF1);
+ assertEquals( 2, riaMem1.getRiaPathMemory().getLinkedSegmentMask() ); // E deleted
+
+ // assert e, f are in the same segment, and that this is the only segment in ria2 memory
+ assertNotNull( null, eMem.getSegmentMemory() ); //subnetworks are recursively created, so segment already exists
+ assertSame( fMem.getSegmentMemory(), eMem.getSegmentMemory() );
+
+ assertEquals( 3, riaMem2.getRiaPathMemory().getSegmentMemories().length );
+ assertEquals( null, riaMem2.getRiaPathMemory().getSegmentMemories()[0] ); // only needs to know about segments in the subnetwork
+ assertEquals( null, riaMem2.getRiaPathMemory().getSegmentMemories()[1] ); // only needs to know about segments in the subnetwork
+ assertEquals( fMem.getSegmentMemory(), riaMem2.getRiaPathMemory().getSegmentMemories()[2] );
+ assertSame( riaMem2.getRiaPathMemory(), eMem.getSegmentMemory().getPathMemories().get(0) );
+ assertEquals( 3, eMem.getSegmentMemory().getAllLinkedMaskTest() );
+ assertEquals( 0, eMem.getSegmentMemory().getLinkedNodeMask() );
+ assertEquals( 4, riaMem2.getRiaPathMemory().getAllLinkedMaskTest() ); // only cares that the segment for e and f set, ignores the outer two segment
+ assertEquals( 0, riaMem2.getRiaPathMemory().getLinkedSegmentMask() ); // E and F is not yet inserted, so bit is not set
+
+ fhE1 = wm.insert( new E() );
+ wm.insert( new F() );
+
+ assertTrue( rs.isRuleLinked() ); //E and F are now inserted yet, so rule is linked
+ assertEquals( 3, rs.getAllLinkedMaskTest() );
+ assertEquals( 3, rs.getLinkedSegmentMask() );
+
+ // retest bits
+ assertEquals( 3, cMem.getSegmentMemory().getAllLinkedMaskTest() );
+ assertEquals( 3, cMem.getSegmentMemory().getLinkedNodeMask() );
+ assertEquals( 6, riaMem1.getRiaPathMemory().getAllLinkedMaskTest() );
+ assertEquals( 6, riaMem1.getRiaPathMemory().getLinkedSegmentMask() );
+
+ assertEquals( 3, eMem.getSegmentMemory().getAllLinkedMaskTest() );
+ assertEquals( 3, eMem.getSegmentMemory().getLinkedNodeMask() );
+ assertEquals( 4, riaMem2.getRiaPathMemory().getAllLinkedMaskTest() );
+ assertEquals( 4, riaMem2.getRiaPathMemory().getLinkedSegmentMask() );
+
+ wm.delete( fhE1 );
+
+ // retest bits
+ assertFalse( rs.isRuleLinked() );
+
+ assertEquals( 3, cMem.getSegmentMemory().getLinkedNodeMask() );
+ assertEquals( 2, riaMem1.getRiaPathMemory().getLinkedSegmentMask() );
+
+ assertEquals( 2, eMem.getSegmentMemory().getLinkedNodeMask() );
+ assertEquals( 0, riaMem2.getRiaPathMemory().getLinkedSegmentMask() );
+ }
@Test
public void testJoinNodes() throws Exception {
String str = "";
@@ -520,7 +1303,129 @@ public void testNotNodes2() throws Exception {
wm.retract( fh );
wm.fireAllRules();
assertEquals( 9, list.size() );
- }
+ }
+
+ @Test
+ public void testNotNodeMasksWithConstraints() throws Exception {
+ String str = "";
+ str += "package org.kie \n";
+ str += "import " + A.class.getCanonicalName() + "\n" ;
+ str += "import " + B.class.getCanonicalName() + "\n" ;
+ str += "import " + C.class.getCanonicalName() + "\n" ;
+ str += "import " + D.class.getCanonicalName() + "\n" ;
+ str += "import " + E.class.getCanonicalName() + "\n" ;
+ str += "import " + F.class.getCanonicalName() + "\n" ;
+ str += "import " + G.class.getCanonicalName() + "\n" ;
+ str += "global java.util.List list \n";
+
+ str += "rule rule1 when \n";
+ str += " $a : A() \n";
+ str += " not( B( value == $a.value ) ) \n";
+ str += " C() \n";
+ str += "then \n";
+ str += "end \n";
+
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+
+ kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL );
+
+ assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
+
+ KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( LRUnlinkingOption.ENABLED );
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
+ assertEquals( 1, liaNode.getSinkPropagator().size() );
+
+ wm.insert( new A() );
+
+ NotNode notNode = ( NotNode) liaNode.getSinkPropagator().getSinks()[0];
+ JoinNode cNode = ( JoinNode) notNode.getSinkPropagator().getSinks()[0];
+ RuleTerminalNode rtn = ( RuleTerminalNode ) cNode.getSinkPropagator().getSinks()[0];
+
+ PathMemory pmem = ( PathMemory ) wm.getNodeMemory(rtn);
+ assertEquals( 1, pmem.getSegmentMemories().length );
+ assertEquals( 1, pmem.getAllLinkedMaskTest() );
+
+ SegmentMemory sm = pmem.getSegmentMemories()[0];
+ assertEquals( 5, sm.getAllLinkedMaskTest() );
+
+ assertEquals( 3, sm.getLinkedNodeMask() );
+ assertFalse( sm.isSegmentLinked() );
+ assertFalse( pmem.isRuleLinked() );
+
+ wm.insert( new C() );
+ assertEquals( 7, sm.getLinkedNodeMask() ); // only 5 is needed to link, the 'not' turns on but it has no unfleunce either way
+ assertTrue( sm.isSegmentLinked() );
+ assertTrue( pmem.isRuleLinked() );
+ }
+
+ @Test
+ public void testNotNodeMasksWithoutConstraints() throws Exception {
+ String str = "";
+ str += "package org.kie \n";
+ str += "import " + A.class.getCanonicalName() + "\n" ;
+ str += "import " + B.class.getCanonicalName() + "\n" ;
+ str += "import " + C.class.getCanonicalName() + "\n" ;
+ str += "import " + D.class.getCanonicalName() + "\n" ;
+ str += "import " + E.class.getCanonicalName() + "\n" ;
+ str += "import " + F.class.getCanonicalName() + "\n" ;
+ str += "import " + G.class.getCanonicalName() + "\n" ;
+ str += "global java.util.List list \n";
+
+ str += "rule rule1 when \n";
+ str += " A() \n";
+ str += " not( B( ) ) \n";
+ str += " C() \n";
+ str += "then \n";
+ str += "end \n";
+
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+
+ kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
+ ResourceType.DRL );
+
+ assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
+
+ KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( LRUnlinkingOption.ENABLED );
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
+ assertEquals( 1, liaNode.getSinkPropagator().size() );
+
+ wm.insert( new A() );
+
+ NotNode notNode = ( NotNode) liaNode.getSinkPropagator().getSinks()[0];
+ JoinNode cNode = ( JoinNode) notNode.getSinkPropagator().getSinks()[0];
+ RuleTerminalNode rtn = ( RuleTerminalNode ) cNode.getSinkPropagator().getSinks()[0];
+
+ PathMemory pmem = ( PathMemory ) wm.getNodeMemory(rtn);
+ assertEquals( 1, pmem.getSegmentMemories().length );
+ assertEquals( 1, pmem.getAllLinkedMaskTest() );
+
+ SegmentMemory sm = pmem.getSegmentMemories()[0];
+ assertEquals( 7, sm.getAllLinkedMaskTest() );
+
+ assertEquals( 3, sm.getLinkedNodeMask() );
+ assertFalse( sm.isSegmentLinked() );
+ assertFalse( pmem.isRuleLinked() );
+
+ wm.insert( new C() );
+ assertEquals( 7, sm.getLinkedNodeMask() );
+ assertTrue( sm.isSegmentLinked() );
+ assertTrue( pmem.isRuleLinked() );
+ }
@Test
public void testForallNodes() throws Exception {
@@ -858,6 +1763,8 @@ public static ObjectTypeNode getObjectTypeNode(KnowledgeBase kbase, Class<?> nod
}
}
return null;
- }
+ }
+
+
}
View
6 drools-compiler/src/test/java/org/drools/integrationtests/SegmentCreationTest.java
@@ -11,9 +11,9 @@
import org.drools.common.InternalRuleBase;
import org.drools.impl.KnowledgeBaseImpl;
import org.drools.impl.StatefulKnowledgeSessionImpl;
-import org.drools.integrationtests.SubNetworkLinkingTest.A;
-import org.drools.integrationtests.SubNetworkLinkingTest.B;
-import org.drools.integrationtests.SubNetworkLinkingTest.C;
+import org.drools.integrationtests.LinkingTest.A;
+import org.drools.integrationtests.LinkingTest.B;
+import org.drools.integrationtests.LinkingTest.C;
import org.drools.reteoo.BetaMemory;
import org.drools.reteoo.InitialFactImpl;
import org.drools.reteoo.JoinNode;
View
713 drools-compiler/src/test/java/org/drools/integrationtests/SubNetworkLinkingTest.java
@@ -1,713 +0,0 @@
-package org.drools.integrationtests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.List;
-
-import org.drools.FactHandle;
-import org.drools.base.ClassObjectType;
-import org.drools.common.InternalRuleBase;
-import org.drools.impl.KnowledgeBaseImpl;
-import org.drools.impl.StatefulKnowledgeSessionImpl;
-import org.drools.phreak.SegmentUtilities;
-import org.drools.reteoo.*;
-import org.drools.reteoo.LeftInputAdapterNode.LiaNodeMemory;
-import org.drools.reteoo.RightInputAdapterNode.RiaNodeMemory;
-import org.drools.reteoo.PathMemory;
-import org.junit.Test;
-import org.kie.KnowledgeBase;
-import org.kie.KieBaseConfiguration;
-import org.kie.KnowledgeBaseFactory;
-import org.kie.builder.KnowledgeBuilder;
-import org.kie.builder.KnowledgeBuilderFactory;
-import org.kie.builder.conf.LRUnlinkingOption;
-import org.kie.io.ResourceFactory;
-import org.kie.io.ResourceType;
-
-public class SubNetworkLinkingTest {
- public static class A {
- private int value;
-
- public A() {
-
- }
-
- public A(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
- }
-
- public static class B {
- private int value;
-
- public B() {
-
- }
-
- public B(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
- }
-
- public static class C {
- private int value;
-
- public C() {
-
- }
-
- public C(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
- }
-
- public static class D {
- private int value;
-
- public D() {
-
- }
-
- public D(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
- }
-
- public static class E {
- private int value;
-
- public E() {
-
- }
-
- public E(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
- }
-
- public static class F {
- private int value;
-
- public F() {
-
- }
-
- public F(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
- }
-
- public static class G {
- private int value;
-
- public G() {
-
- }
-
- public G(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
- }
-
- @Test
- public void testSubNetworkSharing() throws Exception {
- // Checks the network is correctly formed, with sharing
- String str = "";
- str += "package org.kie \n";
- str += "import " + A.class.getCanonicalName() + "\n" ;
- str += "import " + B.class.getCanonicalName() + "\n" ;
- str += "import " + C.class.getCanonicalName() + "\n" ;
- str += "import " + D.class.getCanonicalName() + "\n" ;
- str += "import " + E.class.getCanonicalName() + "\n" ;
- str += "global java.util.List list \n";
-
- str += "rule rule1 when \n";
- str += " A() \n";
- str += " B() \n";
- str += " C() \n";
- str += " D() \n";
- str += "then \n";
- str += "end \n";
-
- str += "rule rule2 when \n";
- str += " A() \n";
- str += " exists( B() and C() ) \n";
- str += " D() \n";
- str += "then \n";
- str += "end \n";
-
- str += "rule rule3 when \n";
- str += " A() \n";
- str += " exists( B() and C() and D() ) \n";
- str += " E() \n";
- str += "then \n";
- str += "end \n";
-
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-
- kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
- ResourceType.DRL );
-
- assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
-
- KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
- kconf.setOption( LRUnlinkingOption.ENABLED );
- KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
- kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
-
- ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
- ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
-
- LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
- assertEquals( 3, liaNode.getSinkPropagator().size() );
-
- ExistsNode existsNode2 = ( ExistsNode) liaNode.getSinkPropagator().getSinks()[1];
-
- ExistsNode existsNode3 = ( ExistsNode) liaNode.getSinkPropagator().getSinks()[2];
-
- JoinNode joinNodeB = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0];
- assertSame( joinNodeB.getRightInput(), getObjectTypeNode(kbase, B.class ) );
-
- JoinNode joinNodeC = ( JoinNode) joinNodeB.getSinkPropagator().getSinks()[0];
- assertSame( joinNodeC.getRightInput(), getObjectTypeNode(kbase, C.class ) );
- assertEquals( 2, joinNodeC.getSinkPropagator().size() );
-
- JoinNode joinNodeD = ( JoinNode) joinNodeC.getSinkPropagator().getSinks()[0];
- assertSame( joinNodeD.getRightInput(), getObjectTypeNode(kbase, D.class ) );
- assertEquals( 2, joinNodeD.getSinkPropagator().size() );
-
-
- assertSame( existsNode2, (( RightInputAdapterNode) joinNodeC.getSinkPropagator().getSinks()[1]).getSinkPropagator().getSinks()[0] );
-
- assertSame( existsNode3, (( RightInputAdapterNode) joinNodeD.getSinkPropagator().getSinks()[1]).getSinkPropagator().getSinks()[0] );
- }
-
- @Test
- public void testSubNetworkSharingMemories() throws Exception {
- // checks the memory sharing works, and linking, uses the already checked network from testSubNetworkSharing
- String str = "";
- str += "package org.kie \n";
- str += "import " + A.class.getCanonicalName() + "\n" ;
- str += "import " + B.class.getCanonicalName() + "\n" ;
- str += "import " + C.class.getCanonicalName() + "\n" ;
- str += "import " + D.class.getCanonicalName() + "\n" ;
- str += "import " + E.class.getCanonicalName() + "\n" ;
- str += "global java.util.List list \n";
-
- str += "rule rule1 when \n";
- str += " A() \n";
- str += " B() \n";
- str += " C() \n";
- str += " D() \n";
- str += "then \n";
- str += "end \n";
-
- str += "rule rule2 when \n";
- str += " A() \n";
- str += " exists( B() and C() ) \n";
- str += " D() \n";
- str += "then \n";
- str += "end \n";
-
- str += "rule rule3 when \n";
- str += " A() \n";
- str += " exists( B() and C() and D() ) \n";
- str += " E() \n";
- str += "then \n";
- str += "end \n";
-
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-
- kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
- ResourceType.DRL );
-
- assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
-
- KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
- kconf.setOption( LRUnlinkingOption.ENABLED );
- KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
- kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
-
- ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
- ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
-
- LeftInputAdapterNode liaNodeA = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
- ExistsNode existsNode2 = ( ExistsNode) liaNodeA.getSinkPropagator().getSinks()[1];
- ExistsNode existsNode3 = ( ExistsNode) liaNodeA.getSinkPropagator().getSinks()[2];
- JoinNode joinNodeB = ( JoinNode) liaNodeA.getSinkPropagator().getSinks()[0];
- JoinNode joinNodeC = ( JoinNode) joinNodeB.getSinkPropagator().getSinks()[0];
-
- JoinNode joinNodeD1 = ( JoinNode) joinNodeC.getSinkPropagator().getSinks()[0];
- JoinNode joinNodeD2 = ( JoinNode) existsNode2.getSinkPropagator().getSinks()[0];
-
- JoinNode joinNodeE = ( JoinNode) existsNode3.getSinkPropagator().getSinks()[0];
-
- RuleTerminalNode rtn1 = ( RuleTerminalNode ) joinNodeD1.getSinkPropagator().getSinks()[0];
- RuleTerminalNode rtn2 = ( RuleTerminalNode ) joinNodeD2.getSinkPropagator().getSinks()[0];
- RuleTerminalNode rtn3 = ( RuleTerminalNode ) joinNodeE.getSinkPropagator().getSinks()[0];
-
- FactHandle fha = wm.insert( new A() );
- wm.insert( new B() );
- wm.insert( new C() );
- wm.insert( new D() );
-
- BetaMemory bm = null;
-
- LiaNodeMemory liam = ( LiaNodeMemory ) wm.getNodeMemory( liaNodeA );
-
- BetaMemory bm1 = ( BetaMemory ) wm.getNodeMemory( joinNodeB );
- BetaMemory bm2 = ( BetaMemory ) wm.getNodeMemory( joinNodeC );
- BetaMemory bm3 = ( BetaMemory ) wm.getNodeMemory( joinNodeD1 );
- assertEquals(1, liam.getNodePosMaskBit() );
- assertEquals(1, bm1.getNodePosMaskBit() );
- assertEquals(2, bm2.getNodePosMaskBit() );
- assertEquals(1, bm3.getNodePosMaskBit() );
-
- assertNotSame( liam.getSegmentMemory(), bm1.getSegmentMemory() );
- assertSame( bm1.getSegmentMemory(), bm2.getSegmentMemory() );
- assertNotSame( bm2.getSegmentMemory(), bm3.getSegmentMemory() );
-
- BetaMemory bm4 = ( BetaMemory ) wm.getNodeMemory( existsNode2 );
- BetaMemory bm5 = ( BetaMemory ) wm.getNodeMemory( joinNodeD2 );
- assertEquals(1, bm4.getNodePosMaskBit() );
- assertEquals(2, bm5.getNodePosMaskBit() );
- assertSame( bm4.getSegmentMemory(), bm5.getSegmentMemory() );
-
- PathMemory rs1 = (PathMemory) wm.getNodeMemory( rtn1 );
- PathMemory rs2 = (PathMemory) wm.getNodeMemory( rtn2 );
- PathMemory rs3 = (PathMemory) wm.getNodeMemory( rtn3 );
-
- assertTrue( rs1.isRuleLinked() );
- assertTrue( rs2.isRuleLinked() );
- assertFalse( rs3.isRuleLinked() ); // no E yet
-
-
- wm.insert( new E() );
- BetaMemory bm6 = ( BetaMemory ) wm.getNodeMemory( existsNode3 );
- BetaMemory bm7 = ( BetaMemory ) wm.getNodeMemory( joinNodeE );
- assertEquals(1, bm6.getNodePosMaskBit() );
- assertEquals(2, bm7.getNodePosMaskBit() );
- assertSame( bm6.getSegmentMemory(), bm7.getSegmentMemory() );
-
- assertTrue( rs1.isRuleLinked() );
- assertTrue( rs2.isRuleLinked() );
- assertTrue( rs3.isRuleLinked() );
-
- wm.retract( fha );
- wm.fireAllRules(); // need to have rules evalulated, for unlinking to happen
- assertFalse( rs1.isRuleLinked() );
- assertFalse( rs2.isRuleLinked() );
- assertFalse( rs3.isRuleLinked() );
- }
-
- @Test
- public void testSubNetworkRiaLinking() throws Exception {
- String str = "";
- str += "package org.kie \n";
- str += "import " + A.class.getCanonicalName() + "\n" ;
- str += "import " + B.class.getCanonicalName() + "\n" ;
- str += "import " + C.class.getCanonicalName() + "\n" ;
- str += "import " + D.class.getCanonicalName() + "\n" ;
- str += "import " + E.class.getCanonicalName() + "\n" ;
- str += "global java.util.List list \n";
-
- str += "rule rule1 when \n";
- str += " A() \n";
- str += " B() \n";
- str += " exists( C() and D() ) \n";
- str += " E() \n";
- str += "then \n";
- str += "end \n";
-
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-
- kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
- ResourceType.DRL );
-
- assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
-
- KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
- kconf.setOption( LRUnlinkingOption.ENABLED );
- KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
- kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
-
- ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
- ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
-
- LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
- assertEquals( 1, liaNode.getSinkPropagator().size() );
-
- JoinNode bNode = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0];
- assertEquals( 2, bNode.getSinkPropagator().size() );
-
- ExistsNode exists1n = ( ExistsNode) bNode.getSinkPropagator().getSinks()[1];
-
- JoinNode cNode = ( JoinNode) bNode.getSinkPropagator().getSinks()[0];
- JoinNode dNode = ( JoinNode) cNode.getSinkPropagator().getSinks()[0];
- assertEquals( 1, dNode.getSinkPropagator().size() );
-
- RightInputAdapterNode riaNode1 = ( RightInputAdapterNode ) dNode.getSinkPropagator().getSinks()[0];
-
-
- JoinNode eNode = ( JoinNode ) exists1n.getSinkPropagator().getSinks()[0];
- RuleTerminalNode rtn = ( RuleTerminalNode ) eNode.getSinkPropagator().getSinks()[0];
-
- SegmentUtilities.createSegmentMemory( exists1n, wm );
- BetaMemory existsBm = ( BetaMemory ) wm.getNodeMemory( exists1n );
-
- assertEquals( 0, existsBm.getSegmentMemory().getLinkedNodeMask() );
-
- FactHandle fhc = wm.insert( new C() );
- FactHandle fhd = wm.insert( new D() );
-
- assertEquals( 1, existsBm.getSegmentMemory().getLinkedNodeMask() ); // exists is start of new segment
-
- wm.retract( fhd );
- assertEquals( 0, existsBm.getSegmentMemory().getLinkedNodeMask() );
-
- PathMemory rs = (PathMemory) wm.getNodeMemory( rtn );
- assertFalse( rs.isRuleLinked() );
-
- wm.insert( new A() );
- wm.insert( new B() );
- wm.insert( new E() );
- assertFalse( rs.isRuleLinked() );
-
-
- wm.insert( new D() );
- assertTrue( rs.isRuleLinked() );
-
- wm.retract( fhc );
- assertFalse( rs.isRuleLinked() );
-
- wm.insert( new C() );
- assertTrue( rs.isRuleLinked() );
- }
-
- @Test
- public void testNestedSubNetwork() throws Exception {
- String str = "";
- str += "package org.kie \n";
- str += "import " + A.class.getCanonicalName() + "\n" ;
- str += "import " + B.class.getCanonicalName() + "\n" ;
- str += "import " + C.class.getCanonicalName() + "\n" ;
- str += "import " + D.class.getCanonicalName() + "\n" ;
- str += "import " + E.class.getCanonicalName() + "\n" ;
- str += "import " + F.class.getCanonicalName() + "\n" ;
- str += "import " + G.class.getCanonicalName() + "\n" ;
- str += "global java.util.List list \n";
-
- str += "rule rule1 when \n";
- str += " A() \n";
- str += " B() \n";
- str += " exists( C() and D() and exists( E() and F() ) ) \n";
- str += " G() \n";
- str += "then \n";
- str += "end \n";
-
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-
- kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
- ResourceType.DRL );
-
- assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
-
- KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
- kconf.setOption( LRUnlinkingOption.ENABLED );
- KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
- kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
-
- ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
- ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
-
- LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
- assertEquals( 1, liaNode.getSinkPropagator().size() );
-
- JoinNode bNode = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0];
- assertEquals( 2, bNode.getSinkPropagator().size() );
-
- ExistsNode exists1n = ( ExistsNode) bNode.getSinkPropagator().getSinks()[1];
-
- JoinNode cNode = ( JoinNode) bNode.getSinkPropagator().getSinks()[0];
- JoinNode dNode = ( JoinNode) cNode.getSinkPropagator().getSinks()[0];
- assertEquals( 2, dNode.getSinkPropagator().size() );
-
- ExistsNode exists2n = ( ExistsNode) dNode.getSinkPropagator().getSinks()[1];
-
- JoinNode eNode = ( JoinNode) dNode.getSinkPropagator().getSinks()[0];
- JoinNode fNode = ( JoinNode) eNode.getSinkPropagator().getSinks()[0];
-
- RightInputAdapterNode riaNode2 = ( RightInputAdapterNode ) fNode.getSinkPropagator().getSinks()[0];
- assertEquals( exists2n, riaNode2.getSinkPropagator().getSinks()[0] );
-
- RightInputAdapterNode riaNode1 = ( RightInputAdapterNode ) exists2n.getSinkPropagator().getSinks()[0];
- assertEquals( exists1n, riaNode1.getSinkPropagator().getSinks()[0] );
-
- JoinNode gNode = ( JoinNode) exists1n.getSinkPropagator().getSinks()[0];
- RuleTerminalNode rtn = ( RuleTerminalNode) gNode.getSinkPropagator().getSinks()[0];
-
- wm.insert( new A() );
- wm.insert( new B() );
- wm.insert( new C() );
- wm.insert( new D() );
- wm.insert( new F() );
- wm.insert( new G() );
-
- PathMemory rs = (PathMemory) wm.getNodeMemory( rtn );
- assertFalse( rs.isRuleLinked() );
-
- FactHandle fhE1 = wm.insert( new E() );
- FactHandle fhE2 = wm.insert( new E() );
- assertTrue( rs.isRuleLinked() );
-
- wm.retract( fhE1 );
- assertTrue( rs.isRuleLinked() );
-
- wm.retract( fhE2 );
- assertFalse( rs.isRuleLinked() );
- }
-
- @Test
- public void testNestedSubNetworkMasks() throws Exception {
- String str = "";
- str += "package org.kie \n";
- str += "import " + A.class.getCanonicalName() + "\n" ;
- str += "import " + B.class.getCanonicalName() + "\n" ;
- str += "import " + C.class.getCanonicalName() + "\n" ;
- str += "import " + D.class.getCanonicalName() + "\n" ;
- str += "import " + E.class.getCanonicalName() + "\n" ;
- str += "import " + F.class.getCanonicalName() + "\n" ;
- str += "import " + G.class.getCanonicalName() + "\n" ;
- str += "global java.util.List list \n";
-
- str += "rule rule1 when \n";
- str += " A() \n";
- str += " B() \n";
- str += " exists( C() and D() and exists( E() and F() ) ) \n";
- str += " G() \n";
- str += "then \n";
- str += "end \n";
-
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-
- kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ),
- ResourceType.DRL );
-
- assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
-
- KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
- kconf.setOption( LRUnlinkingOption.ENABLED );
- KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf);
- kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
-
- ObjectTypeNode node = getObjectTypeNode(kbase, A.class );
- ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
-
- LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
- JoinNode bNode = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0];
-
- ExistsNode exists1n = ( ExistsNode) bNode.getSinkPropagator().getSinks()[1];
-
- JoinNode cNode = ( JoinNode) bNode.getSinkPropagator().getSinks()[0];
- JoinNode dNode = ( JoinNode) cNode.getSinkPropagator().getSinks()[0];
-
- ExistsNode exists2n = ( ExistsNode) dNode.getSinkPropagator().getSinks()[1];
-
- JoinNode eNode = ( JoinNode) dNode.getSinkPropagator().getSinks()[0];
- JoinNode fNode = ( JoinNode) eNode.getSinkPropagator().getSinks()[0];
-
- RightInputAdapterNode riaNode2 = ( RightInputAdapterNode ) fNode.getSinkPropagator().getSinks()[0];
- RightInputAdapterNode riaNode1 = ( RightInputAdapterNode ) exists2n.getSinkPropagator().getSinks()[0];
-
- JoinNode gNode = ( JoinNode) exists1n.getSinkPropagator().getSinks()[0];
- RuleTerminalNode rtn = ( RuleTerminalNode) gNode.getSinkPropagator().getSinks()[0];
-
- wm.insert( new A() );
- wm.insert( new B() );
- wm.insert( new C() );
- wm.insert( new D() );
- wm.insert( new G() );
-
- LiaNodeMemory liaMem = ( LiaNodeMemory ) wm.getNodeMemory( liaNode );
- BetaMemory bMem = ( BetaMemory ) wm.getNodeMemory( bNode );
- BetaMemory exists1Mem = ( BetaMemory ) wm.getNodeMemory( exists1n );
- BetaMemory cMem = ( BetaMemory ) wm.getNodeMemory( cNode );
- BetaMemory dMem = ( BetaMemory ) wm.getNodeMemory( dNode );
- BetaMemory exists2Mem = ( BetaMemory ) wm.getNodeMemory( exists2n );
- BetaMemory eMem = ( BetaMemory ) wm.getNodeMemory( eNode );
- BetaMemory fMem = ( BetaMemory ) wm.getNodeMemory( fNode );
- BetaMemory gMem = ( BetaMemory ) wm.getNodeMemory( gNode );
-
- RiaNodeMemory riaMem1 = ( RiaNodeMemory ) wm.getNodeMemory( riaNode1 );
- RiaNodeMemory riaMem2 = ( RiaNodeMemory ) wm.getNodeMemory( riaNode2 );
-
- PathMemory rs = (PathMemory) wm.getNodeMemory( rtn );
-
- assertFalse( rs.isRuleLinked() ); //E and F are not inserted yet, so rule is unlinked
-
- //---
- // assert a and b in same segment
- assertSame( liaMem.getSegmentMemory(), bMem.getSegmentMemory() );
-
- // exists1 and b not in same segment
- assertNotSame( bMem.getSegmentMemory(), exists1Mem.getSegmentMemory() );
-
- // exists1 and b are in same segment
- assertSame( exists1Mem.getSegmentMemory(), gMem.getSegmentMemory() );
-
- // check segment masks
- assertEquals( 2, rs.getSegmentMemories().length );
- assertEquals( 3, rs.getAllLinkedMaskTest() );
- assertEquals( 1, rs.getLinkedSegmentMask() );
-
- assertEquals( 3, liaMem.getSegmentMemory().getAllLinkedMaskTest() );
- assertEquals( 1, liaMem.getNodePosMaskBit() );
- assertEquals( 2, bMem.getNodePosMaskBit() );
-
- assertEquals( 3, exists1Mem.getSegmentMemory().getAllLinkedMaskTest() );
- assertEquals( 1, exists1Mem.getNodePosMaskBit() );
- assertEquals( 2, gMem.getNodePosMaskBit() );
-
-
- // assert c, d are in the same segment, and that this is the only segment in ria1 memory
- assertSame( dMem.getSegmentMemory(), cMem.getSegmentMemory() );
-
- // assert d and exists are not in the same segment
- assertNotSame( exists2Mem.getSegmentMemory(), dMem.getSegmentMemory() );
- assertEquals( 3, riaMem1.getRiaPathMemory().getSegmentMemories().length );
- assertEquals( null, riaMem1.getRiaPathMemory().getSegmentMemories()[0] ); // only needs to know about segments in the subnetwork
- assertEquals( dMem.getSegmentMemory(), riaMem1.getRiaPathMemory().getSegmentMemories()[1] );
- assertEquals( 1, dMem.getSegmentMemory().getPathMemories().size() );
- assertSame( riaMem1.getRiaPathMemory(), cMem.getSegmentMemory().getPathMemories().get(0) );
-
- assertEquals( 3, cMem.getSegmentMemory().getAllLinkedMaskTest() );
- assertEquals( 3, cMem.getSegmentMemory().getLinkedNodeMask() ); // E and F is not yet inserted, so bit is not set
- assertEquals( 1, cMem.getNodePosMaskBit() );
- assertEquals( 2, dMem.getNodePosMaskBit() );
-
- assertEquals( 0, exists2Mem.getNodePosMaskBit() );
- FactHandle fhE1 = wm.insert( new E() ); // insert to lazy initialize exists2Mem segment
- FactHandle fhF1 = wm.insert( new F() );
- assertEquals( 1, exists2Mem.getNodePosMaskBit() );
- assertEquals( 6, riaMem1.getRiaPathMemory().getAllLinkedMaskTest() ); // only cares that the segment for c, E and exists1 are set, ignores the outer first segment
- assertEquals( 6, riaMem1.getRiaPathMemory().getLinkedSegmentMask() ); // E and F are inerted, so 6
- wm.delete(fhE1);
- wm.delete(fhF1);
- assertEquals( 2, riaMem1.getRiaPathMemory().getLinkedSegmentMask() ); // E deleted
-
- // assert e, f are in the same segment, and that this is the only segment in ria2 memory
- assertNotNull( null, eMem.getSegmentMemory() ); //subnetworks are recursively created, so segment already exists
- assertSame( fMem.getSegmentMemory(), eMem.getSegmentMemory() );
-
- assertEquals( 3, riaMem2.getRiaPathMemory().getSegmentMemories().length );
- assertEquals( null, riaMem2.getRiaPathMemory().getSegmentMemories()[0] ); // only needs to know about segments in the subnetwork
- assertEquals( null, riaMem2.getRiaPathMemory().getSegmentMemories()[1] ); // only needs to know about segments in the subnetwork
- assertEquals( fMem.getSegmentMemory(), riaMem2.getRiaPathMemory().getSegmentMemories()[2] );
- assertSame( riaMem2.getRiaPathMemory(), eMem.getSegmentMemory().getPathMemories().get(0) );
- assertEquals( 3, eMem.getSegmentMemory().getAllLinkedMaskTest() );
- assertEquals( 0, eMem.getSegmentMemory().getLinkedNodeMask() );
- assertEquals( 4, riaMem2.getRiaPathMemory().getAllLinkedMaskTest() ); // only cares that the segment for e and f set, ignores the outer two segment
- assertEquals( 0, riaMem2.getRiaPathMemory().getLinkedSegmentMask() ); // E and F is not yet inserted, so bit is not set
-
- fhE1 = wm.insert( new E() );
- wm.insert( new F() );
-
- assertTrue( rs.isRuleLinked() ); //E and F are now inserted yet, so rule is linked
- assertEquals( 3, rs.getAllLinkedMaskTest() );
- assertEquals( 3, rs.getLinkedSegmentMask() );
-
- // retest bits
- assertEquals( 3, cMem.getSegmentMemory().getAllLinkedMaskTest() );
- assertEquals( 3, cMem.getSegmentMemory().getLinkedNodeMask() );
- assertEquals( 6, riaMem1.getRiaPathMemory().getAllLinkedMaskTest() );
- assertEquals( 6, riaMem1.getRiaPathMemory().getLinkedSegmentMask() );
-
- assertEquals( 3, eMem.getSegmentMemory().getAllLinkedMaskTest() );
- assertEquals( 3, eMem.getSegmentMemory().getLinkedNodeMask() );
- assertEquals( 4, riaMem2.getRiaPathMemory().getAllLinkedMaskTest() );
- assertEquals( 4, riaMem2.getRiaPathMemory().getLinkedSegmentMask() );
-
- wm.delete( fhE1 );
-
- // retest bits
- assertFalse( rs.isRuleLinked() );
-
- assertEquals( 3, cMem.getSegmentMemory().getLinkedNodeMask() );
- assertEquals( 2, riaMem1.getRiaPathMemory().getLinkedSegmentMask() );
-
- assertEquals( 2, eMem.getSegmentMemory().getLinkedNodeMask() );
- assertEquals( 0, riaMem2.getRiaPathMemory().getLinkedSegmentMask() );
- }
-
- public ObjectTypeNode getObjectTypeNode(KnowledgeBase kbase, Class<?> nodeClass) {
- List<ObjectTypeNode> nodes = ((InternalRuleBase)((KnowledgeBaseImpl)kbase).ruleBase).getRete().getObjectTypeNodes();
- for ( ObjectTypeNode n : nodes ) {
- if ( ((ClassObjectType)n.getObjectType()).getClassType() == nodeClass ) {
- return n;
- }
- }
- return null;
- }
-
-}
View
2 drools-compiler/src/test/java/org/drools/reteoo/MockLeftTupleSink.java
@@ -202,7 +202,7 @@ protected ObjectTypeNode getObjectTypeNode() {
return null;
}
- public Memory createMemory(RuleBaseConfiguration config) {
+ public Memory createMemory(RuleBaseConfiguration config, InternalWorkingMemory wm) {
return null;
}
View
2 drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
@@ -951,7 +951,7 @@ public void queueWorkingMemoryAction(final WorkingMemoryAction action) {
* @return The node's memory.
*/
public Memory getNodeMemory(final MemoryFactory node) {
- return nodeMemories.getNodeMemory( node );
+ return nodeMemories.getNodeMemory( node, this );
}
public void clearNodeMemory(final MemoryFactory node) {
View
9 drools-core/src/main/java/org/drools/common/ConcurrentNodeMemories.java
@@ -59,14 +59,14 @@ public void clear() {
*
* @see org.kie.common.NodeMemories#getNodeMemory(org.kie.common.MemoryFactory)
*/
- public Memory getNodeMemory( MemoryFactory node ) {
+ public Memory getNodeMemory(MemoryFactory node, InternalWorkingMemory wm) {
if( node.getId() >= this.memories.length() ) {
resize( node );
}
Memory memory = this.memories.get( node.getId() );
if( memory == null ) {
- memory = createNodeMemory( node );
+ memory = createNodeMemory( node, wm );
}
return memory;
@@ -81,14 +81,15 @@ public Memory getNodeMemory( MemoryFactory node ) {
* @param node
* @return
*/
- private Memory createNodeMemory( MemoryFactory node ) {
+ private Memory createNodeMemory( MemoryFactory node,
+ InternalWorkingMemory wm ) {
try {
this.lock.lock();
// need to try again in a synchronized code block to make sure
// it was not created yet
Memory memory = this.memories.get( node.getId() );
if( memory == null ) {
- memory = node.createMemory( this.rulebase.getConfiguration() );
+ memory = node.createMemory( this.rulebase.getConfiguration(), wm );
if( !this.memories.compareAndSet( node.getId(), null, memory ) ) {
memory = this.memories.get( node.getId() );
View
2 drools-core/src/main/java/org/drools/common/MemoryFactory.java
@@ -21,5 +21,5 @@
public interface MemoryFactory {
public int getId();
- public Memory createMemory(RuleBaseConfiguration config);
+ public Memory createMemory(RuleBaseConfiguration config, InternalWorkingMemory wm);
}
View
2 drools-core/src/main/java/org/drools/common/NodeMemories.java
@@ -22,7 +22,7 @@
*/
public interface NodeMemories {
- public Memory getNodeMemory( MemoryFactory node );
+ public Memory getNodeMemory(MemoryFactory node, InternalWorkingMemory wm);
public void clearNodeMemory( MemoryFactory node );
View
84 drools-core/src/main/java/org/drools/phreak/SegmentUtilities.java
@@ -38,14 +38,23 @@
*/
public static SegmentMemory createSegmentMemory(LeftTupleSource tupleSource ,
final InternalWorkingMemory wm) {
+ boolean initRtn = false;
+ if ( tupleSource.getType() == NodeTypeEnums.LeftInputAdapterNode ) {
+ initRtn = true;
+ }
+
// find segment root
while ( tupleSource.getType() != NodeTypeEnums.LeftInputAdapterNode &&
SegmentUtilities.parentInSameSegment(tupleSource) ) {
tupleSource = tupleSource.getLeftTupleSource();
}
-
+
LeftTupleSource segmentRoot = tupleSource;
-
+
+ if ( initRtn ) {
+ initialiseRtnMemory(segmentRoot, wm);
+ }
+
SegmentMemory smem = new SegmentMemory(segmentRoot);
// Iterate all nodes on the same segment, assigning their position as a bit mask value
@@ -55,17 +64,17 @@ public static SegmentMemory createSegmentMemory(LeftTupleSource tupleSource ,
while ( true ) {
if ( NodeTypeEnums.isBetaNode( tupleSource ) ) {
- BetaMemory betaMemory;
+ BetaMemory bm;
BetaNode betaNode = ( BetaNode ) tupleSource;
if ( NodeTypeEnums.AccumulateNode == tupleSource.getType() ) {
- betaMemory = (( AccumulateMemory ) smem.createNodeMemory( ( AccumulateNode ) tupleSource, wm )).getBetaMemory();
+ bm = (( AccumulateMemory ) smem.createNodeMemory( ( AccumulateNode ) tupleSource, wm )).getBetaMemory();
} else {
- betaMemory = ( BetaMemory ) smem.createNodeMemory( betaNode, wm );
+ bm = ( BetaMemory ) smem.createNodeMemory( betaNode, wm );
}
// this must be set first, to avoid recursion as sub networks can be initialised multiple ways
// and bm.getSegmentMemory == null check can be used to avoid recursion.
- betaMemory.setSegmentMemory( smem );
+ bm.setSegmentMemory(smem);
if ( betaNode.isRightInputIsRiaNode() ) {
// Iterate to find outermost rianode
@@ -86,29 +95,21 @@ public static SegmentMemory createSegmentMemory(LeftTupleSource tupleSource ,
}
RiaNodeMemory riaMem = ( RiaNodeMemory ) wm.getNodeMemory( (MemoryFactory) riaNode );
- // riaMem will be initialised as part of the subnetwork createSegmentMemory, if it does not already exist.
- betaMemory.setRiaRuleMemory(riaMem.getRiaPathMemory());
-
- if ( riaMem.getRiaPathMemory().getAllLinkedMaskTest() == 0 ) {
- // node's with right inputs that have no beta nodes, need to have their bit's set
- smem.linkNode( nodePosMask, wm );
+ bm.setRiaRuleMemory(riaMem.getRiaPathMemory());
+ if ( riaMem.getRiaPathMemory().getAllLinkedMaskTest() > 0 ) {
+ // only ria's with reactive subnetworks can be disabled and thus need checking
+ allLinkedTestMask = allLinkedTestMask | nodePosMask;
}
+ } else if ( ( !(NodeTypeEnums.NotNode == tupleSource.getType() && !((NotNode)tupleSource).isEmptyBetaConstraints()) &&
+ NodeTypeEnums.AccumulateNode != tupleSource.getType()) ) {
+ // non empty not nodes and accumulates can never be disabled and thus don't need checking
+ allLinkedTestMask = allLinkedTestMask | nodePosMask;
-// SegmentMemory subNetworkSegmentMemory = mem.getSegmentMemory();
-// if ( subNetworkSegmentMemory == null ) {
-// // we need to stop recursion here
-// subNetworkSegmentMemory = createSegmentMemory( ( LeftTupleSource ) riaNode.getLeftTupleSource(), wm );
-// }
-// betaMemory.setRiaPathMemory( (RiaPathMemory) ((RiaNodeMemory) mem).getRiaPathMemory() );
-// if ( subNetworkSegmentMemory.getAllLinkedMaskTest() == 0 ) {
-// smem.linkNode( nodePosMask, wm );
-// }
}
- betaMemory.setNodePosMaskBit( nodePosMask );
- allLinkedTestMask = allLinkedTestMask | nodePosMask;
- if ( NodeTypeEnums.NotNode == tupleSource.getType() || NodeTypeEnums.AccumulateNode == tupleSource.getType()) {
- // NotNode's and Accumulate are initialised as linkedin
- smem.linkNode( nodePosMask, wm );
+ bm.setNodePosMaskBit(nodePosMask);
+ if ( NodeTypeEnums.NotNode == tupleSource.getType() ) {
+ // not nodes start up linked in
+ smem.linkNodeWithoutRuleNotify(bm.getNodePosMaskBit());
}
nodePosMask = nodePosMask << 1;
} else if ( tupleSource.getType() == NodeTypeEnums.LeftInputAdapterNode ) {
@@ -217,7 +218,7 @@ public static SegmentMemory createSegmentMemory(LeftTupleSource tupleSource ,
smem.setSegmentPosMaskBit( ruleSegmentPosMask );
smem.setPos( counter );
- SegmentUtilities.updateRiaAndTerminalMemory( 0, tupleSource, tupleSource, smem, wm );
+ updateRiaAndTerminalMemory( tupleSource, tupleSource, smem, wm );
return smem;
}
@@ -283,50 +284,57 @@ public static boolean inSubNetwork(RightInputAdapterNode riaNode, LeftTupleSourc
* In the case of the ria node its all the segments up to the start of the subnetwork.
* This is because the rianode only cares if all of it's segments are linked, then
* it sets the bit of node it is the right input for.
- * @param pos
* @param lt
* @param originalLt
* @param smem
* @param wm
*/
- public static void updateRiaAndTerminalMemory(int pos, LeftTupleSource lt,
+ public static void updateRiaAndTerminalMemory(LeftTupleSource lt,
LeftTupleSource originalLt,
SegmentMemory smem,
InternalWorkingMemory wm) {
for ( LeftTupleSink sink : lt.getSinkPropagator().getSinks() ) {
if (NodeTypeEnums.isLeftTupleSource( sink ) ) {
- if ( sink.getType() == NodeTypeEnums.NotNode ) {
+ if ( NodeTypeEnums.NotNode == sink.getType() && ((NotNode)sink).isEmptyBetaConstraints() ) {
BetaMemory bm = ( BetaMemory) wm.getNodeMemory( (MemoryFactory) sink );
if ( bm.getSegmentMemory() == null ) {
// Not nodes must be initialised
createSegmentMemory( (NotNode) sink, wm );
}
}
- updateRiaAndTerminalMemory(++pos, ( LeftTupleSource ) sink, originalLt, smem, wm);
+ updateRiaAndTerminalMemory(( LeftTupleSource ) sink, originalLt, smem, wm);
} else if ( sink.getType() == NodeTypeEnums.RightInputAdaterNode) {
// Only add the RIANode, if the LeftTupleSource is part of the RIANode subnetwork.
if ( inSubNetwork( (RightInputAdapterNode)sink, originalLt ) ) {
RiaNodeMemory riaMem = ( RiaNodeMemory) wm.getNodeMemory( (MemoryFactory) sink );
PathMemory rmem = (PathMemory) riaMem.getRiaPathMemory();
smem.getPathMemories().add( rmem );
rmem.getSegmentMemories()[smem.getPos()] = smem;
- if ( smem.getAllLinkedMaskTest() != 0 & smem.isSegmentLinked() ) {
- // only happens for segments with only a 'not' node
- rmem.linkSegment(smem.getSegmentPosMaskBit(), wm);
- }
}
} else if ( NodeTypeEnums.isTerminalNode( sink) ) {
PathMemory rmem = (PathMemory) wm.getNodeMemory( (MemoryFactory) sink );
smem.getPathMemories().add( rmem );
rmem.getSegmentMemories()[smem.getPos()] = smem;
- if ( smem.getAllLinkedMaskTest() != 0 & smem.isSegmentLinked() ) {
- // only happens for segments with only a 'not' node
- rmem.linkSegment(smem.getSegmentPosMaskBit(), wm);
+ if ( smem.isSegmentLinked() ) {
+ // not's can cause segments to be linked, and the rules need to be notified for evaluation
+ smem.notifyRuleLinkSegment(wm);
}
}
}
}
+ public static void initialiseRtnMemory(LeftTupleSource lt,
+ InternalWorkingMemory wm) {
+ for ( LeftTupleSink sink : lt.getSinkPropagator().getSinks() ) {
+ if (NodeTypeEnums.isLeftTupleSource( sink ) ) {
+ initialiseRtnMemory((LeftTupleSource) sink, wm);
+ } else if ( NodeTypeEnums.isTerminalNode( sink) ) {
+ // getting will cause an initialization of rtn, which will recursively initialise rians too.
+ PathMemory rmem = (PathMemory) wm.getNodeMemory( (MemoryFactory) sink );
+ }
+ }
+ }
+
public static boolean parentInSameSegment(LeftTupleSource lt) {
return lt.getLeftTupleSource().getSinkPropagator().size() == 1;
// comments out for now, as the optimization to preserve subnetwork segments down one side is troublesome.
View
21 drools-core/src/main/java/org/drools/reteoo/AbstractTerminalNode.java
@@ -10,6 +10,7 @@
import org.drools.common.RuleBasePartitionId;
import org.drools.phreak.SegmentUtilities;
import org.drools.reteoo.builder.BuildContext;
+import org.drools.reteoo.RightInputAdapterNode.RiaNodeMemory;
import org.drools.rule.Pattern;
import org.drools.rule.Rule;
import org.drools.rule.TypeDeclaration;
@@ -113,16 +114,16 @@ public void modifyLeftTuple(InternalFactHandle factHandle,
public abstract Rule getRule();
- public Memory createMemory(RuleBaseConfiguration config) {
+ public Memory createMemory(RuleBaseConfiguration config, InternalWorkingMemory wm) {
PathMemory rmem = new PathMemory(this);
- initPathMemory(rmem, getLeftTupleSource(), null);
+ initPathMemory(rmem, getLeftTupleSource(), null, wm );
return rmem;
}
/**
* Creates and return the node memory
*/
- public static void initPathMemory(PathMemory pmem, LeftTupleSource tupleSource, LeftTupleSource startTupleSource) {
+ public static void initPathMemory(PathMemory pmem, LeftTupleSource tupleSource, LeftTupleSource startTupleSource, InternalWorkingMemory wm) {
int counter = 0;
long allLinkedTestMask = 0;
@@ -135,7 +136,19 @@ public static void initPathMemory(PathMemory pmem, LeftTupleSource tupleSource,
while ( tupleSource.getType() != NodeTypeEnums.LeftInputAdapterNode ) {
if ( updateAllLinkedTest && updateBitInNewSegment && NodeTypeEnums.isBetaNode( tupleSource )) {
updateBitInNewSegment = false;
- allLinkedTestMask = allLinkedTestMask | 1;
+ BetaNode bn = ( BetaNode) tupleSource;
+ if ( bn.isRightInputIsRiaNode() ) {
+ // only ria's without reactive subnetworks can be disabled and thus need checking
+ // The getNodeMemory will call this method recursive for sub networks it reaches
+ RiaNodeMemory rnmem = ( RiaNodeMemory ) wm.getNodeMemory((MemoryFactory) bn.getRightInput());
+ if ( rnmem.getRiaPathMemory().getAllLinkedMaskTest() != 0 ) {
+ allLinkedTestMask = allLinkedTestMask | 1;
+ }
+ } else if ( ( !(NodeTypeEnums.NotNode == bn.getType() && !((NotNode)bn).isEmptyBetaConstraints()) &&
+ NodeTypeEnums.AccumulateNode != bn.getType()) ) {
+ // non empty not nodes and accumulates can never be disabled and thus don't need checking
+ allLinkedTestMask = allLinkedTestMask | 1;
+ }
}
if ( !SegmentUtilities.parentInSameSegment( tupleSource ) ) {
View
3 drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
@@ -31,7 +31,6 @@
import org.drools.common.InternalWorkingMemory;
import org.drools.common.Memory;
import org.drools.common.PropagationContextImpl;
-import org.drools.common.RightTupleSets;
import org.drools.core.util.AbstractBaseLinkedListNode;
import org.drools.core.util.ArrayUtils;
import org.drools.core.util.FastIterator;
@@ -842,7 +841,7 @@ public boolean equals( final Object object ) {
/**
* Creates a BetaMemory for the BetaNode's memory.
*/
- public Memory createMemory( final RuleBaseConfiguration config ) {
+ public Memory createMemory(final RuleBaseConfiguration config, InternalWorkingMemory wm) {
AccumulateMemory memory = new AccumulateMemory();
memory.betaMemory = this.constraints.createBetaMemory( config,
NodeTypeEnums.AccumulateNode );
View
4 drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
@@ -15,7 +15,6 @@
*/
package org.drools.reteoo;
-import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
@@ -31,7 +30,6 @@
import org.drools.common.RuleBasePartitionId;
import org.drools.reteoo.builder.BuildContext;
import org.drools.rule.ContextEntry;
-import org.drools.rule.Pattern;
import org.drools.rule.constraint.MvelConstraint;
import org.drools.spi.AlphaNodeFieldConstraint;
import org.drools.spi.PropagationContext;
@@ -214,7 +212,7 @@ public void updateSink(final ObjectSink sink,
/**
* Creates a HashSet for the AlphaNode's memory.
*/
- public Memory createMemory(final RuleBaseConfiguration config) {
+ public Memory createMemory(final RuleBaseConfiguration config, InternalWorkingMemory wm) {
AlphaMemory memory = new AlphaMemory();
memory.context = this.constraint.createContextEntry();
return memory;
View
4 drools-core/src/main/java/org/drools/reteoo/BetaNode.java
@@ -45,8 +45,6 @@
import org.drools.spi.BetaNodeFieldConstraint;
import org.drools.spi.ObjectType;
import org.drools.spi.PropagationContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.ObjectInput;
@@ -713,7 +711,7 @@ public void setConcurrentRightTupleMemory(boolean concurrentRightTupleMemory) {
this.concurrentRightTupleMemory = concurrentRightTupleMemory;
}
- public Memory createMemory(RuleBaseConfiguration config) {
+ public Memory createMemory(RuleBaseConfiguration config, InternalWorkingMemory wm) {
return constraints.createBetaMemory(config, getType());
}