From: <jbo...@li...> - 2006-04-27 11:58:25
|
Author: mar...@jb... Date: 2006-04-27 07:58:15 -0400 (Thu, 27 Apr 2006) New Revision: 3994 Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java Log: JBRULES-245 Not with Logical Assertions is invalidating the WorkingMemory propagation -I've added a queue now. So retractions due to logical assertions will not take place until the last WMA is finished. Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java =================================================================== --- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java 2006-04-27 10:10:38 UTC (rev 3993) +++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java 2006-04-27 11:58:15 UTC (rev 3994) @@ -117,8 +117,6 @@ private final WorkingMemoryEventSupport workingMemoryEventSupport = new WorkingMemoryEventSupport( this ); private final AgendaEventSupport agendaEventSupport = new AgendaEventSupport( this ); - //private LinkedList factQueue = new LinkedList(); - private ReentrantLock lock = new ReentrantLock(); /** The <code>RuleBase</code> with which this memory is associated. */ @@ -133,6 +131,8 @@ private boolean firing; private long propagationIdCounter; + + private List factQueue = new ArrayList(); // ------------------------------------------------------------ // Constructors @@ -525,6 +525,9 @@ this.workingMemoryEventSupport.fireObjectAsserted( propagationContext, handle, object ); + + propagateQueuedActions(); + return handle; } finally { this.lock.unlock(); @@ -666,6 +669,8 @@ oldObject ); ((FactHandleImpl) handle).invalidate(); + + propagateQueuedActions(); } finally { this.lock.unlock(); } @@ -732,10 +737,22 @@ handle, originalObject, object ); + + propagateQueuedActions(); } finally { this.lock.unlock(); } } + + private void propagateQueuedActions() { + for ( Iterator it = this.factQueue.iterator(); it.hasNext(); ) { + WorkingMemoryAction action = (WorkingMemoryAction) it.next(); + it.remove(); + action.propagate(); + } + + + } /** * Retrieve the <code>JoinMemory</code> for a particular @@ -813,11 +830,12 @@ set.remove( node ); if ( set.isEmpty() ) { this.justified.remove( handle.getId() ); - retractObject( handle, - false, - true, - context.getRuleOrigin(), - context.getActivationOrigin() ); + // this needs to be scheduled so we don't upset the current working memory operation + this.factQueue.add( new WorkingMemoryRetractAction( handle, + false, + true, + context.getRuleOrigin(), + context.getActivationOrigin() ) ); } } } @@ -863,7 +881,42 @@ public Lock getLock() { return this.lock; } + + private interface WorkingMemoryAction { + public void propagate(); + } + + private class WorkingMemoryRetractAction implements WorkingMemoryAction { + private InternalFactHandle factHandle; + private boolean removeLogical; + private boolean updateEqualsMap; + private Rule ruleOrigin; + private Activation activationOrigin; + + + + public WorkingMemoryRetractAction(InternalFactHandle factHandle, + boolean removeLogical, + boolean updateEqualsMap, + Rule ruleOrigin, + Activation activationOrigin) { + super(); + this.factHandle = factHandle; + this.removeLogical = removeLogical; + this.updateEqualsMap = updateEqualsMap; + this.ruleOrigin = ruleOrigin; + this.activationOrigin = activationOrigin; + } + public void propagate() { + retractObject( this.factHandle, + this.removeLogical, + this.updateEqualsMap, + this.ruleOrigin, + this.activationOrigin ); + } + } + private static class FactStatus { private int counter; private String status; |