[jboss-svn-commits] JBL Code SVN: r6984 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Oct 20 17:09:34 EDT 2006
Author: tirelli
Date: 2006-10-20 17:09:26 -0400 (Fri, 20 Oct 2006)
New Revision: 6984
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/EvalConditionNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java
Log:
JBRULES-527: fixing compilation problems
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 2006-10-20 20:57:00 UTC (rev 6983)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2006-10-20 21:09:26 UTC (rev 6984)
@@ -24,6 +24,7 @@
import org.drools.common.BetaConstraints;
import org.drools.common.DefaultBetaConstraints;
+import org.drools.common.EmptyBetaConstraints;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.rule.Collect;
@@ -31,6 +32,7 @@
import org.drools.spi.PropagationContext;
import org.drools.util.LinkedList;
import org.drools.util.LinkedListEntry;
+import org.drools.util.AbstractHashTable.FactEntry;
/**
* @author etirelli
@@ -67,8 +69,8 @@
leftInput,
rightInput,
new AlphaNodeFieldConstraint[0],
- new DefaultBetaConstraints(),
- new DefaultBetaConstraints(),
+ EmptyBetaConstraints.getInstance(),
+ EmptyBetaConstraints.getInstance(),
collect );
}
@@ -125,22 +127,15 @@
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
- memory.add( workingMemory,
- leftTuple );
+ memory.getTupleMemory().add( leftTuple );
- //final BetaNodeBinder binder = getJoinNodeBinder();
-
final Collection result = this.collect.instantiateResultObject();
- for ( final Iterator it = memory.rightObjectIterator( workingMemory,
- leftTuple ); it.hasNext(); ) {
- final ObjectMatches objectMatches = (ObjectMatches) it.next();
- final InternalFactHandle handle = objectMatches.getFactHandle();
-
- if ( attemptJoin( leftTuple,
- handle,
- objectMatches,
- this.resultsBinder,
- workingMemory ) != null ) {
+ final org.drools.util.Iterator it = memory.getObjectMemory().iterator( leftTuple );
+ this.constraints.updateFromTuple( workingMemory, leftTuple );
+
+ for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
+ final InternalFactHandle handle = entry.getFactHandle();
+ if ( this.constraints.isAllowedCachedLeft( handle.getObject() ) ) {
result.add( handle.getObject() );
}
}
@@ -149,7 +144,6 @@
boolean isAllowed = true;
for ( int i = 0, length = this.resultConstraints.length; i < length; i++ ) {
if ( !this.resultConstraints[i].isAllowed( result,
- leftTuple,
workingMemory ) ) {
isAllowed = false;
break;
@@ -158,9 +152,7 @@
if ( isAllowed ) {
final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result );
- if ( this.resultsBinder.isAllowed( handle,
- leftTuple,
- workingMemory ) ) {
+ if ( this.resultsBinder.isAllowedCachedLeft( result ) ) {
this.sink.propagateAssertTuple( leftTuple,
handle,
context,
@@ -171,34 +163,15 @@
/**
* @inheritDoc
- *
- * As the collect node will propagate the tuple,
- * but will recalculate the collection result object every time,
- * a modify is really a retract + assert.
- *
*/
- public void modifyTuple(final ReteTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
-
- this.retractTuple( leftTuple,
- context,
- workingMemory );
- this.assertTuple( leftTuple,
- context,
- workingMemory );
-
- }
-
- /**
- * @inheritDoc
- */
public void retractTuple(final ReteTuple leftTuple,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
- memory.remove( workingMemory,
- leftTuple );
+ memory.getTupleMemory().remove( leftTuple );
+
+
+
final Map matches = leftTuple.getTupleMatches();
@@ -257,38 +230,6 @@
}
/**
- * @inheritDoc
- *
- * If an object is modified, iterate over all matching tuples
- * and propagate a modify tuple for them.
- *
- * NOTE: a modify tuple for collect node is exactly the
- * same as a retract+assert tuple, since the collection object changes.
- * So, a modify object is in fact a retract+assert object.
- *
- */
- public void modifyObject(final InternalFactHandle handle,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-
- // Remove the FactHandle from memory
- final ObjectMatches objectMatches = memory.remove( workingMemory,
- handle );
-
- // remove references from tuple to the handle
- for ( CompositeTupleMatch compositeTupleMatch = objectMatches.getFirstTupleMatch(); compositeTupleMatch != null; compositeTupleMatch = (CompositeTupleMatch) compositeTupleMatch.getNext() ) {
- final ReteTuple leftTuple = compositeTupleMatch.getTuple();
- leftTuple.removeMatch( handle );
- }
-
- // reassert object modifying appropriate tuples
- this.assertObject( handle,
- context,
- workingMemory );
- }
-
- /**
* @inheritDoc
*
* If an object is retract, call modify tuple for each
@@ -313,44 +254,15 @@
}
}
- /**
- * @inheritDoc
- */
- public List getPropagatedTuples(final InternalWorkingMemory workingMemory,
- final TupleSink sink) {
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
- final List propagatedTuples = new ArrayList();
-
- for ( final Iterator it = memory.getLeftTupleMemory().iterator(); it.hasNext(); ) {
- final ReteTuple leftTuple = (ReteTuple) it.next();
- final LinkedList linkedTuples = leftTuple.getChildEntries();
-
- final LinkedListEntry wrapper = (LinkedListEntry) linkedTuples.getFirst();
- propagatedTuples.add( wrapper.getObject() );
- }
- return propagatedTuples;
- }
-
- /**
- * @inheritDoc
- */
- public void updateNewNode(final InternalWorkingMemory workingMemory,
- final PropagationContext context) {
- this.attachingNewNode = true;
-
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-
- for ( final Iterator it = memory.getLeftTupleMemory().iterator(); it.hasNext(); ) {
- final ReteTuple leftTuple = (ReteTuple) it.next();
- this.sink.propagateNewTupleSink( (ReteTuple) leftTuple.getChildEntries().getFirst(),
- context,
- workingMemory );
- }
- this.attachingNewNode = false;
- }
-
public String toString() {
return "[ " + this.getClass().getName() + "(" + this.id + ") ]";
}
+ public void updateSink(TupleSink sink,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory) {
+ // TODO Auto-generated method stub
+
+ }
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java 2006-10-20 20:57:00 UTC (rev 6983)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java 2006-10-20 21:09:26 UTC (rev 6984)
@@ -16,8 +16,8 @@
* limitations under the License.
*/
-import java.util.ArrayList;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import org.drools.RuleBaseConfiguration;
@@ -27,8 +27,6 @@
import org.drools.common.PropagationContextImpl;
import org.drools.rule.EvalCondition;
import org.drools.spi.PropagationContext;
-import org.drools.util.LinkedList;
-import org.drools.util.LinkedListEntry;
/**
* Node which filters <code>ReteTuple</code>s.
@@ -102,8 +100,9 @@
PropagationContext.RULE_ADDITION,
null,
null );
- this.tupleSource.updateNewNode( workingMemory,
- propagationContext );
+ this.tupleSource.updateSink( this,
+ propagationContext,
+ workingMemory );
}
}
@@ -142,7 +141,7 @@
workingMemory );
if ( allowed ) {
- final LinkedList memory = (LinkedList) workingMemory.getNodeMemory( this );
+ final List memory = (LinkedList) workingMemory.getNodeMemory( this );
memory.add( tuple );
this.sink.propagateAssertTuple( tuple,
@@ -154,60 +153,14 @@
public void retractTuple(final ReteTuple tuple,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
- final LinkedList memory = (LinkedList) workingMemory.getNodeMemory( this );
+ final List memory = (LinkedList) workingMemory.getNodeMemory( this );
- // checks if the tuple is attach to tuple
- if ( tuple.getChildEntries() != null && !tuple.getChildEntries().isEmpty() ) {
- memory.remove( tuple );
-
- tuple.retractChildEntries( context,
- workingMemory );
- }
- }
-
- public void modifyTuple(final ReteTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- final LinkedList memory = (LinkedList) workingMemory.getNodeMemory( this );
- boolean exists = (tuple.getChildEntries() != null && !tuple.getChildEntries().isEmpty());
-
- if ( exists ) {
- // Remove the tuple so it can be readded to the top of the list
- memory.remove( tuple );
- }
-
- final boolean allowed = this.condition.isAllowed( tuple,
- workingMemory );
-
- if ( allowed ) {
- memory.add( tuple );
- if ( !exists ) {
- this.sink.propagateAssertTuple( tuple,
- context,
- workingMemory );
- } else {
- tuple.modifyChildEntries( context,
- workingMemory );
- }
- } else {
- tuple.retractChildEntries( context,
- workingMemory );
- }
- }
-
- public void updateNewNode(final InternalWorkingMemory workingMemory,
- final PropagationContext context) {
- this.attachingNewNode = true;
-
- final LinkedList memory = (LinkedList) workingMemory.getNodeMemory( this );
-
- for ( final Iterator it = memory.iterator(); it.hasNext(); ) {
- final ReteTuple tuple = (ReteTuple) it.next();
- this.sink.propagateNewTupleSink( (ReteTuple) tuple.getChildEntries().getFirst(),
+ // can we improve that?
+ if ( memory.remove( tuple ) ) {
+ this.sink.propagateRetractTuple( tuple,
context,
workingMemory );
}
- this.attachingNewNode = false;
}
/**
@@ -216,7 +169,7 @@
* @return The debug string.
*/
public String toString() {
- return "[ConditionNode: cond=" + this.condition + "]";
+ return "[EvalConditionNode: cond=" + this.condition + "]";
}
public int hashCode() {
@@ -241,28 +194,37 @@
return new LinkedList();
}
- /**
- * @inheritDoc
+ /* (non-Javadoc)
+ * @see org.drools.reteoo.BaseNode#updateNewNode(org.drools.reteoo.WorkingMemoryImpl, org.drools.spi.PropagationContext)
*/
- public List getPropagatedTuples(final InternalWorkingMemory workingMemory,
- final TupleSink sink) {
- // FIXME
- final LinkedList memory = (LinkedList) workingMemory.getNodeMemory( this );
- final List propagatedTuples = new ArrayList();
+ public void updateSink(final TupleSink sink,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
- for ( final Iterator it = memory.iterator(); it.hasNext(); ) {
- final ReteTuple leftTuple = (ReteTuple) it.next();
- final LinkedList linkedTuples = leftTuple.getChildEntries();
+ final List memory = (List) workingMemory.getNodeMemory( this );
- final LinkedListEntry wrapper = (LinkedListEntry) linkedTuples.getFirst();
- propagatedTuples.add( wrapper.getObject() );
+ for ( Iterator tupleIter = memory.iterator(); tupleIter.hasNext(); ) {
+ ReteTuple tuple = (ReteTuple) tupleIter.next();
+ sink.assertTuple( tuple,
+ context,
+ workingMemory );
}
- return propagatedTuples;
}
- public void remove(final BaseNode node,
- final InternalWorkingMemory[] workingMemories) {
- // FIXME
+ public void remove(BaseNode node,
+ InternalWorkingMemory[] workingMemories) {
+ if ( !node.isInUse() ) {
+ removeTupleSink( (TupleSink) node );
+ }
+ removeShare();
+ if ( !this.isInUse() ) {
+ for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
+ workingMemories[i].clearNodeMemory( this );
+ }
+ }
+ this.tupleSource.remove( this,
+ workingMemories );
+
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java 2006-10-20 20:57:00 UTC (rev 6983)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java 2006-10-20 21:09:26 UTC (rev 6984)
@@ -140,8 +140,7 @@
PropagationContext.RULE_ADDITION,
null,
null );
- this.tupleSource.updateNewNode( workingMemory,
- propagationContext );
+ this.tupleSource.updateSink( this, propagationContext, workingMemory );
}
}
More information about the jboss-svn-commits
mailing list