[jboss-svn-commits] JBL Code SVN: r9431 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/common and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Feb 10 22:46:51 EST 2007


Author: mark.proctor at jboss.com
Date: 2007-02-10 22:46:51 -0500 (Sat, 10 Feb 2007)
New Revision: 9431

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java
Log:
JBRULES-662 Make the TMS optional

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2007-02-11 03:15:11 UTC (rev 9430)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2007-02-11 03:46:51 UTC (rev 9431)
@@ -56,7 +56,8 @@
     private static final long serialVersionUID = 320L;
 
     private boolean           immutable;
-
+    
+    private boolean           maintainTms;    
     private boolean           removeIdentities;
     private boolean           shareAlphaNodes;
     private boolean           shareBetaNodes;
@@ -71,6 +72,9 @@
     public RuleBaseConfiguration() {
         this.immutable = false;
 
+        setMaintainTms( Boolean.valueOf( System.getProperty( "drools.maintainTms",
+                             "true" ) ).booleanValue() );
+        
         setRemoveIdentities( Boolean.valueOf( System.getProperty( "drools.removeIdentities",
                                                                   "false" ) ).booleanValue() );
         
@@ -116,19 +120,30 @@
     public boolean isImmutable() {
         return this.immutable;
     }
+    
+    private void checkCanChange() {
+        if ( this.immutable ) {
+            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
+        }
+    }
         
     
+    public boolean getMaintainTms() {
+        return this.maintainTms;
+    }
     
+    public void setMaintainTms(boolean maintainTms) {
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.maintainTms = maintainTms;
+    }
+            
     public boolean isRemoveIdentities() {
         return removeIdentities;
     }
 
     public void setRemoveIdentities(boolean removeIdentities) {
-        if ( !this.immutable ) {
-            this.removeIdentities = removeIdentities;
-        } else {
-            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
-        }
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.removeIdentities = removeIdentities;        
     }
 
     public boolean isAlphaMemory() {
@@ -136,11 +151,8 @@
     }
 
     public void setAlphaMemory(boolean alphaMemory) {
-        if ( !this.immutable ) {
-            this.alphaMemory = alphaMemory;
-        } else {
-            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
-        }
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.alphaMemory = alphaMemory;
     }
 
     public boolean isShareAlphaNodes() {
@@ -148,11 +160,8 @@
     }
 
     public void setShareAlphaNodes(boolean shareAlphaNodes) {
-        if ( !this.immutable ) {
-            this.shareAlphaNodes = shareAlphaNodes;
-        } else {
-            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
-        }
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.shareAlphaNodes = shareAlphaNodes;
     }
 
     public boolean isShareBetaNodes() {
@@ -160,11 +169,8 @@
     }
 
     public void setShareBetaNodes(boolean shareBetaNodes) {
-        if ( !this.immutable ) {
-            this.shareBetaNodes = shareBetaNodes;
-        } else {
-            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
-        }
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.shareBetaNodes = shareBetaNodes;        
     }
 
     public int getAlphaNodeHashingThreshold() {
@@ -172,11 +178,8 @@
     }
 
     public void setAlphaNodeHashingThreshold(int alphaNodeHashingThreshold) {
-        if ( !this.immutable ) {
-            this.alphaNodeHashingThreshold = alphaNodeHashingThreshold;
-        } else {
-            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
-        }
+        checkCanChange(); // throws an exception if a change isn't possible;        
+        this.alphaNodeHashingThreshold = alphaNodeHashingThreshold;
     }
 
     public AssertBehaviour getAssertBehaviour() {
@@ -184,11 +187,8 @@
     }
 
     public void setAssertBehaviour(AssertBehaviour assertBehaviour) {
-        if ( !this.immutable ) {
-            this.assertBehaviour = assertBehaviour;
-        } else {
-            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
-        }
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.assertBehaviour = assertBehaviour;
     }
 
     public int getCompositeKeyDepth() {
@@ -211,23 +211,17 @@
     }
 
     public void setIndexLeftBetaMemory(boolean indexLeftBetaMemory) {
-        if ( !this.immutable ) {
-            this.indexLeftBetaMemory = indexLeftBetaMemory;
-        } else {
-            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
-        }
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.indexLeftBetaMemory = indexLeftBetaMemory;
     }
 
     public boolean isIndexRightBetaMemory() {
         return indexRightBetaMemory;
     }
 
-    public void setIndexRightBetaMemory(boolean indexRightBetaMemory) {
-        if ( !this.immutable ) {
-            this.indexRightBetaMemory = indexRightBetaMemory;
-        } else {
-            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
-        }
+    public void setIndexRightBetaMemory(boolean indexRightBetaMemory) {        
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.indexRightBetaMemory = indexRightBetaMemory;
     }
 
     public LogicalOverride getLogicalOverride() {
@@ -235,11 +229,8 @@
     }
 
     public void setLogicalOverride(LogicalOverride logicalOverride) {
-        if ( !this.immutable ) {
-            this.logicalOverride = logicalOverride;
-        } else {
-            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
-        }
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.logicalOverride = logicalOverride;
     }
 
     public static class AssertBehaviour

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-02-11 03:15:11 UTC (rev 9430)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-02-11 03:46:51 UTC (rev 9431)
@@ -117,13 +117,15 @@
     /** Rule-firing agenda. */
     protected DefaultAgenda                   agenda;
 
-    protected final List                      factQueue                                     = new ArrayList();   
+    protected final List                      factQueue                                     = new ArrayList();
 
     protected final ReentrantLock             lock                                          = new ReentrantLock();
 
     protected final boolean                   discardOnLogicalOverride;
 
     protected long                            propagationIdCounter;
+    
+    private final boolean                     maintainTms;
 
     /** Flag to determine if a rule is currently being fired. */
     protected boolean                         firing;
@@ -144,16 +146,21 @@
         this.id = id;
         this.ruleBase = ruleBase;
         this.handleFactory = handleFactory;
-        this.tms = new TruthMaintenanceSystem( this );
+        this.maintainTms = this.ruleBase.getConfiguration().getMaintainTms();
+        
+        if ( this.maintainTms ) {
+            this.tms = new TruthMaintenanceSystem( this );
+        } else {
+            this.tms = null;
+        }
+        
         this.assertMap = new ObjectHashMap();
         final RuleBaseConfiguration conf = this.ruleBase.getConfiguration();
-        
-        
-        
+
         if ( conf.getAssertBehaviour() == AssertBehaviour.IDENTITY ) {
-            this.assertMap.setComparator( new IdentityAssertMapComparator( ) );
+            this.assertMap.setComparator( new IdentityAssertMapComparator() );
         } else {
-            this.assertMap.setComparator( new EqualityAssertMapComparator( ) );
+            this.assertMap.setComparator( new EqualityAssertMapComparator() );
         }
 
         // Only takes effect if are using idententity behaviour for assert        
@@ -343,22 +350,22 @@
         if ( !this.factQueue.isEmpty() ) {
             propagateQueuedActions();
         }
-        
+
         boolean noneFired = true;
 
         if ( !this.firing ) {
             try {
                 this.firing = true;
-                
+
                 while ( this.agenda.fireNextItem( agendaFilter ) ) {
-                    noneFired = false;                    
+                    noneFired = false;
                 }
             } finally {
                 this.firing = false;
-                if (noneFired) {
-                    doOtherwise(agendaFilter);
+                if ( noneFired ) {
+                    doOtherwise( agendaFilter );
                 }
-                
+
             }
         }
     }
@@ -373,42 +380,41 @@
         if ( !this.factQueue.isEmpty() ) {
             propagateQueuedActions();
         }
-        
+
         while ( this.agenda.fireNextItem( agendaFilter ) ) {
             ;
         }
-        
+
         this.retractObject( handle );
     }
 
+    //
+    //        MN: The following is the traditional fireAllRules (without otherwise).
+    //            Purely kept here as this implementation of otherwise is still experimental.    
+    //    
+    //    public synchronized void fireAllRules(final AgendaFilter agendaFilter) throws FactException {
+    //        // If we're already firing a rule, then it'll pick up
+    //        // the firing for any other assertObject(..) that get
+    //        // nested inside, avoiding concurrent-modification
+    //        // exceptions, depending on code paths of the actions.
+    //
+    //        if ( !this.factQueue.isEmpty() ) {
+    //            propagateQueuedActions();
+    //        }
+    //
+    //        if ( !this.firing ) {
+    //            try {
+    //                this.firing = true;
+    //
+    //                while ( this.agenda.fireNextItem( agendaFilter ) ) {
+    //                    ;
+    //                }
+    //            } finally {
+    //                this.firing = false;
+    //            }
+    //        }
+    //    }    
 
-//
-//        MN: The following is the traditional fireAllRules (without otherwise).
-//            Purely kept here as this implementation of otherwise is still experimental.    
-//    
-//    public synchronized void fireAllRules(final AgendaFilter agendaFilter) throws FactException {
-//        // If we're already firing a rule, then it'll pick up
-//        // the firing for any other assertObject(..) that get
-//        // nested inside, avoiding concurrent-modification
-//        // exceptions, depending on code paths of the actions.
-//
-//        if ( !this.factQueue.isEmpty() ) {
-//            propagateQueuedActions();
-//        }
-//
-//        if ( !this.firing ) {
-//            try {
-//                this.firing = true;
-//
-//                while ( this.agenda.fireNextItem( agendaFilter ) ) {
-//                    ;
-//                }
-//            } finally {
-//                this.firing = false;
-//            }
-//        }
-//    }    
-
     /**
      * Returns the fact Object for the given <code>FactHandle</code>. It
      * actually attemps to return the value from the handle, before retrieving
@@ -424,19 +430,19 @@
     public Object getObject(final FactHandle handle) {
         try {
             this.lock.lock();
-                        
+
             // Make sure the FactHandle is from this WorkingMemory
-            InternalFactHandle internalHandle = ( InternalFactHandle ) this.assertMap.get( handle );
+            InternalFactHandle internalHandle = (InternalFactHandle) this.assertMap.get( handle );
             if ( internalHandle == null ) {
                 return null;
             }
-            
+
             Object object = internalHandle.getObject();
-            
+
             if ( object != null && internalHandle.isShadowFact() ) {
-                object = ( (ShadowProxy) object ).getShadowedObject();
+                object = ((ShadowProxy) object).getShadowedObject();
             }
-        
+
             return object;
         } finally {
             this.lock.unlock();
@@ -463,10 +469,10 @@
             this.lock.lock();
             List list = new ArrayList( this.assertMap.size() );
             org.drools.util.Iterator it = this.assertMap.iterator();
-            for ( ObjectEntry entry = ( ObjectEntry ) it.next(); entry != null; entry = ( ObjectEntry ) it.next() ) {
-                list.add ( entry.getKey() );
+            for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
+                list.add( entry.getKey() );
             }
-            return list; 
+            return list;
         } finally {
             this.lock.unlock();
         }
@@ -490,9 +496,9 @@
         final List list = new ArrayList( this.assertMap.size() );
 
         org.drools.util.Iterator it = this.assertMap.iterator();
-        for ( ObjectEntry entry = (ObjectEntry)it.next(); entry != null; entry = (ObjectEntry)it.next() ) {
-            InternalFactHandle  handle  = (InternalFactHandle) entry.getKey();
-            Object object = ( handle.isShadowFact() ) ? ((ShadowProxy)handle.getObject()).getShadowedObject() : handle.getObject();
+        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
+            InternalFactHandle handle = (InternalFactHandle) entry.getKey();
+            Object object = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
             list.add( object );
         }
         return list;
@@ -502,12 +508,12 @@
         final List list = new ArrayList( this.assertMap.size() );
 
         org.drools.util.Iterator it = this.assertMap.iterator();
-        for ( ObjectEntry entry = (ObjectEntry)it.next(); entry != null; entry = (ObjectEntry)it.next() ) {
-            InternalFactHandle  handle  = (InternalFactHandle) entry.getKey();
-            Object object = ( handle.isShadowFact() ) ? ((ShadowProxy)handle.getObject()).getShadowedObject() : handle.getObject();
+        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
+            InternalFactHandle handle = (InternalFactHandle) entry.getKey();
+            Object object = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
             if ( objectClass.isInstance( object ) ) {
                 list.add( object );
-            }       
+            }
         }
         return list;
     }
@@ -585,108 +591,120 @@
             // check if the object already exists in the WM
             handle = (InternalFactHandle) this.assertMap.get( object );
 
-            EqualityKey key = null;
+            if ( this.maintainTms ) {
 
-            if ( handle == null ) {
-                // lets see if the object is already logical asserted
-                key = this.tms.get( object );
-            } else {
-                // Object is already asserted, so check and possibly correct its
-                // status and then return the handle
-                key = handle.getEqualityKey();
+                EqualityKey key = null;
 
-                if ( key.getStatus() == EqualityKey.STATED ) {
-                    // return null as you cannot justify a stated object.
-                    return handle;
-                }
-
-                if ( !logical ) {
-                    // this object was previously justified, so we have to
-                    // override it to stated
-                    key.setStatus( EqualityKey.STATED );
-                    this.tms.removeLogicalDependencies( handle );
+                if ( handle == null ) {
+                    // lets see if the object is already logical asserted
+                    key = this.tms.get( object );
                 } else {
-                    // this was object is already justified, so just add new
-                    // logical dependency
-                    this.tms.addLogicalDependency( handle,
-                                                   activation,
-                                                   activation.getPropagationContext(),
-                                                   rule );
-                }
+                    // Object is already asserted, so check and possibly correct its
+                    // status and then return the handle
+                    key = handle.getEqualityKey();
 
-                return handle;
-            }
+                    if ( key.getStatus() == EqualityKey.STATED ) {
+                        // return null as you cannot justify a stated object.
+                        return handle;
+                    }
 
-            // At this point we know the handle is null
-            if ( key == null ) {
-                // key is also null, so treat as a totally new stated/logical
-                // assert
-                handle = this.handleFactory.newFactHandle( object );
-                this.assertMap.put( handle,
-                                    handle,
-                                    false );
-                key = new EqualityKey( handle );
-                handle.setEqualityKey( key );
-                this.tms.put( key );
-                if ( !logical ) {
-                    key.setStatus( EqualityKey.STATED );
-                } else {
-                    key.setStatus( EqualityKey.JUSTIFIED );
-                    this.tms.addLogicalDependency( handle,
-                                                   activation,
-                                                   activation.getPropagationContext(),
-                                                   rule );
+                    if ( !logical ) {
+                        // this object was previously justified, so we have to
+                        // override it to stated
+                        key.setStatus( EqualityKey.STATED );
+                        this.tms.removeLogicalDependencies( handle );
+                    } else {
+                        // this was object is already justified, so just add new
+                        // logical dependency
+                        this.tms.addLogicalDependency( handle,
+                                                       activation,
+                                                       activation.getPropagationContext(),
+                                                       rule );
+                    }
+
+                    return handle;
                 }
-            } else if ( !logical ) {
-                if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
-                    // Its previous justified, so switch to stated and remove
-                    // logical dependencies
-                    final InternalFactHandle justifiedHandle = key.getFactHandle();
-                    this.tms.removeLogicalDependencies( justifiedHandle );
 
-                    if ( this.discardOnLogicalOverride ) {
-                        // override, setting to new instance, and return
-                        // existing handle
+                // At this point we know the handle is null
+                if ( key == null ) {
+                    // key is also null, so treat as a totally new stated/logical
+                    // assert
+                    handle = this.handleFactory.newFactHandle( object );
+                    this.assertMap.put( handle,
+                                        handle,
+                                        false );
+                    key = new EqualityKey( handle );
+                    handle.setEqualityKey( key );
+                    this.tms.put( key );
+                    if ( !logical ) {
                         key.setStatus( EqualityKey.STATED );
-                        handle = key.getFactHandle();
-                        handle.setObject( object );
-                        return handle;
                     } else {
-                        // override, then instantiate new handle for assertion
-                        key.setStatus( EqualityKey.STATED );
+                        key.setStatus( EqualityKey.JUSTIFIED );
+                        this.tms.addLogicalDependency( handle,
+                                                       activation,
+                                                       activation.getPropagationContext(),
+                                                       rule );
+                    }
+                } else if ( !logical ) {
+                    if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
+                        // Its previous justified, so switch to stated and remove
+                        // logical dependencies
+                        final InternalFactHandle justifiedHandle = key.getFactHandle();
+                        this.tms.removeLogicalDependencies( justifiedHandle );
+
+                        if ( this.discardOnLogicalOverride ) {
+                            // override, setting to new instance, and return
+                            // existing handle
+                            key.setStatus( EqualityKey.STATED );
+                            handle = key.getFactHandle();
+                            handle.setObject( object );
+                            return handle;
+                        } else {
+                            // override, then instantiate new handle for assertion
+                            key.setStatus( EqualityKey.STATED );
+                            handle = this.handleFactory.newFactHandle( object );
+                            handle.setEqualityKey( key );
+                            key.addFactHandle( handle );
+                            this.assertMap.put( handle,
+                                                handle,
+                                                false );
+                        }
+
+                    } else {
                         handle = this.handleFactory.newFactHandle( object );
-                        handle.setEqualityKey( key );
-                        key.addFactHandle( handle );
                         this.assertMap.put( handle,
                                             handle,
                                             false );
+                        key.addFactHandle( handle );
+                        handle.setEqualityKey( key );
                     }
 
                 } else {
-                    handle = this.handleFactory.newFactHandle( object );
-                    this.assertMap.put( handle,
-                                        handle,
-                                        false );
-                    key.addFactHandle( handle );
-                    handle.setEqualityKey( key );
+                    if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
+                        // only add as logical dependency if this wasn't previously
+                        // stated
+                        this.tms.addLogicalDependency( key.getFactHandle(),
+                                                       activation,
+                                                       activation.getPropagationContext(),
+                                                       rule );
+                        return key.getFactHandle();
+                    } else {
+                        // You cannot justify a previously stated equality equal
+                        // object, so return null
+                        return null;
+                    }
                 }
 
             } else {
-                if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
-                    // only add as logical dependency if this wasn't previously
-                    // stated
-                    this.tms.addLogicalDependency( key.getFactHandle(),
-                                                   activation,
-                                                   activation.getPropagationContext(),
-                                                   rule );
-                    return key.getFactHandle();
-                } else {
-                    // You cannot justify a previously stated equality equal
-                    // object, so return null
-                    return null;
+                if ( handle != null ) {
+                    return handle;
                 }
+                handle = this.handleFactory.newFactHandle( object );
+                this.assertMap.put( handle,
+                                    handle,
+                                    false );
             }
-
+            
             if ( dynamic ) {
                 addPropertyChangeListener( object );
             }
@@ -694,7 +712,9 @@
             final PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++,
                                                                                       PropagationContext.ASSERTION,
                                                                                       rule,
-                                                                                      activation );
+                                                                                      activation,
+                                                                                      this.agenda.getActiveActivations(),
+                                                                                      this.agenda.getDormantActivations() );
 
             // this.ruleBase.assertObject( handle,
             // object,
@@ -750,7 +770,7 @@
         try {
             object = getObject( handle );
 
-            if(object != null) {
+            if ( object != null ) {
                 final Method mehod = object.getClass().getMethod( "removePropertyChangeListener",
                                                                   AbstractWorkingMemory.ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES );
 
@@ -831,29 +851,33 @@
             final PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++,
                                                                                       PropagationContext.RETRACTION,
                                                                                       rule,
-                                                                                      activation );
+                                                                                      activation,
+                                                                                      this.agenda.getActiveActivations(),
+                                                                                      this.agenda.getDormantActivations() );
 
             doRetract( handle,
                        propagationContext );
 
-            // Update the equality key, which maintains a list of stated
-            // FactHandles
-            final EqualityKey key = handle.getEqualityKey();
-
-            // Its justified so attempt to remove any logical dependencies for
-            // the handle
-            if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
-                this.tms.removeLogicalDependencies( handle );
+            if ( this.maintainTms ) {
+                // Update the equality key, which maintains a list of stated
+                // FactHandles
+                final EqualityKey key = handle.getEqualityKey();
+    
+                // Its justified so attempt to remove any logical dependencies for
+                // the handle
+                if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
+                    this.tms.removeLogicalDependencies( handle );
+                }
+    
+                key.removeFactHandle( handle );
+                handle.setEqualityKey( null );
+    
+                // If the equality key is now empty, then remove it
+                if ( key.isEmpty() ) {
+                    this.tms.remove( key );
+                }
             }
 
-            key.removeFactHandle( handle );
-            handle.setEqualityKey( null );
-
-            // If the equality key is now empty, then remove it
-            if ( key.isEmpty() ) {
-                this.tms.remove( key );
-            }
-
             final Object object = handle.getObject();
 
             this.workingMemoryEventSupport.fireObjectRetracted( propagationContext,
@@ -892,9 +916,13 @@
                              final Activation activation) throws FactException {
         try {
             this.lock.lock();
-            final int status = ((InternalFactHandle) factHandle).getEqualityKey().getStatus();
+            // only needed if we maintain tms, but either way we must get it before we do the retract
+            int status = -1;
+            if ( this.maintainTms ) {
+                status = ((InternalFactHandle) factHandle).getEqualityKey().getStatus();
+            }
             final InternalFactHandle handle = (InternalFactHandle) factHandle;
-            final Object originalObject = ( handle.isShadowFact() ) ? ((ShadowProxy)handle.getObject()).getShadowedObject() : handle.getObject();
+            final Object originalObject = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
 
             if ( handle.getId() == -1 || object == null ) {
                 // the handle is invalid, most likely already  retracted, so return
@@ -906,40 +934,44 @@
             final PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++,
                                                                                       PropagationContext.MODIFICATION,
                                                                                       rule,
-                                                                                      activation );
+                                                                                      activation,
+                                                                                      this.agenda.getActiveActivations(),
+                                                                                      this.agenda.getDormantActivations() );
             doRetract( handle,
-                       propagationContext );            
-            
+                       propagationContext );
+
             // set anyway, so that it updates the hashCodes
             handle.setObject( object );
 
-            // We only need to put objects, if its a new object
-            if ( originalObject != object ) {
-                this.assertMap.put( handle,
-                                    handle );
+            if ( this.maintainTms ) {            
+                // We only need to put objects, if its a new object
+                if ( originalObject != object ) {
+                    this.assertMap.put( handle,
+                                        handle );
+                }
+    
+                // the hashCode and equality has changed, so we must update the EqualityKey
+                EqualityKey key = handle.getEqualityKey();
+                key.removeFactHandle( handle );
+    
+                // If the equality key is now empty, then remove it
+                if ( key.isEmpty() ) {
+                    this.tms.remove( key );
+                }
+    
+                // now use an  existing  EqualityKey, if it exists, else create a new one
+                key = this.tms.get( object );
+                if ( key == null ) {
+                    key = new EqualityKey( handle,
+                                           status );
+                    this.tms.put( key );
+                } else {
+                    key.addFactHandle( handle );
+                }
+    
+                handle.setEqualityKey( key );
             }
 
-            // the hashCode and equality has changed, so we must update the EqualityKey
-            EqualityKey key = handle.getEqualityKey();
-            key.removeFactHandle( handle );
-
-            // If the equality key is now empty, then remove it
-            if ( key.isEmpty() ) {
-                this.tms.remove( key );
-            }
-
-            // now use an  existing  EqualityKey, if it exists, else create a new one
-            key = this.tms.get( object );
-            if ( key == null ) {
-                key = new EqualityKey( handle,
-                                       status );
-                this.tms.put( key );
-            } else {
-                key.addFactHandle( handle );
-            }
-
-            handle.setEqualityKey( key );
-
             this.handleFactory.increaseFactHandleRecency( handle );
 
             doAssertObject( handle,
@@ -983,6 +1015,14 @@
                                                                   ruleOrigin,
                                                                   activationOrigin ) );
     }
+    
+    public void removeLogicalDependencies(final Activation activation,
+                                          final PropagationContext context,
+                                          final Rule rule) throws FactException {
+        if ( this.maintainTms ) {
+            this.tms.removeLogicalDependencies( activation, context, rule );
+        }
+    }
 
     /**
      * Retrieve the <code>JoinMemory</code> for a particular
@@ -1008,8 +1048,8 @@
 
     public void clearNodeMemory(final NodeMemory node) {
         this.nodeMemories.remove( node.getId() );
-    }  
-    
+    }
+
     public WorkingMemoryEventSupport getWorkingMemoryEventSupport() {
         return this.workingMemoryEventSupport;
     }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2007-02-11 03:15:11 UTC (rev 9430)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2007-02-11 03:46:51 UTC (rev 9431)
@@ -2,9 +2,13 @@
 
 import java.util.Map;
 
+import org.drools.FactException;
 import org.drools.WorkingMemory;
 import org.drools.event.AgendaEventSupport;
+import org.drools.rule.Rule;
+import org.drools.spi.Activation;
 import org.drools.spi.FactHandleFactory;
+import org.drools.spi.PropagationContext;
 import org.drools.util.ObjectHashMap;
 
 public interface InternalWorkingMemory
@@ -27,4 +31,8 @@
     public void propagateQueuedActions();
 
     public FactHandleFactory getFactHandleFactory();
+    
+    public void removeLogicalDependencies(final Activation activation,
+                                          final PropagationContext context,
+                                          final Rule rule) throws FactException;
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2007-02-11 03:15:11 UTC (rev 9430)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2007-02-11 03:46:51 UTC (rev 9431)
@@ -255,8 +255,8 @@
                                                                              workingMemory );
             }
         }
-        
-        agenda.increaseActiveActivations();        
+
+        agenda.increaseActiveActivations();
     }
 
     public void retractTuple(final ReteTuple leftTuple,
@@ -274,14 +274,14 @@
 
             workingMemory.getAgendaEventSupport().fireActivationCancelled( activation,
                                                                            workingMemory );
-            ((InternalAgenda)workingMemory.getAgenda()).decreaseActiveActivations();
+            ((InternalAgenda) workingMemory.getAgenda()).decreaseActiveActivations();
         } else {
-            ((InternalAgenda)workingMemory.getAgenda()).decreaseDormantActivations();
+            ((InternalAgenda) workingMemory.getAgenda()).decreaseDormantActivations();
         }
 
-        workingMemory.getTruthMaintenanceSystem().removeLogicalDependencies( activation,
-                                                                             context,
-                                                                             this.rule );
+        workingMemory.removeLogicalDependencies( activation,
+                                                 context,
+                                                 this.rule );
     }
 
     public String toString() {

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java	2007-02-11 03:15:11 UTC (rev 9430)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java	2007-02-11 03:46:51 UTC (rev 9431)
@@ -67,7 +67,7 @@
         };
 
         //workingMemory.addEventListener(listener );
-        final InputStream is = getClass().getResourceAsStream( "/manners128.dat" );
+        final InputStream is = getClass().getResourceAsStream( "/manners64.dat" );
         final List list = getInputObjects( is );
         for ( final Iterator it = list.iterator(); it.hasNext(); ) {
             final Object object = it.next();




More information about the jboss-svn-commits mailing list