[jboss-svn-commits] JBL Code SVN: r18209 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/reteoo and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 30 21:28:04 EST 2008
Author: tirelli
Date: 2008-01-30 21:28:04 -0500 (Wed, 30 Jan 2008)
New Revision: 18209
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeConstraint.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/VariableConstraint.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/VariableRestriction.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/BetaNodeFieldConstraint.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Restriction.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/spi/MockConstraint.java
Log:
JBRULES-1392: fixing a concurrency problem due to node context sharing between concurrent threads
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BetaConstraints.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BetaConstraints.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -5,33 +5,41 @@
import org.drools.RuleBaseConfiguration;
import org.drools.reteoo.BetaMemory;
import org.drools.reteoo.ReteTuple;
+import org.drools.rule.ContextEntry;
import org.drools.util.LinkedList;
public interface BetaConstraints
extends
Serializable {
- public void updateFromTuple(InternalWorkingMemory workingMemory,
+ public ContextEntry[] createContext();
+
+ public void updateFromTuple(ContextEntry[] context,
+ InternalWorkingMemory workingMemory,
ReteTuple tuple);
- public void updateFromFactHandle(InternalWorkingMemory workingMemory,
+ public void updateFromFactHandle(ContextEntry[] context,
+ InternalWorkingMemory workingMemory,
InternalFactHandle handle);
- public boolean isAllowedCachedLeft(InternalFactHandle handle);
+ public boolean isAllowedCachedLeft(ContextEntry[] context,
+ InternalFactHandle handle);
- public boolean isAllowedCachedRight(ReteTuple tuple);
+ public boolean isAllowedCachedRight(ContextEntry[] context,
+ ReteTuple tuple);
public LinkedList getConstraints();
public boolean isIndexed();
-
+
public int getIndexCount();
public boolean isEmpty();
public BetaMemory createBetaMemory(final RuleBaseConfiguration config);
-
- public void resetTuple();
-
- public void resetFactHandle();
+
+ public void resetTuple(final ContextEntry[] context);
+
+ public void resetFactHandle(final ContextEntry[] context);
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -47,38 +47,37 @@
/**
*
*/
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
- private final LinkedList constraints;
+ private final LinkedList constraints;
- private ContextEntry contexts;
+ private int indexed;
- private int indexed;
-
public DefaultBetaConstraints(final BetaNodeFieldConstraint[] constraints,
final RuleBaseConfiguration conf) {
- this( constraints, conf, false );
-
+ this( constraints,
+ conf,
+ false );
+
}
-
+
public DefaultBetaConstraints(final BetaNodeFieldConstraint[] constraints,
final RuleBaseConfiguration conf,
- final boolean disableIndexing ) {
+ final boolean disableIndexing) {
this.indexed = -1;
this.constraints = new LinkedList();
- ContextEntry current = null;
final int depth = conf.getCompositeKeyDepth();
// First create a LinkedList of constraints, with the indexed constraints first.
for ( int i = 0, length = constraints.length; i < length; i++ ) {
// Determine if this constraint is indexable
- if ( (!disableIndexing) && conf.isIndexLeftBetaMemory() && conf.isIndexRightBetaMemory() && isIndexable( constraints[i] ) && ( this.indexed < depth-1 ) ) {
+ if ( (!disableIndexing) && conf.isIndexLeftBetaMemory() && conf.isIndexRightBetaMemory() && isIndexable( constraints[i] ) && (this.indexed < depth - 1) ) {
if ( depth >= 1 && this.indexed == -1 ) {
// first index, so just add to the front
this.constraints.insertAfter( null,
new LinkedListEntry( constraints[i] ) );
this.indexed++;
- } else {
+ } else {
// insert this index after the previous index
this.constraints.insertAfter( findNode( this.indexed++ ),
new LinkedListEntry( constraints[i] ) );
@@ -89,18 +88,17 @@
}
}
+ }
+
+ public ContextEntry[] createContext() {
// Now create the ContextEntries in the same order the constraints
+ ContextEntry[] contexts = new ContextEntry[this.constraints.size()];
+ int i = 0;
for ( LinkedListEntry entry = (LinkedListEntry) this.constraints.getFirst(); entry != null; entry = (LinkedListEntry) entry.getNext() ) {
final BetaNodeFieldConstraint constraint = (BetaNodeFieldConstraint) entry.getObject();
- final ContextEntry context = constraint.getContextEntry();
- if ( current == null ) {
- current = context;
- this.contexts = context;
- } else {
- current.setNext( context );
- }
- current = context;
+ contexts[i++] = constraint.createContextEntry();
}
+ return contexts;
}
private LinkedListEntry findNode(final int pos) {
@@ -111,14 +109,6 @@
return current;
}
- private ContextEntry findContext(final int pos) {
- ContextEntry current = this.contexts;
- for ( int i = 0; i < pos; i++ ) {
- current = current.getNext();
- }
- return current;
- }
-
private boolean isIndexable(final BetaNodeFieldConstraint constraint) {
if ( constraint instanceof VariableConstraint ) {
final VariableConstraint variableConstraint = (VariableConstraint) constraint;
@@ -131,52 +121,55 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromTuple(org.drools.reteoo.ReteTuple)
*/
- public void updateFromTuple(final InternalWorkingMemory workingMemory,
+ public void updateFromTuple(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final ReteTuple tuple) {
- for ( ContextEntry context = this.contexts; context != null; context = context.getNext() ) {
- context.updateFromTuple( workingMemory,
- tuple );
+ for ( int i = 0; i < context.length; i++ ) {
+ context[i].updateFromTuple( workingMemory,
+ tuple );
}
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromFactHandle(org.drools.common.InternalFactHandle)
*/
- public void updateFromFactHandle(final InternalWorkingMemory workingMemory,
+ public void updateFromFactHandle(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final InternalFactHandle handle) {
- for ( ContextEntry context = this.contexts; context != null; context = context.getNext() ) {
- context.updateFromFactHandle( workingMemory,
- handle );
+ for ( int i = 0; i < context.length; i++ ) {
+ context[i].updateFromFactHandle( workingMemory,
+ handle );
}
}
-
- public void resetTuple() {
- for ( ContextEntry context = this.contexts; context != null; context = context.getNext() ) {
- context.resetTuple();
+
+ public void resetTuple(final ContextEntry[] context) {
+ for ( int i = 0; i < context.length; i++ ) {
+ context[i].resetTuple();
}
}
-
- public void resetFactHandle() {
- for ( ContextEntry context = this.contexts; context != null; context = context.getNext() ) {
- context.resetFactHandle();
+
+ public void resetFactHandle(final ContextEntry[] context) {
+ for ( int i = 0; i < context.length; i++ ) {
+ context[i].resetFactHandle();
}
- }
+ }
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
+ public boolean isAllowedCachedLeft(final ContextEntry[] context,
+ final InternalFactHandle handle) {
// skip the indexed constraints
- LinkedListEntry entry = (LinkedListEntry) findNode( this.indexed );
+ LinkedListEntry entry = (LinkedListEntry) findNode( this.indexed+1 );
- ContextEntry context = findContext( this.indexed );
+ int i = 1;
while ( entry != null ) {
- if ( !((BetaNodeFieldConstraint) entry.getObject()).isAllowedCachedLeft( context,
+ if ( !((BetaNodeFieldConstraint) entry.getObject()).isAllowedCachedLeft( context[this.indexed + i],
handle ) ) {
return false;
}
entry = (LinkedListEntry) entry.getNext();
- context = context.getNext();
+ i++;
}
return true;
}
@@ -184,18 +177,19 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedRight(org.drools.reteoo.ReteTuple)
*/
- public boolean isAllowedCachedRight(final ReteTuple tuple) {
+ public boolean isAllowedCachedRight(final ContextEntry[] context,
+ final ReteTuple tuple) {
// skip the indexed constraints
- LinkedListEntry entry = (LinkedListEntry) findNode( this.indexed );
+ LinkedListEntry entry = (LinkedListEntry) findNode( this.indexed+1 );
- ContextEntry context = findContext( this.indexed );
+ int i = 1;
while ( entry != null ) {
if ( !((BetaNodeFieldConstraint) entry.getObject()).isAllowedCachedRight( tuple,
- context ) ) {
+ context[this.indexed + i] ) ) {
return false;
}
entry = (LinkedListEntry) entry.getNext();
- context = context.getNext();
+ i++;
}
return true;
}
@@ -204,10 +198,10 @@
// false if -1
return this.indexed >= 0;
}
-
+
public int getIndexCount() {
- return this.indexed+1;
- }
+ return this.indexed + 1;
+ }
public boolean isEmpty() {
return false;
@@ -244,10 +238,12 @@
factHandleMemory = config.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable();
}
memory = new BetaMemory( config.isSequential() ? null : tupleMemory,
- factHandleMemory );
+ factHandleMemory,
+ this.createContext() );
} else {
memory = new BetaMemory( config.isSequential() ? null : new TupleHashTable(),
- config.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable() );
+ config.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable(),
+ this.createContext() );
}
return memory;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -51,9 +51,6 @@
private final BetaNodeFieldConstraint constraint0;
private final BetaNodeFieldConstraint constraint1;
- private ContextEntry context0;
- private ContextEntry context1;
-
private boolean indexed0;
private boolean indexed1;
@@ -94,10 +91,7 @@
}
this.constraint0 = constraints[0];
- this.context0 = this.constraint0.getContextEntry();
-
this.constraint1 = constraints[1];
- this.context1 = this.constraint1.getContextEntry();
}
private void swap(final BetaNodeFieldConstraint[] constraints,
@@ -120,51 +114,55 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromTuple(org.drools.reteoo.ReteTuple)
*/
- public void updateFromTuple(final InternalWorkingMemory workingMemory,
+ public void updateFromTuple(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final ReteTuple tuple) {
- this.context0.updateFromTuple( workingMemory,
- tuple );
- this.context1.updateFromTuple( workingMemory,
- tuple );
+ context[0].updateFromTuple( workingMemory,
+ tuple );
+ context[1].updateFromTuple( workingMemory,
+ tuple );
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromFactHandle(org.drools.common.InternalFactHandle)
*/
- public void updateFromFactHandle(final InternalWorkingMemory workingMemory,
+ public void updateFromFactHandle(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final InternalFactHandle handle) {
- this.context0.updateFromFactHandle( workingMemory,
- handle );
- this.context1.updateFromFactHandle( workingMemory,
- handle );
+ context[0].updateFromFactHandle( workingMemory,
+ handle );
+ context[1].updateFromFactHandle( workingMemory,
+ handle );
}
-
- public void resetTuple() {
- this.context0.resetTuple();
- this.context1.resetTuple();
+
+ public void resetTuple(final ContextEntry[] context) {
+ context[0].resetTuple();
+ context[1].resetTuple();
}
-
- public void resetFactHandle() {
- this.context0.resetFactHandle();
- this.context1.resetFactHandle();
- }
+ public void resetFactHandle(final ContextEntry[] context) {
+ context[0].resetFactHandle();
+ context[1].resetFactHandle();
+ }
+
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
- return (this.indexed0 || this.constraint0.isAllowedCachedLeft( this.context0,
- handle )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( this.context1,
+ public boolean isAllowedCachedLeft(final ContextEntry[] context,
+ final InternalFactHandle handle) {
+ return (this.indexed0 || this.constraint0.isAllowedCachedLeft( context[0],
+ handle )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( context[1],
handle ));
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedRight(org.drools.reteoo.ReteTuple)
*/
- public boolean isAllowedCachedRight(final ReteTuple tuple) {
+ public boolean isAllowedCachedRight(final ContextEntry[] context,
+ final ReteTuple tuple) {
return this.constraint0.isAllowedCachedRight( tuple,
- this.context0 ) && this.constraint1.isAllowedCachedRight( tuple,
- this.context1 );
+ context[0] ) && this.constraint1.isAllowedCachedRight( tuple,
+ context[1] );
}
public boolean isIndexed() {
@@ -224,10 +222,12 @@
factHandleMemory = config.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable();
}
memory = new BetaMemory( config.isSequential() ? null : tupleMemory,
- factHandleMemory );
+ factHandleMemory,
+ this.createContext() );
} else {
memory = new BetaMemory( config.isSequential() ? null : new TupleHashTable(),
- config.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable() );
+ config.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable(),
+ this.createContext() );
}
return memory;
@@ -278,4 +278,8 @@
return true;
}
+ public ContextEntry[] createContext() {
+ return new ContextEntry[]{this.constraint0.createContextEntry(), this.constraint1.createContextEntry()};
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -22,6 +22,7 @@
import org.drools.reteoo.BetaMemory;
import org.drools.reteoo.FactHandleMemory;
import org.drools.reteoo.ReteTuple;
+import org.drools.rule.ContextEntry;
import org.drools.util.FactHashTable;
import org.drools.util.FactList;
import org.drools.util.LinkedList;
@@ -33,6 +34,7 @@
BetaConstraints {
private static final BetaConstraints INSTANCE = new EmptyBetaConstraints();
+ private static final ContextEntry[] EMPTY = new ContextEntry[0];
public static BetaConstraints getInstance() {
return EmptyBetaConstraints.INSTANCE;
@@ -49,41 +51,45 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromTuple(org.drools.reteoo.ReteTuple)
*/
- public void updateFromTuple(final InternalWorkingMemory workingMemory,
+ public void updateFromTuple(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final ReteTuple tuple) {
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromFactHandle(org.drools.common.InternalFactHandle)
*/
- public void updateFromFactHandle(final InternalWorkingMemory workingMemory,
+ public void updateFromFactHandle(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final InternalFactHandle handle) {
}
- public void resetTuple() {
+ public void resetTuple(final ContextEntry[] context) {
}
-
- public void resetFactHandle() {
- }
-
+
+ public void resetFactHandle(final ContextEntry[] context) {
+ }
+
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
+ public boolean isAllowedCachedLeft(final ContextEntry[] context,
+ final InternalFactHandle handle) {
return true;
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedRight(org.drools.reteoo.ReteTuple)
*/
- public boolean isAllowedCachedRight(final ReteTuple tuple) {
+ public boolean isAllowedCachedRight(final ContextEntry[] context,
+ final ReteTuple tuple) {
return true;
}
public boolean isIndexed() {
return false;
}
-
+
public int getIndexCount() {
return 0;
}
@@ -94,7 +100,8 @@
public BetaMemory createBetaMemory(final RuleBaseConfiguration config) {
final BetaMemory memory = new BetaMemory( config.isSequential() ? null : new TupleHashTable(),
- config.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable() );
+ config.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable(),
+ this.createContext() );
return memory;
}
@@ -128,4 +135,8 @@
return (object != null && (object instanceof EmptyBetaConstraints));
}
+ public ContextEntry[] createContext() {
+ return EMPTY;
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -57,7 +57,7 @@
return this.otherPattern;
}
- public ContextEntry getContextEntry() {
+ public ContextEntry createContextEntry() {
return new InstanceEqualsConstraintContextEntry( this.otherPattern );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -48,7 +48,7 @@
return this.otherPattern;
}
- public ContextEntry getContextEntry() {
+ public ContextEntry createContextEntry() {
return new InstanceNotEqualsConstraintContextEntry( this.otherPattern );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -53,11 +53,6 @@
private final BetaNodeFieldConstraint constraint2;
private final BetaNodeFieldConstraint constraint3;
- private final ContextEntry context0;
- private final ContextEntry context1;
- private final ContextEntry context2;
- private final ContextEntry context3;
-
private boolean indexed0;
private boolean indexed1;
private boolean indexed2;
@@ -73,7 +68,7 @@
public QuadroupleBetaConstraints(final BetaNodeFieldConstraint[] constraints,
final RuleBaseConfiguration conf,
final boolean disableIndexing) {
- if ( disableIndexing || ( !conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory() ) ) {
+ if ( disableIndexing || (!conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory()) ) {
this.indexed0 = false;
this.indexed1 = false;
this.indexed2 = false;
@@ -141,16 +136,9 @@
}
this.constraint0 = constraints[0];
- this.context0 = this.constraint0.getContextEntry();
-
this.constraint1 = constraints[1];
- this.context1 = this.constraint1.getContextEntry();
-
this.constraint2 = constraints[2];
- this.context2 = this.constraint2.getContextEntry();
-
this.constraint3 = constraints[3];
- this.context3 = this.constraint3.getContextEntry();
}
private void swap(final BetaNodeFieldConstraint[] constraints,
@@ -173,80 +161,84 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromTuple(org.drools.reteoo.ReteTuple)
*/
- public void updateFromTuple(final InternalWorkingMemory workingMemory,
+ public void updateFromTuple(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final ReteTuple tuple) {
- this.context0.updateFromTuple( workingMemory,
- tuple );
- this.context1.updateFromTuple( workingMemory,
- tuple );
- this.context2.updateFromTuple( workingMemory,
- tuple );
- this.context3.updateFromTuple( workingMemory,
- tuple );
+ context[0].updateFromTuple( workingMemory,
+ tuple );
+ context[1].updateFromTuple( workingMemory,
+ tuple );
+ context[2].updateFromTuple( workingMemory,
+ tuple );
+ context[3].updateFromTuple( workingMemory,
+ tuple );
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromFactHandle(org.drools.common.InternalFactHandle)
*/
- public void updateFromFactHandle(final InternalWorkingMemory workingMemory,
+ public void updateFromFactHandle(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final InternalFactHandle handle) {
- this.context0.updateFromFactHandle( workingMemory,
- handle );
- this.context1.updateFromFactHandle( workingMemory,
- handle );
- this.context2.updateFromFactHandle( workingMemory,
- handle );
- this.context3.updateFromFactHandle( workingMemory,
- handle );
+ context[0].updateFromFactHandle( workingMemory,
+ handle );
+ context[1].updateFromFactHandle( workingMemory,
+ handle );
+ context[2].updateFromFactHandle( workingMemory,
+ handle );
+ context[3].updateFromFactHandle( workingMemory,
+ handle );
}
-
- public void resetTuple() {
- this.context0.resetTuple();
- this.context1.resetTuple();
- this.context2.resetTuple();
- this.context3.resetTuple();
+
+ public void resetTuple(final ContextEntry[] context) {
+ context[0].resetTuple();
+ context[1].resetTuple();
+ context[2].resetTuple();
+ context[3].resetTuple();
}
-
- public void resetFactHandle() {
- this.context0.resetFactHandle();
- this.context1.resetFactHandle();
- this.context2.resetFactHandle();
- this.context3.resetFactHandle();
- }
+ public void resetFactHandle(final ContextEntry[] context) {
+ context[0].resetFactHandle();
+ context[1].resetFactHandle();
+ context[2].resetFactHandle();
+ context[3].resetFactHandle();
+ }
+
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
- // return ( this.indexed0 || this.constraint0.isAllowedCachedLeft( context0,
- // object ) ) && this.constraint1.isAllowedCachedLeft( context1,
- // object ) && this.constraint2.isAllowedCachedLeft( context2,
+ public boolean isAllowedCachedLeft(final ContextEntry[] context,
+ final InternalFactHandle handle) {
+ // return ( this.indexed0 || this.constraint0.isAllowedCachedLeft( context[0],
+ // object ) ) && this.constraint1.isAllowedCachedLeft( context[1],
+ // object ) && this.constraint2.isAllowedCachedLeft( context[2],
// object );
- return (this.indexed0 || this.constraint0.isAllowedCachedLeft( this.context0,
- handle )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( this.context1,
- handle )) && (this.indexed2 || this.constraint2.isAllowedCachedLeft( this.context2,
+ return (this.indexed0 || this.constraint0.isAllowedCachedLeft( context[0],
+ handle )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( context[1],
+ handle )) && (this.indexed2 || this.constraint2.isAllowedCachedLeft( context[2],
handle ))
- && (this.indexed3 || this.constraint3.isAllowedCachedLeft( this.context3,
+ && (this.indexed3 || this.constraint3.isAllowedCachedLeft( context[3],
handle ));
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedRight(org.drools.reteoo.ReteTuple)
*/
- public boolean isAllowedCachedRight(final ReteTuple tuple) {
+ public boolean isAllowedCachedRight(final ContextEntry[] context,
+ final ReteTuple tuple) {
return this.constraint0.isAllowedCachedRight( tuple,
- this.context0 ) && this.constraint1.isAllowedCachedRight( tuple,
- this.context1 ) && this.constraint2.isAllowedCachedRight( tuple,
- this.context2 )
+ context[0] ) && this.constraint1.isAllowedCachedRight( tuple,
+ context[1] ) && this.constraint2.isAllowedCachedRight( tuple,
+ context[2] )
&& (this.indexed3 || this.constraint3.isAllowedCachedRight( tuple,
- this.context3 ));
+ context[3] ));
}
public boolean isIndexed() {
return this.indexed0;
}
-
+
public int getIndexCount() {
int count = 0;
if ( this.indexed0 ) {
@@ -260,9 +252,9 @@
}
if ( this.indexed3 ) {
count++;
- }
- return count;
- }
+ }
+ return count;
+ }
public boolean isEmpty() {
return false;
@@ -322,10 +314,12 @@
factHandleMemory = conf.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable();
}
memory = new BetaMemory( conf.isSequential() ? null : tupleMemory,
- factHandleMemory );
+ factHandleMemory,
+ this.createContext() );
} else {
memory = new BetaMemory( conf.isSequential() ? null : new TupleHashTable(),
- conf.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable() );
+ conf.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable(),
+ this.createContext() );
}
return memory;
@@ -386,4 +380,8 @@
return true;
}
+ public ContextEntry[] createContext() {
+ return new ContextEntry[]{this.constraint0.createContextEntry(), this.constraint1.createContextEntry(), this.constraint2.createContextEntry(), this.constraint3.createContextEntry()};
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -47,18 +47,16 @@
private final BetaNodeFieldConstraint constraint;
- private ContextEntry context;
-
private boolean indexed;
private RuleBaseConfiguration conf;
-
+
public SingleBetaConstraints(final BetaNodeFieldConstraint[] constraint,
final RuleBaseConfiguration conf) {
this( constraint[0],
conf,
false );
- }
+ }
public SingleBetaConstraints(final BetaNodeFieldConstraint constraint,
final RuleBaseConfiguration conf) {
@@ -80,7 +78,6 @@
}
this.constraint = constraint;
- this.context = constraint.getContextEntry();
}
private boolean isIndexable(final BetaNodeFieldConstraint constraint) {
@@ -92,54 +89,54 @@
}
}
+ public ContextEntry[] createContext() {
+ return new ContextEntry[] { this.constraint.createContextEntry() };
+ }
+
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromTuple(org.drools.reteoo.ReteTuple)
*/
- public void updateFromTuple(final InternalWorkingMemory workingMemory,
+ public void updateFromTuple(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final ReteTuple tuple) {
- this.context.updateFromTuple( workingMemory,
- tuple );
+ context[0].updateFromTuple( workingMemory,
+ tuple );
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromFactHandle(org.drools.common.InternalFactHandle)
*/
- public void updateFromFactHandle(final InternalWorkingMemory workingMemory,
+ public void updateFromFactHandle(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final InternalFactHandle handle) {
- this.context.updateFromFactHandle( workingMemory,
+ context[0].updateFromFactHandle( workingMemory,
handle );
}
-
- public void resetTuple() {
- this.context.resetTuple();
- }
-
- public void resetFactHandle() {
- this.context.resetFactHandle();
- }
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
- return this.indexed || this.constraint.isAllowedCachedLeft( this.context,
+ public boolean isAllowedCachedLeft(final ContextEntry[] context,
+ final InternalFactHandle handle) {
+ return this.indexed || this.constraint.isAllowedCachedLeft( context[0],
handle );
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedRight(org.drools.reteoo.ReteTuple)
*/
- public boolean isAllowedCachedRight(final ReteTuple tuple) {
+ public boolean isAllowedCachedRight(final ContextEntry[] context,
+ final ReteTuple tuple) {
return this.constraint.isAllowedCachedRight( tuple,
- this.context );
+ context[0] );
}
public boolean isIndexed() {
return this.indexed;
}
-
+
public int getIndexCount() {
- return ( this.indexed ? 1 : 0 );
+ return (this.indexed ? 1 : 0);
}
public boolean isEmpty() {
@@ -167,10 +164,12 @@
factHandleMemory = new FactHashTable();
}
memory = new BetaMemory( config.isSequential() ? null : tupleMemory,
- factHandleMemory );
+ factHandleMemory,
+ this.createContext() );
} else {
memory = new BetaMemory( config.isSequential() ? null : new TupleHashTable(),
- new FactHashTable() );
+ new FactHashTable(),
+ this.createContext() );
}
return memory;
@@ -212,4 +211,12 @@
return this.constraint == other.constraint || this.constraint.equals( other.constraint );
}
+ public void resetFactHandle(ContextEntry[] context) {
+ context[0].resetFactHandle();
+ }
+
+ public void resetTuple(ContextEntry[] context) {
+ context[0].resetTuple();
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -52,10 +52,6 @@
private final BetaNodeFieldConstraint constraint1;
private final BetaNodeFieldConstraint constraint2;
- private final ContextEntry context0;
- private final ContextEntry context1;
- private final ContextEntry context2;
-
private boolean indexed0;
private boolean indexed1;
private boolean indexed2;
@@ -114,13 +110,8 @@
}
}
this.constraint0 = constraints[0];
- this.context0 = this.constraint0.getContextEntry();
-
this.constraint1 = constraints[1];
- this.context1 = this.constraint1.getContextEntry();
-
this.constraint2 = constraints[2];
- this.context2 = this.constraint2.getContextEntry();
}
private void swap(final BetaNodeFieldConstraint[] constraints,
@@ -143,64 +134,68 @@
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromTuple(org.drools.reteoo.ReteTuple)
*/
- public void updateFromTuple(final InternalWorkingMemory workingMemory,
+ public void updateFromTuple(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final ReteTuple tuple) {
- this.context0.updateFromTuple( workingMemory,
- tuple );
- this.context1.updateFromTuple( workingMemory,
- tuple );
- this.context2.updateFromTuple( workingMemory,
- tuple );
+ context[0].updateFromTuple( workingMemory,
+ tuple );
+ context[1].updateFromTuple( workingMemory,
+ tuple );
+ context[2].updateFromTuple( workingMemory,
+ tuple );
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#updateFromFactHandle(org.drools.common.InternalFactHandle)
*/
- public void updateFromFactHandle(final InternalWorkingMemory workingMemory,
+ public void updateFromFactHandle(final ContextEntry[] context,
+ final InternalWorkingMemory workingMemory,
final InternalFactHandle handle) {
- this.context0.updateFromFactHandle( workingMemory,
- handle );
- this.context1.updateFromFactHandle( workingMemory,
- handle );
- this.context2.updateFromFactHandle( workingMemory,
- handle );
+ context[0].updateFromFactHandle( workingMemory,
+ handle );
+ context[1].updateFromFactHandle( workingMemory,
+ handle );
+ context[2].updateFromFactHandle( workingMemory,
+ handle );
}
-
- public void resetTuple() {
- this.context0.resetTuple();
- this.context1.resetTuple();
- this.context2.resetTuple();
+
+ public void resetTuple(final ContextEntry[] context) {
+ context[0].resetTuple();
+ context[1].resetTuple();
+ context[2].resetTuple();
}
-
- public void resetFactHandle() {
- this.context0.resetFactHandle();
- this.context1.resetFactHandle();
- this.context2.resetFactHandle();
- }
+ public void resetFactHandle(final ContextEntry[] context) {
+ context[0].resetFactHandle();
+ context[1].resetFactHandle();
+ context[2].resetFactHandle();
+ }
+
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedLeft(java.lang.Object)
*/
- public boolean isAllowedCachedLeft(final InternalFactHandle handle) {
+ public boolean isAllowedCachedLeft(final ContextEntry[] context,
+ final InternalFactHandle handle) {
// return ( this.indexed0 || this.constraint0.isAllowedCachedLeft( context0,
// object ) ) && this.constraint1.isAllowedCachedLeft( context1,
// object ) && this.constraint2.isAllowedCachedLeft( context2,
// object );
- return (this.indexed0 || this.constraint0.isAllowedCachedLeft( this.context0,
- handle )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( this.context1,
- handle )) && (this.indexed2 || this.constraint2.isAllowedCachedLeft( this.context2,
+ return (this.indexed0 || this.constraint0.isAllowedCachedLeft( context[0],
+ handle )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( context[1],
+ handle )) && (this.indexed2 || this.constraint2.isAllowedCachedLeft( context[2],
handle ));
}
/* (non-Javadoc)
* @see org.drools.common.BetaNodeConstraints#isAllowedCachedRight(org.drools.reteoo.ReteTuple)
*/
- public boolean isAllowedCachedRight(final ReteTuple tuple) {
+ public boolean isAllowedCachedRight(final ContextEntry[] context,
+ final ReteTuple tuple) {
return this.constraint0.isAllowedCachedRight( tuple,
- this.context0 ) && this.constraint1.isAllowedCachedRight( tuple,
- this.context1 ) && this.constraint2.isAllowedCachedRight( tuple,
- this.context2 );
+ context[0] ) && this.constraint1.isAllowedCachedRight( tuple,
+ context[1] ) && this.constraint2.isAllowedCachedRight( tuple,
+ context[2] );
}
public boolean isIndexed() {
@@ -271,10 +266,12 @@
factHandleMemory = conf.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable();
}
memory = new BetaMemory( conf.isSequential() ? null : tupleMemory,
- factHandleMemory );
+ factHandleMemory,
+ this.createContext() );
} else {
memory = new BetaMemory( conf.isSequential() ? null : new TupleHashTable(),
- conf.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable() );
+ conf.isSequential() ? (FactHandleMemory) new FactList() : (FactHandleMemory) new FactHashTable(),
+ this.createContext() );
}
return memory;
@@ -330,4 +327,8 @@
return true;
}
+ public ContextEntry[] createContext() {
+ return new ContextEntry[]{this.constraint0.createContextEntry(), this.constraint1.createContextEntry(), this.constraint2.createContextEntry()};
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -69,7 +69,7 @@
Declaration newDecl) {
}
- public ContextEntry getContextEntry() {
+ public ContextEntry createContextEntry() {
return new TupleStartEqualsConstraintContextEntry();
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -25,6 +25,7 @@
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.builder.BuildContext;
import org.drools.rule.Accumulate;
+import org.drools.rule.ContextEntry;
import org.drools.spi.AlphaNodeFieldConstraint;
import org.drools.spi.PropagationContext;
import org.drools.util.ArrayUtils;
@@ -114,12 +115,14 @@
workingMemory );
final Iterator it = memory.betaMemory.getFactHandleMemory().iterator( leftTuple );
- this.constraints.updateFromTuple( workingMemory,
+ this.constraints.updateFromTuple( memory.betaMemory.getContext(),
+ workingMemory,
leftTuple );
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle ) ) {
+ if ( this.constraints.isAllowedCachedLeft( memory.betaMemory.getContext(),
+ handle ) ) {
if ( this.unwrapRightObject ) {
// if there is a subnetwork, handle must be unwrapped
ReteTuple tuple = (ReteTuple) handle.getObject();
@@ -139,7 +142,7 @@
}
}
- this.constraints.resetTuple();
+ this.constraints.resetTuple( memory.betaMemory.getContext() );
final Object result = this.accumulate.getResult( memory.workingMemoryContext,
accContext,
@@ -162,9 +165,11 @@
}
}
if ( isAllowed ) {
- this.resultBinder.updateFromTuple( workingMemory,
+ this.resultBinder.updateFromTuple( memory.resultsContext,
+ workingMemory,
leftTuple );
- if ( this.resultBinder.isAllowedCachedLeft( handle ) ) {
+ if ( this.resultBinder.isAllowedCachedLeft( memory.resultsContext,
+ handle ) ) {
accresult.handle = handle;
this.sink.propagateAssertTuple( leftTuple,
@@ -228,14 +233,16 @@
return;
}
- this.constraints.updateFromFactHandle( workingMemory,
+ this.constraints.updateFromFactHandle( memory.betaMemory.getContext(),
+ workingMemory,
handle );
// need to clone the tuples to avoid concurrent modification exceptions
Entry[] tuples = memory.betaMemory.getTupleMemory().toArray();
for ( int i = 0; i < tuples.length; i++ ) {
ReteTuple tuple = (ReteTuple) tuples[i];
- if ( this.constraints.isAllowedCachedRight( tuple ) ) {
+ if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(),
+ tuple ) ) {
if ( this.accumulate.supportsReverse() || context.getType() == PropagationContext.ASSERTION ) {
modifyTuple( true,
tuple,
@@ -254,7 +261,7 @@
}
}
- this.constraints.resetFactHandle();
+ this.constraints.resetFactHandle( memory.betaMemory.getContext() );
}
/**
@@ -271,13 +278,15 @@
return;
}
- this.constraints.updateFromFactHandle( workingMemory,
+ this.constraints.updateFromFactHandle( memory.betaMemory.getContext(),
+ workingMemory,
handle );
// need to clone the tuples to avoid concurrent modification exceptions
Entry[] tuples = memory.betaMemory.getTupleMemory().toArray();
for ( int i = 0; i < tuples.length; i++ ) {
ReteTuple tuple = (ReteTuple) tuples[i];
- if ( this.constraints.isAllowedCachedRight( tuple ) ) {
+ if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(),
+ tuple ) ) {
if ( this.accumulate.supportsReverse() ) {
this.modifyTuple( false,
tuple,
@@ -295,7 +304,7 @@
}
}
- this.constraints.resetFactHandle();
+ this.constraints.resetFactHandle( memory.betaMemory.getContext() );
}
public void modifyTuple(final boolean isAssert,
@@ -390,9 +399,11 @@
}
}
if ( isAllowed ) {
- this.resultBinder.updateFromTuple( workingMemory,
+ this.resultBinder.updateFromTuple( memory.resultsContext,
+ workingMemory,
leftTuple );
- if ( this.resultBinder.isAllowedCachedLeft( createdHandle ) ) {
+ if ( this.resultBinder.isAllowedCachedLeft( memory.resultsContext,
+ createdHandle ) ) {
accresult.handle = createdHandle;
this.sink.propagateAssertTuple( leftTuple,
@@ -403,7 +414,7 @@
workingMemory.getFactHandleFactory().destroyFactHandle( createdHandle );
}
- this.resultBinder.resetTuple();
+ this.resultBinder.resetTuple( memory.resultsContext );
} else {
workingMemory.getFactHandleFactory().destroyFactHandle( createdHandle );
}
@@ -465,6 +476,7 @@
AccumulateMemory memory = new AccumulateMemory();
memory.betaMemory = this.constraints.createBetaMemory( config );
memory.workingMemoryContext = this.accumulate.createWorkingMemoryContext();
+ memory.resultsContext = this.resultBinder.createContext();
return memory;
}
@@ -473,6 +485,7 @@
public Object workingMemoryContext;
public BetaMemory betaMemory;
+ public ContextEntry[] resultsContext;
}
private static class AccumulateResult {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaMemory.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaMemory.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -2,6 +2,7 @@
import java.io.Serializable;
+import org.drools.rule.ContextEntry;
import org.drools.util.ObjectHashMap;
public class BetaMemory
@@ -13,11 +14,14 @@
private TupleMemory tupleMemory;
private FactHandleMemory factHandleMemory;
private ObjectHashMap createdHandles;
+ private ContextEntry[] context;
public BetaMemory(final TupleMemory tupleMemory,
- final FactHandleMemory objectMemory) {
+ final FactHandleMemory objectMemory,
+ final ContextEntry[] context ) {
this.tupleMemory = tupleMemory;
this.factHandleMemory = objectMemory;
+ this.context = context;
}
public FactHandleMemory getFactHandleMemory() {
@@ -34,4 +38,11 @@
}
return this.createdHandles;
}
+
+ /**
+ * @return the context
+ */
+ public ContextEntry[] getContext() {
+ return context;
+ }
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -25,6 +25,7 @@
import org.drools.common.InternalWorkingMemory;
import org.drools.common.NodeMemory;
import org.drools.common.PropagationContextImpl;
+import org.drools.rule.ContextEntry;
import org.drools.spi.BetaNodeFieldConstraint;
import org.drools.spi.PropagationContext;
import org.drools.util.LinkedList;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -19,11 +19,13 @@
import java.util.Arrays;
import java.util.Collection;
+import org.drools.RuleBaseConfiguration;
import org.drools.common.BetaConstraints;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.builder.BuildContext;
import org.drools.rule.Collect;
+import org.drools.rule.ContextEntry;
import org.drools.spi.AlphaNodeFieldConstraint;
import org.drools.spi.PropagationContext;
import org.drools.util.ArrayUtils;
@@ -103,7 +105,7 @@
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+ final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
final Collection result = this.collect.instantiateResultObject();
final InternalFactHandle resultHandle = workingMemory.getFactHandleFactory().newFactHandle( result, false, workingMemory );
@@ -113,20 +115,22 @@
// do not add tuple and result to the memory in sequential mode
if ( this.tupleMemoryEnabled ) {
- memory.getTupleMemory().add( leftTuple );
- memory.getCreatedHandles().put( leftTuple,
+ memory.betaMemory.getTupleMemory().add( leftTuple );
+ memory.betaMemory.getCreatedHandles().put( leftTuple,
colresult,
false );
}
- final Iterator it = memory.getFactHandleMemory().iterator( leftTuple );
- this.constraints.updateFromTuple( workingMemory,
+ final Iterator it = memory.betaMemory.getFactHandleMemory().iterator( leftTuple );
+ this.constraints.updateFromTuple( memory.betaMemory.getContext(),
+ workingMemory,
leftTuple );
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle ) ) {
+ if ( this.constraints.isAllowedCachedLeft( memory.betaMemory.getContext(),
+ handle ) ) {
if( this.unwrapRightObject ) {
handle = ((ReteTuple) handle.getObject()).getLastHandle();
}
@@ -134,7 +138,7 @@
}
}
- this.constraints.resetTuple();
+ this.constraints.resetTuple(memory.betaMemory.getContext() );
// First alpha node filters
boolean isAllowed = true;
@@ -146,15 +150,18 @@
}
}
if ( isAllowed ) {
- this.resultsBinder.updateFromTuple( workingMemory,
+ this.resultsBinder.updateFromTuple( memory.resultsContext,
+ workingMemory,
leftTuple );
- if ( this.resultsBinder.isAllowedCachedLeft( resultHandle ) ) {
+ if ( this.resultsBinder.isAllowedCachedLeft( memory.resultsContext,
+ resultHandle ) ) {
colresult.propagated = true;
this.sink.propagateAssertTuple( leftTuple,
resultHandle,
context,
workingMemory );
}
+ this.resultsBinder.resetTuple( memory.resultsContext );
}
}
@@ -165,9 +172,9 @@
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
- memory.getTupleMemory().remove( leftTuple );
- CollectResult result = (CollectResult) memory.getCreatedHandles().remove( leftTuple );
+ final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
+ memory.betaMemory.getTupleMemory().remove( leftTuple );
+ CollectResult result = (CollectResult) memory.betaMemory.getCreatedHandles().remove( leftTuple );
final InternalFactHandle handle = result.handle;
// if tuple was propagated
@@ -196,22 +203,24 @@
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
- memory.getFactHandleMemory().add( handle );
+ final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
+ memory.betaMemory.getFactHandleMemory().add( handle );
if ( !this.tupleMemoryEnabled ) {
// do nothing here, as we know there are no left tuples at this stage in sequential mode.
return;
}
- this.constraints.updateFromFactHandle( workingMemory,
+ this.constraints.updateFromFactHandle( memory.betaMemory.getContext(),
+ workingMemory,
handle );
// need to clone the tuples to avoid concurrent modification exceptions
- Entry[] tuples = memory.getTupleMemory().toArray();
+ Entry[] tuples = memory.betaMemory.getTupleMemory().toArray();
for ( int i = 0; i < tuples.length; i++ ) {
ReteTuple tuple = (ReteTuple) tuples[i];
- if ( this.constraints.isAllowedCachedRight( tuple ) ) {
+ if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(),
+ tuple ) ) {
this.modifyTuple( true,
tuple,
handle,
@@ -220,7 +229,7 @@
}
}
- this.constraints.resetFactHandle();
+ this.constraints.resetFactHandle( memory.betaMemory.getContext() );
}
/**
@@ -233,19 +242,21 @@
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
- if ( !memory.getFactHandleMemory().remove( handle ) ) {
+ final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
+ if ( !memory.betaMemory.getFactHandleMemory().remove( handle ) ) {
return;
}
- this.constraints.updateFromFactHandle( workingMemory,
+ this.constraints.updateFromFactHandle( memory.betaMemory.getContext(),
+ workingMemory,
handle );
// need to clone the tuples to avoid concurrent modification exceptions
- Entry[] tuples = memory.getTupleMemory().toArray();
+ Entry[] tuples = memory.betaMemory.getTupleMemory().toArray();
for ( int i = 0; i < tuples.length; i++ ) {
ReteTuple tuple = (ReteTuple) tuples[i];
- if ( this.constraints.isAllowedCachedRight( tuple ) ) {
+ if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(),
+ tuple ) ) {
this.modifyTuple( false,
tuple,
@@ -255,7 +266,7 @@
}
}
- this.constraints.resetFactHandle();
+ this.constraints.resetFactHandle( memory.betaMemory.getContext() );
}
/**
@@ -273,9 +284,9 @@
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+ final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
- CollectResult result = (CollectResult) memory.getCreatedHandles().get( leftTuple );
+ CollectResult result = (CollectResult) memory.betaMemory.getCreatedHandles().get( leftTuple );
// if tuple was propagated
if ( result.propagated ) {
@@ -315,9 +326,11 @@
}
}
if ( isAllowed ) {
- this.resultsBinder.updateFromTuple( workingMemory,
+ this.resultsBinder.updateFromTuple( memory.resultsContext,
+ workingMemory,
leftTuple );
- if ( this.resultsBinder.isAllowedCachedLeft( result.handle ) ) {
+ if ( this.resultsBinder.isAllowedCachedLeft( memory.resultsContext,
+ result.handle ) ) {
result.propagated = true;
this.sink.propagateAssertTuple( leftTuple,
result.handle,
@@ -325,16 +338,16 @@
workingMemory );
}
- this.resultsBinder.resetTuple();
+ this.resultsBinder.resetTuple( memory.resultsContext );
}
}
public void updateSink(final TupleSink sink,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+ final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
- final Iterator it = memory.getCreatedHandles().iterator();
+ final Iterator it = memory.betaMemory.getCreatedHandles().iterator();
for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
CollectResult result = (CollectResult) entry.getValue();
@@ -378,6 +391,22 @@
return "[ " + this.getClass().getName() + "(" + this.id + ") ]";
}
+ /**
+ * Creates a BetaMemory for the BetaNode's memory.
+ */
+ public Object createMemory(final RuleBaseConfiguration config) {
+ CollectMemory memory = new CollectMemory();
+ memory.betaMemory = this.constraints.createBetaMemory( config );
+ memory.resultsContext = this.resultsBinder.createContext();
+ return memory;
+ }
+
+ public static class CollectMemory {
+ private static final long serialVersionUID = 400L;
+ public BetaMemory betaMemory;
+ public ContextEntry[] resultsContext;
+ }
+
private static class CollectResult {
// keeping attributes public just for performance
public InternalFactHandle handle;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -96,17 +96,19 @@
}
final Iterator it = memory.getFactHandleMemory().iterator( leftTuple );
- this.constraints.updateFromTuple( workingMemory,
+ this.constraints.updateFromTuple( memory.getContext(),
+ workingMemory,
leftTuple );
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
final InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle ) ) {
+ if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
+ handle ) ) {
leftTuple.setMatch( handle );
break;
}
}
- this.constraints.resetTuple();
+ this.constraints.resetTuple( memory.getContext() );
if ( leftTuple.getMatch() != null ) {
this.sink.propagateAssertTuple( leftTuple,
@@ -139,10 +141,12 @@
}
final Iterator it = memory.getTupleMemory().iterator( handle );
- this.constraints.updateFromFactHandle( workingMemory,
+ this.constraints.updateFromFactHandle( memory.getContext(),
+ workingMemory,
handle );
for ( ReteTuple tuple = (ReteTuple) it.next(); tuple != null; tuple = (ReteTuple) it.next() ) {
- if ( this.constraints.isAllowedCachedRight( tuple ) && tuple.getMatch() == null) {
+ if ( this.constraints.isAllowedCachedRight( memory.getContext(),
+ tuple ) && tuple.getMatch() == null) {
tuple.setMatch( handle );
this.sink.propagateAssertTuple( tuple,
context,
@@ -150,7 +154,7 @@
}
}
- this.constraints.resetFactHandle();
+ this.constraints.resetFactHandle( memory.getContext() );
}
/**
@@ -174,27 +178,31 @@
}
final Iterator it = memory.getTupleMemory().iterator( handle );
- this.constraints.updateFromFactHandle( workingMemory,
+ this.constraints.updateFromFactHandle( memory.getContext(),
+ workingMemory,
handle );
for ( ReteTuple tuple = (ReteTuple) it.next(); tuple != null; tuple = (ReteTuple) it.next() ) {
- if ( this.constraints.isAllowedCachedRight( tuple ) ) {
+ if ( this.constraints.isAllowedCachedRight( memory.getContext(),
+ tuple ) ) {
if ( tuple.getMatch() == handle ) {
// reset the match
tuple.setMatch( null );
// find next match, remember it and break.
final Iterator tupleIt = memory.getFactHandleMemory().iterator( tuple );
- this.constraints.updateFromTuple( workingMemory, tuple );
+ this.constraints.updateFromTuple( memory.getContext(),
+ workingMemory, tuple );
for ( FactEntry entry = (FactEntry) tupleIt.next(); entry != null; entry = (FactEntry) tupleIt.next() ) {
final InternalFactHandle rightHandle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( rightHandle ) ) {
+ if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
+ rightHandle ) ) {
tuple.setMatch( rightHandle );
break;
}
}
- this.constraints.resetTuple();
+ this.constraints.resetTuple( memory.getContext() );
// if there is now no new tuple match then propagate assert.
if ( tuple.getMatch() == null ) {
@@ -207,7 +215,7 @@
}
}
- this.constraints.resetFactHandle();
+ this.constraints.resetFactHandle( memory.getContext() );
}
/**
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -58,7 +58,8 @@
memory.getTupleMemory().add( leftTuple );
final LinkedList list = new LinkedList();
- this.betaConstraints.updateFromTuple( workingMemory,
+ this.betaConstraints.updateFromTuple( memory.getContext(),
+ workingMemory,
leftTuple );
for ( final java.util.Iterator it = this.dataProvider.getResults( leftTuple,
@@ -81,7 +82,8 @@
}
}
- if ( isAllowed && this.betaConstraints.isAllowedCachedLeft( handle ) ) {
+ if ( isAllowed && this.betaConstraints.isAllowedCachedLeft( memory.getContext(),
+ handle ) ) {
list.add( new LinkedListEntry( handle ) );
this.sink.propagateAssertTuple( leftTuple,
@@ -93,7 +95,7 @@
}
}
- this.betaConstraints.resetTuple();
+ this.betaConstraints.resetTuple( memory.getContext() );
if ( !list.isEmpty() ) {
memory.getCreatedHandles().put( leftTuple,
@@ -184,7 +186,8 @@
public Object createMemory(final RuleBaseConfiguration config) {
return new BetaMemory( new TupleHashTable(),
- null );
+ null,
+ this.betaConstraints.createContext() );
}
public boolean isTupleMemoryEnabled() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -99,11 +99,13 @@
}
final Iterator it = memory.getFactHandleMemory().iterator( leftTuple );
- this.constraints.updateFromTuple( workingMemory,
+ this.constraints.updateFromTuple( memory.getContext(),
+ workingMemory,
leftTuple );
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
final InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle ) ) {
+ if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
+ handle ) ) {
this.sink.propagateAssertTuple( leftTuple,
handle,
context,
@@ -111,7 +113,7 @@
}
}
- this.constraints.resetTuple();
+ this.constraints.resetTuple( memory.getContext() );
}
/**
@@ -144,17 +146,19 @@
}
final Iterator it = memory.getTupleMemory().iterator( handle );
- this.constraints.updateFromFactHandle( workingMemory,
+ this.constraints.updateFromFactHandle( memory.getContext(),
+ workingMemory,
handle );
for ( ReteTuple tuple = (ReteTuple) it.next(); tuple != null; tuple = (ReteTuple) it.next() ) {
- if ( this.constraints.isAllowedCachedRight( tuple ) ) {
+ if ( this.constraints.isAllowedCachedRight( memory.getContext(),
+ tuple ) ) {
this.sink.propagateAssertTuple( tuple,
handle,
context,
workingMemory );
}
}
- this.constraints.resetFactHandle();
+ this.constraints.resetFactHandle( memory.getContext() );
}
/**
@@ -177,10 +181,12 @@
}
final Iterator it = memory.getTupleMemory().iterator( handle );
- this.constraints.updateFromFactHandle( workingMemory,
+ this.constraints.updateFromFactHandle( memory.getContext(),
+ workingMemory,
handle );
for ( ReteTuple tuple = (ReteTuple) it.next(); tuple != null; tuple = (ReteTuple) it.next() ) {
- if ( this.constraints.isAllowedCachedRight( tuple ) ) {
+ if ( this.constraints.isAllowedCachedRight( memory.getContext(),
+ tuple ) ) {
this.sink.propagateRetractTuple( tuple,
handle,
context,
@@ -188,7 +194,7 @@
}
}
- this.constraints.resetFactHandle();
+ this.constraints.resetFactHandle( memory.getContext() );
}
/**
@@ -213,11 +219,13 @@
}
final Iterator it = memory.getFactHandleMemory().iterator( leftTuple );
- this.constraints.updateFromTuple( workingMemory,
+ this.constraints.updateFromTuple( memory.getContext(),
+ workingMemory,
leftTuple );
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
final InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle ) ) {
+ if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
+ handle ) ) {
this.sink.propagateRetractTuple( leftTuple,
handle,
context,
@@ -225,7 +233,7 @@
}
}
- this.constraints.resetTuple();
+ this.constraints.resetTuple( memory.getContext() );
}
/* (non-Javadoc)
@@ -240,11 +248,13 @@
final Iterator tupleIter = memory.getTupleMemory().iterator();
for ( ReteTuple tuple = (ReteTuple) tupleIter.next(); tuple != null; tuple = (ReteTuple) tupleIter.next() ) {
final Iterator objectIter = memory.getFactHandleMemory().iterator( tuple );
- this.constraints.updateFromTuple( workingMemory,
+ this.constraints.updateFromTuple( memory.getContext(),
+ workingMemory,
tuple );
for ( FactEntry entry = (FactEntry) objectIter.next(); entry != null; entry = (FactEntry) objectIter.next() ) {
final InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle ) ) {
+ if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
+ handle ) ) {
sink.assertTuple( new ReteTuple( tuple,
handle ),
context,
@@ -252,7 +262,7 @@
}
}
- this.constraints.resetTuple();
+ this.constraints.resetTuple( memory.getContext() );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -94,18 +94,20 @@
}
final Iterator it = memory.getFactHandleMemory().iterator( leftTuple );
- this.constraints.updateFromTuple( workingMemory,
+ this.constraints.updateFromTuple( memory.getContext(),
+ workingMemory,
leftTuple );
for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
final InternalFactHandle handle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( handle ) ) {
+ if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
+ handle ) ) {
leftTuple.setMatch( handle );
break;
}
}
- this.constraints.resetTuple();
+ this.constraints.resetTuple( memory.getContext() );
if ( leftTuple.getMatch() == null ) {
this.sink.propagateAssertTuple( leftTuple,
@@ -138,10 +140,12 @@
}
final Iterator it = memory.getTupleMemory().iterator( handle );
- this.constraints.updateFromFactHandle( workingMemory,
+ this.constraints.updateFromFactHandle( memory.getContext(),
+ workingMemory,
handle );
for ( ReteTuple tuple = (ReteTuple) it.next(); tuple != null; tuple = (ReteTuple) it.next() ) {
- if ( this.constraints.isAllowedCachedRight( tuple ) && tuple.getMatch() == null) {
+ if ( this.constraints.isAllowedCachedRight( memory.getContext(),
+ tuple ) && tuple.getMatch() == null) {
tuple.setMatch( handle );
this.sink.propagateRetractTuple( tuple,
context,
@@ -149,7 +153,7 @@
}
}
- this.constraints.resetFactHandle();
+ this.constraints.resetFactHandle( memory.getContext() );
}
/**
@@ -174,10 +178,12 @@
}
final Iterator it = memory.getTupleMemory().iterator( handle );
- this.constraints.updateFromFactHandle( workingMemory,
+ this.constraints.updateFromFactHandle( memory.getContext(),
+ workingMemory,
handle );
for ( ReteTuple tuple = (ReteTuple) it.next(); tuple != null; tuple = (ReteTuple) it.next() ) {
- if ( this.constraints.isAllowedCachedRight( tuple ) ) {
+ if ( this.constraints.isAllowedCachedRight( memory.getContext(),
+ tuple ) ) {
if ( tuple.getMatch() == handle ) {
// reset the match
@@ -185,17 +191,19 @@
// find next match, remember it and break.
final Iterator tupleIt = memory.getFactHandleMemory().iterator( tuple );
- this.constraints.updateFromTuple( workingMemory, tuple );
+ this.constraints.updateFromTuple( memory.getContext(),
+ workingMemory, tuple );
for ( FactEntry entry = (FactEntry) tupleIt.next(); entry != null; entry = (FactEntry) tupleIt.next() ) {
final InternalFactHandle rightHandle = entry.getFactHandle();
- if ( this.constraints.isAllowedCachedLeft( rightHandle ) ) {
+ if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
+ rightHandle ) ) {
tuple.setMatch( rightHandle );
break;
}
}
- this.constraints.resetTuple();
+ this.constraints.resetTuple( memory.getContext() );
// if there is now no new tuple match then propagate assert.
if ( tuple.getMatch() == null ) {
this.sink.propagateAssertTuple( tuple,
@@ -206,7 +214,7 @@
}
}
- this.constraints.resetFactHandle();
+ this.constraints.resetFactHandle( memory.getContext() );
}
/**
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeConstraint.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeConstraint.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -150,7 +150,7 @@
/**
* {@inheritDoc}
*/
- public ContextEntry getContextEntry() {
+ public ContextEntry createContextEntry() {
return new MultiFieldConstraintContextEntry( this.betaConstraints );
}
@@ -201,7 +201,7 @@
public MultiFieldConstraintContextEntry(BetaNodeFieldConstraint[] constraints) {
contexts = new ContextEntry[constraints.length];
for ( int i = 0; i < contexts.length; i++ ) {
- contexts[i] = constraints[i].getContextEntry();
+ contexts[i] = constraints[i].createContextEntry();
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -16,11 +16,9 @@
private static final long serialVersionUID = 400L;
protected final Restriction[] restrictions;
- protected final CompositeContextEntry contextEntry;
public AbstractCompositeRestriction(final Restriction[] restriction) {
this.restrictions = restriction;
- this.contextEntry = new CompositeContextEntry( this.restrictions );
}
public Declaration[] getRequiredDeclarations() {
@@ -81,8 +79,8 @@
return true;
}
- public ContextEntry getContextEntry() {
- return this.contextEntry;
+ public ContextEntry createContextEntry() {
+ return new CompositeContextEntry( this.restrictions );
}
public abstract Object clone();
@@ -100,7 +98,7 @@
public CompositeContextEntry(final Restriction[] restrictions) {
contextEntries = new ContextEntry[restrictions.length];
for ( int i = 0; i < restrictions.length; i++ ) {
- contextEntries[i] = restrictions[i].getContextEntry();
+ contextEntries[i] = restrictions[i].createContextEntry();
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -29,8 +29,9 @@
public boolean isAllowedCachedLeft(final ContextEntry context,
final InternalFactHandle handle) {
+ CompositeContextEntry contextEntry = (CompositeContextEntry) context;
for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
- if ( !this.restrictions[i].isAllowedCachedLeft( this.contextEntry.contextEntries[i],
+ if ( !this.restrictions[i].isAllowedCachedLeft( contextEntry.contextEntries[i],
handle ) ) {
return false;
}
@@ -40,9 +41,10 @@
public boolean isAllowedCachedRight(final ReteTuple tuple,
final ContextEntry context) {
+ CompositeContextEntry contextEntry = (CompositeContextEntry) context;
for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
if ( !this.restrictions[i].isAllowedCachedRight( tuple,
- this.contextEntry.contextEntries[i] ) ) {
+ contextEntry.contextEntries[i] ) ) {
return false;
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -35,16 +35,16 @@
private final Evaluator evaluator;
+ private final FieldExtractor extractor;
+
private static final Declaration[] requiredDeclarations = new Declaration[0];
- private final LiteralContextEntry contextEntry;
-
public LiteralRestriction(final FieldValue field,
final Evaluator evaluator,
final FieldExtractor fieldExtractor) {
this.field = field;
this.evaluator = evaluator;
- this.contextEntry = new LiteralContextEntry( fieldExtractor );
+ this.extractor = fieldExtractor;
}
public Evaluator getEvaluator() {
@@ -117,14 +117,14 @@
return this.field.equals( other.field ) && this.evaluator.equals( other.evaluator );
}
- public ContextEntry getContextEntry() {
- return this.contextEntry;
+ public ContextEntry createContextEntry() {
+ return new LiteralContextEntry( this.extractor );
}
public Object clone() {
return new LiteralRestriction( this.field,
this.evaluator,
- this.contextEntry.extractor );
+ this.extractor );
}
private static class LiteralContextEntry
@@ -165,13 +165,13 @@
final ReteTuple tuple) {
// nothing to do
}
-
- public void resetTuple() {
+
+ public void resetTuple() {
}
-
+
public void resetFactHandle() {
this.object = null;
- }
+ }
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -73,8 +73,8 @@
workingMemory );
}
- public ContextEntry getContextEntry() {
- return this.restrictions.getContextEntry();
+ public ContextEntry createContextEntry() {
+ return this.restrictions.createContextEntry();
}
public boolean isAllowedCachedLeft(final ContextEntry context,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -3,6 +3,7 @@
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
+import org.drools.rule.AbstractCompositeRestriction.CompositeContextEntry;
import org.drools.spi.Extractor;
import org.drools.spi.Restriction;
@@ -29,8 +30,9 @@
public boolean isAllowedCachedLeft(final ContextEntry context,
final InternalFactHandle handle) {
+ CompositeContextEntry contextEntry = (CompositeContextEntry) context;
for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
- if ( this.restrictions[i].isAllowedCachedLeft( this.contextEntry.contextEntries[i],
+ if ( this.restrictions[i].isAllowedCachedLeft( contextEntry.contextEntries[i],
handle ) ) {
return true;
}
@@ -40,9 +42,10 @@
public boolean isAllowedCachedRight(final ReteTuple tuple,
final ContextEntry context) {
+ CompositeContextEntry contextEntry = (CompositeContextEntry) context;
for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
if ( this.restrictions[i].isAllowedCachedRight( tuple,
- this.contextEntry.contextEntries[i] ) ) {
+ contextEntry.contextEntries[i] ) ) {
return true;
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -210,7 +210,7 @@
return this.expression.equals( other.expression );
}
- public ContextEntry getContextEntry() {
+ public ContextEntry createContextEntry() {
return new PredicateContextEntry();
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -94,8 +94,8 @@
return this.fieldExtractor.equals( other.fieldExtractor ) && this.restriction.equals( other.restriction );
}
- public ContextEntry getContextEntry() {
- return this.restriction.getContextEntry();
+ public ContextEntry createContextEntry() {
+ return this.restriction.createContextEntry();
}
public boolean isAllowed(final InternalFactHandle handle,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -34,26 +34,26 @@
implements
Restriction {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
- private ReturnValueExpression expression;
+ private ReturnValueExpression expression;
- private final Declaration[] requiredDeclarations;
-
- private final String[] requiredGlobals;
+ private final Declaration[] requiredDeclarations;
- private final Declaration[] previousDeclarations;
+ private final String[] requiredGlobals;
- private final Declaration[] localDeclarations;
+ private final Declaration[] previousDeclarations;
- private final Evaluator evaluator;
+ private final Declaration[] localDeclarations;
- private static final Declaration[] noRequiredDeclarations = new Declaration[]{};
+ private final Evaluator evaluator;
- private static final String[] noRequiredGlobals = new String[]{};
+ private final FieldExtractor extractor;
- private final ReturnValueContextEntry contextEntry;
+ private static final Declaration[] noRequiredDeclarations = new Declaration[]{};
+ private static final String[] noRequiredGlobals = new String[]{};
+
public ReturnValueRestriction(final FieldExtractor fieldExtractor,
final Declaration[] previousDeclarations,
final Declaration[] localDeclarations,
@@ -74,6 +74,7 @@
final String[] requiredGlobals,
final Evaluator evaluator) {
this.expression = returnValueExpression;
+ this.extractor = fieldExtractor;
if ( previousDeclarations != null ) {
this.previousDeclarations = previousDeclarations;
@@ -86,7 +87,7 @@
} else {
this.localDeclarations = ReturnValueRestriction.noRequiredDeclarations;
}
-
+
if ( requiredGlobals != null ) {
this.requiredGlobals = requiredGlobals;
} else {
@@ -94,9 +95,6 @@
}
this.evaluator = evaluator;
- this.contextEntry = new ReturnValueContextEntry( fieldExtractor,
- this.previousDeclarations,
- this.localDeclarations );
this.requiredDeclarations = new Declaration[this.previousDeclarations.length + this.localDeclarations.length];
System.arraycopy( this.previousDeclarations,
@@ -122,25 +120,25 @@
public Declaration[] getLocalDeclarations() {
return this.localDeclarations;
}
-
+
public String[] getRequiredGlobals() {
return this.requiredGlobals;
}
-
+
public void replaceDeclaration(Declaration oldDecl,
Declaration newDecl) {
- for( int i = 0; i < this.requiredDeclarations.length; i++) {
- if( this.requiredDeclarations[i].equals( oldDecl ) ) {
+ for ( int i = 0; i < this.requiredDeclarations.length; i++ ) {
+ if ( this.requiredDeclarations[i].equals( oldDecl ) ) {
this.requiredDeclarations[i] = newDecl;
}
}
- for( int i = 0; i < this.previousDeclarations.length; i++) {
- if( this.previousDeclarations[i].equals( oldDecl ) ) {
+ for ( int i = 0; i < this.previousDeclarations.length; i++ ) {
+ if ( this.previousDeclarations[i].equals( oldDecl ) ) {
this.previousDeclarations[i] = newDecl;
}
}
- for( int i = 0; i < this.localDeclarations.length; i++) {
- if( this.localDeclarations[i].equals( oldDecl ) ) {
+ for ( int i = 0; i < this.localDeclarations.length; i++ ) {
+ if ( this.localDeclarations[i].equals( oldDecl ) ) {
this.localDeclarations[i] = newDecl;
}
}
@@ -165,11 +163,12 @@
try {
return this.evaluator.evaluate( null,
extractor,
- handle.getObject(), this.expression.evaluate( handle.getObject(),
- tuple,
- this.previousDeclarations,
- this.localDeclarations,
- workingMemory ) );
+ handle.getObject(),
+ this.expression.evaluate( handle.getObject(),
+ tuple,
+ this.previousDeclarations,
+ this.localDeclarations,
+ workingMemory ) );
} catch ( final Exception e ) {
throw new RuntimeDroolsException( e );
}
@@ -255,22 +254,24 @@
return result;
}
- public ContextEntry getContextEntry() {
- return this.contextEntry;
+ public ContextEntry createContextEntry() {
+ return new ReturnValueContextEntry( this.extractor,
+ this.previousDeclarations,
+ this.localDeclarations );
}
-
+
public Object clone() {
- Declaration[] previous = new Declaration[ this.previousDeclarations.length ];
- for( int i = 0; i < previous.length; i++ ) {
+ Declaration[] previous = new Declaration[this.previousDeclarations.length];
+ for ( int i = 0; i < previous.length; i++ ) {
previous[i] = (Declaration) this.previousDeclarations[i].clone();
}
-
- Declaration[] local = new Declaration[ this.localDeclarations.length ];
- for( int i = 0; i < local.length; i++ ) {
+
+ Declaration[] local = new Declaration[this.localDeclarations.length];
+ for ( int i = 0; i < local.length; i++ ) {
local[i] = (Declaration) this.localDeclarations[i].clone();
}
-
- return new ReturnValueRestriction( this.contextEntry.fieldExtractor,
+
+ return new ReturnValueRestriction( this.extractor,
previous,
local,
this.requiredGlobals,
@@ -358,14 +359,14 @@
public InternalWorkingMemory getWorkingMemory() {
return this.workingMemory;
}
-
+
public void resetTuple() {
this.leftTuple = null;
}
-
+
public void resetFactHandle() {
this.handle = null;
- }
+ }
}
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/VariableConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/VariableConstraint.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/VariableConstraint.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -90,8 +90,8 @@
return "[VariableConstraint fieldExtractor=" + this.fieldExtractor + " declaration=" + getRequiredDeclarations() + "]";
}
- public ContextEntry getContextEntry() {
- return this.restriction.getContextEntry();
+ public ContextEntry createContextEntry() {
+ return this.restriction.createContextEntry();
}
public int hashCode() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/VariableRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/VariableRestriction.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/VariableRestriction.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -31,15 +31,15 @@
implements
Restriction {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
- private Declaration declaration;
+ private Declaration declaration;
- private final Declaration[] requiredDeclarations;
+ private final Declaration[] requiredDeclarations;
- private final Evaluator evaluator;
+ private final Evaluator evaluator;
- private final VariableContextEntry contextEntry;
+ private final FieldExtractor extractor;
public VariableRestriction(final FieldExtractor fieldExtractor,
final Declaration declaration,
@@ -47,8 +47,7 @@
this.declaration = declaration;
this.requiredDeclarations = new Declaration[]{declaration};
this.evaluator = evaluator;
- this.contextEntry = this.createContextEntry( this.evaluator,
- fieldExtractor );
+ this.extractor = fieldExtractor;
}
public Declaration[] getRequiredDeclarations() {
@@ -60,7 +59,6 @@
if ( this.declaration.equals( oldDecl ) ) {
this.declaration = newDecl;
this.requiredDeclarations[0] = newDecl;
- this.contextEntry.declaration = newDecl;
}
}
@@ -72,9 +70,9 @@
final InternalFactHandle handle,
final InternalWorkingMemory workingMemory) {
return this.evaluator.evaluate( workingMemory,
- this.contextEntry.extractor,
+ this.extractor,
this.evaluator.prepareObject( handle ),
- this.contextEntry.declaration.getExtractor(),
+ this.declaration.getExtractor(),
this.evaluator.prepareObject( handle ) );
}
@@ -126,7 +124,7 @@
private final VariableContextEntry createContextEntry(final Evaluator eval,
final FieldExtractor fieldExtractor) {
ValueType coerced = eval.getCoercedValueType();
-
+
if ( coerced.isBoolean() ) {
return new BooleanVariableContextEntry( fieldExtractor,
this.declaration,
@@ -150,12 +148,13 @@
}
}
- public ContextEntry getContextEntry() {
- return this.contextEntry;
+ public ContextEntry createContextEntry() {
+ return this.createContextEntry( this.evaluator,
+ this.extractor );
}
public Object clone() {
- return new VariableRestriction( this.contextEntry.extractor,
+ return new VariableRestriction( this.extractor,
(Declaration) this.declaration.clone(),
this.evaluator );
}
@@ -212,14 +211,14 @@
public boolean isRightNull() {
return this.rightNull;
}
-
+
public void resetTuple() {
this.reteTuple = null;
}
-
+
public void resetFactHandle() {
this.object = null;
- }
+ }
}
public static class ObjectVariableContextEntry extends VariableContextEntry {
@@ -233,7 +232,7 @@
final Evaluator evaluator) {
super( extractor,
declaration,
- evaluator);
+ evaluator );
}
public void updateFromTuple(final InternalWorkingMemory workingMemory,
@@ -255,16 +254,16 @@
this.right = this.extractor.getValue( workingMemory,
evaluator.prepareObject( handle ) );
}
-
+
public void resetTuple() {
this.left = null;
this.reteTuple = null;
}
-
+
public void resetFactHandle() {
this.right = null;
this.object = null;
- }
+ }
}
public static class LongVariableContextEntry extends VariableContextEntry {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/BetaNodeFieldConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/BetaNodeFieldConstraint.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/BetaNodeFieldConstraint.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -30,6 +30,6 @@
public boolean isAllowedCachedRight(ReteTuple tuple,
ContextEntry context);
- public ContextEntry getContextEntry();
+ public ContextEntry createContextEntry();
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Restriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Restriction.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Restriction.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -24,7 +24,7 @@
public boolean isAllowedCachedRight(ReteTuple tuple,
ContextEntry context);
- public ContextEntry getContextEntry();
+ public ContextEntry createContextEntry();
/**
* A restriction may be required to replace an old
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -28,6 +28,7 @@
import org.drools.common.DefaultFactHandle;
import org.drools.common.EmptyBetaConstraints;
import org.drools.common.PropagationContextImpl;
+import org.drools.reteoo.CollectNode.CollectMemory;
import org.drools.reteoo.builder.BuildContext;
import org.drools.rule.Collect;
import org.drools.rule.Pattern;
@@ -51,7 +52,7 @@
MockTupleSource tupleSource;
MockTupleSink sink;
BetaNode node;
- BetaMemory memory;
+ CollectMemory memory;
MockConstraint constraint = new MockConstraint();
Collect collect;
@@ -101,13 +102,13 @@
this.node.addTupleSink( this.sink );
- this.memory = (BetaMemory) this.workingMemory.getNodeMemory( this.node );
+ this.memory = (CollectMemory) this.workingMemory.getNodeMemory( this.node );
// check memories are empty
assertEquals( 0,
- this.memory.getTupleMemory().size() );
+ this.memory.betaMemory.getTupleMemory().size() );
assertEquals( 0,
- this.memory.getFactHandleMemory().size() );
+ this.memory.betaMemory.getFactHandleMemory().size() );
}
/* (non-Javadoc)
@@ -158,9 +159,9 @@
this.workingMemory );
// check memories
assertEquals( 1,
- this.memory.getTupleMemory().size() );
+ this.memory.betaMemory.getTupleMemory().size() );
assertEquals( 0,
- this.memory.getFactHandleMemory().size() );
+ this.memory.betaMemory.getFactHandleMemory().size() );
Assert.assertTrue( "An empty collection should be propagated",
((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
@@ -172,12 +173,12 @@
this.contextAssert,
this.workingMemory );
assertEquals( 2,
- this.memory.getTupleMemory().size() );
+ this.memory.betaMemory.getTupleMemory().size() );
Assert.assertTrue( "An empty collection should be propagated",
((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).isEmpty() );
- assertTrue( this.memory.getTupleMemory().contains( tuple0 ) );
- assertTrue( this.memory.getTupleMemory().contains( tuple1 ) );
+ assertTrue( this.memory.betaMemory.getTupleMemory().contains( tuple0 ) );
+ assertTrue( this.memory.betaMemory.getTupleMemory().contains( tuple1 ) );
Assert.assertEquals( "Two tuples should have been propagated",
2,
@@ -203,9 +204,9 @@
this.workingMemory );
// check memories
assertEquals( 1,
- this.memory.getTupleMemory().size() );
+ this.memory.betaMemory.getTupleMemory().size() );
assertEquals( 2,
- this.memory.getFactHandleMemory().size() );
+ this.memory.betaMemory.getFactHandleMemory().size() );
Assert.assertEquals( "Wrong number of elements in matching objects list ",
2,
((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).size() );
@@ -216,13 +217,13 @@
this.contextAssert,
this.workingMemory );
assertEquals( 2,
- this.memory.getTupleMemory().size() );
+ this.memory.betaMemory.getTupleMemory().size() );
Assert.assertEquals( "Wrong number of elements in matching objects list ",
2,
((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
- assertTrue( this.memory.getTupleMemory().contains( tuple0 ) );
- assertTrue( this.memory.getTupleMemory().contains( tuple1 ) );
+ assertTrue( this.memory.betaMemory.getTupleMemory().contains( tuple0 ) );
+ assertTrue( this.memory.betaMemory.getTupleMemory().contains( tuple1 ) );
Assert.assertEquals( "Two tuples should have been propagated",
2,
@@ -240,9 +241,9 @@
this.workingMemory );
// check memories
assertEquals( 1,
- this.memory.getTupleMemory().size() );
+ this.memory.betaMemory.getTupleMemory().size() );
assertEquals( 0,
- this.memory.getFactHandleMemory().size() );
+ this.memory.betaMemory.getFactHandleMemory().size() );
Assert.assertTrue( "An empty collection should be propagated",
((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
@@ -250,7 +251,7 @@
this.contextRetract,
this.workingMemory );
assertEquals( 0,
- this.memory.getTupleMemory().size() );
+ this.memory.betaMemory.getTupleMemory().size() );
assertEquals( 1,
this.sink.getRetracted().size() );
assertEquals( 1,
@@ -270,7 +271,7 @@
// check memory
assertEquals( 1,
- this.memory.getTupleMemory().size() );
+ this.memory.betaMemory.getTupleMemory().size() );
assertEquals( 1,
this.sink.getAsserted().size() );
Assert.assertTrue( "An empty collection should be propagated",
@@ -280,7 +281,7 @@
this.contextAssert,
this.workingMemory );
assertEquals( 1,
- this.memory.getFactHandleMemory().size() );
+ this.memory.betaMemory.getFactHandleMemory().size() );
assertEquals( 2,
this.sink.getAsserted().size() );
Assert.assertEquals( "Wrong number of elements in matching objects list ",
@@ -292,7 +293,7 @@
this.workingMemory );
assertEquals( 2,
- this.memory.getFactHandleMemory().size() );
+ this.memory.betaMemory.getFactHandleMemory().size() );
assertEquals( 3,
this.sink.getAsserted().size() );
Assert.assertEquals( "Wrong number of elements in matching objects list ",
@@ -314,7 +315,7 @@
this.contextAssert,
this.workingMemory );
assertEquals( 2,
- this.memory.getFactHandleMemory().size() );
+ this.memory.betaMemory.getFactHandleMemory().size() );
// assert tuple, should add one to left memory
this.node.assertTuple( tuple0,
@@ -323,7 +324,7 @@
// check memory
assertEquals( 1,
- this.memory.getTupleMemory().size() );
+ this.memory.betaMemory.getTupleMemory().size() );
assertEquals( 0,
this.sink.getRetracted().size() );
assertEquals( 1,
@@ -336,7 +337,7 @@
this.contextRetract,
this.workingMemory );
assertEquals( 1,
- this.memory.getFactHandleMemory().size() );
+ this.memory.betaMemory.getFactHandleMemory().size() );
assertEquals( 1,
this.sink.getRetracted().size() );
assertEquals( 2,
@@ -349,7 +350,7 @@
this.contextRetract,
this.workingMemory );
assertEquals( 0,
- this.memory.getFactHandleMemory().size() );
+ this.memory.betaMemory.getFactHandleMemory().size() );
assertEquals( 2,
this.sink.getRetracted().size() );
assertEquals( 3,
@@ -380,7 +381,7 @@
false,
buildContext );
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( collectNode );
+ final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( collectNode );
assertNotNull( memory );
}
@@ -392,7 +393,7 @@
this.workingMemory = new ReteooWorkingMemory( 1,
(ReteooRuleBase) RuleBaseFactory.newRuleBase( conf ) );
- this.memory = (BetaMemory) this.workingMemory.getNodeMemory( this.node );
+ this.memory = (CollectMemory) this.workingMemory.getNodeMemory( this.node );
this.node.setTupleMemoryEnabled( false );
final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
@@ -412,9 +413,9 @@
this.contextAssert,
this.workingMemory );
// check memories
- assertNull( this.memory.getTupleMemory() );
+ assertNull( this.memory.betaMemory.getTupleMemory() );
assertEquals( 2,
- this.memory.getFactHandleMemory().size() );
+ this.memory.betaMemory.getFactHandleMemory().size() );
Assert.assertEquals( "Wrong number of elements in matching objects list ",
2,
((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).size() );
@@ -424,7 +425,7 @@
this.node.assertTuple( tuple1,
this.contextAssert,
this.workingMemory );
- assertNull( this.memory.getTupleMemory() );
+ assertNull( this.memory.betaMemory.getTupleMemory() );
Assert.assertEquals( "Wrong number of elements in matching objects list ",
2,
((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -228,7 +228,7 @@
tuple = new InstrumentedReteTuple( tuple,
f1 );
- final PredicateContextEntry context = (PredicateContextEntry) constraint1.getContextEntry();
+ final PredicateContextEntry context = (PredicateContextEntry) constraint1.createContextEntry();
context.updateFromTuple( workingMemory,
tuple );
assertTrue( constraint1.isAllowedCachedLeft( context,
@@ -315,13 +315,13 @@
tuple = new InstrumentedReteTuple( tuple,
f1 );
- final ReturnValueContextEntry context1 = (ReturnValueContextEntry) constraint1.getContextEntry();
+ final ReturnValueContextEntry context1 = (ReturnValueContextEntry) constraint1.createContextEntry();
context1.updateFromTuple( workingMemory,
tuple );
assertTrue( constraint1.isAllowedCachedLeft( context1,
f1 ) );
- final ReturnValueContextEntry context2 = (ReturnValueContextEntry) constraint2.getContextEntry();
+ final ReturnValueContextEntry context2 = (ReturnValueContextEntry) constraint2.createContextEntry();
context2.updateFromTuple( workingMemory,
tuple );
assertFalse( constraint2.isAllowedCachedLeft( context2,
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/spi/MockConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/spi/MockConstraint.java 2008-01-30 15:56:52 UTC (rev 18208)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/spi/MockConstraint.java 2008-01-31 02:28:04 UTC (rev 18209)
@@ -54,7 +54,7 @@
return this;
}
- public ContextEntry getContextEntry() {
+ public ContextEntry createContextEntry() {
return new ContextEntry() {
private static final long serialVersionUID = 400L;
private ContextEntry next;
More information about the jboss-svn-commits
mailing list