[jboss-svn-commits] JBL Code SVN: r6214 - 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
Wed Sep 13 17:34:11 EDT 2006


Author: mark.proctor at jboss.com
Date: 2006-09-13 17:34:04 -0400 (Wed, 13 Sep 2006)
New Revision: 6214

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatch.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatchFactory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatch.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatchFactory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatchFactory.java
Removed:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatchChildren.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatchChildren.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatch.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatchChildren.java
Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectMatches.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleSinkAdapter.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleSinkPropagator.java
Log:
JBRULES-484 refactor the core reteoo code for sinle and composite propagations
-BetaNode now uses Single and Composite TupleMatchFactories

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -197,8 +197,8 @@
 
         if ( !matches.isEmpty() ) {
             for ( final Iterator it = matches.values().iterator(); it.hasNext(); ) {
-                final TupleMatch tupleMatch = (TupleMatch) it.next();
-                tupleMatch.getObjectMatches().remove( tupleMatch );
+                final CompositeTupleMatch compositeTupleMatch = (CompositeTupleMatch) it.next();
+                compositeTupleMatch.getObjectMatches().remove( compositeTupleMatch );
                 it.remove();
             }
         }
@@ -272,8 +272,8 @@
                                                            handle );
 
         // remove references from tuple to the handle
-        for ( TupleMatch tupleMatch = objectMatches.getFirstTupleMatch(); tupleMatch != null; tupleMatch = (TupleMatch) tupleMatch.getNext() ) {
-            final ReteTuple leftTuple = tupleMatch.getTuple();
+        for ( CompositeTupleMatch compositeTupleMatch = objectMatches.getFirstTupleMatch(); compositeTupleMatch != null; compositeTupleMatch = (CompositeTupleMatch) compositeTupleMatch.getNext() ) {
+            final ReteTuple leftTuple = compositeTupleMatch.getTuple();
             leftTuple.removeMatch( handle );
         }
         
@@ -298,8 +298,8 @@
         final ObjectMatches objectMatches = memory.remove( workingMemory,
                                                            handle );
 
-        for ( TupleMatch tupleMatch = objectMatches.getFirstTupleMatch(); tupleMatch != null; tupleMatch = (TupleMatch) tupleMatch.getNext() ) {
-            final ReteTuple leftTuple = tupleMatch.getTuple();
+        for ( CompositeTupleMatch compositeTupleMatch = objectMatches.getFirstTupleMatch(); compositeTupleMatch != null; compositeTupleMatch = (CompositeTupleMatch) compositeTupleMatch.getNext() ) {
+            final ReteTuple leftTuple = compositeTupleMatch.getTuple();
             leftTuple.removeMatch( handle );
 
             this.modifyTuple( leftTuple,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -59,6 +59,8 @@
     
     private ObjectSinkNode previousObjectSinkNode;
     private ObjectSinkNode nextObjectSinkNode;   
+    
+    protected TupleMatchFactory tupleMatchFactory;
 
     // ------------------------------------------------------------
     // Constructors
@@ -97,8 +99,32 @@
         this.leftInput = leftInput;
         this.rightInput = rightInput;
         this.joinNodeBinder = joinNodeBinder;
-
+        
+        this.tupleMatchFactory = SingleTupleMatchFactory.getInstance();     
     }
+    
+    public void addTupleSink(TupleSink tupleSink) {
+        int previousSize = 0;
+        if ( this.sink != null ) {
+            previousSize = this.sink.size();
+        }
+        super.addTupleSink( tupleSink );
+        
+        // we are now greater than one, so use a CompositeTupleMatchFactory
+        if ( previousSize == 1 ) {
+            this.tupleMatchFactory = CompositeTupleMatchFactory.getInstance();
+        }        
+    }
+    
+    public void removeTupleSink(TupleSink tupleSink) {
+        super.removeTupleSink( tupleSink );
+        
+        // We are now only one, so use a SingleTupleMatchFactory
+        if ( this.sink.size() == 1 ) {
+            this.tupleMatchFactory = SingleTupleMatchFactory.getInstance();
+        }        
+    }
+    
 
     public FieldConstraint[] getConstraints() {
         return this.joinNodeBinder.getConstraints();
@@ -163,8 +189,8 @@
         if ( binder.isAllowed( handle,
                                leftTuple,
                                workingMemory ) ) {
-            TupleMatch tupleMatch = objectMatches.add( leftTuple );          
-
+            TupleMatch tupleMatch = this.tupleMatchFactory.newTupleMatch( leftTuple, objectMatches );          
+			objectMatches.add( tupleMatch );
             leftTuple.addTupleMatch( handle,
                                      tupleMatch );
             return tupleMatch;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -203,8 +203,8 @@
 
         if ( !matches.isEmpty() ) {
             for ( final Iterator it = matches.values().iterator(); it.hasNext(); ) {
-                final TupleMatch tupleMatch = (TupleMatch) it.next();
-                tupleMatch.getObjectMatches().remove( tupleMatch );
+                final CompositeTupleMatch compositeTupleMatch = (CompositeTupleMatch) it.next();
+                compositeTupleMatch.getObjectMatches().remove( compositeTupleMatch );
                 it.remove();
             }
         }
@@ -278,8 +278,8 @@
                                                            handle );
 
         // remove references from tuple to the handle
-        for ( TupleMatch tupleMatch = objectMatches.getFirstTupleMatch(); tupleMatch != null; tupleMatch = (TupleMatch) tupleMatch.getNext() ) {
-            final ReteTuple leftTuple = tupleMatch.getTuple();
+        for ( CompositeTupleMatch compositeTupleMatch = objectMatches.getFirstTupleMatch(); compositeTupleMatch != null; compositeTupleMatch = (CompositeTupleMatch) compositeTupleMatch.getNext() ) {
+            final ReteTuple leftTuple = compositeTupleMatch.getTuple();
             leftTuple.removeMatch( handle );
         }
 
@@ -304,8 +304,8 @@
         final ObjectMatches objectMatches = memory.remove( workingMemory,
                                                            handle );
 
-        for ( TupleMatch tupleMatch = objectMatches.getFirstTupleMatch(); tupleMatch != null; tupleMatch = (TupleMatch) tupleMatch.getNext() ) {
-            final ReteTuple leftTuple = tupleMatch.getTuple();
+        for ( CompositeTupleMatch compositeTupleMatch = objectMatches.getFirstTupleMatch(); compositeTupleMatch != null; compositeTupleMatch = (CompositeTupleMatch) compositeTupleMatch.getNext() ) {
+            final ReteTuple leftTuple = compositeTupleMatch.getTuple();
             leftTuple.removeMatch( handle );
 
             this.modifyTuple( leftTuple,

Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatch.java (from rev 6207, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatch.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatch.java	2006-09-13 18:58:07 UTC (rev 6207)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatch.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -0,0 +1,107 @@
+package org.drools.reteoo;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.drools.common.InternalWorkingMemory;
+import org.drools.spi.PropagationContext;
+import org.drools.util.AbstractBaseLinkedListNode;
+
+/**
+ * <code>TupleMatch</code> maintains a reference to the parent <code>ReteTuple</code> and a <code>List</code> of all resulting joins. 
+ * This is a List rather than a single instance reference because we need to create a join for each TupleSink branches.
+ * A reference is also maintained to the <code>ObjectMatches</code> instance; this is so the <code>FactHandleImpl</code> that 
+ * is used in the join can be referenced, and also any other <code>TupleMatch</code>es the <code>FactHandleImpl</code> is joined with.
+ * 
+ * @see CompositeTupleMatch
+ * @see ObjectMatches
+ * @see ReteTuple
+ * 
+ * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
+ * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
+ *
+ */
+public class CompositeTupleMatch extends AbstractBaseLinkedListNode implements TupleMatch {
+    private ReteTuple          tuple;
+    
+    private LinkedList list;
+
+    private ObjectMatches      objectMatches;
+
+    /**
+     * Construct a <code>TupleMatch</code> with references to the parent <code>ReteTuple</code> and 
+     * <code>FactHandleImpl</code>, via ObjecMatches.
+     * 
+     * @param tuple
+     * @param objectMatches
+     */
+    public CompositeTupleMatch(final ReteTuple tuple,
+                      final ObjectMatches objectMatches) {
+        this.tuple = tuple;
+        this.objectMatches = objectMatches;       
+        this.list = new LinkedList();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.ITupleMatch#getTuple()
+     */
+    public ReteTuple getTuple() {
+        return this.tuple;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.ITupleMatch#getObjectMatches()
+     */
+    public ObjectMatches getObjectMatches() {
+        return this.objectMatches;
+    }
+
+    public void addJoinedTuple(ReteTuple tuple) {
+        list.add( tuple );
+    }
+
+    public void propagateRetractTuple(final PropagationContext context,
+                                      final InternalWorkingMemory workingMemory) {
+        for ( Iterator it = this.list.iterator(); it.hasNext(); ) {
+            ReteTuple joined = (ReteTuple) it.next();
+            joined.retractTuple( context,
+                                 workingMemory );
+        }
+    }
+
+    public void propagateModifyTuple(final PropagationContext context,
+                                     final InternalWorkingMemory workingMemory) {
+        for ( Iterator it = this.list.iterator(); it.hasNext(); ) {
+            ReteTuple joined = (ReteTuple) it.next();
+            joined.modifyTuple( context,
+                                workingMemory );
+        }
+    }
+
+    public ReteTuple getTupleForSink(TupleSink sink) {
+        for ( Iterator it = this.list.iterator(); it.hasNext(); ) {
+            ReteTuple joined = (ReteTuple) it.next();
+            if ( sink.equals(  joined.getTupleSink() ) ) {
+                return joined;
+            }
+        }    
+        return null;
+    }
+
+}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatchChildren.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatchChildren.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatchChildren.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -1,52 +0,0 @@
-package org.drools.reteoo;
-
-import java.util.LinkedList;
-import java.util.Iterator;
-
-import org.drools.common.InternalWorkingMemory;
-import org.drools.spi.PropagationContext;
-
-public class CompositeTupleMatchChildren
-    implements
-    TupleMatchChildren {
-    private LinkedList list;
-
-    public CompositeTupleMatchChildren() {
-        this.list = new LinkedList();
-    }
-
-    public void add(ReteTuple tuple) {
-        list.add( tuple );
-    }
-
-    public void propagateRetractTuple(final PropagationContext context,
-                                      final InternalWorkingMemory workingMemory) {
-        for ( Iterator it = this.list.iterator(); it.hasNext(); ) {
-            ReteTuple joined = (ReteTuple) it.next();
-            joined.retractTuple( context,
-                                 workingMemory );
-        }
-    }
-
-    public void propagateModifyTuple(final PropagationContext context,
-                                     final InternalWorkingMemory workingMemory) {
-        for ( Iterator it = this.list.iterator(); it.hasNext(); ) {
-            ReteTuple joined = (ReteTuple) it.next();
-            joined.modifyTuple( context,
-                                workingMemory );
-        }
-    }
-
-    public ReteTuple getTupleForSink(TupleSink sink) {
-        for ( Iterator it = this.list.iterator(); it.hasNext(); ) {
-            ReteTuple joined = (ReteTuple) it.next();
-            if ( sink.equals(  joined.getTupleSink() ) ) {
-                return joined;
-            }
-        }    
-        return null;
-    }
-    
-    
-
-}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatchFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatchFactory.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeTupleMatchFactory.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -0,0 +1,25 @@
+package org.drools.reteoo;
+
+public class CompositeTupleMatchFactory
+    implements
+    TupleMatchFactory {
+    
+    private static TupleMatchFactory INSTANCE;
+    
+    public static TupleMatchFactory getInstance() {
+        if ( INSTANCE == null ) {
+            INSTANCE = new CompositeTupleMatchFactory();
+        }
+        return INSTANCE;
+    }
+    
+    private CompositeTupleMatchFactory() {
+        
+    }
+
+    public TupleMatch newTupleMatch(ReteTuple tuple,
+                                    ObjectMatches objectMatches) {
+        return new CompositeTupleMatch(tuple, objectMatches);
+    }
+
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -82,7 +82,7 @@
             if ( binder.isAllowed( handle,
                                    leftTuple,
                                    workingMemory ) ) {
-                final TupleMatch tupleMatch = new TupleMatch( leftTuple,
+                final TupleMatch tupleMatch = new CompositeTupleMatch( leftTuple,
                                                               objectMatches );
 
                 leftTuple.addTupleMatch( (DefaultFactHandle) handle,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -288,7 +288,8 @@
                         tupleMatch.propagateModifyTuple( context,
                                                          workingMemory );
                     } else {
-                        tupleMatch = objectMatches.add( leftTuple );
+                        tupleMatch = this.tupleMatchFactory.newTupleMatch( leftTuple, objectMatches );
+                        objectMatches.add( tupleMatch );
                         leftTuple.addTupleMatch( handle,
                                                  tupleMatch );
                         this.sink.propagateAssertTuple( leftTuple,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -283,7 +283,8 @@
                 TupleMatch tupleMatch = (TupleMatch) oldMatches.remove( handle );
                 if ( tupleMatch == null ) {
                     // no previous matches so add a match now
-                    tupleMatch = objectMatches.add( leftTuple );
+                    tupleMatch = this.tupleMatchFactory.newTupleMatch( leftTuple, objectMatches );
+                    objectMatches.add( tupleMatch );
                 }
                 leftTuple.addTupleMatch( handle,
                                          tupleMatch );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectMatches.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectMatches.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectMatches.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -25,7 +25,7 @@
  * 
  * <code>ObjectMatches</code> maintains a reference to its <code>FactHandleImpl</code> and a <code>LinkedList</code> of <code>TupleMatch</code>es.
  * 
- * @see TupleMatch
+ * @see CompositeTupleMatch
  * @see LinkedList
  * 
  * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
@@ -46,23 +46,7 @@
         this.list = new LinkedList();
         this.handle = handle;
     }
-
-    /**
-     * Adds a matched <code>ReteTuple</code>, which is then wrapped in a <code>TupleMatch</code> which is added to 
-     * the <code>LinkedList</code> and then returned.
-     * 
-     * @param tuple
-     * @return
-     */
-    TupleMatch add(final ReteTuple tuple) {
-        final TupleMatch tupleMatch = new TupleMatch( tuple,
-                                                      this );
-
-        this.list.add( tupleMatch );
-
-        return tupleMatch;
-    }
-    
+   
     void add(final TupleMatch tupleMatch) {
         this.list.add( tupleMatch );
     }
@@ -70,7 +54,7 @@
     /**
      * Removes the <code>TupleMatch</code> as the underlying <code>ReteTuple</code> has been retracted and no longer matches.
      * 
-     * @param tupleMatch
+     * @param compositeTupleMatch
      */
     void remove(final TupleMatch tupleMatch) {
         this.list.remove( tupleMatch );
@@ -89,8 +73,8 @@
      * 
      * @return the <code>TupleMatch</code>
      */
-    public TupleMatch getFirstTupleMatch() {
-        return (TupleMatch) this.list.getFirst();
+    public CompositeTupleMatch getFirstTupleMatch() {
+        return (CompositeTupleMatch) this.list.getFirst();
     }
 
     /**

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -46,7 +46,7 @@
  * hashCode implementation for <code>ReteTuple</code>.
  * 
  * @see Tuple
- * @see TupleMatch
+ * @see CompositeTupleMatch
  * @see TupleKey
  * 
  * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
@@ -235,8 +235,8 @@
         return (TupleMatch) this.matches.get( handle );
     }
 
-    public TupleMatch removeMatch(final InternalFactHandle handle) {
-        return (TupleMatch) this.matches.remove( handle );
+    public CompositeTupleMatch removeMatch(final InternalFactHandle handle) {
+        return (CompositeTupleMatch) this.matches.remove( handle );
     }
 
     //    public void remove(PropagationContext context,

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatch.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatch.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatch.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -0,0 +1,101 @@
+package org.drools.reteoo;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.common.InternalWorkingMemory;
+import org.drools.spi.PropagationContext;
+import org.drools.util.AbstractBaseLinkedListNode;
+
+/**
+ * <code>TupleMatch</code> maintains a reference to the parent <code>ReteTuple</code> and a <code>List</code> of all resulting joins. 
+ * This is a List rather than a single instance reference because we need to create a join for each TupleSink branches.
+ * A reference is also maintained to the <code>ObjectMatches</code> instance; this is so the <code>FactHandleImpl</code> that 
+ * is used in the join can be referenced, and also any other <code>TupleMatch</code>es the <code>FactHandleImpl</code> is joined with.
+ * 
+ * @see SingleTupleMatch
+ * @see ObjectMatches
+ * @see ReteTuple
+ * 
+ * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
+ * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
+ *
+ */
+public class SingleTupleMatch extends AbstractBaseLinkedListNode implements TupleMatch {
+    private ReteTuple          tuple;
+
+    private ReteTuple          child;
+
+    private ObjectMatches      objectMatches;
+
+    /**
+     * Construct a <code>TupleMatch</code> with references to the parent <code>ReteTuple</code> and 
+     * <code>FactHandleImpl</code>, via ObjecMatches.
+     * 
+     * @param tuple
+     * @param objectMatches
+     */
+    public SingleTupleMatch(final ReteTuple tuple,
+                      final ObjectMatches objectMatches) {
+        this.tuple = tuple;
+        this.objectMatches = objectMatches;    
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.ITupleMatch#getTuple()
+     */
+    public ReteTuple getTuple() {
+        return this.tuple;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.ITupleMatch#getObjectMatches()
+     */
+    public ObjectMatches getObjectMatches() {
+        return this.objectMatches;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.ITupleMatch#addJoinedTuple(org.drools.reteoo.ReteTuple)
+     */
+    public void addJoinedTuple(final ReteTuple tuple) {
+        this.child = tuple;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.ITupleMatch#propagateRetractTuple(org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
+     */
+    public void propagateRetractTuple(final PropagationContext context,
+                                      final InternalWorkingMemory workingMemory) {
+        this.child.retractTuple( context, workingMemory );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.ITupleMatch#propagateModifyTuple(org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
+     */
+    public void propagateModifyTuple(final PropagationContext context,
+                                     final InternalWorkingMemory workingMemory) {
+        this.child.modifyTuple( context, workingMemory );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.ITupleMatch#getTupleForSink(org.drools.reteoo.TupleSink)
+     */
+    public ReteTuple getTupleForSink(TupleSink sink) {
+        return this.child;
+    }
+
+}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatchChildren.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatchChildren.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatchChildren.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -1,5 +0,0 @@
-package org.drools.reteoo;
-
-public class SingleTupleMatchChildren {
-
-}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatchFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatchFactory.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleMatchFactory.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -0,0 +1,26 @@
+package org.drools.reteoo;
+
+public class SingleTupleMatchFactory
+    implements
+    TupleMatchFactory {
+
+    private static TupleMatchFactory INSTANCE;
+    
+    public static TupleMatchFactory getInstance() {
+        if ( INSTANCE == null ) {
+            INSTANCE = new SingleTupleMatchFactory();
+        }
+        return INSTANCE;
+    }
+    
+    private SingleTupleMatchFactory() {
+        
+    }
+    
+    
+    public TupleMatch newTupleMatch(ReteTuple tuple,
+                                    ObjectMatches objectMatches) {
+        return new CompositeTupleMatch(tuple, objectMatches);
+    }
+
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleSinkAdapter.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleTupleSinkAdapter.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -88,5 +88,9 @@
 
         return propagatedTuples;
     }
+    
+    public int size() {
+        return 1;
+    }
 
 }

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatch.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatch.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatch.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -1,102 +0,0 @@
-package org.drools.reteoo;
-
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.common.InternalWorkingMemory;
-import org.drools.spi.PropagationContext;
-import org.drools.util.AbstractBaseLinkedListNode;
-
-/**
- * <code>TupleMatch</code> maintains a reference to the parent <code>ReteTuple</code> and a <code>List</code> of all resulting joins. 
- * This is a List rather than a single instance reference because we need to create a join for each TupleSink branches.
- * A reference is also maintained to the <code>ObjectMatches</code> instance; this is so the <code>FactHandleImpl</code> that 
- * is used in the join can be referenced, and also any other <code>TupleMatch</code>es the <code>FactHandleImpl</code> is joined with.
- * 
- * @see TupleMatch
- * @see ObjectMatches
- * @see ReteTuple
- * 
- * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
- * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
- *
- */
-public class TupleMatch extends AbstractBaseLinkedListNode {
-    private ReteTuple          tuple;
-
-    private TupleMatchChildren children;
-
-    private ObjectMatches      objectMatches;
-
-    /**
-     * Construct a <code>TupleMatch</code> with references to the parent <code>ReteTuple</code> and 
-     * <code>FactHandleImpl</code>, via ObjecMatches.
-     * 
-     * @param tuple
-     * @param objectMatches
-     */
-    public TupleMatch(final ReteTuple tuple,
-                      final ObjectMatches objectMatches) {
-        this.tuple = tuple;
-        this.objectMatches = objectMatches;
-        this.children = new CompositeTupleMatchChildren();
-    }
-
-    /**
-     * Return the parent <code>ReteTuple</code>
-     * 
-     * @return the <code>ReteTuple</code>
-     */
-    public ReteTuple getTuple() {
-        return this.tuple;
-    }
-
-    /**
-     * Returns the referenced <code>ObjectMatches</code> which provides the 
-     * <code>FactHandleImpl</code> the <code>ReteTuple</code> is joined with.
-     * 
-     * @return the <code>ObjectMatches</code>
-     */
-    public ObjectMatches getObjectMatches() {
-        return this.objectMatches;
-    }
-
-    /**
-     * Adds a resulting join to the <code>List</code>. A join is made for each <code>TupleSink</code>.
-     * 
-     * @param tuple
-     */
-    public void addJoinedTuple(final ReteTuple tuple) {
-        this.children.add( tuple );
-    }
-
-    public void propagateRetractTuple(final PropagationContext context,
-                                      final InternalWorkingMemory workingMemory) {
-        this.children.propagateRetractTuple( context,
-                                             workingMemory );
-    }
-
-    public void propagateModifyTuple(final PropagationContext context,
-                                     final InternalWorkingMemory workingMemory) {
-        this.children.propagateModifyTuple( context,
-                                            workingMemory );
-    }
-
-    public ReteTuple getTupleForSink(TupleSink sink) {
-        return this.children.getTupleForSink( sink );
-    }
-
-}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatchChildren.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatchChildren.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatchChildren.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -1,16 +0,0 @@
-package org.drools.reteoo;
-
-import org.drools.common.InternalWorkingMemory;
-import org.drools.spi.PropagationContext;
-
-public interface TupleMatchChildren {
-    public void add(ReteTuple tuple);
-
-    public void propagateRetractTuple(final PropagationContext context,
-                                      final InternalWorkingMemory workingMemory);
-
-    public void propagateModifyTuple(final PropagationContext context,
-                                     final InternalWorkingMemory workingMemory);
-    
-    public ReteTuple getTupleForSink(TupleSink sink);
-}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatchFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatchFactory.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleMatchFactory.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -0,0 +1,5 @@
+package org.drools.reteoo;
+
+public interface TupleMatchFactory {
+    public TupleMatch newTupleMatch(ReteTuple tuple, ObjectMatches objectMatches);
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleSinkPropagator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleSinkPropagator.java	2006-09-13 21:19:52 UTC (rev 6213)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TupleSinkPropagator.java	2006-09-13 21:34:04 UTC (rev 6214)
@@ -38,5 +38,7 @@
     public List getPropagatedTuples(final Map memory,
                                     final InternalWorkingMemory workingMemory,
                                     final TupleSink sink);
+    
+    public int size();
 
 }




More information about the jboss-svn-commits mailing list