[jboss-svn-commits] JBL Code SVN: r7000 - 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
Sat Oct 21 11:21:43 EDT 2006
Author: tirelli
Date: 2006-10-21 11:21:40 -0400 (Sat, 21 Oct 2006)
New Revision: 7000
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
Log:
JBRULES-527: solving compilation problems
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 2006-10-21 15:05:39 UTC (rev 6999)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2006-10-21 15:21:40 UTC (rev 7000)
@@ -1,14 +1,9 @@
package org.drools.reteoo;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
import org.drools.RuleBaseConfiguration;
import org.drools.common.BaseNode;
import org.drools.common.BetaConstraints;
-import org.drools.common.DefaultBetaConstraints;
-import org.drools.common.DefaultFactHandle;
+import org.drools.common.EmptyBetaConstraints;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.common.NodeMemory;
@@ -16,6 +11,8 @@
import org.drools.spi.AlphaNodeFieldConstraint;
import org.drools.spi.DataProvider;
import org.drools.spi.PropagationContext;
+import org.drools.util.Iterator;
+import org.drools.util.ObjectHashMap.ObjectEntry;
public class FromNode extends TupleSource
implements
@@ -40,135 +37,68 @@
this.dataProvider = dataProvider;
this.tupleSource = tupleSource;
this.constraints = constraints;
- if ( binder == null ) {
- this.binder = new DefaultBetaConstraints();
- } else {
- this.binder = binder;
- }
+ this.binder = ( binder == null ) ? EmptyBetaConstraints.getInstance() : binder;
}
/**
- * This method isn't as efficient as it could be, as its using the standard join node mechanisms - so everything is bidirectionally
- * linked. As FactHandle's are never retracted, this relationship does not need to be maintined - but as this optimisation would
- * need refactoring, I've used the standard join node mechanism for now.
- *
+ * @inheritDoc
*/
public void assertTuple(final ReteTuple leftTuple,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
- memory.add( workingMemory,
- leftTuple );
+ memory.getTupleMemory().add( leftTuple );
+ this.binder.updateFromTuple( workingMemory, leftTuple );
- for ( final Iterator it = this.dataProvider.getResults( leftTuple,
+ for ( final java.util.Iterator it = this.dataProvider.getResults( leftTuple,
workingMemory,
context ); it.hasNext(); ) {
final Object object = it.next();
// First alpha node filters
- boolean isAllowed = true;
for ( int i = 0, length = this.constraints.length; i < length; i++ ) {
if ( !this.constraints[i].isAllowed( object,
- leftTuple,
workingMemory ) ) {
- isAllowed = false;
- break;
+ // next iteration
+ continue;
}
}
- if ( !isAllowed ) {
- continue;
- }
+ if ( this.binder.isAllowedCachedLeft( object ) ) {
+ final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( object );
+
+ memory.getCreatedHandles().put( leftTuple, handle );
- final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( object );
- final ObjectMatches objectMatches = new ObjectMatches( (DefaultFactHandle) handle );
-
- if ( this.binder.isAllowed( handle,
- leftTuple,
- workingMemory ) ) {
- final TupleMatch tupleMatch = new CompositeTupleMatch( leftTuple,
- objectMatches );
-
- leftTuple.addTupleMatch( (DefaultFactHandle) handle,
- tupleMatch );
-
this.sink.propagateAssertTuple( leftTuple,
handle,
- tupleMatch,
context,
workingMemory );
}
}
}
- /**
- * This could be made more intelligent by finding out if the modified Fact is depended upon by the requiredDeclarations.
- * If it isn't then we can continue to just propagate as a normal modify, without having to retrieve and check values
- * from the DataProvider.
- */
- public void modifyTuple(final ReteTuple leftTuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-
- // We remove the tuple as now its modified it needs to go to the top of
- // the stack, which is added back in else where
- memory.remove( workingMemory,
- leftTuple );
-
- final Map matches = leftTuple.getTupleMatches();
-
- if ( matches.isEmpty() ) {
- // No child propagations, so try as a new assert, will ensure the
- // tuple is added to the top of the memory
- assertTuple( leftTuple,
- context,
- workingMemory );
- } else {
- // first purge the network of all future uses of the 'from' facts
- for ( final Iterator it = matches.values().iterator(); it.hasNext(); ) {
- final TupleMatch tupleMatch = (TupleMatch) it.next();
- tupleMatch.getTuple().retractChildEntries( context,
- workingMemory );
- workingMemory.getFactHandleFactory().destroyFactHandle( tupleMatch.getObjectMatches().getFactHandle() );
- }
-
- // now all existing matches must now be cleared and the DataProvider re-processed.
- leftTuple.clearTupleMatches();
-
- assertTuple( leftTuple,
- context,
- workingMemory );
-
- }
- }
-
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 InternalFactHandle handle = (InternalFactHandle) memory.getCreatedHandles().remove( leftTuple );
- final Map matches = leftTuple.getTupleMatches();
+ // if tuple was propagated
+ if ( handle != null ) {
- if ( !matches.isEmpty() ) {
- for ( final Iterator it = matches.values().iterator(); it.hasNext(); ) {
- final TupleMatch tupleMatch = (TupleMatch) it.next();
- tupleMatch.getTuple().retractChildEntries( context,
- workingMemory );
- workingMemory.getFactHandleFactory().destroyFactHandle( tupleMatch.getObjectMatches().getFactHandle() );
- }
+ this.sink.propagateRetractTuple( leftTuple,
+ handle,
+ context,
+ workingMemory );
+
+ // Destroying the 'from' result object
+ workingMemory.getFactHandleFactory().destroyFactHandle( handle );
}
}
- public List getPropagatedTuples(final InternalWorkingMemory workingMemory,
- final TupleSink sink) {
- // TODO Auto-generated method stub
- return null;
- }
-
public void attach() {
this.tupleSource.addTupleSink( this );
}
@@ -182,59 +112,44 @@
PropagationContext.RULE_ADDITION,
null,
null );
- this.tupleSource.updateNewNode( workingMemory,
- propagationContext );
+ this.tupleSource.updateSink( this, propagationContext, workingMemory );
}
}
public void remove(final BaseNode node,
final InternalWorkingMemory[] workingMemories) {
- // FIXME
- // if ( !node.isInUse() ) {
- // getTupleSinks().remove( node );
- // }
- // removeShare();
- //
- // if ( !this.isInUse() ) {
- // for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
- // workingMemories[i].clearNodeMemory( this );
- // }
- // }
- // this.tupleSource.remove( this,
- // 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 );
}
- public void updateNewNode(final InternalWorkingMemory workingMemory,
- final PropagationContext context) {
- this.attachingNewNode = true;
+ public Object createMemory(final RuleBaseConfiguration config) {
+ return this.binder.createBetaMemory();
+ }
+ public void updateSink(TupleSink sink,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory) {
+
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+
+ final Iterator it = memory.getCreatedHandles().iterator();
- // @todo:as there is no right memory
-
- // for ( final Iterator it = memory.getRightObjectMemory().iterator(); it.hasNext(); ) {
- // final ObjectMatches objectMatches = (ObjectMatches) it.next();
- // final DefaultFactHandle handle = objectMatches.getFactHandle();
- // for ( TupleMatch tupleMatch = objectMatches.getFirstTupleMatch(); tupleMatch != null; tupleMatch = (TupleMatch) tupleMatch.getNext() ) {
- // final ReteTuple tuple = new ReteTuple( tupleMatch.getTuple(),
- // handle );
- // final TupleSink sink = (TupleSink) this.tupleSinks.get( this.tupleSinks.size() - 1 );
- // if ( sink != null ) {
- // tupleMatch.addJoinedTuple( tuple );
- // sink.assertTuple( tuple,
- // context,
- // workingMemory );
- // } else {
- // throw new RuntimeException( "Possible BUG: trying to propagate an assert to a node that was the last added node" );
- // }
- // }
- // }
-
- this.attachingNewNode = false;
+ for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next()) {
+ sink.assertTuple( new ReteTuple( (ReteTuple)entry.getKey(),
+ (InternalFactHandle) entry.getValue()),
+ context,
+ workingMemory );
+ }
}
-
- public Object createMemory(final RuleBaseConfiguration config) {
- return new BetaMemory( config,
- this.binder );
- }
}
More information about the jboss-svn-commits
mailing list