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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 26 22:21:54 EDT 2006


Author: mark.proctor at jboss.com
Date: 2006-10-26 22:21:48 -0400 (Thu, 26 Oct 2006)
New Revision: 7165

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java
Log:
-Added many more confirurations

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	2006-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -48,6 +48,7 @@
 
     private boolean           shareAlphaNodes;
     private boolean           shareBetaNodes;
+    private boolean           alphaMemory;
     private int               alphaNodeHashingThreshold;
     private int               compositeKeyDepth;
     private boolean           indexLeftBetaMemory;
@@ -58,6 +59,9 @@
     public RuleBaseConfiguration() {
         this.immutable = false;
 
+        setAlphaMemory( Boolean.valueOf( System.getProperty( "drools.alphaMemory",
+                                                             "true" ) ).booleanValue() );
+        
         setShareAlphaNodes( Boolean.valueOf( System.getProperty( "drools.shareAlphaNodes",
                                                                  "true" ) ).booleanValue() );
 
@@ -97,7 +101,19 @@
     public boolean isImmutable() {
         return this.immutable;
     }
+        
+    public boolean isAlphaMemory() {
+        return alphaMemory;
+    }
 
+    public void setAlphaMemory(boolean alphaMemory) {
+        if ( !this.immutable ) {
+            this.alphaMemory = alphaMemory;
+        } else {
+            throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
+        }
+    }
+
     public boolean isShareAlphaNodes() {
         return shareAlphaNodes;
     }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java	2006-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -20,9 +20,12 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.drools.RuleBaseConfiguration;
 import org.drools.base.evaluators.Operator;
 import org.drools.reteoo.BetaMemory;
+import org.drools.reteoo.FactHandleMemory;
 import org.drools.reteoo.ReteTuple;
+import org.drools.reteoo.TupleMemory;
 import org.drools.rule.ContextEntry;
 import org.drools.rule.VariableConstraint;
 import org.drools.spi.BetaNodeFieldConstraint;
@@ -50,26 +53,27 @@
     private ContextEntry      contexts;
 
     private int               indexed;
+    
+    private RuleBaseConfiguration         conf;
 
-    public DefaultBetaConstraints(final BetaNodeFieldConstraint[] constraints) {
-        this( constraints, true );
-    }
-
-    public DefaultBetaConstraints(final BetaNodeFieldConstraint[] constraints, boolean index ) {
+    public DefaultBetaConstraints(final BetaNodeFieldConstraint[] constraints,
+                                  final RuleBaseConfiguration conf) {
+        this.conf = conf;        
         this.indexed = -1;
         this.constraints = new LinkedList();
         ContextEntry current = null;
-
+        int depth = conf.getCompositeKeyDepth();
+        
         // First create a LinkedList of constraints, with the indexed constraints first.
         for ( int i = 0, length = constraints.length; i < length; i++ ) {
             // Determine  if this constraint is indexable
-            if ( index && isIndexable( constraints[i] ) ) {
-                if ( indexed == -1 ) {
+            if ( isIndexable( constraints[i] ) ) {
+                if ( depth >= 1 && indexed == -1 ) {
                     // first index, so just add to the front
                     this.constraints.insertAfter( null,
                                                   new LinkedListEntry( constraints[i] ) );
                     indexed++;
-                } else {
+                } else if ( depth >= this.indexed +1){ //this.indexed is zero based, so adjust
                     // insert this index after  the previous index
                     this.constraints.insertAfter( findNode( indexed++ ),
                                                   new LinkedListEntry( constraints[i] ) );
@@ -192,8 +196,21 @@
             }
             
             FieldIndex[] indexes = ( FieldIndex[] ) list.toArray( new FieldIndex[ list.size() ] );
-            memory = new BetaMemory( new TupleIndexHashTable( indexes ),
-                                     new FactHandleIndexHashTable( indexes ) );
+            TupleMemory tupleMemory;
+            if ( conf.isIndexLeftBetaMemory() ) {
+                tupleMemory = new TupleIndexHashTable( indexes );
+            } else {
+                tupleMemory = new TupleHashTable();
+            }
+
+            FactHandleMemory factHandleMemory;
+            if ( conf.isIndexRightBetaMemory() ) {
+                factHandleMemory = new FactHandleIndexHashTable( indexes );           
+            }  else {
+                factHandleMemory = new FactHashTable();
+            }
+            memory = new BetaMemory( tupleMemory,
+                                     factHandleMemory );   
         } else {
             memory = new BetaMemory( new TupleHashTable(),
                                      new FactHashTable() );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java	2006-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -23,7 +23,9 @@
 import org.drools.RuleBaseConfiguration;
 import org.drools.base.evaluators.Operator;
 import org.drools.reteoo.BetaMemory;
+import org.drools.reteoo.FactHandleMemory;
 import org.drools.reteoo.ReteTuple;
+import org.drools.reteoo.TupleMemory;
 import org.drools.rule.ContextEntry;
 import org.drools.rule.VariableConstraint;
 import org.drools.spi.BetaNodeFieldConstraint;
@@ -54,7 +56,10 @@
     private boolean                       indexed0;
     private boolean                       indexed1;
     
+    private RuleBaseConfiguration         conf;
+    
     public DoubleBetaConstraints(final BetaNodeFieldConstraint[] constraints, RuleBaseConfiguration conf) {
+        this.conf = conf;        
         if  (!conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory()) {
             this.indexed0 = false;
             this.indexed1 = false;
@@ -167,8 +172,22 @@
 
         if ( !list.isEmpty() ) {
             final FieldIndex[] indexes = (FieldIndex[]) list.toArray( new FieldIndex[list.size()] );
-            memory = new BetaMemory( new TupleIndexHashTable( indexes ),
-                                     new FactHandleIndexHashTable( indexes ) );
+
+            TupleMemory tupleMemory;
+            if ( conf.isIndexLeftBetaMemory() ) {
+                tupleMemory = new TupleIndexHashTable( indexes );
+            } else {
+                tupleMemory = new TupleHashTable();
+            }
+
+            FactHandleMemory factHandleMemory;
+            if ( conf.isIndexRightBetaMemory() ) {
+                factHandleMemory = new FactHandleIndexHashTable( indexes );           
+            }  else {
+                factHandleMemory = new FactHashTable();
+            }
+            memory = new BetaMemory( tupleMemory,
+                                     factHandleMemory );            
         } else {
             memory = new BetaMemory( new TupleHashTable(),
                                      new FactHashTable() );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java	2006-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -23,7 +23,9 @@
 import org.drools.RuleBaseConfiguration;
 import org.drools.base.evaluators.Operator;
 import org.drools.reteoo.BetaMemory;
+import org.drools.reteoo.FactHandleMemory;
 import org.drools.reteoo.ReteTuple;
+import org.drools.reteoo.TupleMemory;
 import org.drools.rule.ContextEntry;
 import org.drools.rule.VariableConstraint;
 import org.drools.spi.BetaNodeFieldConstraint;
@@ -32,6 +34,7 @@
 import org.drools.util.LinkedList;
 import org.drools.util.LinkedListEntry;
 import org.drools.util.TupleHashTable;
+import org.drools.util.TupleIndexHashTable;
 import org.drools.util.AbstractHashTable.FieldIndex;
 
 public class QuadroupleBetaConstraints
@@ -57,9 +60,12 @@
     private boolean                       indexed0;
     private boolean                       indexed1;
     private boolean                       indexed2;
+    
+    private RuleBaseConfiguration         conf;
 
     public QuadroupleBetaConstraints(final BetaNodeFieldConstraint[] constraints,
                                      final RuleBaseConfiguration conf) {
+        this.conf = conf;        
         if  (!conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory()) {
             this.indexed0 = false;
             this.indexed1 = false;
@@ -254,8 +260,21 @@
 
         if ( !list.isEmpty() ) {
             final FieldIndex[] indexes = (FieldIndex[]) list.toArray( new FieldIndex[list.size()] );
-            memory = new BetaMemory( new TupleHashTable(),
-                                     new FactHandleIndexHashTable( indexes ) );
+            TupleMemory tupleMemory;
+            if ( conf.isIndexLeftBetaMemory() ) {
+                tupleMemory = new TupleIndexHashTable( indexes );
+            } else {
+                tupleMemory = new TupleHashTable();
+            }
+
+            FactHandleMemory factHandleMemory;
+            if ( conf.isIndexRightBetaMemory() ) {
+                factHandleMemory = new FactHandleIndexHashTable( indexes );           
+            }  else {
+                factHandleMemory = new FactHashTable();
+            }
+            memory = new BetaMemory( tupleMemory,
+                                     factHandleMemory );    
         } else {
             memory = new BetaMemory( new TupleHashTable(),
                                      new FactHashTable() );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java	2006-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -22,7 +22,9 @@
 import org.drools.RuleBaseConfiguration;
 import org.drools.base.evaluators.Operator;
 import org.drools.reteoo.BetaMemory;
+import org.drools.reteoo.FactHandleMemory;
 import org.drools.reteoo.ReteTuple;
+import org.drools.reteoo.TupleMemory;
 import org.drools.rule.ContextEntry;
 import org.drools.rule.VariableConstraint;
 import org.drools.spi.BetaNodeFieldConstraint;
@@ -50,14 +52,18 @@
 
     private boolean                       indexed;
     
-    public SingleBetaConstraints(final BetaNodeFieldConstraint constraint, RuleBaseConfiguration conf ) {
-        if  (!conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory()) {
+    private RuleBaseConfiguration         conf;
+
+    public SingleBetaConstraints(final BetaNodeFieldConstraint constraint,
+                                 RuleBaseConfiguration conf) {
+        this.conf = conf;
+        if ( !conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory() ) {
             this.indexed = false;
         } else {
-            int depth = conf.getCompositeKeyDepth();    
+            int depth = conf.getCompositeKeyDepth();
             // Determine  if this constraint is indexable
-                this.indexed = depth >= 1 && isIndexable( constraint );
-        }        
+            this.indexed = depth >= 1 && isIndexable( constraint );
+        }
 
         this.constraint = constraint;
         this.context = constraint.getContextEntry();
@@ -75,15 +81,19 @@
     /* (non-Javadoc)
      * @see org.drools.common.BetaNodeConstraints#updateFromTuple(org.drools.reteoo.ReteTuple)
      */
-    public void updateFromTuple(final InternalWorkingMemory workingMemory, final ReteTuple tuple) {
-        this.context.updateFromTuple( workingMemory, tuple );
+    public void updateFromTuple(final InternalWorkingMemory workingMemory,
+                                final ReteTuple tuple) {
+        this.context.updateFromTuple( workingMemory,
+                                      tuple );
     }
 
     /* (non-Javadoc)
      * @see org.drools.common.BetaNodeConstraints#updateFromFactHandle(org.drools.common.InternalFactHandle)
      */
-    public void updateFromFactHandle(final InternalWorkingMemory workingMemory, final InternalFactHandle handle) {
-        this.context.updateFromFactHandle( workingMemory, handle );
+    public void updateFromFactHandle(final InternalWorkingMemory workingMemory,
+                                     final InternalFactHandle handle) {
+        this.context.updateFromFactHandle( workingMemory,
+                                           handle );
     }
 
     /* (non-Javadoc)
@@ -115,10 +125,23 @@
         if ( this.indexed ) {
             final VariableConstraint variableConstraint = (VariableConstraint) this.constraint;
             final FieldIndex index = new FieldIndex( variableConstraint.getFieldExtractor(),
-                                               variableConstraint.getRequiredDeclarations()[0],
-                                               variableConstraint.getEvaluator());
-            memory = new BetaMemory( new TupleIndexHashTable( new FieldIndex[]{index} ),
-                                     new FactHandleIndexHashTable( new FieldIndex[]{index} ) );
+                                                     variableConstraint.getRequiredDeclarations()[0],
+                                                     variableConstraint.getEvaluator() );
+            TupleMemory tupleMemory;
+            if ( conf.isIndexLeftBetaMemory() ) {
+                tupleMemory = new TupleIndexHashTable( new FieldIndex[]{index} );
+            } else {
+                tupleMemory = new TupleHashTable();
+            }
+
+            FactHandleMemory factHandleMemory;
+            if ( conf.isIndexRightBetaMemory() ) {
+                factHandleMemory = new FactHandleIndexHashTable( new FieldIndex[]{index} );           
+            }  else {
+                factHandleMemory = new FactHashTable();
+            }
+            memory = new BetaMemory( tupleMemory,
+                                     factHandleMemory );
         } else {
             memory = new BetaMemory( new TupleHashTable(),
                                      new FactHashTable() );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java	2006-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -23,7 +23,9 @@
 import org.drools.RuleBaseConfiguration;
 import org.drools.base.evaluators.Operator;
 import org.drools.reteoo.BetaMemory;
+import org.drools.reteoo.FactHandleMemory;
 import org.drools.reteoo.ReteTuple;
+import org.drools.reteoo.TupleMemory;
 import org.drools.rule.ContextEntry;
 import org.drools.rule.VariableConstraint;
 import org.drools.spi.BetaNodeFieldConstraint;
@@ -56,8 +58,11 @@
     private boolean                       indexed0;
     private boolean                       indexed1;
     private boolean                       indexed2;
+    
+    private RuleBaseConfiguration         conf;
 
     public TripleBetaConstraints(final BetaNodeFieldConstraint[] constraints, RuleBaseConfiguration conf) {
+        this.conf = conf;        
         if  (!conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory()) {
             this.indexed0 = false;
             this.indexed1 = false;
@@ -219,8 +224,21 @@
 
         if ( !list.isEmpty() ) {
             final FieldIndex[] indexes = (FieldIndex[]) list.toArray( new FieldIndex[list.size()] );
-            memory = new BetaMemory( new TupleIndexHashTable( indexes ),
-                                     new FactHandleIndexHashTable( indexes ) );
+            TupleMemory tupleMemory;
+            if ( conf.isIndexLeftBetaMemory() ) {
+                tupleMemory = new TupleIndexHashTable( indexes );
+            } else {
+                tupleMemory = new TupleHashTable();
+            }
+
+            FactHandleMemory factHandleMemory;
+            if ( conf.isIndexRightBetaMemory() ) {
+                factHandleMemory = new FactHandleIndexHashTable( indexes );           
+            }  else {
+                factHandleMemory = new FactHashTable();
+            }
+            memory = new BetaMemory( tupleMemory,
+                                     factHandleMemory );                
         } else {
             memory = new BetaMemory( new TupleHashTable(),
                                      new FactHashTable() );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2006-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -70,7 +70,8 @@
         this( id,
               constraint,
               objectSource,
-              true );
+              true,
+              3 );
     }
 
     /**
@@ -88,10 +89,10 @@
     AlphaNode(final int id,
               final AlphaNodeFieldConstraint constraint,
               final ObjectSource objectSource,
-              final boolean hasMemory) {
-        super( id );
+              final boolean hasMemory,
+              final int alphaNodeHashingThreshold) {
+        super( id, objectSource, alphaNodeHashingThreshold );
         this.constraint = constraint;
-        this.objectSource = objectSource;
         setHasMemory( hasMemory );
     }
 

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-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -25,14 +25,14 @@
     implements
     ObjectSinkPropagator {
 
-    /** You can override this property via a system property (eg -Ddrools.hashThreshold=4) */
-    public static final String HASH_THRESHOLD_SYSTEM_PROPERTY = "drools.hashThreshold";
+//    /** You can override this property via a system property (eg -Ddrools.hashThreshold=4) */
+//    public static final String HASH_THRESHOLD_SYSTEM_PROPERTY = "drools.hashThreshold";
+//
+//    /** The threshold for when hashing kicks in */
+//    public static final int    THRESHOLD_TO_HASH              = Integer.parseInt( System.getProperty( HASH_THRESHOLD_SYSTEM_PROPERTY,
+//                                                                                                      "3" ) );
 
-    /** The threshold for when hashing kicks in */
-    public static final int    THRESHOLD_TO_HASH              = Integer.parseInt( System.getProperty( HASH_THRESHOLD_SYSTEM_PROPERTY,
-                                                                                                      "3" ) );
-
-    private static final long  serialVersionUID               = 2192568791644369227L;
+    private static final long  serialVersionUID               = 320L;
     ObjectSinkNodeList         otherSinks;
     ObjectSinkNodeList         hashableSinks;
 
@@ -41,9 +41,15 @@
     ObjectHashMap              hashedSinkMap;
 
     private HashKey            hashKey;
+    
+    private final int  alphaNodeHashingThreshold;
 
     public CompositeObjectSinkAdapter() {
+        this(3);
+    }
+    public CompositeObjectSinkAdapter(int alphaNodeHashingThreshold) {
         this.hashKey = new HashKey();
+        this.alphaNodeHashingThreshold = alphaNodeHashingThreshold;
     }
 
     public void addObjectSink(final ObjectSink sink) {
@@ -60,7 +66,7 @@
                     final FieldIndex fieldIndex = registerFieldIndex( index,
                                                                       literalConstraint.getFieldExtractor() );
 
-                    if ( fieldIndex.getCount() >= THRESHOLD_TO_HASH ) {
+                    if ( fieldIndex.getCount() >= alphaNodeHashingThreshold ) {
                         if ( !fieldIndex.isHashed() ) {
                             hashSinks( fieldIndex );
                         }
@@ -106,7 +112,7 @@
                     if ( fieldIndex.isHashed() ) {
                         this.hashKey.setValue( index, value );
                         this.hashedSinkMap.remove( this.hashKey );
-                        if ( fieldIndex.getCount() <= THRESHOLD_TO_HASH - 1 ) {
+                        if ( fieldIndex.getCount() <= alphaNodeHashingThreshold - 1 ) {
                             // we have less than three so unhash
                             unHashSinks( fieldIndex );
                         }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java	2006-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -49,6 +49,8 @@
 
     protected ObjectSource         objectSource;
 
+    private int alphaNodeHashingThreshold;
+    
     // ------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------
@@ -60,7 +62,8 @@
      */
     ObjectSource(final int id) {
         this( id,
-              null );
+              null,
+              3 );
         this.sink = EmptyObjectSinkAdapter.getInstance();
     }
 
@@ -70,9 +73,11 @@
      * @param id
      */
     ObjectSource(final int id,
-                 final ObjectSource objectSource) {
+                 final ObjectSource objectSource,
+                 int alphaNodeHashingThreshold) {
         super( id );
         this.objectSource = objectSource;
+        this.alphaNodeHashingThreshold = alphaNodeHashingThreshold;
     }
 
     // ------------------------------------------------------------
@@ -92,7 +97,7 @@
         if ( this.sink == EmptyObjectSinkAdapter.getInstance() ) {
             this.sink = new SingleObjectSinkAdapter( objectSink );
         } else if ( this.sink.getClass() == SingleObjectSinkAdapter.class ) {
-            final CompositeObjectSinkAdapter sinkAdapter = new CompositeObjectSinkAdapter();
+            final CompositeObjectSinkAdapter sinkAdapter = new CompositeObjectSinkAdapter(alphaNodeHashingThreshold);
             sinkAdapter.addObjectSink( this.sink.getSinks()[0] );
             sinkAdapter.addObjectSink( objectSink );
             this.sink = sinkAdapter;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2006-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -88,8 +88,9 @@
      */
     public ObjectTypeNode(final int id,
                           final ObjectType objectType,
-                          final Rete rete) {
-        super( id );
+                          final Rete rete,
+                          final int alphaNodeHashingThreshold) {
+        super( id, null, alphaNodeHashingThreshold );
         this.rete = rete;
         this.objectType = objectType;
         setHasMemory( true );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java	2006-10-27 01:56:21 UTC (rev 7164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java	2006-10-27 02:21:48 UTC (rev 7165)
@@ -297,7 +297,8 @@
 
                     final ObjectSource objectSource = attachNode( new ObjectTypeNode( this.id++,
                                                                                       new ClassObjectType( InitialFact.class ),
-                                                                                      this.rete ) );
+                                                                                      this.rete,
+                                                                                      this.ruleBase.getConfiguration().getAlphaNodeHashingThreshold()) );
 
                     this.tupleSource = attachNode( new LeftInputAdapterNode( this.id++,
                                                                              objectSource ) );
@@ -351,7 +352,8 @@
 
         final ObjectSource objectTypeSource = attachNode( new ObjectTypeNode( this.id++,
                                                                               new ClassObjectType( DroolsQuery.class ),
-                                                                              this.rete ) );
+                                                                              this.rete,
+                                                                              this.ruleBase.getConfiguration().getAlphaNodeHashingThreshold()) );
 
         final ClassFieldExtractor extractor = new ClassFieldExtractor( DroolsQuery.class,
                                                                        "name" );
@@ -365,7 +367,9 @@
 
         final ObjectSource alphaNodeSource = attachNode( new AlphaNode( this.id++,
                                                                         constraint,
-                                                                        objectTypeSource ) );
+                                                                        objectTypeSource,
+                                                                        this.ruleBase.getConfiguration().isAlphaMemory(),
+                                                                        this.ruleBase.getConfiguration().getAlphaNodeHashingThreshold()) );
 
         this.tupleSource = attachNode( new LeftInputAdapterNode( this.id++,
                                                                  alphaNodeSource ) );
@@ -399,7 +403,8 @@
 
         this.objectSource = attachNode( new ObjectTypeNode( this.id++,
                                                             column.getObjectType(),
-                                                            this.rete ) );
+                                                            this.rete,
+                                                            this.ruleBase.getConfiguration().getAlphaNodeHashingThreshold()) );
 
         final List betaConstraints = new ArrayList();
 
@@ -491,7 +496,7 @@
                                                                                                        column,
                                                                                                        notNode ) );
 
-        final BetaConstraints identityBinder = new SingleBetaConstraints( new InstanceEqualsConstraint( column ) );
+        final BetaConstraints identityBinder = new SingleBetaConstraints( new InstanceEqualsConstraint( column ), this.ruleBase.getConfiguration() );
         notNode = (NotNode) attachNode( new NotNode( this.id++,
                                                      tupleSource,
                                                      adapter,
@@ -532,7 +537,17 @@
     private TupleSource attachNode(final TupleSource candidate) {
         TupleSource node = (TupleSource) this.attachedNodes.get( candidate );
 
-        if ( node == null ) {
+        if ( this.ruleBase.getConfiguration().isShareBetaNodes() && node !=  null ) {
+            if ( !node.isInUse() ) {
+                if ( this.workingMemories.length == 0 ) {
+                    node.attach();
+                } else {
+                    node.attach( this.workingMemories );
+                }
+            }
+            node.addShare();
+            this.id--;
+        } else {
             if ( this.workingMemories.length == 0 ) {
                 candidate.attach();
             } else {
@@ -542,19 +557,9 @@
             this.attachedNodes.put( candidate,
                                     candidate );
 
-            node = candidate;
-        } else {
-            if ( !node.isInUse() ) {
-                if ( this.workingMemories.length == 0 ) {
-                    node.attach();
-                } else {
-                    node.attach( this.workingMemories );
-                }
-            }
-            node.addShare();
-            this.id--;
+            node = candidate;            
         }
-
+        
         return node;
     }
 
@@ -570,7 +575,8 @@
 
             final ObjectSource objectSource = attachNode( new ObjectTypeNode( this.id++,
                                                                               new ClassObjectType( InitialFact.class ),
-                                                                              this.rete ) );
+                                                                              this.rete,
+                                                                              this.ruleBase.getConfiguration().getAlphaNodeHashingThreshold()) );
 
             this.tupleSource = attachNode( new LeftInputAdapterNode( this.id++,
                                                                      objectSource ) );
@@ -633,7 +639,8 @@
 
             final ObjectSource auxObjectSource = attachNode( new ObjectTypeNode( this.id++,
                                                                                  new ClassObjectType( InitialFact.class ),
-                                                                                 this.rete ) );
+                                                                                 this.rete,
+                                                                                 this.ruleBase.getConfiguration().getAlphaNodeHashingThreshold()) );
 
             this.tupleSource = attachNode( new LeftInputAdapterNode( this.id++,
                                                                      auxObjectSource ) );
@@ -703,7 +710,8 @@
 
             final ObjectSource auxObjectSource = attachNode( new ObjectTypeNode( this.id++,
                                                                                  new ClassObjectType( InitialFact.class ),
-                                                                                 this.rete ) );
+                                                                                 this.rete,
+                                                                                 this.ruleBase.getConfiguration().getAlphaNodeHashingThreshold()) );
 
             this.tupleSource = attachNode( new LeftInputAdapterNode( this.id++,
                                                                      auxObjectSource ) );
@@ -765,7 +773,17 @@
     private ObjectSource attachNode(final ObjectSource candidate) {
         ObjectSource node = (ObjectSource) this.attachedNodes.get( candidate );
 
-        if ( node == null ) {
+        if ( this.ruleBase.getConfiguration().isShareAlphaNodes() && node != null) {
+            if ( !node.isInUse() ) {
+                if ( this.workingMemories.length == 0 ) {
+                    node.attach();
+                } else {
+                    node.attach( this.workingMemories );
+                }
+            }
+            node.addShare();
+            this.id--;
+        } else {
             if ( this.workingMemories.length == 0 ) {
                 candidate.attach();
             } else {
@@ -776,16 +794,6 @@
                                     candidate );
 
             node = candidate;
-        } else {
-            if ( !node.isInUse() ) {
-                if ( this.workingMemories.length == 0 ) {
-                    node.attach();
-                } else {
-                    node.attach( this.workingMemories );
-                }
-            }
-            node.addShare();
-            this.id--;
         }
 
         return node;




More information about the jboss-svn-commits mailing list