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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Dec 14 16:26:42 EST 2007


Author: tirelli
Date: 2007-12-14 16:26:42 -0500 (Fri, 14 Dec 2007)
New Revision: 17242

Added:
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/EntryPoint.java
Modified:
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/BetaNode.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/ReteooWorkingMemory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.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/main/java/org/drools/spi/PropagationContext.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/ReteTest.java
Log:
JBRULES-1290: Adding core support to streams

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -56,6 +56,7 @@
 import org.drools.reteoo.LIANodePropagation;
 import org.drools.reteoo.ObjectTypeConf;
 import org.drools.rule.Declaration;
+import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
 import org.drools.ruleflow.common.core.Process;
 import org.drools.ruleflow.common.instance.ProcessInstance;
@@ -92,73 +93,73 @@
     // ------------------------------------------------------------
     // Constants
     // ------------------------------------------------------------
-    protected static final Class[]         ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES = new Class[]{PropertyChangeListener.class};
+    protected static final Class[]                       ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES = new Class[]{PropertyChangeListener.class};
 
     // ------------------------------------------------------------
     // Instance members
     // ------------------------------------------------------------
-    protected final long                   id;
+    protected final long                                 id;
 
     /** The arguments used when adding/removing a property change listener. */
-    protected final Object[]               addRemovePropertyChangeListenerArgs           = new Object[]{this};
+    protected final Object[]                             addRemovePropertyChangeListenerArgs           = new Object[]{this};
 
     /** The actual memory for the <code>JoinNode</code>s. */
-    protected final PrimitiveLongMap       nodeMemories                                  = new PrimitiveLongMap( 32,
-                                                                                                                 8 );
+    protected final PrimitiveLongMap                     nodeMemories                                  = new PrimitiveLongMap( 32,
+                                                                                                                               8 );
     /** Object-to-handle mapping. */
-    private final ObjectHashMap            assertMap;
-    private final ObjectHashMap            identityMap;
+    private final ObjectHashMap                          assertMap;
+    private final ObjectHashMap                          identityMap;
 
-    protected Map                          queryResults                                  = Collections.EMPTY_MAP;
+    protected Map                                        queryResults                                  = Collections.EMPTY_MAP;
 
     /** Global values which are associated with this memory. */
-    protected GlobalResolver               globalResolver;
+    protected GlobalResolver                             globalResolver;
 
-    protected static final Object          NULL                                          = new Serializable() {
-                                                                                             private static final long serialVersionUID = 400L;
-                                                                                         };
+    protected static final Object                        NULL                                          = new Serializable() {
+                                                                                                           private static final long serialVersionUID = 400L;
+                                                                                                       };
 
     /** The eventSupport */
-    protected WorkingMemoryEventSupport    workingMemoryEventSupport                     = new WorkingMemoryEventSupport();
+    protected WorkingMemoryEventSupport                  workingMemoryEventSupport                     = new WorkingMemoryEventSupport();
 
-    protected AgendaEventSupport           agendaEventSupport                            = new AgendaEventSupport();
+    protected AgendaEventSupport                         agendaEventSupport                            = new AgendaEventSupport();
 
-    protected RuleFlowEventSupport         ruleFlowEventSupport                          = new RuleFlowEventSupport();
+    protected RuleFlowEventSupport                       ruleFlowEventSupport                          = new RuleFlowEventSupport();
 
     /** The <code>RuleBase</code> with which this memory is associated. */
-    protected transient InternalRuleBase   ruleBase;
+    protected transient InternalRuleBase                 ruleBase;
 
-    protected final FactHandleFactory      handleFactory;
+    protected final FactHandleFactory                    handleFactory;
 
-    protected final TruthMaintenanceSystem tms;
+    protected final TruthMaintenanceSystem               tms;
 
     /** Rule-firing agenda. */
-    protected DefaultAgenda                agenda;
+    protected DefaultAgenda                              agenda;
 
-    protected final List                   actionQueue                                   = new ArrayList();
+    protected final List                                 actionQueue                                   = new ArrayList();
 
-    protected final ReentrantLock          lock                                          = new ReentrantLock();
+    protected final ReentrantLock                        lock                                          = new ReentrantLock();
 
-    protected final boolean                discardOnLogicalOverride;
+    protected final boolean                              discardOnLogicalOverride;
 
-    protected long                         propagationIdCounter;
+    protected long                                       propagationIdCounter;
 
-    private final boolean                  maintainTms;
+    private final boolean                                maintainTms;
 
-    private final boolean                  sequential;
+    private final boolean                                sequential;
 
-    private List                           liaPropagations                               = Collections.EMPTY_LIST;
+    private List                                         liaPropagations                               = Collections.EMPTY_LIST;
 
     /** Flag to determine if a rule is currently being fired. */
-    protected boolean                      firing;
+    protected boolean                                    firing;
 
-    protected boolean                      halt;
+    protected boolean                                    halt;
 
-    private int                            processCounter;
+    private int                                          processCounter;
 
-    private Map<Object, ObjectTypeConf>    typeConfMap;
+    private Map<EntryPoint, Map<Object, ObjectTypeConf>> typeConfMap;
 
-    private SessionClock                   sessionClock;
+    private SessionClock                                 sessionClock;
 
     // ------------------------------------------------------------
     // Constructors
@@ -204,8 +205,8 @@
         } else {
             this.discardOnLogicalOverride = false;
         }
-        
-        this.typeConfMap = new HashMap<Object, ObjectTypeConf>();
+
+        this.typeConfMap = new HashMap<EntryPoint, Map<Object, ObjectTypeConf>>();
     }
 
     // ------------------------------------------------------------
@@ -708,19 +709,38 @@
                              boolean logical,
                              final Rule rule,
                              final Activation activation) throws FactException {
+        return this.insert( EntryPoint.DEFAULT,
+                            object,
+                            dynamic,
+                            logical,
+                            rule,
+                            activation );
+
+    }
+
+    protected FactHandle insert(final EntryPoint entryPoint,
+                                final Object object,
+                                final boolean dynamic,
+                                boolean logical,
+                                final Rule rule,
+                                final Activation activation) throws FactException {
         if ( object == null ) {
             // you cannot assert a null object
             return null;
         }
-        
-        ObjectTypeConf typeConf = getObjectTypeConf( object );
 
+        ObjectTypeConf typeConf = getObjectTypeConf( entryPoint,
+                                                     object );
+
         InternalFactHandle handle = null;
 
         if ( isSequential() ) {
-            handle = this.handleFactory.newFactHandle( object, typeConf.isEvent(), this );
+            handle = this.handleFactory.newFactHandle( object,
+                                                       typeConf.isEvent(),
+                                                       this );
             addHandleToMaps( handle );
-            insert( handle,
+            insert( entryPoint,
+                    handle,
                     object,
                     rule,
                     activation );
@@ -770,7 +790,9 @@
                 if ( key == null ) {
                     // key is also null, so treat as a totally new stated/logical
                     // assert
-                    handle = this.handleFactory.newFactHandle( object, typeConf.isEvent(), this );
+                    handle = this.handleFactory.newFactHandle( object,
+                                                               typeConf.isEvent(),
+                                                               this );
                     addHandleToMaps( handle );
 
                     key = new EqualityKey( handle );
@@ -824,7 +846,9 @@
                         } else {
                             // override, then instantiate new handle for assertion
                             key.setStatus( EqualityKey.STATED );
-                            handle = this.handleFactory.newFactHandle( object, typeConf.isEvent(), this );
+                            handle = this.handleFactory.newFactHandle( object,
+                                                                       typeConf.isEvent(),
+                                                                       this );
                             handle.setEqualityKey( key );
                             key.addFactHandle( handle );
                             addHandleToMaps( handle );
@@ -832,7 +856,9 @@
                         }
 
                     } else {
-                        handle = this.handleFactory.newFactHandle( object, typeConf.isEvent(), this );
+                        handle = this.handleFactory.newFactHandle( object,
+                                                                   typeConf.isEvent(),
+                                                                   this );
                         addHandleToMaps( handle );
                         key.addFactHandle( handle );
                         handle.setEqualityKey( key );
@@ -859,7 +885,9 @@
                 if ( handle != null ) {
                     return handle;
                 }
-                handle = this.handleFactory.newFactHandle( object, typeConf.isEvent(), this );
+                handle = this.handleFactory.newFactHandle( object,
+                                                           typeConf.isEvent(),
+                                                           this );
                 addHandleToMaps( handle );
 
             }
@@ -868,7 +896,8 @@
                 addPropertyChangeListener( object );
             }
 
-            insert( handle,
+            insert( entryPoint,
+                    handle,
                     object,
                     rule,
                     activation );
@@ -879,10 +908,11 @@
         return handle;
     }
 
-    protected void insert(InternalFactHandle handle,
-                          Object object,
-                          Rule rule,
-                          Activation activation) {
+    protected void insert(final EntryPoint entryPoint,
+                          final InternalFactHandle handle,
+                          final Object object,
+                          final Rule rule,
+                          final Activation activation) {
         this.ruleBase.executeQueuedActions();
 
         if ( activation != null ) {
@@ -894,7 +924,8 @@
                                                                                   rule,
                                                                                   activation,
                                                                                   this.agenda.getActiveActivations(),
-                                                                                  this.agenda.getDormantActivations() );
+                                                                                  this.agenda.getDormantActivations(),
+                                                                                  entryPoint );
 
         doInsert( handle,
                   object,
@@ -987,6 +1018,21 @@
                         final boolean updateEqualsMap,
                         final Rule rule,
                         final Activation activation) throws FactException {
+        this.retract( EntryPoint.DEFAULT,
+                      factHandle,
+                      removeLogical,
+                      updateEqualsMap,
+                      rule,
+                      activation );
+
+    }
+
+    protected void retract(final EntryPoint entryPoint,
+                           final FactHandle factHandle,
+                           final boolean removeLogical,
+                           final boolean updateEqualsMap,
+                           final Rule rule,
+                           final Activation activation) throws FactException {
         try {
             this.lock.lock();
             this.ruleBase.executeQueuedActions();
@@ -1007,7 +1053,8 @@
                                                                                       rule,
                                                                                       activation,
                                                                                       this.agenda.getActiveActivations(),
-                                                                                      this.agenda.getDormantActivations() );
+                                                                                      this.agenda.getDormantActivations(),
+                                                                                      entryPoint );
 
             doRetract( handle,
                        propagationContext );
@@ -1078,6 +1125,13 @@
     public void modifyRetract(final FactHandle factHandle,
                               final Rule rule,
                               final Activation activation) {
+
+    }
+
+    protected void modifyRetract(final EntryPoint entryPoint,
+                                 final FactHandle factHandle,
+                                 final Rule rule,
+                                 final Activation activation) {
         try {
             this.lock.lock();
             this.ruleBase.executeQueuedActions();
@@ -1105,7 +1159,8 @@
                                                                                       rule,
                                                                                       activation,
                                                                                       this.agenda.getActiveActivations(),
-                                                                                      this.agenda.getDormantActivations() );
+                                                                                      this.agenda.getDormantActivations(),
+                                                                                      entryPoint );
             doRetract( handle,
                        propagationContext );
 
@@ -1137,6 +1192,18 @@
                              final Object object,
                              final Rule rule,
                              final Activation activation) {
+        this.modifyInsert( EntryPoint.DEFAULT,
+                           factHandle,
+                           object,
+                           rule,
+                           activation );
+    }
+
+    protected void modifyInsert(final EntryPoint entryPoint,
+                                final FactHandle factHandle,
+                                final Object object,
+                                final Rule rule,
+                                final Activation activation) {
         try {
             this.lock.lock();
             this.ruleBase.executeQueuedActions();
@@ -1172,7 +1239,8 @@
                                                                                       rule,
                                                                                       activation,
                                                                                       this.agenda.getActiveActivations(),
-                                                                                      this.agenda.getDormantActivations() );
+                                                                                      this.agenda.getDormantActivations(),
+                                                                                      entryPoint );
 
             doInsert( handle,
                       object,
@@ -1212,6 +1280,19 @@
                        final Object object,
                        final Rule rule,
                        final Activation activation) throws FactException {
+        this.update( EntryPoint.DEFAULT,
+                     factHandle,
+                     object,
+                     rule,
+                     activation );
+
+    }
+
+    protected void update(final EntryPoint entryPoint,
+                          final FactHandle factHandle,
+                          final Object object,
+                          final Rule rule,
+                          final Activation activation) throws FactException {
         try {
             this.lock.lock();
             this.ruleBase.executeQueuedActions();
@@ -1240,7 +1321,8 @@
                                                                                       rule,
                                                                                       activation,
                                                                                       this.agenda.getActiveActivations(),
-                                                                                      this.agenda.getDormantActivations() );
+                                                                                      this.agenda.getDormantActivations(),
+                                                                                      entryPoint );
             doRetract( handle,
                        propagationContext );
 
@@ -1362,7 +1444,7 @@
     public RuleFlowEventSupport getRuleFlowEventSupport() {
         return this.ruleFlowEventSupport;
     }
-    
+
     /**
      * Sets the AsyncExceptionHandler to handle exceptions thrown by the Agenda
      * Scheduler used for duration rules.
@@ -1474,17 +1556,25 @@
      * @param object
      * @return
      */
-    public ObjectTypeConf getObjectTypeConf(Object object) {
+    public ObjectTypeConf getObjectTypeConf(EntryPoint entrypoint,
+                                            Object object ) {
+        Map<Object, ObjectTypeConf> map = this.typeConfMap.get( entrypoint );
+        if( map == null ) {
+            map = new HashMap<Object, ObjectTypeConf>();
+            this.typeConfMap.put( entrypoint, map );
+        }
         ObjectTypeConf objectTypeConf;
 
         if ( object instanceof Fact ) {
             String key = ((Fact) object).getFactTemplate().getName();
-            objectTypeConf = (ObjectTypeConf) this.typeConfMap.get( key );
+            objectTypeConf = map.get( key ); 
             if ( objectTypeConf == null ) {
-                objectTypeConf = new FactTemplateTypeConf( ((Fact) object).getFactTemplate(),
-                                                          this.ruleBase );
-                this.typeConfMap.put( key,
-                                      objectTypeConf );
+                objectTypeConf = new FactTemplateTypeConf( entrypoint,
+                                                           ((Fact) object).getFactTemplate(),
+                                                           this.ruleBase );
+                this.addObjectTypeConf( entrypoint,
+                                        key,
+                                        objectTypeConf );
             }
             object = key;
         } else {
@@ -1495,23 +1585,42 @@
                 cls = object.getClass();
             }
 
-            objectTypeConf = (ObjectTypeConf) this.typeConfMap.get( cls );
+            objectTypeConf = map.get( cls );
             if ( objectTypeConf == null ) {
 
                 final boolean isEvent = this.ruleBase.isEvent( cls );
-                objectTypeConf = new ClassObjectTypeConf( cls,
-                                                         isEvent,
-                                                         this.ruleBase );
-                this.typeConfMap.put( cls,
-                                      objectTypeConf );
+                objectTypeConf = new ClassObjectTypeConf( entrypoint,
+                                                          cls,
+                                                          isEvent,
+                                                          this.ruleBase );
+                this.addObjectTypeConf( entrypoint,
+                                        cls,
+                                        objectTypeConf );
             }
 
         }
         return objectTypeConf;
     }
-    
-    public Map<Object, ObjectTypeConf> getObjectTypeConfMap() {
-        return this.typeConfMap;
+
+    public Map<Object, ObjectTypeConf> getObjectTypeConfMap(EntryPoint entryPoint) {
+        Map<Object, ObjectTypeConf> map = this.typeConfMap.get( entryPoint );
+        if( map == null ) {
+            map = Collections.emptyMap();
+        }
+        return map;
     }
 
+    private void addObjectTypeConf(EntryPoint entryPoint,
+                                   Object key,
+                                   ObjectTypeConf conf) {
+        Map<Object, ObjectTypeConf> map = this.typeConfMap.get( entryPoint );
+        if ( map == null ) {
+            map = new HashMap<Object, ObjectTypeConf>();
+            this.typeConfMap.put( entryPoint,
+                                  map );
+        }
+        map.put( key,
+                 conf );
+    }
+
 }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -10,6 +10,7 @@
 import org.drools.event.WorkingMemoryEventSupport;
 import org.drools.reteoo.LIANodePropagation;
 import org.drools.reteoo.ObjectTypeConf;
+import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
 import org.drools.spi.FactHandleFactory;
@@ -69,7 +70,7 @@
      * @param object
      * @return
      */
-    public ObjectTypeConf getObjectTypeConf(Object object);
+    public ObjectTypeConf getObjectTypeConf(EntryPoint entryPoint, Object object);
     
     /**
      * Returns the Map<Object key, ObjectTypeConf conf> of object type
@@ -77,5 +78,5 @@
      *  
      * @return
      */
-    public Map<Object, ObjectTypeConf> getObjectTypeConfMap();
+    public Map<Object, ObjectTypeConf> getObjectTypeConfMap(EntryPoint entryPoint);
 }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -17,29 +17,34 @@
  */
 
 import org.drools.reteoo.ReteTuple;
+import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
 import org.drools.spi.PropagationContext;
 import org.drools.util.ObjectHashMap;
-import org.drools.util.TupleHashTable;
 
 public class PropagationContextImpl
     implements
     PropagationContext {
-    private final int        type;
 
-    private Rule       rule;
+    private static final long serialVersionUID = 8400185220119865618L;
 
-    private Activation activation;
+    private final int    type;
 
-    private final long       propagationNumber;
+    private Rule         rule;
 
-    public final int         activeActivations;
+    private Activation   activation;
 
-    public final int         dormantActivations;
+    private final long   propagationNumber;
 
-    public ObjectHashMap     retracted;
+    public final int     activeActivations;
 
+    public final int     dormantActivations;
+
+    public ObjectHashMap retracted;
+
+    private EntryPoint   entryPoint;
+
     public PropagationContextImpl(final long number,
                                   final int type,
                                   final Rule rule,
@@ -50,6 +55,7 @@
         this.propagationNumber = number;
         this.activeActivations = 0;
         this.dormantActivations = 0;
+        this.entryPoint = EntryPoint.DEFAULT;
     }
 
     public PropagationContextImpl(final long number,
@@ -57,13 +63,15 @@
                                   final Rule rule,
                                   final Activation activation,
                                   final int activeActivations,
-                                  final int dormantActivations) {
+                                  final int dormantActivations,
+                                  final EntryPoint entryPoint) {
         this.type = type;
         this.rule = rule;
         this.activation = activation;
         this.propagationNumber = number;
         this.activeActivations = activeActivations;
         this.dormantActivations = dormantActivations;
+        this.entryPoint = entryPoint;
     }
 
     public long getPropagationNumber() {
@@ -110,27 +118,28 @@
         if ( this.retracted == null ) {
             this.retracted = new ObjectHashMap();
         }
-        
-        ReteTuple tuple = ( ReteTuple) activation.getTuple();
 
+        ReteTuple tuple = (ReteTuple) activation.getTuple();
+
         ObjectHashMap tuples = (ObjectHashMap) this.retracted.get( rule );
         if ( tuples == null ) {
             tuples = new ObjectHashMap();
             this.retracted.put( rule,
                                 tuples );
         }
-        tuples.put( tuple, activation );
+        tuples.put( tuple,
+                    activation );
     }
 
     public Activation removeRetractedTuple(final Rule rule,
-                                          final ReteTuple tuple) {
+                                           final ReteTuple tuple) {
         if ( this.retracted == null ) {
             return null;
         }
 
         final ObjectHashMap tuples = (ObjectHashMap) this.retracted.get( rule );
-        if  ( tuples != null ) {
-            return ( Activation ) tuples.remove( tuple );
+        if ( tuples != null ) {
+            return (Activation) tuples.remove( tuple );
         } else {
             return null;
         }
@@ -145,4 +154,18 @@
         this.retracted = null;
         this.rule = null;
     }
+
+    /**
+     * @return the entryPoint
+     */
+    public EntryPoint getEntryPoint() {
+        return entryPoint;
+    }
+
+    /**
+     * @param entryPoint the entryPoint to set
+     */
+    public void setEntryPoint(EntryPoint entryPoint) {
+        this.entryPoint = entryPoint;
+    }
 }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -22,7 +22,6 @@
 import org.drools.RuleBaseConfiguration;
 import org.drools.common.BaseNode;
 import org.drools.common.BetaConstraints;
-import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.NodeMemory;
 import org.drools.common.PropagationContextImpl;

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	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -38,6 +38,7 @@
 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;
@@ -58,17 +59,23 @@
     protected transient ObjectInstantiator instantiator;
 
     private ObjectTypeNode                 concreteObjectTypeNode;
-    
-    public ClassObjectTypeConf(final Class clazz, final boolean isEvent,
+    private EntryPoint                     entryPoint;
+
+    public ClassObjectTypeConf(final EntryPoint entryPoint,
+                               final Class clazz,
+                               final boolean isEvent,
                                final InternalRuleBase ruleBase) {
         this.cls = clazz;
         this.ruleBase = ruleBase;
+        this.entryPoint = entryPoint;
 
-        ObjectType objectType = new ClassObjectType( clazz, isEvent );
-        this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes().get( objectType );
+        ObjectType objectType = new ClassObjectType( clazz,
+                                                     isEvent );
+        this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes( entryPoint ).get( objectType );
         if ( this.concreteObjectTypeNode == null ) {
             BuildContext context = new BuildContext( ruleBase,
                                                      ((ReteooRuleBase) ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator() );
+            context.setCurrentEntryPoint( entryPoint );
             if ( DroolsQuery.class == clazz ) {
                 context.setTupleMemoryEnabled( false );
                 context.setObjectTypeNodeMemoryEnabled( false );
@@ -277,7 +284,7 @@
     private ObjectTypeNode[] getMatchingObjectTypes(final Class clazz) throws FactException {
         final List cache = new ArrayList();
 
-        final Iterator it = ruleBase.getRete().getObjectTypeNodes().newIterator();
+        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();
             if ( node.isAssignableFrom( clazz ) ) {
@@ -291,7 +298,7 @@
     public boolean isActive() {
         return getConcreteObjectTypeNode().getSinkPropagator().getSinks().length > 0;
     }
-    
+
     public boolean isEvent() {
         return this.concreteObjectTypeNode.getObjectType().isEvent();
     }

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	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FactTemplateTypeConf.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -25,6 +25,7 @@
 import org.drools.facttemplates.FactTemplateObjectType;
 import org.drools.reteoo.builder.BuildContext;
 import org.drools.reteoo.builder.PatternBuilder;
+import org.drools.rule.EntryPoint;
 import org.drools.spi.ObjectType;
 
 public class FactTemplateTypeConf
@@ -35,13 +36,17 @@
     private FactTemplate     factTemplate;
     private ObjectTypeNode   concreteObjectTypeNode;
     private ObjectTypeNode[] cache;
+    private EntryPoint       entryPoint;
 
-    public FactTemplateTypeConf(FactTemplate factTemplate,
-                                InternalRuleBase ruleBase) {
+    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().get( objectType );
+        this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes( entryPoint ).get( objectType );
         if ( this.concreteObjectTypeNode == null ) {
             BuildContext context = new BuildContext( ruleBase,
                                                      ((ReteooRuleBase) ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator() );
@@ -92,7 +97,7 @@
     public boolean isActive() {
         return true;
     }
-    
+
     public boolean isEvent() {
         return false;
     }

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	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/MemoryVisitor.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -1,18 +1,17 @@
 package org.drools.reteoo;
 
 import java.lang.reflect.Field;
+import java.util.Map;
 
 import org.drools.common.InternalWorkingMemory;
 import org.drools.reteoo.RuleTerminalNode.TerminalNodeMemory;
+import org.drools.spi.ObjectType;
 import org.drools.util.AbstractHashTable;
 import org.drools.util.Entry;
-import org.drools.util.FactHashTable;
 import org.drools.util.FactHandleIndexHashTable;
-import org.drools.util.Iterator;
-import org.drools.util.ObjectHashMap;
+import org.drools.util.FactHashTable;
 import org.drools.util.ReflectiveVisitor;
 import org.drools.util.FactHandleIndexHashTable.FieldIndexEntry;
-import org.drools.util.ObjectHashMap.ObjectEntry;
 
 public class MemoryVisitor extends ReflectiveVisitor {
     private InternalWorkingMemory workingMemory;
@@ -36,11 +35,10 @@
      * Rete visits each of its ObjectTypeNodes.
      */
     public void visitRete(final Rete rete) {
-        final ObjectHashMap map = rete.getObjectTypeNodes();
+        final Map<ObjectType, ObjectTypeNode> map = rete.getObjectTypeNodes();
 
-        final Iterator it = map.newIterator();
-        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
-            visit( entry.getValue() );
+        for( ObjectTypeNode node : map.values() ) {
+            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	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -26,6 +26,7 @@
 import org.drools.common.PropagationContextImpl;
 import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Declaration;
+import org.drools.rule.EntryPoint;
 import org.drools.spi.Constraint;
 import org.drools.spi.ObjectType;
 import org.drools.spi.PropagationContext;
@@ -78,6 +79,8 @@
 
     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.
@@ -96,6 +99,7 @@
         this.rete = (Rete) this.objectSource;
         this.objectType = objectType;
         setObjectMemoryEnabled( context.isObjectTypeNodeMemoryEnabled() );
+        this.entryPoint = context.getCurrentEntryPoint() == null ? EntryPoint.DEFAULT : context.getCurrentEntryPoint();
     }
 
     /**
@@ -144,7 +148,7 @@
             return;
         }
 
-        if ( this.objectMemoryEnabled) {
+        if ( this.objectMemoryEnabled ) {
             final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( this );
             memory.add( handle,
                         false );
@@ -210,10 +214,11 @@
         // to working memories
         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 );
+            final PropagationContextImpl propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
+                                                                                          PropagationContext.RULE_ADDITION,
+                                                                                          null,
+                                                                                          null );
+            propagationContext.setEntryPoint( this.entryPoint );
             this.rete.updateSink( this,
                                   propagationContext,
                                   workingMemory );
@@ -260,14 +265,14 @@
     }
 
     public String toString() {
-        return "[ObjectTypeNode(" + this.id + ") objectType=" + this.objectType + "]";
+        return "[ObjectTypeNode(" + this.id + ") " + this.entryPoint + " objectType=" + this.objectType + "]";
     }
 
     /**
      * Uses he hashCode() of the underlying ObjectType implementation.
      */
     public int hashCode() {
-        return this.objectType.hashCode();
+        return this.objectType.hashCode() ^ this.entryPoint.hashCode();
     }
 
     public boolean equals(final Object object) {
@@ -281,7 +286,7 @@
 
         final ObjectTypeNode other = (ObjectTypeNode) object;
 
-        return this.objectType.equals( other.objectType );
+        return this.objectType.equals( other.objectType ) && this.entryPoint.equals( other.entryPoint );
     }
 
     /** 
@@ -343,4 +348,11 @@
         }
         return usesDecl;
     }
+
+    /**
+     * @return the entryPoint
+     */
+    public EntryPoint getEntryPoint() {
+        return entryPoint;
+    }
 }

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	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/Rete.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -19,6 +19,8 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.drools.base.ShadowProxy;
 import org.drools.common.BaseNode;
@@ -27,12 +29,14 @@
 import org.drools.common.InternalRuleBase;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.NodeMemory;
+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.
@@ -64,19 +68,21 @@
     /**
      *
      */
-    private static final long          serialVersionUID = 400L;
-    /** The <code>Map</code> of <code>ObjectTypeNodes</code>. */
-    private final ObjectHashMap        objectTypeNodes;
+    private static final long                    serialVersionUID = 400L;
 
-    private transient InternalRuleBase ruleBase;
+    private final Map<EntryPoint, ObjectHashMap> entryPoints;
 
+    private transient InternalRuleBase           ruleBase;
+
     // ------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------
 
     public Rete(InternalRuleBase ruleBase) {
         super( 0 );
-        this.objectTypeNodes = new ObjectHashMap();
+        this.entryPoints = new HashMap<EntryPoint, ObjectHashMap>();
+        this.entryPoints.put( EntryPoint.DEFAULT,
+                              new ObjectHashMap() );
         this.ruleBase = ruleBase;
     }
 
@@ -106,7 +112,8 @@
                              final PropagationContext context,
                              final InternalWorkingMemory workingMemory) {
 
-        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( handle.getObject() );
+        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( context.getEntryPoint(),
+                                                                         handle.getObject() );
 
         // checks if shadow is enabled
         if ( objectTypeConf.isShadowEnabled() ) {
@@ -143,7 +150,8 @@
                               final InternalWorkingMemory workingMemory) {
         final Object object = handle.getObject();
 
-        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( object );
+        ObjectTypeConf objectTypeConf = workingMemory.getObjectTypeConf( context.getEntryPoint(),
+                                                                         object );
         ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
 
         if ( cachedNodes == null ) {
@@ -159,23 +167,30 @@
     }
 
     /**
-     * Adds the <code>TupleSink</code> so that it may receive
-     * <code>Tuples</code> propagated from this <code>TupleSource</code>.
+     * Adds the <code>ObjectSink</code> so that it may receive
+     * <code>Objects</code> propagated from this <code>ObjectSource</code>.
      *
-     * @param tupleSink
-     *            The <code>TupleSink</code> to receive propagated
-     *            <code>Tuples</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,
-                                  true );
+        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 );
     }
 
     protected void removeObjectSink(final ObjectSink objectSink) {
         final ObjectTypeNode node = (ObjectTypeNode) objectSink;
-        this.objectTypeNodes.remove( node.getObjectType() );
+        this.entryPoints.get( node.getEntryPoint() ).remove( node.getObjectType() );
     }
 
     public void attach() {
@@ -196,16 +211,27 @@
         }
     }
 
-    public ObjectHashMap getObjectTypeNodes() {
-        return this.objectTypeNodes;
+    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() );
+            }
+        }
+        return allNodes;
     }
 
+    public ObjectHashMap getObjectTypeNodes(EntryPoint entryPoint) {
+        return this.entryPoints.get( entryPoint );
+    }
+
     public InternalRuleBase getRuleBase() {
         return this.ruleBase;
     }
 
     public int hashCode() {
-        return this.objectTypeNodes.hashCode();
+        return this.entryPoints.hashCode();
     }
 
     public boolean equals(final Object object) {
@@ -218,7 +244,7 @@
         }
 
         final Rete other = (Rete) object;
-        return this.objectTypeNodes.equals( other.objectTypeNodes );
+        return this.entryPoints.equals( other.entryPoints );
     }
 
     public void updateSink(final ObjectSink sink,
@@ -228,7 +254,7 @@
         final ObjectTypeNode node = (ObjectTypeNode) sink;
         final ObjectType newObjectType = node.getObjectType();
 
-        for ( ObjectTypeConf objectTypeConf : workingMemory.getObjectTypeConfMap().values() ) {
+        for ( ObjectTypeConf objectTypeConf : workingMemory.getObjectTypeConfMap( context.getEntryPoint() ).values() ) {
             if ( newObjectType.isAssignableFrom( objectTypeConf.getConcreteObjectTypeNode().getObjectType() ) ) {
                 objectTypeConf.resetCache();
                 ObjectTypeNode sourceNode = objectTypeConf.getConcreteObjectTypeNode();
@@ -242,13 +268,13 @@
             }
         }
     }
-    
+
     public boolean isObjectMemoryEnabled() {
-        throw new UnsupportedOperationException("Rete has no Object memory");
+        throw new UnsupportedOperationException( "Rete has no Object memory" );
     }
 
     public void setObjectMemoryEnabled(boolean objectMemoryEnabled) {
-        throw new UnsupportedOperationException("ORete has no Object memory");
+        throw new UnsupportedOperationException( "ORete has no Object memory" );
     }
 
 }

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -32,6 +32,7 @@
 import org.drools.common.PropagationContextImpl;
 import org.drools.common.WorkingMemoryAction;
 import org.drools.event.RuleBaseEventListener;
+import org.drools.rule.EntryPoint;
 import org.drools.rule.Query;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
@@ -84,12 +85,14 @@
     public QueryResults getQueryResults(final String query) {
         return getQueryResults( query, null );
     }
+    
     public QueryResults getQueryResults(final String query, final Object[] arguments) {
 
         Object object = new DroolsQuery( query, arguments );
         InternalFactHandle handle = this.handleFactory.newFactHandle( object, false, this );
         
-        insert( handle,
+        insert( EntryPoint.DEFAULT, // query dummy objects always use default entry point
+                handle,
                 object,
                 null,
                 null );

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -29,6 +29,7 @@
 import org.drools.reteoo.ReteooBuilder;
 import org.drools.reteoo.ReteooRuleBase;
 import org.drools.reteoo.TupleSource;
+import org.drools.rule.EntryPoint;
 import org.drools.rule.RuleConditionElement;
 
 /**
@@ -68,6 +69,9 @@
     // alpha constraints from the last pattern attached
     private List                      alphaConstraints;
     
+    // the current entry point
+    private EntryPoint                currentEntryPoint;
+    
     private boolean                   tupleMemoryEnabled;
     
     private boolean                   objectTypeNodeMemoryEnabled;    
@@ -96,6 +100,8 @@
         this.tupleMemoryEnabled = true;
         
         this.objectTypeNodeMemoryEnabled = true;
+        
+        this.currentEntryPoint = EntryPoint.DEFAULT;
     }
 
     /**
@@ -328,5 +334,19 @@
     public boolean isAlphaMemoryAllowed() {
         return this.alphaNodeMemoryAllowed;
     }
+
+    /**
+     * @return the currentEntryPoint
+     */
+    public EntryPoint getCurrentEntryPoint() {
+        return currentEntryPoint;
+    }
+
+    /**
+     * @param currentEntryPoint the currentEntryPoint to set
+     */
+    public void setCurrentEntryPoint(EntryPoint currentEntryPoint) {
+        this.currentEntryPoint = currentEntryPoint;
+    }
         
 }

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	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -90,7 +90,7 @@
         if( candidate instanceof ObjectTypeNode ) {
             // object type nodes are always shared
             ObjectTypeNode otn = (ObjectTypeNode) candidate;
-            otn = (ObjectTypeNode) context.getRuleBase().getRete().getObjectTypeNodes().get( otn.getObjectType() );
+            otn = (ObjectTypeNode) context.getRuleBase().getRete().getObjectTypeNodes( context.getCurrentEntryPoint() ).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	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -28,6 +28,7 @@
 import org.drools.reteoo.ObjectSource;
 import org.drools.reteoo.ObjectTypeNode;
 import org.drools.rule.Declaration;
+import org.drools.rule.EntryPoint;
 import org.drools.rule.InvalidPatternException;
 import org.drools.rule.Pattern;
 import org.drools.rule.PatternSource;
@@ -79,15 +80,7 @@
         // Create BetaConstraints object
         context.setBetaconstraints( betaConstraints );
 
-        if ( pattern.getSource() == null ) {
-            // pattern is selected from working memory, so 
-            // Attach alpha nodes
-            attachAlphaNodes( context,
-                              utils,
-                              pattern,
-                              alphaConstraints );
-
-        } else {
+        if ( pattern.getSource() != null ) {
             context.setAlphaConstraints( alphaConstraints );
             final int currentOffset = context.getCurrentPatternOffset();
 
@@ -100,8 +93,17 @@
                            source );
             // restoring offset
             context.setCurrentPatternOffset( currentOffset );
+            
         }
         
+        if( pattern.getSource() == null || context.getCurrentEntryPoint() != EntryPoint.DEFAULT ) {
+            attachAlphaNodes( context,
+                              utils,
+                              pattern,
+                              alphaConstraints );
+            context.setCurrentEntryPoint( EntryPoint.DEFAULT );
+        }
+
         // last thing to do is increment the offset, since if the pattern has a source,
         // offset must be overriden
         context.incrementCurrentPatternOffset();

Added: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/EntryPoint.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/EntryPoint.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/rule/EntryPoint.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -0,0 +1,142 @@
+/*
+ * 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 Dec 14, 2007
+ */
+package org.drools.rule;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class defines a Rete "Entry Point".
+ * An entry point is used as a source of facts that
+ * are scoped to a separate alpha network. The alpha
+ * network is not shared among separate entry points
+ * and this allows them to safelly run in parallel
+ * and concurrent modes.
+ * 
+ * @author etirelli
+ *
+ */
+public class EntryPoint extends ConditionalElement
+    implements
+    PatternSource {
+
+    public static final EntryPoint DEFAULT = new EntryPoint("DEFAULT");
+    
+    private static final long serialVersionUID = 1435985794248365232L;
+    
+    private final String entryPointId;
+    
+    /**
+     * Constructor.
+     * 
+     * @param entryPointId the ID for this entry point
+     */
+    public EntryPoint( final String entryPointId ) {
+        this.entryPointId = entryPointId;
+    }
+
+    /** 
+     * There is not reason to clone this object since it is stateless. 
+     * So a clone() call will return the instance itself.
+     *  
+     * @see org.drools.rule.ConditionalElement#clone()
+     */
+    @Override
+    public Object clone() {
+        return this;
+    }
+
+    /** 
+     * It is not possible to declare any new variables, so always
+     * return an Empty Map
+     * 
+     * @see org.drools.rule.RuleConditionElement#getInnerDeclarations()
+     */
+    public Map getInnerDeclarations() {
+        return Collections.EMPTY_MAP;
+    }
+
+    /**
+     * It is not possible to nest elements inside an entry point, so
+     * always return an empty list.
+     * 
+     * @see org.drools.rule.RuleConditionElement#getNestedElements()
+     */
+    public List getNestedElements() {
+        return Collections.EMPTY_LIST;
+    }
+
+    /**
+     * It is not possible to declare and export any variables,
+     * so always return an empty map
+     * 
+     * @see org.drools.rule.RuleConditionElement#getOuterDeclarations()
+     */
+    public Map getOuterDeclarations() {
+        return Collections.EMPTY_MAP;
+    }
+
+    /** 
+     * Not possible to resolve any declaration, so always return null.
+     * 
+     * @see org.drools.rule.RuleConditionElement#resolveDeclaration(java.lang.String)
+     */
+    public Declaration resolveDeclaration(String identifier) {
+        return null;
+    }
+    
+    /**
+     * Returns this entry point ID
+     * @return
+     */
+    public String getEntryPointId() {
+        return this.entryPointId;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = 1;
+        result = PRIME * result + ((entryPointId == null) ? 0 : entryPointId.hashCode());
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if ( this == obj ) return true;
+        if ( obj == null ) return false;
+        if ( getClass() != obj.getClass() ) return false;
+        final EntryPoint other = (EntryPoint) obj;
+        if ( entryPointId == null ) {
+            if ( other.entryPointId != null ) return false;
+        } else if ( !entryPointId.equals( other.entryPointId ) ) return false;
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "EntryPoint::"+this.entryPointId;
+    }
+}

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/PropagationContext.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/PropagationContext.java	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/PropagationContext.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -18,6 +18,7 @@
 
 import java.io.Serializable;
 import org.drools.reteoo.ReteTuple;
+import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
 
 public interface PropagationContext
@@ -51,5 +52,7 @@
     public void clearRetractedTuples();
     
     public void releaseResources();
+    
+    public EntryPoint getEntryPoint();
 
 }
\ No newline at end of file

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	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -18,6 +18,7 @@
 
 import java.lang.reflect.Field;
 import java.util.List;
+import java.util.Map;
 
 import org.drools.Cheese;
 import org.drools.DroolsTestCase;
@@ -35,6 +36,7 @@
 import org.drools.common.PropagationContextImpl;
 import org.drools.reteoo.ReteooBuilder.IdGenerator;
 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.FactHashTable;
@@ -64,9 +66,7 @@
         assertEquals( id,
                       objectTypeNode.getId() );
 
-        final Field field = Rete.class.getDeclaredField( "objectTypeNodes" );
-        field.setAccessible( true );
-        final ObjectHashMap map = (ObjectHashMap) field.get( source );
+        ObjectHashMap map = source.getObjectTypeNodes( EntryPoint.DEFAULT );
 
         assertEquals( 0,
                       map.size() );

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	2007-12-14 17:11:27 UTC (rev 17241)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2007-12-14 21:26:42 UTC (rev 17242)
@@ -38,6 +38,7 @@
 import org.drools.common.PropagationContextImpl;
 import org.drools.reteoo.ReteooBuilder.IdGenerator;
 import org.drools.reteoo.builder.BuildContext;
+import org.drools.rule.EntryPoint;
 import org.drools.spi.PropagationContext;
 import org.drools.util.ObjectHashMap;
 
@@ -72,9 +73,7 @@
                                                                   buildContext );
         stringTypeNode.attach();
 
-        final Field field = Rete.class.getDeclaredField( "objectTypeNodes" );
-        field.setAccessible( true );
-        final ObjectHashMap map = (ObjectHashMap) field.get( rete );
+        final Map map = rete.getObjectTypeNodes();
 
         // Check the ObjectTypeNodes are correctly added to Rete
         assertEquals( 2,
@@ -134,7 +133,7 @@
                                                        null ),
                            workingMemory );
 
-        final Map map = workingMemory.getObjectTypeConfMap();
+        final Map map = workingMemory.getObjectTypeConfMap( EntryPoint.DEFAULT );
         ClassObjectTypeConf conf = (ClassObjectTypeConf) map.get( ArrayList.class );
         assertLength( 3,
                       conf.getObjectTypeNodes() );
@@ -238,7 +237,7 @@
                     rete.getObjectTypeNodes().get( new ClassObjectType( List.class ) ) );
 
         // ArrayConf should match two ObjectTypenodes for List and ArrayList
-        Map memory = workingMemory.getObjectTypeConfMap();
+        Map memory = workingMemory.getObjectTypeConfMap( EntryPoint.DEFAULT );
         ObjectTypeConf arrayConf = (ObjectTypeConf) memory.get( ArrayList.class );
         final ObjectTypeNode arrayOtn = arrayConf.getConcreteObjectTypeNode();
         assertEquals( 2,




More information about the jboss-svn-commits mailing list