[jboss-svn-commits] JBL Code SVN: r31739 - in labs/jbossrules/branches/true_modify_20100215: drools-core/src/main/java/org/drools/marshalling/impl and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Feb 19 00:09:43 EST 2010
Author: tirelli
Date: 2010-02-19 00:09:41 -0500 (Fri, 19 Feb 2010)
New Revision: 31739
Modified:
labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java
labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/SerializationHelper.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/RuleRemovalContext.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
Log:
JBRULES-2339: JBRULES-2340: not there yet... :(
Modified: labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java 2010-02-19 02:32:22 UTC (rev 31738)
+++ labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java 2010-02-19 05:09:41 UTC (rev 31739)
@@ -55,7 +55,6 @@
import org.drools.marshalling.MarshallerFactory;
import org.drools.marshalling.ObjectMarshallingStrategy;
import org.drools.marshalling.ObjectMarshallingStrategyAcceptor;
-import org.drools.marshalling.impl.OutputMarshaller;
import org.drools.marshalling.impl.RuleBaseNodes;
import org.drools.reteoo.ObjectTypeNode;
import org.drools.reteoo.ReteooStatefulSession;
Modified: labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/SerializationHelper.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/SerializationHelper.java 2010-02-19 02:32:22 UTC (rev 31738)
+++ labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/SerializationHelper.java 2010-02-19 05:09:41 UTC (rev 31739)
@@ -81,6 +81,7 @@
// bytes should be the same.
if ( !areByteArraysEqual( b1,
b2 ) ) {
+
throw new IllegalArgumentException( "byte streams for serialisation test are not equal" );
}
@@ -146,6 +147,7 @@
for ( int i = 0, length = b1.length; i < length; i++ ) {
if ( b1[i] != b2[i] ) {
+ System.out.println("Difference at "+i+": ["+b1[i]+"] != ["+b2[i]+"]");
return false;
}
}
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java 2010-02-19 02:32:22 UTC (rev 31738)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/marshalling/impl/InputMarshaller.java 2010-02-19 05:09:41 UTC (rev 31739)
@@ -421,7 +421,8 @@
ObjectInputStream stream = context.stream;
while ( stream.readShort() == PersisterEnums.LEFT_TUPLE ) {
- LeftTupleSink sink = (LeftTupleSink) context.sinks.get( stream.readInt() );
+ int nodeId = stream.readInt();
+ LeftTupleSink sink = (LeftTupleSink) context.sinks.get( nodeId );
int factHandleId = stream.readInt();
LeftTuple leftTuple = new LeftTuple( context.handles.get( factHandleId ),
sink,
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java 2010-02-19 02:32:22 UTC (rev 31738)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/marshalling/impl/OutputMarshaller.java 2010-02-19 05:09:41 UTC (rev 31739)
@@ -348,7 +348,7 @@
// context.out.println( "InitialFact LeftTuples Start" );
InternalFactHandle handle = context.wm.getInitialFactHandle();
- for ( LeftTuple leftTuple = getLeftTuple( handle.getLastLeftTuple() ); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
+ for ( LeftTuple leftTuple = handle.getFirstLeftTuple(); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
stream.writeShort( PersisterEnums.LEFT_TUPLE );
stream.writeInt( leftTuple.getLeftTupleSink().getId() );
@@ -365,12 +365,8 @@
MarshallerWriteContext context) throws IOException {
ObjectOutputStream stream = context.stream;
// context.out.println( "RightTuples Start" );
-
- RightTuple rightTuple = handle.getFirstRightTuple();
- for ( RightTuple tempRightTuple = rightTuple; tempRightTuple != null; tempRightTuple = (RightTuple) tempRightTuple.getHandleNext() ) {
- rightTuple = tempRightTuple;
- }
- for ( ; rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandlePrevious() ) {
+
+ for (RightTuple rightTuple = handle.getFirstRightTuple(); rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandleNext() ) {
stream.writeShort( PersisterEnums.RIGHT_TUPLE );
writeRightTuple( rightTuple,
context );
@@ -396,7 +392,7 @@
for ( InternalFactHandle handle : orderFacts( wm.getObjectStore() ) ) {
//InternalFactHandle handle = (InternalFactHandle) it.next();
- for ( LeftTuple leftTuple = getLeftTuple( handle.getLastLeftTuple() ); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
+ for ( LeftTuple leftTuple = handle.getFirstLeftTuple(); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
stream.writeShort( PersisterEnums.LEFT_TUPLE );
stream.writeInt( leftTuple.getLeftTupleSink().getId() );
@@ -424,7 +420,7 @@
switch ( sink.getType() ) {
case NodeTypeEnums.JoinNode : {
// context.out.println( "JoinNode" );
- for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.firstChild ); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentPrevious() ) {
+ for ( LeftTuple childLeftTuple = leftTuple.firstChild; childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext() ) {
stream.writeShort( PersisterEnums.RIGHT_TUPLE );
stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
stream.writeInt( childLeftTuple.getRightParent().getFactHandle().getId() );
@@ -439,7 +435,7 @@
}
case NodeTypeEnums.EvalConditionNode : {
// context.out.println( "EvalConditionNode" );
- for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.firstChild ); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentPrevious() ) {
+ for ( LeftTuple childLeftTuple = leftTuple.firstChild; childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext() ) {
stream.writeShort( PersisterEnums.LEFT_TUPLE );
stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
writeLeftTuple( childLeftTuple,
@@ -455,7 +451,7 @@
// is not blocked so has children
stream.writeShort( PersisterEnums.LEFT_TUPLE_NOT_BLOCKED );
- for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.firstChild ); childLeftTuple != null; childLeftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
+ for ( LeftTuple childLeftTuple = leftTuple.firstChild; childLeftTuple != null; childLeftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
stream.writeShort( PersisterEnums.LEFT_TUPLE );
stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
writeLeftTuple( childLeftTuple,
@@ -478,7 +474,7 @@
stream.writeShort( PersisterEnums.LEFT_TUPLE_BLOCKED );
stream.writeInt( leftTuple.getBlocker().getFactHandle().getId() );
- for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.firstChild ); childLeftTuple != null; childLeftTuple = (LeftTuple) leftTuple.getLeftParentPrevious() ) {
+ for ( LeftTuple childLeftTuple = leftTuple.firstChild; childLeftTuple != null; childLeftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
stream.writeShort( PersisterEnums.LEFT_TUPLE );
stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
writeLeftTuple( childLeftTuple,
@@ -505,7 +501,7 @@
stream.writeBoolean( accctx.propagated );
// then we serialize all the propagated tuples
- for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.firstChild ); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentPrevious() ) {
+ for ( LeftTuple childLeftTuple = leftTuple.firstChild; childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext() ) {
if( leftTuple.getLeftTupleSink().getId() == childLeftTuple.getLeftTupleSink().getId()) {
// this is a matching record, so, associate the right tuples
// context.out.println( "RightTuple(match) int:" + childLeftTuple.getLeftTupleSink().getId() + " int:" + childLeftTuple.getRightParent().getFactHandle().getId() );
@@ -539,7 +535,7 @@
stream.writeBoolean( colctx.propagated );
// then we serialize all the propagated tuples
- for ( LeftTuple childLeftTuple = getLeftTuple( leftTuple.firstChild ); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentPrevious() ) {
+ for ( LeftTuple childLeftTuple = leftTuple.firstChild; childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext() ) {
if( leftTuple.getLeftTupleSink().getId() == childLeftTuple.getLeftTupleSink().getId()) {
// this is a matching record, so, associate the right tuples
// context.out.println( "RightTuple(match) int:" + childLeftTuple.getLeftTupleSink().getId() + " int:" + childLeftTuple.getRightParent().getFactHandle().getId() );
@@ -585,13 +581,6 @@
}
}
- public static LeftTuple getLeftTuple(LeftTuple leftTuple) {
- for ( LeftTuple tempLeftTuple = leftTuple; tempLeftTuple != null; tempLeftTuple = (LeftTuple) tempLeftTuple.getLeftParentNext() ) {
- leftTuple = tempLeftTuple;
- }
- return leftTuple;
- }
-
public static void writeActivations(MarshallerWriteContext context) throws IOException {
ObjectOutputStream stream = context.stream;
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/BetaNode.java 2010-02-19 02:32:22 UTC (rev 31738)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/BetaNode.java 2010-02-19 05:09:41 UTC (rev 31739)
@@ -229,8 +229,9 @@
context.visitTupleSource( this );
if ( !node.isInUse() ) {
removeTupleSink( (LeftTupleSink) node );
+
}
- if ( !this.isInUse() ) {
+ if ( !this.isInUse() || context.getCleanupAdapter() != null ) {
for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
BetaMemory memory = null;
Object object = workingMemories[i].getNodeMemory( this );
@@ -249,33 +250,45 @@
Iterator it = memory.getLeftTupleMemory().iterator();
for ( LeftTuple leftTuple = (LeftTuple) it.next(); leftTuple != null; leftTuple = (LeftTuple) it.next() ) {
- leftTuple.unlinkFromLeftParent();
- leftTuple.unlinkFromRightParent();
+ if( ! this.isInUse() ) {
+ leftTuple.unlinkFromLeftParent();
+ leftTuple.unlinkFromRightParent();
+ } else if( context.getCleanupAdapter() != null ) {
+ for( LeftTuple child = leftTuple.firstChild; child != null; child = child.getLeftParentNext() ) {
+ if( child.getLeftTupleSink() == node ) {
+ context.getCleanupAdapter().cleanUp( child, workingMemories[i] );
+ }
+ }
+
+ }
}
-
- it = memory.getRightTupleMemory().iterator();
- for ( RightTuple rightTuple = (RightTuple) it.next(); rightTuple != null; rightTuple = (RightTuple) it.next() ) {
- if ( rightTuple.getBlocked() != null ) {
- // special case for a not, so unlink left tuple from here, as they aren't in the left memory
- for ( LeftTuple leftTuple = (LeftTuple)rightTuple.getBlocked(); leftTuple != null; ) {
- LeftTuple temp = leftTuple.getBlockedNext();
-
- leftTuple.setBlocker( null );
- leftTuple.setBlockedPrevious( null );
- leftTuple.setBlockedNext( null );
- leftTuple.unlinkFromLeftParent();
- leftTuple = temp;
- }
- }
-
- if ( rightTuple.getRightTupleSink() == null ) {
- // special case for FromNode
- workingMemories[i].getFactHandleFactory().destroyFactHandle( rightTuple.getFactHandle() );
- }
- rightTuple.unlinkFromRightParent();
- }
- workingMemories[i].clearNodeMemory( this );
+
+ if( ! this.isInUse() ) {
+ it = memory.getRightTupleMemory().iterator();
+ for ( RightTuple rightTuple = (RightTuple) it.next(); rightTuple != null; rightTuple = (RightTuple) it.next() ) {
+ if ( rightTuple.getBlocked() != null ) {
+ // special case for a not, so unlink left tuple from here, as they aren't in the left memory
+ for ( LeftTuple leftTuple = (LeftTuple)rightTuple.getBlocked(); leftTuple != null; ) {
+ LeftTuple temp = leftTuple.getBlockedNext();
+
+ leftTuple.setBlocker( null );
+ leftTuple.setBlockedPrevious( null );
+ leftTuple.setBlockedNext( null );
+ leftTuple.unlinkFromLeftParent();
+ leftTuple = temp;
+ }
+ }
+
+ if ( rightTuple.getRightTupleSink() == null ) {
+ // special case for FromNode
+ workingMemories[i].getFactHandleFactory().destroyFactHandle( rightTuple.getFactHandle() );
+ }
+ rightTuple.unlinkFromRightParent();
+ }
+ workingMemories[i].clearNodeMemory( this );
+ }
}
+ context.setCleanupAdapter( null );
}
this.rightInput.remove( context,
builder,
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java 2010-02-19 02:32:22 UTC (rev 31738)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java 2010-02-19 05:09:41 UTC (rev 31739)
@@ -27,6 +27,7 @@
import org.drools.common.NodeMemory;
import org.drools.common.PropagationContextImpl;
import org.drools.common.RuleBasePartitionId;
+import org.drools.reteoo.RuleRemovalContext.CleanupAdapter;
import org.drools.reteoo.builder.BuildContext;
import org.drools.spi.PropagationContext;
import org.drools.util.RightTupleList;
@@ -49,14 +50,14 @@
/**
*
*/
- private static final long serialVersionUID = 400L;
- private ObjectSource objectSource;
+ private static final long serialVersionUID = 400L;
+ private ObjectSource objectSource;
- private ObjectSinkNode previousRightTupleSinkNode;
- private ObjectSinkNode nextRightTupleSinkNode;
-
- private boolean leftTupleMemoryEnabled;
+ private ObjectSinkNode previousRightTupleSinkNode;
+ private ObjectSinkNode nextRightTupleSinkNode;
+ private boolean leftTupleMemoryEnabled;
+
public LeftInputAdapterNode() {
}
@@ -144,22 +145,28 @@
workingMemory,
this.leftTupleMemoryEnabled );
} else {
- workingMemory.addLIANodePropagation( new LIANodePropagation(this, factHandle, context) );
+ workingMemory.addLIANodePropagation( new LIANodePropagation( this,
+ factHandle,
+ context ) );
}
}
-
+
public void modifyObject(InternalFactHandle factHandle,
final ModifyPreviousTuples modifyPreviousTuples,
PropagationContext context,
InternalWorkingMemory workingMemory) {
- this.sink.propagateModifyObject( factHandle, modifyPreviousTuples, context, workingMemory );
-
- }
+ this.sink.propagateModifyObject( factHandle,
+ modifyPreviousTuples,
+ context,
+ workingMemory );
+ }
+
public void updateSink(final LeftTupleSink sink,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
- final RightTupleSinkAdapter adapter = new RightTupleSinkAdapter( sink, this.leftTupleMemoryEnabled );
+ final RightTupleSinkAdapter adapter = new RightTupleSinkAdapter( sink,
+ this.leftTupleMemoryEnabled );
this.objectSource.updateSink( adapter,
context,
workingMemory );
@@ -252,9 +259,10 @@
implements
ObjectSink {
private LeftTupleSink sink;
- private boolean leftTupleMemoryEnabled;
+ private boolean leftTupleMemoryEnabled;
- public RightTupleSinkAdapter(final LeftTupleSink sink, boolean leftTupleMemoryEnabled) {
+ public RightTupleSinkAdapter(final LeftTupleSink sink,
+ boolean leftTupleMemoryEnabled) {
this.sink = sink;
this.leftTupleMemoryEnabled = leftTupleMemoryEnabled;
}
@@ -275,13 +283,13 @@
final InternalWorkingMemory workingMemory) {
throw new UnsupportedOperationException( "ObjectSinkAdapter onlys supports assertObject method calls" );
}
-
+
public void modifyObject(InternalFactHandle factHandle,
ModifyPreviousTuples modifyPreviousTuples,
PropagationContext context,
InternalWorkingMemory workingMemory) {
throw new UnsupportedOperationException( "ObjectSinkAdapter onlys supports assertObject method calls" );
- }
+ }
public int getId() {
return 0;
@@ -291,12 +299,13 @@
return sink.getPartitionId();
}
- public void writeExternal( ObjectOutput out ) throws IOException {
+ public void writeExternal(ObjectOutput out) throws IOException {
// this is a short living adapter class used only during an update operation, and
// as so, no need for serialization code
}
- public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
// this is a short living adapter class used only during an update operation, and
// as so, no need for serialization code
}
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java 2010-02-19 02:32:22 UTC (rev 31738)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java 2010-02-19 05:09:41 UTC (rev 31739)
@@ -208,8 +208,14 @@
previousParent.leftParentNext = null;
} else {
// single remaining item, no previous or next
- this.leftParent.firstChild = null;
- this.leftParent.lastChild = null;
+ if( leftParent != null ) {
+ this.leftParent.firstChild = null;
+ this.leftParent.lastChild = null;
+ } else {
+ // it is a root tuple - only happens during rule removal
+ this.handle.setFirstLeftTuple( null );
+ this.handle.setLastLeftTuple( null );
+ }
}
this.leftParent = null;
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2010-02-19 02:32:22 UTC (rev 31738)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2010-02-19 05:09:41 UTC (rev 31739)
@@ -33,6 +33,7 @@
import org.drools.common.NodeMemory;
import org.drools.common.PropagationContextImpl;
import org.drools.reteoo.ReteooWorkingMemory.WorkingMemoryReteExpireAction;
+import org.drools.reteoo.RuleRemovalContext.CleanupAdapter;
import org.drools.reteoo.builder.BuildContext;
import org.drools.reteoo.compiled.CompiledNetwork;
import org.drools.rule.Declaration;
@@ -330,6 +331,20 @@
final ReteooBuilder builder,
final BaseNode node,
final InternalWorkingMemory[] workingMemories) {
+ if( context.getCleanupAdapter() != null ) {
+ for( InternalWorkingMemory workingMemory : workingMemories ) {
+ CleanupAdapter adapter = context.getCleanupAdapter();
+ final ObjectHashSet memory = (ObjectHashSet) workingMemory.getNodeMemory( this );
+ Iterator it = memory.iterator();
+ for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
+ InternalFactHandle handle = (InternalFactHandle) entry.getValue();
+ for( LeftTuple leftTuple = handle.getFirstLeftTuple(); leftTuple != null; leftTuple = leftTuple.getLeftParentNext() ) {
+ adapter.cleanUp( leftTuple, workingMemory );
+ }
+ }
+ }
+ context.setCleanupAdapter( null );
+ }
if ( !node.isInUse() ) {
removeObjectSink( (ObjectSink) node );
}
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/RuleRemovalContext.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/RuleRemovalContext.java 2010-02-19 02:32:22 UTC (rev 31738)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/RuleRemovalContext.java 2010-02-19 05:09:41 UTC (rev 31739)
@@ -25,6 +25,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.drools.common.InternalWorkingMemory;
+
/**
* This context class is used during rule removal to ensure
* network consistency.
@@ -36,15 +38,17 @@
implements
Externalizable {
- private Map visitedNodes;
+ private Map<Integer, LeftTupleSource> visitedNodes;
+ private CleanupAdapter cleanupAdapter;
public RuleRemovalContext() {
- this.visitedNodes = new HashMap();
+ this.visitedNodes = new HashMap<Integer, LeftTupleSource>();
}
+ @SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
- visitedNodes = (Map) in.readObject();
+ visitedNodes = (Map<Integer, LeftTupleSource>) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
@@ -76,4 +80,17 @@
public void clear() {
this.visitedNodes.clear();
}
+
+ public void setCleanupAdapter(CleanupAdapter cleanupAdapter) {
+ this.cleanupAdapter = cleanupAdapter;
+ }
+
+ public CleanupAdapter getCleanupAdapter() {
+ return cleanupAdapter;
+ }
+
+ public static interface CleanupAdapter {
+ public void cleanUp(final LeftTuple leftTuple,
+ final InternalWorkingMemory workingMemory);
+ }
}
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java 2010-02-19 02:32:22 UTC (rev 31738)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java 2010-02-19 05:09:41 UTC (rev 31739)
@@ -34,15 +34,13 @@
import org.drools.common.PropagationContextImpl;
import org.drools.common.ScheduledAgendaItem;
import org.drools.event.rule.ActivationCancelledCause;
+import org.drools.reteoo.RuleRemovalContext.CleanupAdapter;
import org.drools.reteoo.builder.BuildContext;
import org.drools.rule.GroupElement;
import org.drools.rule.Rule;
import org.drools.spi.Activation;
-import org.drools.spi.Duration;
import org.drools.spi.PropagationContext;
import org.drools.time.impl.Timer;
-import org.drools.util.Iterator;
-import org.drools.util.LeftTupleList;
/**
* Leaf Rete-OO node responsible for enacting <code>Action</code> s on a
@@ -174,7 +172,7 @@
final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
// if the current Rule is no-loop and the origin rule is the same then return
- if ( this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() ) ) {
+ if ( this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() ) ) {
agenda.increaseDormantActivations();
return;
}
@@ -187,13 +185,14 @@
this.rule,
this.subrule );
- agenda.scheduleItem( item, workingMemory );
+ agenda.scheduleItem( item,
+ workingMemory );
tuple.setActivation( item );
item.setActivated( true );
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
workingMemory );
- } else {
+ } else {
if ( this.rule.getCalendars() != null ) {
// for normal activations check for Calendar inclusion here, scheduled activations check on each trigger point
long timestamp = workingMemory.getSessionClock().getCurrentTime();
@@ -201,7 +200,7 @@
if ( !workingMemory.getCalendars().get( cal ).isTimeIncluded( timestamp ) ) {
return;
}
- }
+ }
}
// -----------------
// Lazy instantiation and addition to the Agenda of AgendGroup
@@ -269,7 +268,7 @@
context,
this.rule );
}
-
+
public void modifyLeftTuple(InternalFactHandle factHandle,
ModifyPreviousTuples modifyPreviousTuples,
PropagationContext context,
@@ -289,8 +288,8 @@
context,
workingMemory );
}
- }
-
+ }
+
public void modifyLeftTuple(LeftTuple leftTuple,
PropagationContext context,
InternalWorkingMemory workingMemory) {
@@ -300,8 +299,8 @@
workingMemory ) ) {
return;
}
-
- AgendaItem item = ( AgendaItem ) leftTuple.getActivation();
+
+ AgendaItem item = (AgendaItem) leftTuple.getActivation();
if ( item.isActivated() ) {
// already activated, do nothing
return;
@@ -311,19 +310,20 @@
// if the current Rule is no-loop and the origin rule is the same then return
if ( this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() ) ) {
- agenda.increaseDormantActivations();
- return;
- }
+ agenda.increaseDormantActivations();
+ return;
+ }
final Timer timer = this.rule.getTimer();
if ( timer != null ) {
- agenda.scheduleItem( ( ScheduledAgendaItem ) item, workingMemory );
+ agenda.scheduleItem( (ScheduledAgendaItem) item,
+ workingMemory );
item.setActivated( true );
-
+
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
workingMemory );
- } else {
+ } else {
if ( this.rule.getCalendars() != null ) {
// for normal activations check for Calendar inclusion here, scheduled activations check on each trigger point
long timestamp = workingMemory.getSessionClock().getCurrentTime();
@@ -331,9 +331,9 @@
if ( !workingMemory.getCalendars().get( cal ).isTimeIncluded( timestamp ) ) {
return;
}
- }
+ }
}
-
+
item.setSalience( rule.getSalience().getValue( leftTuple,
workingMemory ) ); // need to re-evaluate salience, as used fields may have changed
item.setPropagationContext( context ); // update the Propagation Context
@@ -349,11 +349,11 @@
}
}
- agenda.increaseActiveActivations();
- }
+ agenda.increaseActiveActivations();
+ }
public String toString() {
- return "[RuleTerminalNode("+this.getId()+"): rule=" + this.rule.getName() + "]";
+ return "[RuleTerminalNode(" + this.getId() + "): rule=" + this.rule.getName() + "]";
}
public void ruleAttached() {
@@ -387,49 +387,19 @@
final ReteooBuilder builder,
final BaseNode node,
final InternalWorkingMemory[] workingMemories) {
- // TODO: make this work of parent node's memory
-// for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
-// final InternalWorkingMemory workingMemory = workingMemories[i];
-//
-// final Iterator it = memory.getTupleMemory().iterator();
-// for ( LeftTuple leftTuple = (LeftTuple) it.next(); leftTuple != null; leftTuple = (LeftTuple) it.next() ) {
-// final Activation activation = leftTuple.getActivation();
-//
-// if ( activation.isActivated() ) {
-// activation.remove();
-// ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCancelled( activation,
-// workingMemory,
-// ActivationCancelledCause.CLEAR );
-// }
-//
-// final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
-// PropagationContext.RULE_REMOVAL,
-// null,
-// null,
-// null );
-// workingMemory.getTruthMaintenanceSystem().removeLogicalDependencies( activation,
-// propagationContext,
-// this.rule );
-// leftTuple.unlinkFromLeftParent();
-// leftTuple.unlinkFromRightParent();
-// }
-//
-// workingMemory.executeQueuedActions();
-// workingMemory.clearNodeMemory( this );
-// }
-
- if ( !context.alreadyVisited( this.tupleSource ) ) {
- this.tupleSource.remove( context,
- builder,
- this,
- workingMemories );
- }
+ CleanupAdapter adapter = context.getCleanupAdapter();
+ context.setCleanupAdapter( new RTNCleanupAdapter( this ) );
+ this.tupleSource.remove( context,
+ builder,
+ this,
+ workingMemories );
+ context.setCleanupAdapter( adapter );
}
public boolean isInUse() {
return false;
}
-
+
public boolean isLeftTupleMemoryEnabled() {
return tupleMemoryEnabled;
}
@@ -496,6 +466,37 @@
}
public Object createMemory(RuleBaseConfiguration config) {
- throw new UnsupportedOperationException( "RuleTerminalNodes do not have memory");
+ throw new UnsupportedOperationException( "RuleTerminalNodes do not have memory" );
}
+
+ public static class RTNCleanupAdapter implements CleanupAdapter {
+ private RuleTerminalNode node;
+
+ public RTNCleanupAdapter(RuleTerminalNode node) {
+ this.node = node;
+ }
+
+ public void cleanUp(final LeftTuple leftTuple,
+ final InternalWorkingMemory workingMemory) {
+ final Activation activation = leftTuple.getActivation();
+
+ if ( activation.isActivated() ) {
+ activation.remove();
+ ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCancelled( activation,
+ workingMemory,
+ ActivationCancelledCause.CLEAR );
+ }
+
+ final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
+ PropagationContext.RULE_REMOVAL,
+ null,
+ null,
+ null );
+ workingMemory.getTruthMaintenanceSystem().removeLogicalDependencies( activation,
+ propagationContext,
+ node.getRule() );
+ leftTuple.unlinkFromLeftParent();
+ leftTuple.unlinkFromRightParent();
+ }
+ }
}
More information about the jboss-svn-commits
mailing list