[jboss-svn-commits] JBL Code SVN: r17835 - in labs/jbossrules/branches/temporal_rete: drools-core/src/main/java/org/drools/common and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jan 14 15:15:03 EST 2008


Author: tirelli
Date: 2008-01-14 15:15:03 -0500 (Mon, 14 Jan 2008)
New Revision: 17835

Added:
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java
Modified:
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/RuleBaseEventManager.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/event/RuleBaseEventSupport.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/Rete.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
   labs/jbossrules/branches/temporal_rete/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java
Log:
JBRULES-1390: Adding support to the EntryPointNode in the network, as well as the Queuing node.

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/RuleBaseEventManager.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/RuleBaseEventManager.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/RuleBaseEventManager.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -49,6 +49,6 @@
      * 
      * @return listeners The listeners.
      */
-    public List getRuleBaseEventListeners();
+    public List<RuleBaseEventListener> getRuleBaseEventListeners();
 
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -774,7 +774,7 @@
         this.eventSupport.removeEventListener( listener );
     }
 
-    public List getRuleBaseEventListeners() {
+    public List<RuleBaseEventListener> getRuleBaseEventListeners() {
         // since the event support is thread-safe, no need for locks... right?
         return this.eventSupport.getEventListeners();
     }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/event/RuleBaseEventSupport.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/event/RuleBaseEventSupport.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/event/RuleBaseEventSupport.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -37,9 +37,9 @@
     /**
      * 
      */
-    private static final long serialVersionUID = 400L;
-    private final List<EventListener>        listeners        = Collections.synchronizedList( new ArrayList<EventListener>() );
-    private transient RuleBase    ruleBase;
+    private static final long                 serialVersionUID = 400L;
+    private final List<RuleBaseEventListener> listeners        = Collections.synchronizedList( new ArrayList<RuleBaseEventListener>() );
+    private transient RuleBase                ruleBase;
 
     public RuleBaseEventSupport(final RuleBase ruleBase) {
         this.ruleBase = ruleBase;
@@ -50,25 +50,25 @@
             this.listeners.add( listener );
         }
     }
-    
+
     public void setRuleBase(RuleBase ruleBase) {
         this.ruleBase = ruleBase;
     }
-    
+
     public void removeEventListener(Class cls) {
-        for ( Iterator<EventListener> it = this.listeners.iterator(); it.hasNext(); ) {
-            EventListener listener = it.next();
+        for ( Iterator<RuleBaseEventListener> it = this.listeners.iterator(); it.hasNext(); ) {
+            RuleBaseEventListener listener = it.next();
             if ( cls.isAssignableFrom( listener.getClass() ) ) {
                 it.remove();
             }
-        }        
+        }
     }
 
     public void removeEventListener(final RuleBaseEventListener listener) {
         this.listeners.remove( listener );
     }
 
-    public List<EventListener> getEventListeners() {
+    public List<RuleBaseEventListener> getEventListeners() {
         return Collections.unmodifiableList( this.listeners );
     }
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -33,15 +33,11 @@
 import org.drools.base.ShadowProxyFactory;
 import org.drools.common.DroolsObjectInputStream;
 import org.drools.common.InternalRuleBase;
-import org.drools.objenesis.Objenesis;
-import org.drools.objenesis.ObjenesisStd;
 import org.drools.objenesis.instantiator.ObjectInstantiator;
 import org.drools.reteoo.builder.BuildContext;
 import org.drools.reteoo.builder.PatternBuilder;
 import org.drools.rule.EntryPoint;
 import org.drools.spi.ObjectType;
-import org.drools.util.Iterator;
-import org.drools.util.ObjectHashMap.ObjectEntry;
 
 public class ClassObjectTypeConf
     implements
@@ -280,11 +276,9 @@
     }
 
     private ObjectTypeNode[] getMatchingObjectTypes(final Class clazz) throws FactException {
-        final List cache = new ArrayList();
+        final List<ObjectTypeNode> cache = new ArrayList<ObjectTypeNode>();
 
-        final Iterator it = ruleBase.getRete().getObjectTypeNodes( this.entryPoint ).newIterator();
-        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
-            final ObjectTypeNode node = (ObjectTypeNode) entry.getValue();
+        for( ObjectTypeNode node : ruleBase.getRete().getObjectTypeNodes( this.entryPoint ).values() ) {
             if ( node.isAssignableFrom( clazz ) ) {
                 cache.add( node );
             }

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -0,0 +1,279 @@
+package org.drools.reteoo;
+
+/*
+ * Copyright 2007 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.
+ * 
+ * Created on January 8th, 2007
+ */
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.base.ShadowProxy;
+import org.drools.common.BaseNode;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.common.NodeMemory;
+import org.drools.common.PropagationContextImpl;
+import org.drools.reteoo.builder.BuildContext;
+import org.drools.rule.EntryPoint;
+import org.drools.spi.ObjectType;
+import org.drools.spi.PropagationContext;
+import org.drools.util.FactEntry;
+import org.drools.util.FactHashTable;
+import org.drools.util.Iterator;
+
+/**
+ * A node that is an entry point into the Rete network.
+ *
+ * As we move the design to support network partitions and concurrent processing 
+ * of parts of the network, we also need to support multiple, independent entry
+ * points and this class represents that. 
+ * 
+ * It replaces the function of the Rete Node class in previous designs.
+ * 
+ * @see ObjectTypeNode
+ *
+ * @author <a href="mailto:tirelli at post.com">Edson Tirelli</a>
+ */
+public class EntryPointNode extends ObjectSource
+    implements
+    Serializable,
+    ObjectSink {
+    // ------------------------------------------------------------
+    // Instance members
+    // ------------------------------------------------------------
+
+    private static final long   serialVersionUID = 420L;
+
+    /**
+     * The entry point ID for this node
+     */
+    private final EntryPoint    entryPoint;
+
+    /**
+     * The object type nodes under this node
+     */
+    private final Map<ObjectType, ObjectTypeNode> objectTypeNodes;
+
+    // ------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------
+
+    public EntryPointNode(final int id,
+                          final ObjectSource objectSource,
+                          final BuildContext context) {
+        this( id,
+              objectSource,
+              context.getCurrentEntryPoint() ); // irrelevant for this node, since it overrides sink management
+    }
+
+    public EntryPointNode(final int id,
+                          final ObjectSource objectSource,
+                          final EntryPoint entryPoint) {
+        super( id,
+               objectSource,
+               999 ); // irrelevant for this node, since it overrides sink management
+        this.entryPoint = entryPoint;
+        this.objectTypeNodes = new HashMap<ObjectType, ObjectTypeNode>();
+    }
+
+    // ------------------------------------------------------------
+    // Instance methods
+    // ------------------------------------------------------------
+
+    /**
+     * @return the entryPoint
+     */
+    public EntryPoint getEntryPoint() {
+        return entryPoint;
+    }
+
+    /**
+     * This is the entry point into the network for all asserted Facts. Iterates a cache
+     * of matching <code>ObjectTypdeNode</code>s asserting the Fact. If the cache does not
+     * exist it first iterates and builds the cache.
+     *
+     * @param handle
+     *            The FactHandle of the fact to assert
+     * @param context
+     *            The <code>PropagationContext</code> of the <code>WorkingMemory</code> action
+     * @param workingMemory
+     *            The working memory session.
+     */
+    public void assertObject(final InternalFactHandle handle,
+                             final PropagationContext context,
+                             final InternalWorkingMemory workingMemory) {
+
+        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( this.entryPoint,
+                                                                         handle.getObject() );
+
+        // checks if shadow is enabled
+        if ( objectTypeConf.isShadowEnabled() ) {
+            // need to improve this
+            if ( !(handle.getObject() instanceof ShadowProxy) ) {
+                // replaces the actual object by its shadow before propagating
+                handle.setObject( objectTypeConf.getShadow( handle.getObject() ) );
+                handle.setShadowFact( true );
+            } else {
+                ((ShadowProxy) handle.getObject()).updateProxy();
+            }
+        }
+
+        ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
+
+        for ( int i = 0, length = cachedNodes.length; i < length; i++ ) {
+            cachedNodes[i].assertObject( handle,
+                                         context,
+                                         workingMemory );
+        }
+    }
+
+    /**
+     * Retract a fact object from this <code>RuleBase</code> and the specified
+     * <code>WorkingMemory</code>.
+     *
+     * @param handle
+     *            The handle of the fact to retract.
+     * @param workingMemory
+     *            The working memory session.
+     */
+    public void retractObject(final InternalFactHandle handle,
+                              final PropagationContext context,
+                              final InternalWorkingMemory workingMemory) {
+        final Object object = handle.getObject();
+
+        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( this.entryPoint,
+                                                                         object );
+        ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
+
+        if ( cachedNodes == null ) {
+            // it is  possible that there are no ObjectTypeNodes for an  object being retracted
+            return;
+        }
+
+        for ( int i = 0; i < cachedNodes.length; i++ ) {
+            cachedNodes[i].retractObject( handle,
+                                          context,
+                                          workingMemory );
+        }
+    }
+
+    /**
+     * Adds the <code>ObjectSink</code> so that it may receive
+     * <code>Objects</code> propagated from this <code>ObjectSource</code>.
+     *
+     * @param objectSink
+     *            The <code>ObjectSink</code> to receive propagated
+     *            <code>Objects</code>. Rete only accepts <code>ObjectTypeNode</code>s
+     *            as parameters to this method, though.
+     */
+    protected void addObjectSink(final ObjectSink objectSink) {
+        final ObjectTypeNode node = (ObjectTypeNode) objectSink;
+        this.objectTypeNodes.put( node.getObjectType(),
+                                  node );
+    }
+
+    protected void removeObjectSink(final ObjectSink objectSink) {
+        final ObjectTypeNode node = (ObjectTypeNode) objectSink;
+        this.objectTypeNodes.remove( node.getObjectType() );
+    }
+
+    public void attach() {
+        this.objectSource.addObjectSink( this );
+    }
+
+    public void attach(final InternalWorkingMemory[] workingMemories) {
+        attach();
+
+        for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
+            final InternalWorkingMemory workingMemory = workingMemories[i];
+            final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
+                                                                                      PropagationContext.RULE_ADDITION,
+                                                                                      null,
+                                                                                      null );
+            this.objectSource.updateSink( this,
+                                          propagationContext,
+                                          workingMemory );
+        }
+    }
+
+    public void remove(final BaseNode node,
+                       final InternalWorkingMemory[] workingMemories) {
+        final ObjectTypeNode objectTypeNode = (ObjectTypeNode) node;
+        removeObjectSink( objectTypeNode );
+        for ( int i = 0; i < workingMemories.length; i++ ) {
+            // clear the node memory for each working memory.
+            workingMemories[i].clearNodeMemory( (NodeMemory) node );
+        }
+    }
+
+    public Map<ObjectType, ObjectTypeNode> getObjectTypeNodes() {
+        return this.objectTypeNodes;
+    }
+
+    public int hashCode() {
+        return this.entryPoint.hashCode();
+    }
+
+    public boolean equals(final Object object) {
+        if ( object == this ) {
+            return true;
+        }
+
+        if ( object == null || !(object instanceof EntryPointNode) ) {
+            return false;
+        }
+
+        final EntryPointNode other = (EntryPointNode) object;
+        return this.entryPoint.equals( other.entryPoint );
+    }
+
+    public void updateSink(final ObjectSink sink,
+                           final PropagationContext context,
+                           final InternalWorkingMemory workingMemory) {
+        // JBRULES-612: the cache MUST be invalidated when a new node type is added to the network, so iterate and reset all caches.
+        final ObjectTypeNode node = (ObjectTypeNode) sink;
+        final ObjectType newObjectType = node.getObjectType();
+
+        for ( ObjectTypeConf objectTypeConf : workingMemory.getObjectTypeConfMap( this.entryPoint ).values() ) {
+            if ( newObjectType.isAssignableFrom( objectTypeConf.getConcreteObjectTypeNode().getObjectType() ) ) {
+                objectTypeConf.resetCache();
+                ObjectTypeNode sourceNode = objectTypeConf.getConcreteObjectTypeNode();
+                FactHashTable table = (FactHashTable) workingMemory.getNodeMemory( sourceNode );
+                Iterator factIter = table.iterator();
+                for ( FactEntry factEntry = (FactEntry) factIter.next(); factEntry != null; factEntry = (FactEntry) factIter.next() ) {
+                    sink.assertObject( factEntry.getFactHandle(),
+                                       context,
+                                       workingMemory );
+                }
+            }
+        }
+    }
+
+    public boolean isObjectMemoryEnabled() {
+        return false;
+    }
+
+    public void setObjectMemoryEnabled(boolean objectMemoryEnabled) {
+        throw new UnsupportedOperationException( "Entry Point Node has no Object memory" );
+    }
+    
+    public String toString() {
+        return "[EntryPointNode("+this.id+") "+this.entryPoint+" ]";
+    }
+
+}

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -32,18 +32,17 @@
     implements
     ObjectTypeConf,
     Serializable {
-    private InternalRuleBase ruleBase;
+
+    private static final long serialVersionUID = 4493660262148247467L;
+
     private FactTemplate     factTemplate;
     private ObjectTypeNode   concreteObjectTypeNode;
     private ObjectTypeNode[] cache;
-    private EntryPoint       entryPoint;
 
     public FactTemplateTypeConf(final EntryPoint entryPoint,
                                 final FactTemplate factTemplate,
                                 final InternalRuleBase ruleBase) {
-        this.ruleBase = ruleBase;
         this.factTemplate = factTemplate;
-        this.entryPoint = entryPoint;
 
         ObjectType objectType = new FactTemplateObjectType( factTemplate );
         this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes( entryPoint ).get( objectType );

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -35,9 +35,7 @@
      * Rete visits each of its ObjectTypeNodes.
      */
     public void visitRete(final Rete rete) {
-        final Map<ObjectType, ObjectTypeNode> map = rete.getObjectTypeNodes();
-
-        for( ObjectTypeNode node : map.values() ) {
+        for( ObjectTypeNode node : rete.getObjectTypeNodes() ) {
             visit( node );
         }
     }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -72,15 +72,10 @@
     /** The <code>ObjectType</code> semantic module. */
     private final ObjectType  objectType;
 
-    /** The parent Rete node */
-    private final Rete        rete;
-
     private boolean           skipOnModify     = false;
 
     private boolean           objectMemoryEnabled;
 
-    private final EntryPoint  entryPoint;
-
     /**
      * Construct given a semantic <code>ObjectType</code> and the provided
      * unique id. All <code>ObjectTypdeNode</code> have node memory.
@@ -91,15 +86,14 @@
      *           The semantic object-type differentiator.
      */
     public ObjectTypeNode(final int id,
+                          final EntryPointNode source,
                           final ObjectType objectType,
                           final BuildContext context) {
         super( id,
-               context.getRuleBase().getRete(),
+               source,
                context.getRuleBase().getConfiguration().getAlphaNodeHashingThreshold() );
-        this.rete = (Rete) this.objectSource;
         this.objectType = objectType;
         setObjectMemoryEnabled( context.isObjectTypeNodeMemoryEnabled() );
-        this.entryPoint = context.getCurrentEntryPoint() == null ? EntryPoint.DEFAULT : context.getCurrentEntryPoint();
     }
 
     /**
@@ -203,7 +197,7 @@
      * Rete needs to know that this ObjectTypeNode has been added
      */
     public void attach() {
-        this.rete.addObjectSink( this );
+        this.objectSource.addObjectSink( this );
     }
 
     public void attach(final InternalWorkingMemory[] workingMemories) {
@@ -218,10 +212,10 @@
                                                                                           PropagationContext.RULE_ADDITION,
                                                                                           null,
                                                                                           null );
-            propagationContext.setEntryPoint( this.entryPoint );
-            this.rete.updateSink( this,
-                                  propagationContext,
-                                  workingMemory );
+            propagationContext.setEntryPoint( ((EntryPointNode) this.objectSource).getEntryPoint() );
+            this.objectSource.updateSink( this,
+                                          propagationContext,
+                                          workingMemory );
         }
     }
 
@@ -235,7 +229,7 @@
             for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
                 workingMemories[i].clearNodeMemory( this );
             }
-            this.rete.removeObjectSink( this );
+            this.objectSource.removeObjectSink( this );
         }
     }
 
@@ -265,14 +259,14 @@
     }
 
     public String toString() {
-        return "[ObjectTypeNode(" + this.id + ") " + this.entryPoint + " objectType=" + this.objectType + "]";
+        return "[ObjectTypeNode(" + this.id + ")::" + ((EntryPointNode)this.objectSource).getEntryPoint() + " objectType=" + this.objectType + "]";
     }
 
     /**
      * Uses he hashCode() of the underlying ObjectType implementation.
      */
     public int hashCode() {
-        return this.objectType.hashCode() ^ this.entryPoint.hashCode();
+        return this.objectType.hashCode() ^ this.objectSource.hashCode();
     }
 
     public boolean equals(final Object object) {
@@ -286,7 +280,7 @@
 
         final ObjectTypeNode other = (ObjectTypeNode) object;
 
-        return this.objectType.equals( other.objectType ) && this.entryPoint.equals( other.entryPoint );
+        return this.objectType.equals( other.objectType ) && this.objectSource.equals( other.objectSource );
     }
 
     /** 
@@ -353,6 +347,6 @@
      * @return the entryPoint
      */
     public EntryPoint getEntryPoint() {
-        return entryPoint;
+        return ((EntryPointNode)this.objectSource).getEntryPoint();
     }
 }

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -0,0 +1,357 @@
+/*
+ * Copyright 2008 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.
+ */
+package org.drools.reteoo;
+
+import java.io.Serializable;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.drools.RuleBaseConfiguration;
+import org.drools.RuntimeDroolsException;
+import org.drools.common.BaseNode;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.common.NodeMemory;
+import org.drools.common.WorkingMemoryAction;
+import org.drools.reteoo.builder.BuildContext;
+import org.drools.spi.PropagationContext;
+
+/**
+ * A node that will add the propagation to the working memory actions queue,
+ * in order to allow multiple threads to concurrently assert objects to multiple
+ * entry points.
+ * 
+ * @author etirelli
+ *
+ */
+public class PropagationQueuingNode extends ObjectSource
+    implements
+    ObjectSinkNode,
+    NodeMemory {
+
+    private static final long serialVersionUID = -615639068150958767L;
+    
+    // should we make this one configurable?
+    private static final int PROPAGATION_SLICE_LIMIT = 1000;
+
+    private ObjectSinkNode    previousObjectSinkNode;
+    private ObjectSinkNode    nextObjectSinkNode;
+    private PropagateAction   action;
+
+    /**
+     * Construct a <code>PropagationQueuingNode</code> that will queue up
+     * propagations until it the engine reaches a safe propagation point,
+     * when all the queued facts are propagated.
+     * 
+     * @param id Node's ID
+     * @param constraint Node's constraints
+     * @param objectSource Node's object source
+     * @param hasMemory true if node shall be configured with local memory. False otherwise.
+     */
+    public PropagationQueuingNode(final int id,
+                                  final ObjectSource objectSource,
+                                  final BuildContext context) {
+        super( id,
+               objectSource,
+               context.getRuleBase().getConfiguration().getAlphaNodeHashingThreshold() );
+        this.action = new PropagateAction( this );
+    }
+
+    /**
+     * @see org.drools.reteoo.ObjectSource#updateSink(org.drools.reteoo.ObjectSink, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
+     */
+    @Override
+    public void updateSink(ObjectSink sink,
+                           PropagationContext context,
+                           InternalWorkingMemory workingMemory) {
+
+        final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory.getNodeMemory( this );
+
+        // this is just sanity code. We may remove it in the future, but keeping it for now.
+        if ( !memory.isEmpty() ) {
+            throw new RuntimeDroolsException( "Error updating sink. Not safe to update sink as the PropagatingQueueingNode memory is not for node: " + this.toString() );
+        }
+
+        // as this node is simply a queue, ask object source to update the child sink directly
+        this.objectSource.updateSink( sink,
+                                      context,
+                                      workingMemory );
+    }
+
+    /**
+     * @see org.drools.common.BaseNode#attach()
+     */
+    @Override
+    public void attach() {
+        this.objectSource.addObjectSink( this );
+    }
+
+    /**
+     * @see org.drools.common.BaseNode#attach(org.drools.common.InternalWorkingMemory[])
+     */
+    @Override
+    public void attach(InternalWorkingMemory[] workingMemories) {
+        attach();
+        // this node does not require update, so nothing else to do.
+    }
+
+    /**
+     * @see org.drools.common.BaseNode#remove(org.drools.common.BaseNode, org.drools.common.InternalWorkingMemory[])
+     */
+    @Override
+    public void remove(BaseNode node,
+                       InternalWorkingMemory[] workingMemories) {
+        if ( !node.isInUse() ) {
+            removeObjectSink( (ObjectSink) node );
+        }
+        removeShare();
+        if ( !this.isInUse() ) {
+            for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
+                workingMemories[i].clearNodeMemory( this );
+            }
+        }
+        this.objectSource.remove( this,
+                                  workingMemories );
+    }
+
+    /**
+     * @see org.drools.reteoo.ObjectSinkNode#getNextObjectSinkNode()
+     */
+    public ObjectSinkNode getNextObjectSinkNode() {
+        return this.nextObjectSinkNode;
+    }
+
+    /**
+     * @see org.drools.reteoo.ObjectSinkNode#getPreviousObjectSinkNode()
+     */
+    public ObjectSinkNode getPreviousObjectSinkNode() {
+        return this.previousObjectSinkNode;
+    }
+
+    /**
+     * @see org.drools.reteoo.ObjectSinkNode#setNextObjectSinkNode(org.drools.reteoo.ObjectSinkNode)
+     */
+    public void setNextObjectSinkNode(ObjectSinkNode next) {
+        this.nextObjectSinkNode = next;
+    }
+
+    /**
+     * @see org.drools.reteoo.ObjectSinkNode#setPreviousObjectSinkNode(org.drools.reteoo.ObjectSinkNode)
+     */
+    public void setPreviousObjectSinkNode(ObjectSinkNode previous) {
+        this.previousObjectSinkNode = previous;
+    }
+
+    /**
+     * @see org.drools.reteoo.ObjectSink#assertObject(org.drools.common.InternalFactHandle, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
+     */
+    public void assertObject(InternalFactHandle handle,
+                             PropagationContext context,
+                             InternalWorkingMemory workingMemory) {
+        final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory.getNodeMemory( this );
+        memory.addAction( new AssertAction( handle,
+                                            context ) );
+
+        // if not queued yet, we need to queue it up
+        if ( memory.isQueued().compareAndSet( false,
+                                              true ) ) {
+            workingMemory.queueWorkingMemoryAction( this.action );
+        }
+    }
+
+    /**
+     * @see org.drools.reteoo.ObjectSink#isObjectMemoryEnabled()
+     */
+    public boolean isObjectMemoryEnabled() {
+        return true;
+    }
+
+    /**
+     * @see org.drools.reteoo.ObjectSink#retractObject(org.drools.common.InternalFactHandle, org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
+     */
+    public void retractObject(InternalFactHandle handle,
+                              PropagationContext context,
+                              InternalWorkingMemory workingMemory) {
+        final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory.getNodeMemory( this );
+        memory.addAction( new RetractAction( handle,
+                                             context ) );
+
+        // if not queued yet, we need to queue it up
+        if ( memory.isQueued().compareAndSet( false,
+                                              true ) ) {
+            workingMemory.queueWorkingMemoryAction( this.action );
+        }
+    }
+
+    /**
+     * Propagate all queued actions (asserts and retracts).
+     * 
+     * This method implementation is based on optimistic behavior to avoid the 
+     * use of locks. There may eventually be a minimum wasted effort, but overall
+     * it will be better than paying for the lock's cost.
+     * 
+     * @param workingMemory
+     */
+    public void propagateActions(InternalWorkingMemory workingMemory) {
+        final PropagationQueueingNodeMemory memory = (PropagationQueueingNodeMemory) workingMemory.getNodeMemory( this );
+
+        // first we clear up the action queued flag
+        memory.isQueued().set( false );
+
+        // we limit the propagation to avoid a hang when this queue is never empty
+        Action next = memory.getNext();
+        for( int counter = 0; next != null && counter < PROPAGATION_SLICE_LIMIT; next = memory.getNext(), counter++ ) {
+            next.execute( this.sink, workingMemory );
+        }
+        
+        if( memory.hasNext() ) {
+            // add action to the queue again.
+            memory.isQueued().set( true );
+            workingMemory.queueWorkingMemoryAction( this.action );
+        }
+    }
+
+    /**
+     * @see org.drools.reteoo.ObjectSink#setObjectMemoryEnabled(boolean)
+     */
+    public void setObjectMemoryEnabled(boolean objectMemoryOn) {
+        throw new UnsupportedOperationException( "PropagationQueueingNode must have its node memory enabled." );
+    }
+
+    public Object createMemory(RuleBaseConfiguration config) {
+        return new PropagationQueueingNodeMemory();
+    }
+
+    /**
+     * Memory implementation for the node
+     * 
+     * @author etirelli
+     */
+    private static class PropagationQueueingNodeMemory
+        implements
+        Serializable {
+
+        private static final long             serialVersionUID = 7372028632974484023L;
+
+        private ConcurrentLinkedQueue<Action> queue;
+
+        // "singleton" action - there is one of this for each node in each working memory
+        private AtomicBoolean                 isQueued;
+
+        public PropagationQueueingNodeMemory() {
+            super();
+            this.queue = new ConcurrentLinkedQueue<Action>();
+            this.isQueued = new AtomicBoolean( false );
+        }
+
+        public boolean isEmpty() {
+            return this.queue.isEmpty();
+        }
+
+        public void addAction(Action action) {
+            this.queue.add( action );
+        }
+
+        public Action getNext() {
+            return this.queue.poll();
+        }
+
+        public boolean hasNext() {
+            return this.queue.peek() != null;
+        }
+
+        public AtomicBoolean isQueued() {
+            return isQueued;
+        }
+    }
+
+    private static abstract class Action
+        implements
+        Serializable {
+
+        protected final InternalFactHandle handle;
+        protected final PropagationContext context;
+
+        public Action(InternalFactHandle handle,
+                      PropagationContext context) {
+            super();
+            this.handle = handle;
+            this.context = context;
+        }
+
+        public abstract void execute(final ObjectSinkPropagator sink,
+                                     final InternalWorkingMemory workingMemory);
+    }
+
+    private static class AssertAction extends Action {
+        private static final long serialVersionUID = -8478488926430845209L;
+
+        public AssertAction(final InternalFactHandle handle,
+                            final PropagationContext context) {
+            super( handle,
+                   context );
+        }
+
+        public void execute(final ObjectSinkPropagator sink,
+                            final InternalWorkingMemory workingMemory) {
+            sink.propagateAssertObject( this.handle,
+                                        this.context,
+                                        workingMemory );
+        }
+    }
+
+    private static class RetractAction extends Action {
+        private static final long serialVersionUID = -84784886430845209L;
+
+        public RetractAction(final InternalFactHandle handle,
+                             final PropagationContext context) {
+            super( handle,
+                   context );
+        }
+
+        public void execute(final ObjectSinkPropagator sink,
+                            final InternalWorkingMemory workingMemory) {
+            sink.propagateRetractObject( this.handle,
+                                         this.context,
+                                         workingMemory,
+                                         true );
+        }
+    }
+
+    /**
+     * This is the action that is added to the working memory actions queue, so that
+     * this node propagation can be triggered at a safe point
+     * 
+     * @author etirelli
+     *
+     */
+    private static class PropagateAction
+        implements
+        WorkingMemoryAction {
+
+        private static final long      serialVersionUID = 6765029029501617115L;
+
+        private PropagationQueuingNode node;
+
+        public PropagateAction(PropagationQueuingNode node) {
+            this.node = node;
+        }
+
+        public void execute(InternalWorkingMemory workingMemory) {
+            this.node.propagateActions( workingMemory );
+        }
+    }
+}

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/Rete.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/Rete.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/Rete.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -20,23 +20,22 @@
 import java.io.ObjectInputStream;
 import java.io.Serializable;
 import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
-import org.drools.base.ShadowProxy;
 import org.drools.common.BaseNode;
 import org.drools.common.DroolsObjectInputStream;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalRuleBase;
 import org.drools.common.InternalWorkingMemory;
-import org.drools.common.NodeMemory;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.EntryPoint;
 import org.drools.spi.ObjectType;
 import org.drools.spi.PropagationContext;
 import org.drools.util.FactEntry;
 import org.drools.util.FactHashTable;
 import org.drools.util.Iterator;
-import org.drools.util.ObjectHashMap;
-import org.drools.util.ObjectHashMap.ObjectEntry;
 
 /**
  * The Rete-OO network.
@@ -68,11 +67,11 @@
     /**
      *
      */
-    private static final long                    serialVersionUID = 400L;
+    private static final long                     serialVersionUID = 400L;
 
-    private final Map<EntryPoint, ObjectHashMap> entryPoints;
+    private final Map<EntryPoint, EntryPointNode> entryPoints;
 
-    private transient InternalRuleBase           ruleBase;
+    private transient InternalRuleBase            ruleBase;
 
     // ------------------------------------------------------------
     // Constructors
@@ -80,9 +79,7 @@
 
     public Rete(InternalRuleBase ruleBase) {
         super( 0 );
-        this.entryPoints = new HashMap<EntryPoint, ObjectHashMap>();
-        this.entryPoints.put( EntryPoint.DEFAULT,
-                              new ObjectHashMap() );
+        this.entryPoints = new HashMap<EntryPoint, EntryPointNode>();
         this.ruleBase = ruleBase;
     }
 
@@ -111,29 +108,10 @@
     public void assertObject(final InternalFactHandle handle,
                              final PropagationContext context,
                              final InternalWorkingMemory workingMemory) {
-
-        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( context.getEntryPoint(),
-                                                                         handle.getObject() );
-
-        // checks if shadow is enabled
-        if ( objectTypeConf.isShadowEnabled() ) {
-            // need to improve this
-            if ( !(handle.getObject() instanceof ShadowProxy) ) {
-                // replaces the actual object by its shadow before propagating
-                handle.setObject( objectTypeConf.getShadow( handle.getObject() ) );
-                handle.setShadowFact( true );
-            } else {
-                ((ShadowProxy) handle.getObject()).updateProxy();
-            }
-        }
-
-        ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
-
-        for ( int i = 0, length = cachedNodes.length; i < length; i++ ) {
-            cachedNodes[i].assertObject( handle,
-                                         context,
-                                         workingMemory );
-        }
+        EntryPointNode node = this.entryPoints.get( context.getEntryPoint() );
+        node.assertObject( handle,
+                           context,
+                           workingMemory );
     }
 
     /**
@@ -148,22 +126,10 @@
     public void retractObject(final InternalFactHandle handle,
                               final PropagationContext context,
                               final InternalWorkingMemory workingMemory) {
-        final Object object = handle.getObject();
-
-        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( context.getEntryPoint(),
-                                                                         object );
-        ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
-
-        if ( cachedNodes == null ) {
-            // it is  possible that there are no ObjectTypeNodes for an  object being retracted
-            return;
-        }
-
-        for ( int i = 0; i < cachedNodes.length; i++ ) {
-            cachedNodes[i].retractObject( handle,
-                                          context,
-                                          workingMemory );
-        }
+        EntryPointNode node = this.entryPoints.get( context.getEntryPoint() );
+        node.retractObject( handle,
+                            context,
+                            workingMemory );
     }
 
     /**
@@ -176,21 +142,14 @@
      *            as parameters to this method, though.
      */
     protected void addObjectSink(final ObjectSink objectSink) {
-        final ObjectTypeNode node = (ObjectTypeNode) objectSink;
-        ObjectHashMap map = this.entryPoints.get( node.getEntryPoint() );
-        if ( map == null ) {
-            map = new ObjectHashMap();
-            this.entryPoints.put( node.getEntryPoint(),
-                                  map );
-        }
-        map.put( node.getObjectType(),
-                 node,
-                 true );
+        final EntryPointNode node = (EntryPointNode) objectSink;
+        this.entryPoints.put( node.getEntryPoint(),
+                              node );
     }
 
     protected void removeObjectSink(final ObjectSink objectSink) {
-        final ObjectTypeNode node = (ObjectTypeNode) objectSink;
-        this.entryPoints.get( node.getEntryPoint() ).remove( node.getObjectType() );
+        final EntryPointNode node = (EntryPointNode) objectSink;
+        this.entryPoints.remove( node.getEntryPoint() );
     }
 
     public void attach() {
@@ -203,27 +162,24 @@
 
     public void remove(final BaseNode node,
                        final InternalWorkingMemory[] workingMemories) {
-        final ObjectTypeNode objectTypeNode = (ObjectTypeNode) node;
-        removeObjectSink( objectTypeNode );
-        for ( int i = 0; i < workingMemories.length; i++ ) {
-            // clear the node memory for each working memory.
-            workingMemories[i].clearNodeMemory( (NodeMemory) node );
-        }
+        final EntryPointNode entryPointNode = (EntryPointNode) node;
+        removeObjectSink( entryPointNode );
     }
+    
+    public EntryPointNode getEntryPointNode( final EntryPoint entryPoint ) {
+        return this.entryPoints.get( entryPoint );
+    }
 
-    public Map<ObjectType, ObjectTypeNode> getObjectTypeNodes() {
-        Map<ObjectType, ObjectTypeNode> allNodes = new HashMap<ObjectType, ObjectTypeNode>();
-        for( ObjectHashMap map : this.entryPoints.values() ) {
-            Iterator it = map.iterator();
-            for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
-                allNodes.put( (ObjectType) entry.getKey(), (ObjectTypeNode) entry.getValue() );
-            }
+    public List<ObjectTypeNode> getObjectTypeNodes() {
+        List<ObjectTypeNode> allNodes = new LinkedList<ObjectTypeNode>();
+        for( EntryPointNode node : this.entryPoints.values() ) {
+            allNodes.addAll(node.getObjectTypeNodes().values());
         }
         return allNodes;
     }
 
-    public ObjectHashMap getObjectTypeNodes(EntryPoint entryPoint) {
-        return this.entryPoints.get( entryPoint );
+    public Map<ObjectType, ObjectTypeNode> getObjectTypeNodes(EntryPoint entryPoint) {
+        return this.entryPoints.get( entryPoint ).getObjectTypeNodes();
     }
 
     public InternalRuleBase getRuleBase() {
@@ -250,23 +206,7 @@
     public void updateSink(final ObjectSink sink,
                            final PropagationContext context,
                            final InternalWorkingMemory workingMemory) {
-        // JBRULES-612: the cache MUST be invalidated when a new node type is added to the network, so iterate and reset all caches.
-        final ObjectTypeNode node = (ObjectTypeNode) sink;
-        final ObjectType newObjectType = node.getObjectType();
-
-        for ( ObjectTypeConf objectTypeConf : workingMemory.getObjectTypeConfMap( context.getEntryPoint() ).values() ) {
-            if ( newObjectType.isAssignableFrom( objectTypeConf.getConcreteObjectTypeNode().getObjectType() ) ) {
-                objectTypeConf.resetCache();
-                ObjectTypeNode sourceNode = objectTypeConf.getConcreteObjectTypeNode();
-                FactHashTable table = (FactHashTable) workingMemory.getNodeMemory( sourceNode );
-                Iterator factIter = table.iterator();
-                for ( FactEntry factEntry = (FactEntry) factIter.next(); factEntry != null; factEntry = (FactEntry) factIter.next() ) {
-                    sink.assertObject( factEntry.getFactHandle(),
-                                       context,
-                                       workingMemory );
-                }
-            }
-        }
+        // nothing to do, since Rete object itself holds no facts to propagate.
     }
 
     public boolean isObjectMemoryEnabled() {

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -38,6 +38,8 @@
 import org.drools.concurrent.ExecutorService;
 import org.drools.event.RuleBaseEventListener;
 import org.drools.reteoo.ReteooWorkingMemory.WorkingMemoryReteAssertAction;
+import org.drools.reteoo.builder.BuildContext;
+import org.drools.rule.EntryPoint;
 import org.drools.rule.InvalidPatternException;
 import org.drools.rule.Package;
 import org.drools.rule.Rule;
@@ -61,10 +63,10 @@
     private static final long serialVersionUID = 400L;
 
     /** The root Rete-OO for this <code>RuleBase</code>. */
-    private transient Rete              rete;
+    private transient Rete    rete;
 
     private ReteooBuilder     reteooBuilder;
-    
+
     // ------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------
@@ -129,6 +131,13 @@
                factHandleFactory );
         this.rete = new Rete( this );
         this.reteooBuilder = new ReteooBuilder( this );
+        
+        // always add the default entry point
+        EntryPointNode epn = new EntryPointNode( this.reteooBuilder.getIdGenerator().getNextId(), 
+                                                 this.rete,
+                                                 EntryPoint.DEFAULT );
+        epn.attach();
+        
     }
 
     /**
@@ -149,12 +158,12 @@
     public void readExternal(final ObjectInput stream) throws IOException,
                                                       ClassNotFoundException {
         doReadExternal( stream );
-        
+
         // rebuild the Rete network from the pkg information
         this.reteooBuilder = new ReteooBuilder( this );
-        this.rete = new Rete( this );        
-        synchronized ( this.pkgs ) {            
-            for (Package pkg : this.pkgs.values() ) {
+        this.rete = new Rete( this );
+        synchronized ( this.pkgs ) {
+            for ( Package pkg : this.pkgs.values() ) {
                 for ( Rule rule : pkg.getRules() ) {
                     addRule( rule );
                 }
@@ -174,7 +183,7 @@
     public Rete getRete() {
         return this.rete;
     }
-    
+
     public ReteooBuilder getReteooBuilder() {
         return this.reteooBuilder;
     }
@@ -220,50 +229,57 @@
                                  workingMemory );
     }
 
-    public synchronized StatefulSession newStatefulSession( final boolean keepReference ) {
-        return newStatefulSession( keepReference, null );
+    public synchronized StatefulSession newStatefulSession(final boolean keepReference) {
+        return newStatefulSession( keepReference,
+                                   null );
     }
-    
-    public synchronized TemporalSession newTemporalSession( final ClockType clockType ) {
-        return (TemporalSession) newStatefulSession( true, clockType);
+
+    public synchronized TemporalSession newTemporalSession(final ClockType clockType) {
+        return (TemporalSession) newStatefulSession( true,
+                                                     clockType );
     }
-    
-    public synchronized TemporalSession newTemporalSession( final boolean keepReference, final ClockType clockType ) {
-        return (TemporalSession) newStatefulSession( keepReference, clockType );
+
+    public synchronized TemporalSession newTemporalSession(final boolean keepReference,
+                                                           final ClockType clockType) {
+        return (TemporalSession) newStatefulSession( keepReference,
+                                                     clockType );
     }
-    
+
     /**
      * @see RuleBase
      */
-    private StatefulSession newStatefulSession( final boolean keepReference, final ClockType clockType ) {
+    private StatefulSession newStatefulSession(final boolean keepReference,
+                                               final ClockType clockType) {
         if ( this.config.isSequential() ) {
             throw new RuntimeException( "Cannot have a stateful rule session, with sequential configuration set to true" );
         }
         ReteooStatefulSession session = null;
 
         synchronized ( this.pkgs ) {
-            ExecutorService executor = ExecutorServiceFactory.createExecutorService(  this.config.getExecutorService() );;
-            if( clockType == null ) {
+            ExecutorService executor = ExecutorServiceFactory.createExecutorService( this.config.getExecutorService() );;
+            if ( clockType == null ) {
                 session = new ReteooStatefulSession( nextWorkingMemoryCounter(),
                                                      this,
                                                      executor );
             } else {
                 session = new ReteooTemporalSession( nextWorkingMemoryCounter(),
-                                                             this,
-                                                             executor,
-                                                             clockType.createInstance() );
+                                                     this,
+                                                     executor,
+                                                     clockType.createInstance() );
             }
 
             executor.setCommandExecutor( new CommandExecutor( session ) );
 
             if ( keepReference ) {
                 super.addStatefulSession( session );
-                for( Iterator it = session.getRuleBaseUpdateListeners().iterator(); it.hasNext(); ) {
-                    addEventListener( (RuleBaseEventListener) it.next() ); 
+                for ( Iterator it = session.getRuleBaseUpdateListeners().iterator(); it.hasNext(); ) {
+                    addEventListener( (RuleBaseEventListener) it.next() );
                 }
             }
 
-            final InitialFactHandle handle = new InitialFactHandle( session.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(), false, session ) );
+            final InitialFactHandle handle = new InitialFactHandle( session.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(),
+                                                                                                                  false,
+                                                                                                                  session ) );
 
             session.queueWorkingMemoryAction( new WorkingMemoryReteAssertAction( handle,
                                                                                  false,
@@ -271,10 +287,10 @@
                                                                                  null,
                                                                                  null ) );
         }
-        
+
         return session;
     }
-    
+
     public StatelessSession newStatelessSession() {
 
         //orders the rules
@@ -301,5 +317,5 @@
         Serializable {
         private static final long serialVersionUID = 400L;
     }
-    
+
 }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -31,6 +31,7 @@
 import org.drools.common.QuadroupleBetaConstraints;
 import org.drools.common.SingleBetaConstraints;
 import org.drools.common.TripleBetaConstraints;
+import org.drools.reteoo.EntryPointNode;
 import org.drools.reteoo.ObjectSink;
 import org.drools.reteoo.ObjectSource;
 import org.drools.reteoo.ObjectTypeNode;
@@ -40,7 +41,7 @@
 import org.drools.rule.InvalidPatternException;
 import org.drools.rule.RuleConditionElement;
 import org.drools.spi.BetaNodeFieldConstraint;
-import org.drools.util.ObjectHashMap;
+import org.drools.spi.ObjectType;
 
 /**
  * Utility functions for reteoo build
@@ -83,17 +84,23 @@
      *            The node to attach.
      *            
      * @return the actual attached node that may be the one given as parameter
-     *         or eventualy one that was already in the cache if sharing is enabled
+     *         or eventually one that was already in the cache if sharing is enabled
      */
     public BaseNode attachNode(final BuildContext context,
                                final BaseNode candidate) {
         BaseNode node = null;
-        if( candidate instanceof ObjectTypeNode ) {
+        if( candidate instanceof EntryPointNode ) {
+            // entry point nodes are always shared
+            EntryPointNode epn = context.getRuleBase().getRete().getEntryPointNode( ((EntryPointNode)candidate).getEntryPoint() );
+            if( epn != null ) {
+                node = epn;
+            }
+        } else if( candidate instanceof ObjectTypeNode ) {
             // object type nodes are always shared
             ObjectTypeNode otn = (ObjectTypeNode) candidate;
-            ObjectHashMap map = context.getRuleBase().getRete().getObjectTypeNodes( context.getCurrentEntryPoint() );
+            Map<ObjectType, ObjectTypeNode> map = context.getRuleBase().getRete().getObjectTypeNodes( context.getCurrentEntryPoint() );
             if( map != null ) {
-                otn = (ObjectTypeNode) map.get( otn.getObjectType() );
+                otn = map.get( otn.getObjectType() );
                 if ( otn != null ) {
                     node = otn;
                 }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -25,8 +25,10 @@
 import org.drools.common.InstanceNotEqualsConstraint;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.reteoo.AlphaNode;
+import org.drools.reteoo.EntryPointNode;
 import org.drools.reteoo.ObjectSource;
 import org.drools.reteoo.ObjectTypeNode;
+import org.drools.reteoo.PropagationQueuingNode;
 import org.drools.rule.Declaration;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.InvalidPatternException;
@@ -93,15 +95,23 @@
                            source );
             // restoring offset
             context.setCurrentPatternOffset( currentOffset );
-            
+
         }
-        
-        if( pattern.getSource() == null || context.getCurrentEntryPoint() != EntryPoint.DEFAULT ) {
+
+        if ( pattern.getSource() == null || context.getCurrentEntryPoint() != EntryPoint.DEFAULT ) {
             attachAlphaNodes( context,
                               utils,
                               pattern,
                               alphaConstraints );
-            context.setCurrentEntryPoint( EntryPoint.DEFAULT );
+
+            if ( context.getCurrentEntryPoint() != EntryPoint.DEFAULT ) {
+                context.setObjectSource( (ObjectSource) utils.attachNode( context,
+                                                                          new PropagationQueuingNode( context.getNextId(),
+                                                                                                      context.getObjectSource(),
+                                                                                                      context ) ) );
+                // the entry-point specific network nodes are attached, so, set context to default entry-point 
+                context.setCurrentEntryPoint( EntryPoint.DEFAULT );
+            }
         }
 
         // last thing to do is increment the offset, since if the pattern has a source,
@@ -152,20 +162,34 @@
 
     public static ObjectTypeNode attachObjectTypeNode(BuildContext context,
                                                       ObjectType objectType) {
-        synchronized ( context.getRuleBase().getPackagesMap() ) {                           
+        synchronized ( context.getRuleBase().getPackagesMap() ) {
+            InternalWorkingMemory[] wms = context.getWorkingMemories();
+
+            EntryPointNode epn = context.getRuleBase().getRete().getEntryPointNode( context.getCurrentEntryPoint() );
+            if ( epn == null ) {
+                epn = new EntryPointNode( context.getNextId(),
+                                          context.getRuleBase().getRete(),
+                                          context );
+                if ( wms.length > 0 ) {
+                    epn.attach( wms );
+                } else {
+                    epn.attach();
+                }
+            }
+
             ObjectTypeNode otn = new ObjectTypeNode( context.getNextId(),
+                                                     epn,
                                                      objectType,
                                                      context );
-    
-            InternalWorkingMemory[] wms = context.getWorkingMemories();
+
             if ( wms.length > 0 ) {
                 otn.attach( wms );
             } else {
                 otn.attach();
             }
-    
+
             return otn;
-        } 
+        }
     }
 
     public void attachAlphaNodes(final BuildContext context,
@@ -175,10 +199,10 @@
 
         // Drools Query ObjectTypeNode never has memory, but other ObjectTypeNode/AlphaNoesNodes may (if not in sequential), 
         //so need to preserve, so we can resotre after this node is added. LeftMemory  and Terminal remain the same once set.
-        
-        boolean objectMemory = context.isObjectTypeNodeMemoryEnabled(); 
+
+        boolean objectMemory = context.isObjectTypeNodeMemoryEnabled();
         boolean alphaMemory = context.isAlphaMemoryAllowed();
-                
+
         if ( pattern.getObjectType() instanceof ClassObjectType ) {
             // Is this the query node, if so we don't want any memory
             if ( DroolsQuery.class == ((ClassObjectType) pattern.getObjectType()).getClassType() ) {
@@ -190,7 +214,13 @@
         }
 
         context.setObjectSource( (ObjectSource) utils.attachNode( context,
+                                                                  new EntryPointNode( context.getNextId(),
+                                                                                      context.getRuleBase().getRete(),
+                                                                                      context ) ) );
+
+        context.setObjectSource( (ObjectSource) utils.attachNode( context,
                                                                   new ObjectTypeNode( context.getNextId(),
+                                                                                      (EntryPointNode) context.getObjectSource(),
                                                                                       pattern.getObjectType(),
                                                                                       context ) ) );
 
@@ -203,7 +233,7 @@
                                                                                      context.getObjectSource(),
                                                                                      context ) ) );
         }
-        
+
         // now restore back to original values
         context.setObjectTypeNodeMemoryEnabled( objectMemory );
         context.setAlphaNodeMemoryAllowed( alphaMemory );

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -17,10 +17,8 @@
  */
 
 import org.drools.DroolsTestCase;
-import org.drools.RuleBase;
 import org.drools.RuleBaseFactory;
 import org.drools.base.ClassObjectType;
-import org.drools.common.InternalRuleBase;
 import org.drools.reteoo.builder.BuildContext;
 
 public class AddRemoveTest extends DroolsTestCase {
@@ -31,8 +29,14 @@
          */
         final ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();        
         BuildContext context = new BuildContext(ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
+        
+        final EntryPointNode entryPoint = new EntryPointNode( -1,
+                                                              ruleBase.getRete(),
+                                                              context );
+        entryPoint.attach();
                         
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 0,
+                                                                  entryPoint,
                                                                   new ClassObjectType( Object.class ),
                                                                   context );
         objectTypeNode.attach();

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -21,7 +21,6 @@
 import org.drools.DroolsTestCase;
 import org.drools.FactException;
 import org.drools.FactHandle;
-import org.drools.RuleBase;
 import org.drools.RuleBaseConfiguration;
 import org.drools.RuleBaseFactory;
 import org.drools.WorkingMemory;
@@ -30,8 +29,6 @@
 import org.drools.base.ShadowProxy;
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.InternalAgenda;
-import org.drools.common.InternalRuleBase;
-import org.drools.common.InternalWorkingMemory;
 import org.drools.common.PropagationContextImpl;
 import org.drools.reteoo.ReteooBuilder.IdGenerator;
 import org.drools.reteoo.builder.BuildContext;
@@ -43,10 +40,15 @@
 public class LogicalAssertionTest extends DroolsTestCase {
     private ReteooRuleBase ruleBase;
     private BuildContext buildContext;
+    private EntryPointNode entryPoint;
     
     protected void setUp() throws Exception {
         ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
         buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+        this.entryPoint = new EntryPointNode( 0,
+                                              this.ruleBase.getRete(),
+                                              buildContext );
+        this.entryPoint.attach();
     }
     
     public void testSingleLogicalRelationship() throws Exception {
@@ -56,6 +58,7 @@
         // create a RuleBase with a single ObjectTypeNode we attach a
         // MockObjectSink so we can detect assertions and retractions
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
         objectTypeNode.attach();
@@ -158,6 +161,7 @@
 
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
         objectTypeNode.attach();
@@ -248,6 +252,7 @@
 
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
         objectTypeNode.attach();
@@ -389,7 +394,13 @@
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         final Rete rete = ruleBase.getRete();
+        final EntryPointNode entryPoint = new EntryPointNode( 0,
+                                                              rete,
+                                                              buildContext );
+        entryPoint.attach();
+        
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
         objectTypeNode.attach();
@@ -478,6 +489,7 @@
 
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
         objectTypeNode.attach();
@@ -578,6 +590,7 @@
         // Create a RuleBase with a single ObjectTypeNode we attach a
         // MockObjectSink so we can detect assertions and retractions
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
         objectTypeNode.attach();
@@ -708,6 +721,7 @@
 
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
         objectTypeNode.attach();
@@ -809,6 +823,7 @@
 
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
         objectTypeNode.attach();

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -45,10 +45,15 @@
 public class ObjectTypeNodeTest extends DroolsTestCase {
     private ReteooRuleBase ruleBase;
     private BuildContext buildContext;
+    private EntryPointNode entryPoint;
     
     protected void setUp() throws Exception {
         this.ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
         this.buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+        this.entryPoint = new EntryPointNode( 0,
+                                              this.ruleBase.getRete(),
+                                              buildContext );
+        this.entryPoint.attach();
     }
     
     public void testAttach() throws Exception {
@@ -60,13 +65,14 @@
 
         int id = idGenerator.getNextId();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( id,
+                                                                  this.entryPoint,
                                                                   objectType,
                                                                   buildContext );
 
         assertEquals( id,
                       objectTypeNode.getId() );
 
-        ObjectHashMap map = source.getObjectTypeNodes( EntryPoint.DEFAULT );
+        Map<ObjectType, ObjectTypeNode> map = source.getObjectTypeNodes( EntryPoint.DEFAULT );
 
         assertEquals( 0,
                       map.size() );
@@ -93,7 +99,13 @@
 
         final Rete source = ruleBase.getRete();
 
+        final EntryPointNode entryPoint = new EntryPointNode( 0,
+                                                              source, 
+                                                              buildContext );
+        entryPoint.attach();
+
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
 
@@ -140,7 +152,13 @@
 
         final Rete source = ruleBase.getRete();
 
+        final EntryPointNode entryPoint = new EntryPointNode( 0,
+                                                              source, 
+                                                              buildContext );
+        entryPoint.attach();
+
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
+                                                                  entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
 
@@ -176,6 +194,7 @@
         final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) ruleBase.newStatefulSession();
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
 
@@ -190,6 +209,7 @@
         final Rete source = new Rete((InternalRuleBase) ruleBase);
 
         ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                            this.entryPoint,
                                                             new ClassObjectType( String.class ),
                                                             buildContext );
 
@@ -198,6 +218,7 @@
         assertTrue( objectTypeNode.matches( "string" ) );
 
         objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                             this.entryPoint,
                                              new ClassObjectType( Object.class ),
                                              buildContext );
 
@@ -220,6 +241,7 @@
         final Rete source = new Rete((InternalRuleBase) ruleBase);
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
 
@@ -271,6 +293,7 @@
         final Rete source = new Rete( (InternalRuleBase)ruleBase);
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
 
@@ -335,13 +358,19 @@
 
         final Rete source = ruleBase.getRete();
 
+        final EntryPointNode entryPoint = new EntryPointNode( 0,
+                                                              source, 
+                                                              buildContext );
+        entryPoint.attach();
+
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( Cheese.class  ),
                                                                   buildContext );
 
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
-        source.addObjectSink( objectTypeNode );
+        entryPoint.addObjectSink( objectTypeNode );
 
         final Object cheese = new Cheese( "muzzarela",
                                           5 );
@@ -374,9 +403,15 @@
         final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) ruleBase.newStatefulSession();
 
         final Rete source = ruleBase.getRete();
+        
+        final EntryPointNode entryPoint = new EntryPointNode( 0,
+                                                              source, 
+                                                              buildContext );
+        entryPoint.attach();
 
         final Class shadowClass = ShadowProxyFactory.getProxy( Person.class );
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                  entryPoint,
                                                                   new ClassObjectType( Person.class ),
                                                                   buildContext );
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -12,16 +12,22 @@
 public class PropertyChangeListenerTest extends TestCase {
     private ReteooRuleBase ruleBase;
     private BuildContext buildContext;
+    private EntryPointNode entryPoint;
     
     protected void setUp() throws Exception {
         this.ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
         this.buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+        this.entryPoint = new EntryPointNode( 0,
+                                              this.ruleBase.getRete(),
+                                              buildContext );
+        this.entryPoint.attach();
     }
     
     public void test1() {
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( State.class ),
                                                                   buildContext );
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -46,6 +46,7 @@
 public class QueryTerminalNodeTest extends TestCase {
     private ReteooRuleBase   ruleBase;
     private BuildContext     buildContext;
+    private EntryPointNode   entryPoint;
 
     ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
     private EqualityEvaluatorsDefinition equals = new EqualityEvaluatorsDefinition();
@@ -54,11 +55,16 @@
         this.ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         this.buildContext = new BuildContext( ruleBase,
                                               ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
+        this.entryPoint = new EntryPointNode( 0,
+                                              this.ruleBase.getRete(),
+                                              buildContext );
+        this.entryPoint.attach();
     }
 
     public void testQueryTerminalNode() {
         final ClassObjectType queryObjectType = new ClassObjectType( DroolsQuery.class );
         final ObjectTypeNode queryObjectTypeNode = new ObjectTypeNode( this.buildContext.getNextId(),
+                                                                       this.entryPoint,
                                                                        queryObjectType,
                                                                        buildContext );
         queryObjectTypeNode.attach();
@@ -87,6 +93,7 @@
 
         final ClassObjectType cheeseObjectType = new ClassObjectType( Cheese.class );
         final ObjectTypeNode cheeseObjectTypeNode = new ObjectTypeNode( this.buildContext.getNextId(),
+                                                                        this.entryPoint,
                                                                         cheeseObjectType,
                                                                         buildContext );
         cheeseObjectTypeNode.attach();

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -16,7 +16,6 @@
  * limitations under the License.
  */
 
-import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -40,7 +39,6 @@
 import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.EntryPoint;
 import org.drools.spi.PropagationContext;
-import org.drools.util.ObjectHashMap;
 
 /**
  * @author mproctor
@@ -48,13 +46,20 @@
  */
 public class ReteTest extends DroolsTestCase {
     private ReteooRuleBase ruleBase;
-    private BuildContext buildContext;
-    
+    private BuildContext   buildContext;
+    private EntryPointNode entryPoint;
+
     protected void setUp() throws Exception {
-        this.ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
-        this.buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+        this.ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
+        this.buildContext = new BuildContext( ruleBase,
+                                              ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
+        this.entryPoint = new EntryPointNode( 0,
+                                              this.ruleBase.getRete(),
+                                              buildContext );
+        this.entryPoint.attach();
+
     }
-    
+
     /**
      * Tests ObjectTypeNodes are correctly added to the Rete object
      * 
@@ -64,23 +69,25 @@
         final Rete rete = ruleBase.getRete();
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( Object.class ),
                                                                   buildContext );
         objectTypeNode.attach();
 
         final ObjectTypeNode stringTypeNode = new ObjectTypeNode( 2,
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( String.class ),
                                                                   buildContext );
         stringTypeNode.attach();
 
-        final Map map = rete.getObjectTypeNodes();
+        final List<ObjectTypeNode> list = rete.getObjectTypeNodes();
 
         // Check the ObjectTypeNodes are correctly added to Rete
         assertEquals( 2,
-                      map.size() );
+                      list.size() );
 
-        assertNotNull( map.get( new ClassObjectType( Object.class ) ) );
-        assertNotNull( map.get( new ClassObjectType( String.class ) ) );
+        assertTrue( list.contains( objectTypeNode ) );
+        assertTrue( list.contains( stringTypeNode ) );
     }
 
     /**
@@ -89,11 +96,12 @@
      * @throws FactException
      */
     public void testCache() throws FactException {
-        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) this.ruleBase.newStatefulSession();
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
         ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
+                                                            this.entryPoint,
                                                             new ClassObjectType( List.class ),
                                                             buildContext );
         objectTypeNode.attach();
@@ -101,6 +109,7 @@
         objectTypeNode.addObjectSink( sink );
 
         objectTypeNode = new ObjectTypeNode( 1,
+                                             this.entryPoint,
                                              new ClassObjectType( Collection.class ),
                                              buildContext );
         objectTypeNode.attach();
@@ -108,6 +117,7 @@
         objectTypeNode.addObjectSink( sink );
 
         objectTypeNode = new ObjectTypeNode( 1,
+                                             this.entryPoint,
                                              new ClassObjectType( ArrayList.class ),
                                              buildContext );
         objectTypeNode.attach();
@@ -150,11 +160,12 @@
      * @throws Exception
      */
     public void testAssertObject() throws Exception {
-        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) this.ruleBase.newStatefulSession();
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( List.class ),
                                                                   buildContext );
         objectTypeNode.attach();
@@ -199,7 +210,7 @@
     }
 
     public void testAssertObjectWithNoMatchingObjectTypeNode() {
-        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) this.ruleBase.newStatefulSession();
 
         final Rete rete = ruleBase.getRete();
         assertEquals( 0,
@@ -214,13 +225,14 @@
     }
 
     public void testHierarchy() {
-        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) this.ruleBase.newStatefulSession();
 
         final Rete rete = ruleBase.getRete();
         final IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         // Attach a List ObjectTypeNode
         final ObjectTypeNode listOtn = new ObjectTypeNode( idGenerator.getNextId(),
+                                                           this.entryPoint,
                                                            new ClassObjectType( List.class ),
                                                            buildContext );
         listOtn.attach();
@@ -234,7 +246,7 @@
 
         // double check that the Listreference is the same as the one we created, i.e. engine should try and recreate it
         assertSame( listOtn,
-                    rete.getObjectTypeNodes().get( new ClassObjectType( List.class ) ) );
+                    rete.getObjectTypeNodes( EntryPoint.DEFAULT ).get( new ClassObjectType( List.class ) ) );
 
         // ArrayConf should match two ObjectTypenodes for List and ArrayList
         Map memory = workingMemory.getObjectTypeConfMap( EntryPoint.DEFAULT );
@@ -242,13 +254,14 @@
         final ObjectTypeNode arrayOtn = arrayConf.getConcreteObjectTypeNode();
         assertEquals( 2,
                       arrayConf.getObjectTypeNodes().length );
-        
+
         // Check it contains List and ArrayList
         List nodes = Arrays.asList( arrayConf.getObjectTypeNodes() );
-        assertEquals(2, nodes.size() );
+        assertEquals( 2,
+                      nodes.size() );
         assertTrue( nodes.contains( arrayOtn ) );
         assertTrue( nodes.contains( listOtn ) );
-        
+
         // Nodes are there, retract the fact so we can check both nodes are populated
         workingMemory.retract( handle );
 
@@ -267,6 +280,7 @@
 
         // Add a Collection ObjectTypeNode, so that we can check that the data from ArrayList is sent to it
         final ObjectTypeNode collectionOtn = new ObjectTypeNode( idGenerator.getNextId(),
+                                                                 this.entryPoint,
                                                                  new ClassObjectType( Collection.class ),
                                                                  buildContext );
         final MockObjectSink collectionSink = new MockObjectSink();
@@ -274,11 +288,12 @@
         collectionOtn.attach( new InternalWorkingMemory[]{workingMemory} );
 
         assertEquals( 1,
-                      collectionSink.getAsserted().size() );       
-        
+                      collectionSink.getAsserted().size() );
+
         // check that ArrayListConf was updated with the new ObjectTypeNode
         nodes = Arrays.asList( arrayConf.getObjectTypeNodes() );
-        assertEquals(3, nodes.size() );
+        assertEquals( 3,
+                      nodes.size() );
         assertTrue( nodes.contains( arrayOtn ) );
         assertTrue( nodes.contains( listOtn ) );
         assertTrue( nodes.contains( collectionOtn ) );
@@ -289,11 +304,12 @@
      * ObjectTypeNodes.
      */
     public void testRetractObject() throws Exception {
-        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) this.ruleBase.newStatefulSession();
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( List.class ),
                                                                   buildContext );
         objectTypeNode.attach();
@@ -346,11 +362,12 @@
     }
 
     public void testIsShadowed() {
-        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) this.ruleBase.newStatefulSession();
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
+                                                                  this.entryPoint,
                                                                   new ClassObjectType( Cheese.class ),
                                                                   buildContext );
         objectTypeNode.attach();
@@ -384,13 +401,20 @@
                                 "org.drools.Cheese" );
         RuleBaseConfiguration conf = new RuleBaseConfiguration( properties );
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( conf );
-        buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+        buildContext = new BuildContext( ruleBase,
+                                         ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
         final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
                                                                            ruleBase );
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
+        final EntryPointNode entryPoint = new EntryPointNode( 0,
+                                                              rete,
+                                                              buildContext );
+        entryPoint.attach();
+        
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
+                                                                  entryPoint,
                                                                   new ClassObjectType( Cheese.class ),
                                                                   buildContext );
         objectTypeNode.attach();

Modified: labs/jbossrules/branches/temporal_rete/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java	2008-01-14 20:05:12 UTC (rev 17834)
+++ labs/jbossrules/branches/temporal_rete/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java	2008-01-14 20:15:03 UTC (rev 17835)
@@ -415,6 +415,18 @@
                     // TODO Auto-generated method stub
                     return null;
                 }
+
+				public FactHandle insert(Object object, long duration)
+						throws FactException {
+					// TODO Auto-generated method stub
+					return null;
+				}
+
+				public FactHandle insert(Object object, long duration,
+						boolean dynamic) throws FactException {
+					// TODO Auto-generated method stub
+					return null;
+				}
 			};
 		}
 	}




More information about the jboss-svn-commits mailing list