[jboss-svn-commits] JBL Code SVN: r6179 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Sep 12 15:42:07 EDT 2006


Author: mark.proctor at jboss.com
Date: 2006-09-12 15:42:03 -0400 (Tue, 12 Sep 2006)
New Revision: 6179

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java
Log:
JBRULES-484 refactor the core reteoo code for sinle and composite propagations
-another fix to the alpha node hashing

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java	2006-09-12 17:11:47 UTC (rev 6178)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java	2006-09-12 19:42:03 UTC (rev 6179)
@@ -32,8 +32,6 @@
     private HashKey            hashKey;
 
     public CompositeObjectSinkAdapter() {
-        this.otherSinks = new ObjectSinkNodeList();
-        this.hashedSinks = new ObjectSinkNodeList();
         this.hashKey = new HashKey();
     }
 
@@ -50,6 +48,11 @@
                     int index = literalConstraint.getFieldExtractor().getIndex();
                     FieldIndex fieldIndex = registerFieldIndex( index,
                                                                 literalConstraint.getFieldExtractor() );
+
+                    if ( this.hashedSinks == null ) {
+                        this.hashedSinks = new ObjectSinkNodeList();
+                    }
+
                     this.hashedSinks.add( (ObjectSinkNode) sink );
 
                     if ( !fieldIndex.isHashed() && fieldIndex.getCount() >= 3 ) {
@@ -62,6 +65,10 @@
             }
         }
 
+        if ( this.otherSinks == null ) {
+            this.otherSinks = new ObjectSinkNodeList();
+        }
+
         this.otherSinks.add( (ObjectSinkNode) sink );
     }
 
@@ -80,6 +87,10 @@
                     FieldIndex fieldIndex = unregisterFieldIndex( index );
                     this.hashedSinks.remove( (ObjectSinkNode) sink );
 
+                    if ( this.hashedSinks.isEmpty() ) {
+                        this.hashedSinks = null;
+                    }
+
                     if ( fieldIndex.isHashed() ) {
                         this.hashKey.setIndex( index );
                         this.hashKey.setValue( value );
@@ -96,6 +107,10 @@
         }
 
         this.otherSinks.remove( (ObjectSinkNode) sink );
+
+        if ( this.otherSinks.isEmpty() ) {
+            this.otherSinks = null;
+        }
     }
 
     public void hashSinks(FieldIndex fieldIndex) {
@@ -112,6 +127,7 @@
             Evaluator evaluator = literalConstraint.getEvaluator();
             if ( evaluator.getOperator() == Operator.EQUAL && index == literalConstraint.getFieldExtractor().getIndex() ) {
                 Object value = literalConstraint.getField().getValue();
+                this.hashedSinks.remove( sink );
                 hashedSinkMap.put( new HashKey( index,
                                                 value ),
                                    sink );
@@ -132,6 +148,7 @@
                 Object value = literalConstraint.getField().getValue();
                 this.hashKey.setIndex( index );
                 this.hashKey.setValue( value );
+                this.hashedSinks.add( sink );
                 hashedSinkMap.remove( this.hashKey );
             }
         }
@@ -209,7 +226,7 @@
                                       PropagationContext context,
                                       InternalWorkingMemory workingMemory) {
         Object object = handle.getObject();
-        if ( this.hashedSinkMap != null ) {
+        if ( this.hashedFieldIndexes != null ) {
             // Iterate the FieldIndexes to see if any are hashed        
             for ( FieldIndex fieldIndex = (FieldIndex) this.hashedFieldIndexes.getFirst(); fieldIndex != null && fieldIndex.isHashed(); fieldIndex = (FieldIndex) fieldIndex.getNext() ) {
                 // this field is hashed so set the existing hashKey and see if there is a sink for it
@@ -227,18 +244,39 @@
             }
         }
 
-        // propagate others
-        for ( ObjectSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
-            sink.assertObject( handle,
-                               context,
-                               workingMemory );
+        // propagate unhashed
+        if ( this.hashedSinks != null ) {
+            for ( ObjectSinkNode sink = this.hashedSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
+                sink.assertObject( handle,
+                                   context,
+                                   workingMemory );
+            }
         }
 
+        if ( this.otherSinks != null ) {
+            // propagate others
+            for ( ObjectSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
+                sink.assertObject( handle,
+                                   context,
+                                   workingMemory );
+            }
+        }
+
     }
 
     public void propagateModifyObject(InternalFactHandle handle,
                                       PropagationContext context,
                                       InternalWorkingMemory workingMemory) {
+
+        if ( this.hashedSinkMap != null ) {
+            for ( Iterator it = this.hashedSinkMap.values().iterator(); it.hasNext(); ) {
+                ObjectSink sink = (ObjectSink) it.next();
+                sink.modifyObject( handle,
+                                   context,
+                                   workingMemory );
+            }
+        }
+
         if ( this.hashedSinks != null ) {
             // we can't retrieve hashed sinks, as the field value might have changed, so we have to iterate and propagate to all hashed sinks
             for ( ObjectSinkNode sink = this.hashedSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
@@ -248,11 +286,13 @@
             }
         }
 
-        // propagate others
-        for ( ObjectSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
-            sink.modifyObject( handle,
-                               context,
-                               workingMemory );
+        if ( this.otherSinks != null ) {
+            // propagate others
+            for ( ObjectSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
+                sink.modifyObject( handle,
+                                   context,
+                                   workingMemory );
+            }
         }
 
     }
@@ -279,22 +319,33 @@
                                             workingMemory );
                     }
                 }
-            } else {
-                // we can't retrieve hashed sinks, as the field value might have changed, so we have to iterate and propagate to all hashed sinks
-                for ( ObjectSinkNode sink = this.hashedSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
-                    sink.retractObject( handle,
-                                        context,
-                                        workingMemory );
+            } else if ( this.hashedSinkMap != null ) {
+                for ( Iterator it = this.hashedSinkMap.values().iterator(); it.hasNext(); ) {
+                    ObjectSink sink = (ObjectSink) it.next();
+                    sink.modifyObject( handle,
+                                       context,
+                                       workingMemory );
                 }
             }
         }
 
-        // propagate others
-        for ( ObjectSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
-            sink.retractObject( handle,
-                                context,
-                                workingMemory );
+        if ( this.hashedSinks != null ) {
+            // we can't retrieve hashed sinks, as the field value might have changed, so we have to iterate and propagate to all hashed sinks
+            for ( ObjectSinkNode sink = this.hashedSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
+                sink.retractObject( handle,
+                                    context,
+                                    workingMemory );
+            }
         }
+
+        if ( this.otherSinks != null ) {
+            // propagate others
+            for ( ObjectSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
+                sink.retractObject( handle,
+                                    context,
+                                    workingMemory );
+            }
+        }
     }
 
     public void propagateNewObjectSink(InternalFactHandle handle,




More information about the jboss-svn-commits mailing list