[jboss-svn-commits] JBL Code SVN: r31834 - in labs/jbossrules/branches/true_modify_20100215: drools-core/src/main/java/org/drools/reteoo and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Feb 25 00:05:58 EST 2010
Author: tirelli
Date: 2010-02-25 00:05:57 -0500 (Thu, 25 Feb 2010)
New Revision: 31834
Modified:
labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java
labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java
Log:
JBRULES-2339: JBRULES-2340: fixing tests
Modified: labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java 2010-02-24 17:15:27 UTC (rev 31833)
+++ labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java 2010-02-25 05:05:57 UTC (rev 31834)
@@ -620,7 +620,7 @@
wm.update( cheeseryHandle,
cheesery );
wm.fireAllRules();
-
+
// no fire
Assert.assertEquals( 1,
results.size() );
Modified: labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2010-02-24 17:15:27 UTC (rev 31833)
+++ labs/jbossrules/branches/true_modify_20100215/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2010-02-25 05:05:57 UTC (rev 31834)
@@ -91,9 +91,6 @@
import org.drools.Worker;
import org.drools.WorkingMemory;
import org.drools.Cheesery.Maturity;
-import org.drools.audit.WorkingMemoryConsoleLogger;
-import org.drools.audit.WorkingMemoryFileLogger;
-import org.drools.audit.WorkingMemoryInMemoryLogger;
import org.drools.base.ClassObjectType;
import org.drools.base.DroolsQuery;
import org.drools.builder.KnowledgeBuilder;
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2010-02-24 17:15:27 UTC (rev 31833)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2010-02-25 05:05:57 UTC (rev 31834)
@@ -357,9 +357,12 @@
accctx );
} else {
// we must re-add this to ensure deterministic iteration
+ LeftTuple temp = childLeftTuple.getLeftParentNext();
childLeftTuple.reAddLeft();
+ childLeftTuple = temp;
}
} else if ( childLeftTuple != null && childLeftTuple.getRightParent() == rightTuple ) {
+ LeftTuple temp = childLeftTuple.getLeftParentNext();
// remove the match
removeMatch( rightTuple,
childLeftTuple,
@@ -367,6 +370,7 @@
memory,
accctx,
false );
+ childLeftTuple = temp;
// the next line means that when a match is removed from the current leftTuple
// and the accumulate does not support the reverse operation, then the whole
// result is dirty (since removeMatch above is not recalculating the total)
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2010-02-24 17:15:27 UTC (rev 31833)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2010-02-25 05:05:57 UTC (rev 31834)
@@ -374,13 +374,17 @@
colctx );
} else {
// we must re-add this to ensure deterministic iteration
+ LeftTuple temp = childLeftTuple.getLeftParentNext();
childLeftTuple.reAddLeft();
+ childLeftTuple = temp;
}
} else if ( childLeftTuple != null && childLeftTuple.getRightParent() == rightTuple ) {
+ LeftTuple temp = childLeftTuple.getLeftParentNext();
// remove the match
removeMatch( rightTuple,
childLeftTuple,
colctx );
+ childLeftTuple = temp;
}
// else do nothing, was false before and false now.
}
Modified: labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java
===================================================================
--- labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java 2010-02-24 17:15:27 UTC (rev 31833)
+++ labs/jbossrules/branches/true_modify_20100215/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java 2010-02-25 05:05:57 UTC (rev 31834)
@@ -41,16 +41,19 @@
*
* @author etirelli
*/
-public class PropagationQueuingNode extends ObjectSource implements ObjectSinkNode, NodeMemory {
+public class PropagationQueuingNode extends ObjectSource
+ implements
+ ObjectSinkNode,
+ NodeMemory {
- private static final long serialVersionUID = -615639068150958767L;
+ private static final long serialVersionUID = -615639068150958767L;
// should we make this one configurable?
- private static final int PROPAGATION_SLICE_LIMIT = 1000;
+ private static final int PROPAGATION_SLICE_LIMIT = 1000;
- private ObjectSinkNode previousObjectSinkNode;
- private ObjectSinkNode nextObjectSinkNode;
- private PropagateAction action;
+ private ObjectSinkNode previousObjectSinkNode;
+ private ObjectSinkNode nextObjectSinkNode;
+ private PropagateAction action;
public PropagationQueuingNode() {
}
@@ -64,9 +67,9 @@
* @param objectSource Node's object source
* @param context
*/
- public PropagationQueuingNode( final int id,
- final ObjectSource objectSource,
- final BuildContext context ) {
+ public PropagationQueuingNode(final int id,
+ final ObjectSource objectSource,
+ final BuildContext context) {
super( id,
context.getPartitionId(),
context.getRuleBase().getConfiguration().isMultithreadEvaluation(),
@@ -75,14 +78,15 @@
this.action = new PropagateAction( this );
}
- public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
super.readExternal( in );
previousObjectSinkNode = (ObjectSinkNode) in.readObject();
nextObjectSinkNode = (ObjectSinkNode) in.readObject();
action = (PropagateAction) in.readObject();
}
- public void writeExternal( ObjectOutput out ) throws IOException {
+ public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal( out );
out.writeObject( previousObjectSinkNode );
out.writeObject( nextObjectSinkNode );
@@ -92,20 +96,21 @@
/**
* @see org.drools.reteoo.ObjectSource#updateSink(org.drools.reteoo.ObjectSink, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
*/
- public void updateSink( ObjectSink sink, PropagationContext context, InternalWorkingMemory workingMemory ) {
+ public void updateSink(ObjectSink sink,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory) {
- final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory
- .getNodeMemory( this );
+ final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory.getNodeMemory( this );
// this is just sanity code. We may remove it in the future, but keeping it for now.
- if( !memory.isEmpty() ) {
- throw new RuntimeDroolsException(
- "Error updating sink. Not safe to update sink as the PropagatingQueueingNode memory is not for node: " + this
- .toString() );
+ if ( !memory.isEmpty() ) {
+ throw new RuntimeDroolsException( "Error updating sink. Not safe to update sink as the PropagatingQueueingNode memory is not for node: " + this.toString() );
}
// as this node is simply a queue, ask object source to update the child sink directly
- this.source.updateSink( sink, context, workingMemory );
+ this.source.updateSink( sink,
+ context,
+ workingMemory );
}
/**
@@ -118,22 +123,27 @@
/**
* @see org.drools.common.BaseNode#attach(org.drools.common.InternalWorkingMemory[])
*/
- public void attach( InternalWorkingMemory[] workingMemories ) {
+ public void attach(InternalWorkingMemory[] workingMemories) {
attach();
// this node does not require update, so nothing else to do.
}
- protected void doRemove( final RuleRemovalContext context, final ReteooBuilder builder, final BaseNode node,
- final InternalWorkingMemory[] workingMemories ) {
- if( !node.isInUse() ) {
+ protected void doRemove(final RuleRemovalContext context,
+ final ReteooBuilder builder,
+ final BaseNode node,
+ final InternalWorkingMemory[] workingMemories) {
+ if ( !node.isInUse() ) {
removeObjectSink( (ObjectSink) node );
}
- if( !this.isInUse() ) {
- for( int i = 0, length = workingMemories.length; i < length; i++ ) {
+ if ( !this.isInUse() ) {
+ for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
workingMemories[i].clearNodeMemory( this );
}
}
- this.source.remove( context, builder, this, workingMemories );
+ this.source.remove( context,
+ builder,
+ this,
+ workingMemories );
}
/**
@@ -153,44 +163,64 @@
/**
* @see org.drools.reteoo.ObjectSinkNode#setNextObjectSinkNode(org.drools.reteoo.ObjectSinkNode)
*/
- public void setNextObjectSinkNode( ObjectSinkNode next ) {
+ public void setNextObjectSinkNode(ObjectSinkNode next) {
this.nextObjectSinkNode = next;
}
/**
* @see org.drools.reteoo.ObjectSinkNode#setPreviousObjectSinkNode(org.drools.reteoo.ObjectSinkNode)
*/
- public void setPreviousObjectSinkNode( ObjectSinkNode previous ) {
+ public void setPreviousObjectSinkNode(ObjectSinkNode previous) {
this.previousObjectSinkNode = previous;
}
+ public boolean isObjectMemoryEnabled() {
+ return true;
+ }
+
/**
* @see org.drools.reteoo.ObjectSink#assertObject(InternalFactHandle, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
*/
- public void assertObject( InternalFactHandle factHandle, PropagationContext context,
- InternalWorkingMemory workingMemory ) {
- final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory
- .getNodeMemory( this );
- memory.addAction( new AssertAction( factHandle, context ) );
+ public void assertObject(InternalFactHandle factHandle,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory) {
+ final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory.getNodeMemory( this );
+ memory.addAction( new AssertAction( factHandle,
+ context ) );
// if not queued yet, we need to queue it up
- if( memory.isQueued().compareAndSet( false, true ) ) {
+ if ( memory.isQueued().compareAndSet( false,
+ true ) ) {
workingMemory.queueWorkingMemoryAction( this.action );
}
}
- public boolean isObjectMemoryEnabled() {
- return true;
+ public void retractObject(InternalFactHandle handle,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory) {
+ final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory.getNodeMemory( this );
+ memory.addAction( new RetractAction( handle,
+ context ) );
+
+ // if not queued yet, we need to queue it up
+ if ( memory.isQueued().compareAndSet( false,
+ true ) ) {
+ workingMemory.queueWorkingMemoryAction( this.action );
+ }
}
- public void retractObject( InternalFactHandle handle, PropagationContext context,
- InternalWorkingMemory workingMemory ) {
- final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory
- .getNodeMemory( this );
- memory.addAction( new RetractAction( handle, context ) );
+ public void modifyObject(InternalFactHandle factHandle,
+ ModifyPreviousTuples modifyPreviousTuples,
+ PropagationContext context,
+ InternalWorkingMemory workingMemory) {
+ final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory.getNodeMemory( this );
+ memory.addAction( new ModifyAction( factHandle,
+ modifyPreviousTuples,
+ context ) );
// if not queued yet, we need to queue it up
- if( memory.isQueued().compareAndSet( false, true ) ) {
+ if ( memory.isQueued().compareAndSet( false,
+ true ) ) {
workingMemory.queueWorkingMemoryAction( this.action );
}
}
@@ -204,30 +234,32 @@
*
* @param workingMemory
*/
- public void propagateActions( InternalWorkingMemory workingMemory ) {
- final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory
- .getNodeMemory( this );
+ public void propagateActions(InternalWorkingMemory workingMemory) {
+ final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory.getNodeMemory( this );
// first we clear up the action queued flag
- memory.isQueued().compareAndSet( true, false );
+ memory.isQueued().compareAndSet( true,
+ false );
// we limit the propagation to avoid a hang when this queue is never empty
Action next = memory.getNext();
- for( int counter = 0; next != null && counter < PROPAGATION_SLICE_LIMIT; next = memory.getNext(), counter++ ) {
- next.execute( this.sink, workingMemory );
+ for ( int counter = 0; next != null && counter < PROPAGATION_SLICE_LIMIT; next = memory.getNext(), counter++ ) {
+ next.execute( this.sink,
+ workingMemory );
}
- if( memory.hasNext() && memory.isQueued().compareAndSet( false, true )) {
+ if ( memory.hasNext() && memory.isQueued().compareAndSet( false,
+ true ) ) {
// add action to the queue again.
workingMemory.queueWorkingMemoryAction( this.action );
}
}
- public void setObjectMemoryEnabled( boolean objectMemoryOn ) {
+ public void setObjectMemoryEnabled(boolean objectMemoryOn) {
throw new UnsupportedOperationException( "PropagationQueueingNode must have its node memory enabled." );
}
- public Object createMemory( RuleBaseConfiguration config ) {
+ public Object createMemory(RuleBaseConfiguration config) {
return new PropagationQueueingNodeMemory();
}
@@ -236,14 +268,16 @@
*
* @author etirelli
*/
- public static class PropagationQueueingNodeMemory implements Externalizable {
+ public static class PropagationQueueingNodeMemory
+ implements
+ Externalizable {
- private static final long serialVersionUID = 7372028632974484023L;
+ private static final long serialVersionUID = 7372028632974484023L;
private ConcurrentLinkedQueue<Action> queue;
// "singleton" action - there is one of this for each node in each working memory
- private AtomicBoolean isQueued;
+ private AtomicBoolean isQueued;
public PropagationQueueingNodeMemory() {
super();
@@ -251,12 +285,14 @@
this.isQueued = new AtomicBoolean( false );
}
- public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
+ @SuppressWarnings("unchecked")
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
queue = (ConcurrentLinkedQueue<Action>) in.readObject();
isQueued = (AtomicBoolean) in.readObject();
}
- public void writeExternal( ObjectOutput out ) throws IOException {
+ public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject( queue );
out.writeObject( isQueued );
}
@@ -265,7 +301,7 @@
return this.queue.isEmpty();
}
- public void addAction( Action action ) {
+ public void addAction(Action action) {
this.queue.add( action );
}
@@ -280,13 +316,15 @@
public AtomicBoolean isQueued() {
return isQueued;
}
-
+
public long getSize() {
return this.queue.size();
}
}
- private static abstract class Action implements Externalizable {
+ private static abstract class Action
+ implements
+ Externalizable {
protected InternalFactHandle handle;
protected PropagationContext context;
@@ -295,34 +333,42 @@
}
- public Action( InternalFactHandle handle, PropagationContext context ) {
+ public Action(InternalFactHandle handle,
+ PropagationContext context) {
super();
this.handle = handle;
this.context = context;
}
- public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
handle = (InternalFactHandle) in.readObject();
context = (PropagationContext) in.readObject();
}
- public void writeExternal( ObjectOutput out ) throws IOException {
+ public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject( handle );
out.writeObject( context );
}
- public abstract void execute( final ObjectSinkPropagator sink, final InternalWorkingMemory workingMemory );
+ public abstract void execute(final ObjectSinkPropagator sink,
+ final InternalWorkingMemory workingMemory);
}
private static class AssertAction extends Action {
private static final long serialVersionUID = -8478488926430845209L;
- public AssertAction( final InternalFactHandle handle, final PropagationContext context ) {
- super( handle, context );
+ public AssertAction(final InternalFactHandle handle,
+ final PropagationContext context) {
+ super( handle,
+ context );
}
- public void execute( final ObjectSinkPropagator sink, final InternalWorkingMemory workingMemory ) {
- sink.propagateAssertObject( this.handle, this.context, workingMemory );
+ public void execute(final ObjectSinkPropagator sink,
+ final InternalWorkingMemory workingMemory) {
+ sink.propagateAssertObject( this.handle,
+ this.context,
+ workingMemory );
}
}
@@ -333,35 +379,63 @@
}
- public RetractAction( final InternalFactHandle handle, final PropagationContext context ) {
- super( handle, context );
+ public RetractAction(final InternalFactHandle handle,
+ final PropagationContext context) {
+ super( handle,
+ context );
}
- public void execute( final ObjectSinkPropagator sink, final InternalWorkingMemory workingMemory ) {
+ public void execute(final ObjectSinkPropagator sink,
+ final InternalWorkingMemory workingMemory) {
- for( RightTuple rightTuple = this.handle
- .getFirstRightTuple(); rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandleNext() ) {
- rightTuple.getRightTupleSink().retractRightTuple( rightTuple, context, workingMemory );
+ for ( RightTuple rightTuple = this.handle.getFirstRightTuple(); rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandleNext() ) {
+ rightTuple.getRightTupleSink().retractRightTuple( rightTuple,
+ context,
+ workingMemory );
}
this.handle.setFirstRightTuple( null );
- for( LeftTuple leftTuple = this.handle.getLastLeftTuple(); leftTuple != null; leftTuple = (LeftTuple) leftTuple
- .getLeftParentNext() ) {
- leftTuple.getLeftTupleSink().retractLeftTuple( leftTuple, context, workingMemory );
+ for ( LeftTuple leftTuple = this.handle.getLastLeftTuple(); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
+ leftTuple.getLeftTupleSink().retractLeftTuple( leftTuple,
+ context,
+ workingMemory );
}
this.handle.setFirstLeftTuple( null );
}
}
+ private static class ModifyAction extends Action {
+ private static final long serialVersionUID = -8478488926430845209L;
+ private ModifyPreviousTuples modifyPreviousTuples;
+
+ public ModifyAction(final InternalFactHandle handle,
+ final ModifyPreviousTuples modifyPreviousTuples,
+ final PropagationContext context) {
+ super( handle,
+ context );
+ this.modifyPreviousTuples = modifyPreviousTuples;
+ }
+
+ public void execute(final ObjectSinkPropagator sink,
+ final InternalWorkingMemory workingMemory) {
+ sink.propagateModifyObject( handle,
+ modifyPreviousTuples,
+ context,
+ workingMemory );
+ }
+ }
+
/**
* This is the action that is added to the working memory actions queue, so that
* this node propagation can be triggered at a safe point
*
* @author etirelli
*/
- public static class PropagateAction implements WorkingMemoryAction {
+ public static class PropagateAction
+ implements
+ WorkingMemoryAction {
- private static final long serialVersionUID = 6765029029501617115L;
+ private static final long serialVersionUID = 6765029029501617115L;
private PropagationQueuingNode node;
@@ -369,37 +443,31 @@
}
- public PropagateAction( PropagationQueuingNode node ) {
+ public PropagateAction(PropagationQueuingNode node) {
this.node = node;
}
- public PropagateAction( MarshallerReaderContext context ) throws IOException {
+ public PropagateAction(MarshallerReaderContext context) throws IOException {
this.node = (PropagationQueuingNode) context.sinks.get( context.readInt() );
}
- public void write( MarshallerWriteContext context ) throws IOException {
- context.writeInt( WorkingMemoryAction.PropagateAction );
+ public void write(MarshallerWriteContext context) throws IOException {
+ context.writeInt( WorkingMemoryAction.PropagateAction );
context.write( node.getId() );
}
- public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
node = (PropagationQueuingNode) in.readObject();
}
- public void writeExternal( ObjectOutput out ) throws IOException {
+ public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject( node );
}
- public void execute( InternalWorkingMemory workingMemory ) {
+ public void execute(InternalWorkingMemory workingMemory) {
this.node.propagateActions( workingMemory );
}
}
- public void modifyObject(InternalFactHandle factHandle,
- ModifyPreviousTuples modifyPreviousTuples,
- PropagationContext context,
- InternalWorkingMemory workingMemory) {
- // TODO Auto-generated method stub
-
- }
}
More information about the jboss-svn-commits
mailing list