[jboss-svn-commits] JBL Code SVN: r19862 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/common and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon May 5 21:50:22 EDT 2008


Author: mark.proctor at jboss.com
Date: 2008-05-05 21:50:21 -0400 (Mon, 05 May 2008)
New Revision: 19862

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/InputPersister.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/ObjectPlaceholder.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/OutputPersister.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PersisterEnums.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PersisterKey.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PlaceholderResolverStrategy.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PlaceholderResolverStrategyFactory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/Placeholders.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/RightTupleKey.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/RuleBaseNodes.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/SerializablePlaceholder.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/SerializablePlaceholderResolverStrategy.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/WMSerialisationInContext.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/WMSerialisationOutContext.java
Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AgendaItem.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalFactHandle.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactHandle.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Sink.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PropagationContext.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/EvalConditionNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ExistsNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockRightTupleSink.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java
Log:
JBRULES-1598 Efficient WorkingMemory serialization with binary protocol
-initial non-working impl
-refactorings so PropagationContexts reference LeftTuples and not activations, and also the facthandle
-FactHandle now uses an int for id.

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -120,4 +120,12 @@
      * @see org.drools.reteoo.FactHandleFactory#newInstance()
      */
     public abstract FactHandleFactory newInstance();
+    
+    public int getId() {
+        return this.id.get();
+    }
+
+    public long getRecency() {
+        return this.counter.get();
+    }    
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -72,6 +72,7 @@
 import org.drools.process.instance.timer.TimerManager;
 import org.drools.reteoo.EntryPointNode;
 import org.drools.reteoo.LIANodePropagation;
+import org.drools.reteoo.LeftTuple;
 import org.drools.reteoo.ObjectTypeConf;
 import org.drools.rule.Declaration;
 import org.drools.rule.EntryPoint;
@@ -947,7 +948,8 @@
         final PropagationContext propagationContext = new PropagationContextImpl( getNextPropagationIdCounter(),
                                                                                   PropagationContext.ASSERTION,
                                                                                   rule,
-                                                                                  activation,
+                                                                                  (activation == null) ? null : (LeftTuple) activation.getTuple(),
+                                                                                  handle,
                                                                                   this.agenda.getActiveActivations(),
                                                                                   this.agenda.getDormantActivations(),
                                                                                   entryPoint );
@@ -1050,7 +1052,8 @@
             final PropagationContext propagationContext = new PropagationContextImpl( getNextPropagationIdCounter(),
                                                                                       PropagationContext.RETRACTION,
                                                                                       rule,
-                                                                                      activation,
+                                                                                      (activation == null) ? null : (LeftTuple) activation.getTuple(),
+                                                                                      handle,
                                                                                       this.agenda.getActiveActivations(),
                                                                                       this.agenda.getDormantActivations(),
                                                                                       this.entryPoint );
@@ -1137,7 +1140,8 @@
             final PropagationContext propagationContext = new PropagationContextImpl( getNextPropagationIdCounter(),
                                                                                       PropagationContext.MODIFICATION,
                                                                                       rule,
-                                                                                      activation,
+                                                                                      (activation == null) ? null : (LeftTuple) activation.getTuple(),
+                                                                                      handle,
                                                                                       this.agenda.getActiveActivations(),
                                                                                       this.agenda.getDormantActivations(),
                                                                                       entryPoint );
@@ -1211,7 +1215,8 @@
             final PropagationContext propagationContext = new PropagationContextImpl( getNextPropagationIdCounter(),
                                                                                       PropagationContext.MODIFICATION,
                                                                                       rule,
-                                                                                      activation,
+                                                                                      (activation == null) ? null : (LeftTuple) activation.getTuple(),
+                                                                                      handle,
                                                                                       this.agenda.getActiveActivations(),
                                                                                       this.agenda.getDormantActivations(),
                                                                                       entryPoint );
@@ -1282,7 +1287,8 @@
             final PropagationContext propagationContext = new PropagationContextImpl( getNextPropagationIdCounter(),
                                                                                       PropagationContext.MODIFICATION,
                                                                                       rule,
-                                                                                      activation,
+                                                                                      (activation == null) ? null : (LeftTuple) activation.getTuple(),
+                                                                                      handle,
                                                                                       this.agenda.getActiveActivations(),
                                                                                       this.agenda.getDormantActivations(),
                                                                                       entryPoint );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AgendaItem.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AgendaItem.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AgendaItem.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -49,43 +49,43 @@
     /**
      *
      */
-    private static final long        serialVersionUID = 400L;
+    private static final long   serialVersionUID = 400L;
 
     /** The tuple. */
-    private Tuple              tuple;
+    private Tuple               tuple;
 
     /** The rule. */
-    private Rule               rule;
+    private Rule                rule;
 
     /** The salience */
-    private int                salience;
+    private int                 salience;
 
     /** Used for sequential mode */
-    private int                      sequenence;
+    private int                 sequenence;
 
     /** The subrule */
-    private GroupElement       subrule;
+    private GroupElement        subrule;
 
     /** The propagation context */
-    private PropagationContext context;
+    private PropagationContext  context;
 
     /** The activation number */
-    private long               activationNumber;
+    private long                activationNumber;
 
     /** A reference to the PriorityQeue the item is on */
-    private Queue                    queue;
+    private Queue               queue;
 
-    private int                      index;
+    private int                 index;
 
-    private LinkedList               justified;
+    private LinkedList          justified;
 
-    private boolean                  activated;
+    private boolean             activated;
 
-    private InternalAgendaGroup      agendaGroup;
+    private InternalAgendaGroup agendaGroup;
 
-    private ActivationGroupNode      activationGroupNode;
+    private ActivationGroupNode activationGroupNode;
 
-    private RuleFlowGroupNode        ruleFlowGroupNode;
+    private RuleFlowGroupNode   ruleFlowGroupNode;
 
     // ------------------------------------------------------------
     // Constructors
@@ -119,38 +119,39 @@
     // ------------------------------------------------------------
     // Instance methods
     // ------------------------------------------------------------
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        tuple   = (Tuple)in.readObject();
-        rule    = (Rule)in.readObject();
-        salience    = in.readInt();
-        sequenence  = in.readInt();
-        subrule     = (GroupElement)in.readObject();
-        context     = (PropagationContext)in.readObject();
-        activationNumber    = in.readLong();
-        queue     = (Queue)in.readObject();
-        index     = in.readInt();
-        justified     = (LinkedList)in.readObject();
-        activated   = in.readBoolean();
-        agendaGroup     = (InternalAgendaGroup)in.readObject();
-        activationGroupNode     = (ActivationGroupNode)in.readObject();
-        ruleFlowGroupNode     = (RuleFlowGroupNode)in.readObject();
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        tuple = (Tuple) in.readObject();
+        rule = (Rule) in.readObject();
+        salience = in.readInt();
+        sequenence = in.readInt();
+        subrule = (GroupElement) in.readObject();
+        context = (PropagationContext) in.readObject();
+        activationNumber = in.readLong();
+        queue = (Queue) in.readObject();
+        index = in.readInt();
+        justified = (LinkedList) in.readObject();
+        activated = in.readBoolean();
+        agendaGroup = (InternalAgendaGroup) in.readObject();
+        activationGroupNode = (ActivationGroupNode) in.readObject();
+        ruleFlowGroupNode = (RuleFlowGroupNode) in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(tuple);
-        out.writeObject(rule);
-        out.writeInt(salience);
-        out.writeInt(sequenence);
-        out.writeObject(subrule);
-        out.writeObject(context);
-        out.writeLong(activationNumber);
-        out.writeObject(queue);
-        out.writeInt(index);
-        out.writeObject(justified);
-        out.writeBoolean(activated);
-        out.writeObject(agendaGroup);
-        out.writeObject(activationGroupNode);
-        out.writeObject(ruleFlowGroupNode);
+        out.writeObject( tuple );
+        out.writeObject( rule );
+        out.writeInt( salience );
+        out.writeInt( sequenence );
+        out.writeObject( subrule );
+        out.writeObject( context );
+        out.writeLong( activationNumber );
+        out.writeObject( queue );
+        out.writeInt( index );
+        out.writeObject( justified );
+        out.writeBoolean( activated );
+        out.writeObject( agendaGroup );
+        out.writeObject( activationGroupNode );
+        out.writeObject( ruleFlowGroupNode );
     }
 
     public PropagationContext getPropagationContext() {

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -148,7 +148,7 @@
         this.recency = recency;
     }
 
-    public long getId() {
+    public int getId() {
         return this.id;
     }
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalFactHandle.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalFactHandle.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -23,7 +23,7 @@
 public interface InternalFactHandle
     extends
     FactHandle {
-    public long getId();
+    public int getId();
 
     public long getRecency();
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -17,6 +17,7 @@
 import org.drools.base.ShadowProxy;
 import org.drools.event.WorkingMemoryEventSupport;
 import org.drools.reteoo.EntryPointNode;
+import org.drools.reteoo.LeftTuple;
 import org.drools.reteoo.ObjectTypeConf;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
@@ -140,7 +141,8 @@
         final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(),
                                                                                   PropagationContext.ASSERTION,
                                                                                   rule,
-                                                                                  activation,
+                                                                                  (activation == null) ? null : (LeftTuple) activation.getTuple(),
+                                                                                  handle,
                                                                                   -1,
                                                                                   -1,
                                                                                   this.entryPoint );
@@ -196,7 +198,8 @@
             final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(),
                                                                                       PropagationContext.MODIFICATION,
                                                                                       rule,
-                                                                                      activation,
+                                                                                      (activation == null) ? null : (LeftTuple) activation.getTuple(),
+                                                                                      handle,
                                                                                       -1,
                                                                                       -1,
                                                                                       this.entryPoint );
@@ -267,7 +270,8 @@
             final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(),
                                                                                       PropagationContext.RETRACTION,
                                                                                       rule,
-                                                                                      activation,
+                                                                                      (activation == null) ? null : (LeftTuple) activation.getTuple(),
+                                                                                      handle,
                                                                                       -1,
                                                                                       -1,
                                                                                       this.entryPoint );
@@ -329,7 +333,8 @@
             final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(),
                                                                                       PropagationContext.MODIFICATION,
                                                                                       rule,
-                                                                                      activation,
+                                                                                      (activation == null) ? null : (LeftTuple) activation.getTuple(),
+                                                                                      handle,
                                                                                       -1,
                                                                                       -1,
                                                                                       entryPoint );
@@ -388,7 +393,8 @@
             final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(),
                                                                                       PropagationContext.MODIFICATION,
                                                                                       rule,
-                                                                                      activation,
+                                                                                      (activation == null) ? null : (LeftTuple) activation.getTuple(),
+                                                                                      handle,
                                                                                       -1,
                                                                                       -1,
                                                                                       entryPoint );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/PropagationContextImpl.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -31,24 +31,26 @@
     implements
     PropagationContext {
 
-    private static final long serialVersionUID = 8400185220119865618L;
+    private static final long  serialVersionUID = 8400185220119865618L;
 
-    private int    type;
+    private int                type;
 
-    private Rule         rule;
+    private Rule               rule;
 
-    private Activation   activation;
+    private LeftTuple          leftTuple;
 
-    private long   propagationNumber;
+    private InternalFactHandle factHandle;
 
-    public int     activeActivations;
+    private long               propagationNumber;
 
-    public int     dormantActivations;
+    public int                 activeActivations;
 
-    public ObjectHashMap retracted;
+    public int                 dormantActivations;
 
-    private EntryPoint   entryPoint;
+    public ObjectHashMap       retracted;
 
+    private EntryPoint         entryPoint;
+
     public PropagationContextImpl() {
 
     }
@@ -56,10 +58,12 @@
     public PropagationContextImpl(final long number,
                                   final int type,
                                   final Rule rule,
-                                  final Activation activation) {
+                                  final LeftTuple leftTuple,
+                                  final InternalFactHandle factHandle) {
         this.type = type;
         this.rule = rule;
-        this.activation = activation;
+        this.leftTuple = leftTuple;
+        this.factHandle = factHandle;
         this.propagationNumber = number;
         this.activeActivations = 0;
         this.dormantActivations = 0;
@@ -69,39 +73,42 @@
     public PropagationContextImpl(final long number,
                                   final int type,
                                   final Rule rule,
-                                  final Activation activation,
+                                  final LeftTuple leftTuple,
+                                  final InternalFactHandle factHandle,
                                   final int activeActivations,
                                   final int dormantActivations,
                                   final EntryPoint entryPoint) {
         this.type = type;
         this.rule = rule;
-        this.activation = activation;
+        this.leftTuple = leftTuple;
+        this.factHandle = factHandle;
         this.propagationNumber = number;
         this.activeActivations = activeActivations;
         this.dormantActivations = dormantActivations;
         this.entryPoint = entryPoint;
     }
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        type    = in.readInt();
-        activeActivations   = in.readInt();
-        dormantActivations  = in.readInt();
-        propagationNumber   = in.readLong();
-        rule        = (Rule)in.readObject();
-        activation  = (Activation)in.readObject();
-        retracted   = (ObjectHashMap)in.readObject();
-        entryPoint  = (EntryPoint)in.readObject();
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        this.type = in.readInt();
+        this.activeActivations = in.readInt();
+        this.dormantActivations = in.readInt();
+        this.propagationNumber = in.readLong();
+        this.rule = (Rule) in.readObject();
+        this.leftTuple = (LeftTuple) in.readObject();
+        this.retracted = (ObjectHashMap) in.readObject();
+        this.entryPoint = (EntryPoint) in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(type);
-        out.writeInt(activeActivations);
-        out.writeInt(dormantActivations);
-        out.writeLong(propagationNumber);
-        out.writeObject(rule);
-        out.writeObject(activation);
-        out.writeObject(retracted);
-        out.writeObject(entryPoint);
+        out.writeInt( this.type );
+        out.writeInt( this.activeActivations );
+        out.writeInt( this.dormantActivations );
+        out.writeLong( this.propagationNumber );
+        out.writeObject( this.rule );
+        out.writeObject( this.leftTuple );
+        out.writeObject( this.retracted );
+        out.writeObject( this.entryPoint );
     }
 
     public long getPropagationNumber() {
@@ -117,15 +124,14 @@
         return this.rule;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.drools.reteoo.PropagationContext#getActivationOrigin()
-     */
-    public Activation getActivationOrigin() {
-        return this.activation;
+    public LeftTuple getLeftTupleOrigin() {
+        return this.leftTuple;
     }
 
+    public InternalFactHandle getFactHandleOrigin() {
+        return this.factHandle;
+    }
+
     /*
      * (non-Javadoc)
      *
@@ -180,7 +186,7 @@
     }
 
     public void releaseResources() {
-        this.activation = null;
+        this.leftTuple = null;
         this.retracted = null;
         this.rule = null;
     }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -131,7 +131,8 @@
                                                                          node,
                                                                          set,
                                                                          handle,
-                                                                         context );
+                                                                         context,
+                                                                         activation );
                 workingMemory.queueWorkingMemoryAction( action );
             }
         }
@@ -145,15 +146,17 @@
         private Set                    set;
         private InternalFactHandle     handle;
         private PropagationContext     context;
+        private Activation             activation;
 
         public LogicalRetractCallback() {
 
         }
-        public LogicalRetractCallback(TruthMaintenanceSystem tms,
-                                      LogicalDependency node,
-                                      Set set,
-                                      InternalFactHandle handle,
-                                      PropagationContext context) {
+        public LogicalRetractCallback(final TruthMaintenanceSystem tms,
+                                      final LogicalDependency node,
+                                      final Set set,
+                                      final InternalFactHandle handle,
+                                      final PropagationContext context,
+                                      final Activation activation) {
             this.tms = tms;
             this.node = node;
             this.set = set;
@@ -167,6 +170,7 @@
             set         = (Set)in.readObject();
             handle         = (InternalFactHandle)in.readObject();
             context         = (PropagationContext)in.readObject();
+            activation = ( Activation ) in.readObject();
         }
 
         public void writeExternal(ObjectOutput out) throws IOException {
@@ -175,6 +179,7 @@
             out.writeObject(set);
             out.writeObject(handle);
             out.writeObject(context);
+            out.writeObject( activation );
         }
 
         public void execute(InternalWorkingMemory workingMemory) {
@@ -188,7 +193,7 @@
                                                  false,
                                                  true,
                                                  context.getRuleOrigin(),
-                                                 context.getActivationOrigin() );
+                                                 this.activation );
                 }
             }
         }

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/InputPersister.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/InputPersister.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/InputPersister.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,369 @@
+package org.drools.persister;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Map;
+
+import org.drools.base.ClassObjectType;
+import org.drools.common.AgendaItem;
+import org.drools.common.BaseNode;
+import org.drools.common.DefaultAgenda;
+import org.drools.common.DefaultFactHandle;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.common.PropagationContextImpl;
+import org.drools.reteoo.BetaMemory;
+import org.drools.reteoo.BetaNode;
+import org.drools.reteoo.EntryPointNode;
+import org.drools.reteoo.JoinNode;
+import org.drools.reteoo.LeftInputAdapterNode;
+import org.drools.reteoo.LeftTuple;
+import org.drools.reteoo.LeftTupleSink;
+import org.drools.reteoo.LeftTupleSource;
+import org.drools.reteoo.NotNode;
+import org.drools.reteoo.ObjectSink;
+import org.drools.reteoo.ObjectTypeNode;
+import org.drools.reteoo.ReteooFactHandleFactory;
+import org.drools.reteoo.ReteooWorkingMemory;
+import org.drools.reteoo.RightTuple;
+import org.drools.reteoo.RightTupleSink;
+import org.drools.reteoo.RuleTerminalNode;
+import org.drools.reteoo.RuleTerminalNode.TerminalNodeMemory;
+import org.drools.rule.EntryPoint;
+import org.drools.rule.GroupElement;
+import org.drools.rule.Package;
+import org.drools.rule.Rule;
+import org.drools.spi.Activation;
+import org.drools.spi.ObjectType;
+import org.drools.spi.PropagationContext;
+import org.drools.util.BinaryHeapQueue;
+import org.drools.util.ObjectHashMap;
+import org.drools.util.ObjectHashSet;
+
+public class InputPersister {
+    public WMSerialisationInContext context;
+
+    public InputPersister(InternalRuleBase ruleBase,
+                          ObjectInputStream stream,
+                          PlaceholderResolverStrategyFactory resolverStrategyFactory) {
+        context = new WMSerialisationInContext( stream,
+                                                ruleBase,
+                                                RuleBaseNodes.getNodeMap( ruleBase ),
+                                                resolverStrategyFactory );
+    }
+
+    public InternalWorkingMemory read() throws IOException,
+                                       ClassNotFoundException {
+        readFactHandles( context );
+        return context.wm;
+    }
+
+    public static void readFactHandles(WMSerialisationInContext context) throws IOException,
+                                                                        ClassNotFoundException {
+        ObjectInputStream stream = context.stream;
+        InternalRuleBase ruleBase = context.ruleBase;
+        
+        PlaceholderResolverStrategyFactory resolverStrategyFactory = context.resolverStrategyFactory;
+
+        ReteooFactHandleFactory factHandleFactory = new ReteooFactHandleFactory();
+        factHandleFactory.readExternal( stream );
+        context.wm = new ReteooWorkingMemory( 0,
+                                              ruleBase,
+                                              factHandleFactory );
+
+        int size = stream.readInt();
+
+        if ( size == 0 ) {
+            return;
+        }
+
+        // load the handles
+        InternalFactHandle[] handles = new InternalFactHandle[size];
+        for ( int i = 0; i < size; i++ ) {
+            int id = stream.readInt();
+            long recency = stream.readLong();
+            PlaceholderResolverStrategy strategy = resolverStrategyFactory.get( null );
+//            ObjectPlaceholder placeHolder = strategy.read( stream );
+//
+//            Object object = placeHolder.resolveObject();
+            Object object = null;
+            InternalFactHandle handle = new DefaultFactHandle( id,
+                                                               object,
+                                                               recency );
+            context.handles.put( id,
+                                 handle );
+            handles[i] = handle;
+
+            context.wm.getObjectStore().addHandle( handle,
+                                                   object );
+
+            int type = stream.readInt();
+            if ( type == PersisterEnums.RIGHT_TUPLE ) {
+                type = PersisterEnums.REPEAT;
+                while ( type == PersisterEnums.REPEAT ) {
+                    readRightTuple( context,
+                                    handle );
+                    type = stream.readInt();
+                }
+            }
+        }
+
+        EntryPointNode node = ruleBase.getRete().getEntryPointNode( EntryPoint.DEFAULT );
+        Map<ObjectType, ObjectTypeNode> objectTypeNodes = node.getObjectTypeNodes();
+
+        // add handles to object type nodes
+        for ( InternalFactHandle handle : handles ) {
+            Object object = handle.getObject();
+            ClassObjectType objectType = new ClassObjectType( object.getClass() );
+            ObjectTypeNode objectTypeNode = objectTypeNodes.get( objectType );
+            ObjectHashSet set = (ObjectHashSet) context.wm.getNodeMemory( objectTypeNode );
+            set.add( handle,
+                     false );
+        }
+
+        //        type = stream.readInt();
+        //        if ( type == PersisterEnums.LEFT_TUPLE ) {
+        //            type = PersisterEnums.REPEAT;
+        //            while ( type == PersisterEnums.REPEAT ) {
+        //                LeftTupleSink sink = (LeftTupleSink) sinks.get( stream.readInt() );
+        //                int factHandleId = stream.readInt();
+        //                LeftTuple leftTuple = new LeftTuple( context.handles[factHandleId],
+        //                                                     sink,
+        //                                                     true );
+        //                readLeftTuple( leftTuple,
+        //                               context );
+        //            }
+        //        }
+        //
+        //        readPropagationContexts( context );
+
+        //        readActivations( context );        
+    }
+
+    public static void readRightTuple(WMSerialisationInContext context,
+                                      InternalFactHandle factHandle) throws IOException,
+                                                                    ClassNotFoundException {
+        ObjectInputStream stream = context.stream;
+
+        RightTupleSink sink = (RightTupleSink) context.sinks.get( stream.readInt() );
+
+        BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
+
+        RightTuple rightTuple = new RightTuple( factHandle,
+                                                sink );
+        context.rightTuples.put( new RightTupleKey( factHandle.getId(),
+                                                    sink ),
+                                 rightTuple );
+
+        memory.getRightTupleMemory().add( rightTuple );
+    }
+
+    public static void readLeftTuple(LeftTuple parentLeftTuple,
+                                     WMSerialisationInContext context) throws IOException,
+                                                                      ClassNotFoundException {
+        ObjectInputStream stream = context.stream;
+        InternalRuleBase ruleBase = context.ruleBase;
+        InternalWorkingMemory wm = context.wm;
+        Map<Integer, BaseNode> sinks = context.sinks;
+
+        LeftTupleSink sink = parentLeftTuple.getLeftTupleSink();
+
+        if ( sink instanceof JoinNode ) {
+            BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
+            memory.getLeftTupleMemory().add( parentLeftTuple );
+
+            int type = stream.readInt();
+            if ( type == PersisterEnums.RIGHT_TUPLE ) {
+                type = PersisterEnums.REPEAT;
+                while ( type == PersisterEnums.REPEAT ) {
+                    LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
+                    int factHandleId = stream.readInt();
+                    RightTupleKey key = new RightTupleKey( factHandleId,
+                                                           sink );
+                    RightTuple rightTuple = context.rightTuples.get( key );
+                    LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
+                                                              rightTuple,
+                                                              childSink,
+                                                              true );
+                    readLeftTuple( childLeftTuple,
+                                   context );
+                }
+            }
+        } else if ( sink instanceof NotNode ) {
+            BetaMemory memory = (BetaMemory) context.wm.getNodeMemory( (BetaNode) sink );
+            int type = stream.readInt();
+            if ( type == PersisterEnums.LEFT_TUPLE_NOT_BLOCKED ) {
+                memory.getLeftTupleMemory().add( parentLeftTuple );
+
+                type = stream.readInt();
+                if ( type == PersisterEnums.LEFT_TUPLE ) {
+                    type = PersisterEnums.REPEAT;
+                    while ( type == PersisterEnums.REPEAT ) {
+                        LeftTupleSink childSink = (LeftTupleSink) sinks.get( stream.readInt() );
+                        LeftTuple childLeftTuple = new LeftTuple( parentLeftTuple,
+                                                                  childSink,
+                                                                  true );
+                        readLeftTuple( childLeftTuple,
+                                       context );
+                    }
+                }
+            } else {
+                int factHandleId = stream.readInt();
+                RightTupleKey key = new RightTupleKey( factHandleId,
+                                                       sink );
+                RightTuple rightTuple = context.rightTuples.get( key );
+
+                LeftTuple blockedPrevious = rightTuple.getBlocked();
+                if ( blockedPrevious != null ) {
+                    parentLeftTuple.setBlockedNext( blockedPrevious );
+                    blockedPrevious.setBlockedPrevious( parentLeftTuple );
+                }
+                rightTuple.setBlocked( parentLeftTuple );
+            }
+        } else if ( sink instanceof RuleTerminalNode ) {
+            RuleTerminalNode ruleTerminalNode = (RuleTerminalNode) sink;
+            TerminalNodeMemory memory = (TerminalNodeMemory) wm.getNodeMemory( ruleTerminalNode );
+            memory.getTupleMemory().add( parentLeftTuple );
+
+            int pos = context.terminalTupleMap.size();
+            context.terminalTupleMap.put( pos,
+                                          parentLeftTuple );
+        }
+    }
+
+    public static void readActivations(WMSerialisationInContext context) throws IOException,
+                                                                        ClassNotFoundException {
+        ObjectInputStream stream = context.stream;
+
+        int type = stream.readInt();
+        if ( type == PersisterEnums.ACTIVATION ) {
+            type = PersisterEnums.REPEAT;
+            while ( type == PersisterEnums.REPEAT ) {
+                readActivation( context );
+            }
+        }
+    }
+
+    public static Activation readActivation(WMSerialisationInContext context) throws IOException,
+                                                                             ClassNotFoundException {
+        ObjectInputStream stream = context.stream;
+        InternalRuleBase ruleBase = context.ruleBase;
+        InternalWorkingMemory wm = context.wm;
+
+        long activationNumber = stream.readLong();
+
+        LeftTuple leftTuple = context.terminalTupleMap.get( stream.readInt() );
+
+        int salience = stream.readInt();
+
+        //PropagationContext context,
+        String pkgName = (String) stream.readObject();
+        String ruleName = (String) stream.readObject();
+        Package pkg = ruleBase.getPackage( pkgName );
+        Rule rule = pkg.getRule( ruleName );
+
+        RuleTerminalNode ruleTerminalNode = (RuleTerminalNode) context.sinks.get( stream.readInt() );
+        GroupElement subRule = ruleTerminalNode.getSubRule();
+
+        PropagationContext pc = context.propagationContexts.get( stream.readLong() );
+
+        AgendaItem activation = new AgendaItem( activationNumber,
+                                                leftTuple,
+                                                salience,
+                                                pc,
+                                                rule,
+                                                subRule );
+
+        boolean activated = stream.readBoolean();
+        activation.setActivated( activated );
+        if ( activated ) {
+            String agendaGroupName = (String) stream.readObject();
+            BinaryHeapQueue agendaGroup = (BinaryHeapQueue) ((DefaultAgenda) wm.getAgenda()).getAgendaGroup( agendaGroupName );
+            agendaGroup.enqueue( activation );
+        }
+
+        return activation;
+    }
+
+    public static void readPropagationContexts(WMSerialisationInContext context) throws IOException,
+                                                                                ClassNotFoundException {
+        ObjectInputStream stream = context.stream;
+
+        int type = stream.readInt();
+        if ( type == PersisterEnums.PROPAGATION_CONTEXT ) {
+            type = PersisterEnums.REPEAT;
+            while ( type == PersisterEnums.REPEAT ) {
+                readPropagationContext( context );
+            }
+        }
+    }
+
+    public static void readPropagationContext(WMSerialisationInContext context) throws IOException,
+                                                                               ClassNotFoundException {
+        ObjectInputStream stream = context.stream;
+        InternalRuleBase ruleBase = context.ruleBase;
+        InternalWorkingMemory wm = context.wm;
+
+        int type = stream.readInt();
+
+        Rule rule = null;
+        if ( stream.readBoolean() ) {
+            String pkgName = stream.readUTF();
+            String ruleName = stream.readUTF();
+            Package pkg = ruleBase.getPackage( pkgName );
+            rule = pkg.getRule( ruleName );
+        }
+
+        LeftTuple leftTuple = null;
+        if ( stream.readBoolean() ) {
+            int tuplePos = stream.readInt();
+            leftTuple = (LeftTuple) context.terminalTupleMap.get( tuplePos );
+        }
+
+        int factHandleId = stream.readInt();
+        InternalFactHandle factHandle = context.handles.get( factHandleId );
+
+        long propagationNumber = stream.readLong();
+        int activeActivations = stream.readInt();
+        int dormantActivations = stream.readInt();
+        String entryPointId = stream.readUTF();
+
+        EntryPoint entryPoint = context.entryPoints.get( entryPointId );
+        if ( entryPoint == null ) {
+            entryPoint = new EntryPoint( entryPointId );
+            context.entryPoints.put( entryPointId,
+                                     entryPoint );
+        }
+
+        PropagationContext pc = new PropagationContextImpl( propagationNumber,
+                                                            type,
+                                                            rule,
+                                                            leftTuple,
+                                                            factHandle,
+                                                            activeActivations,
+                                                            dormantActivations,
+                                                            entryPoint );
+        context.propagationContexts.put( propagationNumber,
+                                         pc );
+    }
+
+    //
+    //    public long getLastId() {
+    //        return lastId;
+    //    }
+    //
+    //    public long getLastRecency() {
+    //        return lastRecency;
+    //    }
+    //
+    //    public InternalFactHandle[] getHandles() {
+    //        return handles;
+    //    }
+    //
+    //    public int getSize() {
+    //        return this.size;
+    //    }
+
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/ObjectPlaceholder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/ObjectPlaceholder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/ObjectPlaceholder.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,8 @@
+package org.drools.persister;
+
+public interface ObjectPlaceholder {
+    
+    public Object resolveObject();
+    
+    
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/OutputPersister.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/OutputPersister.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/OutputPersister.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,374 @@
+package org.drools.persister;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.base.ShadowProxy;
+import org.drools.common.AbstractFactHandleFactory;
+import org.drools.common.AgendaItem;
+import org.drools.common.BinaryHeapQueueAgendaGroup;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.common.PropagationContextImpl;
+import org.drools.persister.Placeholders.PlaceholderEntry;
+import org.drools.reteoo.BetaMemory;
+import org.drools.reteoo.BetaNode;
+import org.drools.reteoo.JoinNode;
+import org.drools.reteoo.LeftInputAdapterNode;
+import org.drools.reteoo.LeftTuple;
+import org.drools.reteoo.LeftTupleSink;
+import org.drools.reteoo.NotNode;
+import org.drools.reteoo.ReteooFactHandleFactory;
+import org.drools.reteoo.RightTuple;
+import org.drools.reteoo.RightTupleSink;
+import org.drools.reteoo.RuleTerminalNode;
+import org.drools.rule.Rule;
+import org.drools.spi.Activation;
+import org.drools.spi.FactHandleFactory;
+import org.drools.spi.PropagationContext;
+
+public class OutputPersister {
+    public WMSerialisationOutContext context;
+
+    public OutputPersister(InternalRuleBase ruleBase,
+                           InternalWorkingMemory wm,
+                           ObjectOutputStream stream,
+                           PlaceholderResolverStrategyFactory resolverStrategyFactory) {
+        context = new WMSerialisationOutContext( stream,
+                                                 ruleBase,
+                                                 wm,
+                                                 RuleBaseNodes.getNodeMap( ruleBase ),
+                                                 resolverStrategyFactory );
+    }
+
+    public void write() throws IOException {
+        writeFactHandles( context );
+    }
+
+    public static void writeFactHandles(WMSerialisationOutContext context) throws IOException {
+        ObjectOutputStream stream = context.stream;
+        InternalWorkingMemory wm = context.wm;
+        PlaceholderResolverStrategyFactory resolverStrategyFactory = context.resolverStrategyFactory;
+
+        ((AbstractFactHandleFactory) wm.getFactHandleFactory()).writeExternal( stream );
+
+        stream.writeInt( wm.getObjectStore().size() );
+
+        // Write out FactHandles
+        for ( Iterator it = wm.getObjectStore().iterateFactHandles(); it.hasNext(); ) {
+            //stream.writeInt( PersisterEnums.FACT_HANDLE );
+            InternalFactHandle handle = (InternalFactHandle) it.next();
+            stream.writeInt( handle.getId() );
+            stream.writeLong( handle.getRecency() );
+
+            PlaceholderResolverStrategy strategy = resolverStrategyFactory.get( handle.getObject() );
+            //stream.writeInt( strategy.getId() );
+
+            Object object = handle.getObject();
+            if ( object instanceof ShadowProxy ) {
+                object = ((ShadowProxy) object).getShadowedObject();
+            }
+            strategy.write( stream,
+                            object );
+
+            // Write out RightTuples for FactHandle
+            if ( handle.getRightTuple() != null ) {
+                stream.writeInt( PersisterEnums.RIGHT_TUPLE );
+                int i = 0;
+                for ( RightTuple rightTuple = handle.getRightTuple(); rightTuple != null; rightTuple = (RightTuple) rightTuple.getHandleNext() ) {
+                    if ( i != 0 ) {
+                        stream.writeInt( PersisterEnums.REPEAT );
+                    }
+                    writeRightTuple( rightTuple,
+                                     context );
+                    i++;
+                }
+            }
+            stream.writeInt( PersisterEnums.END );
+        }
+
+        // Write out LeftTuples
+        for ( Iterator it = wm.getObjectStore().iterateFactHandles(); it.hasNext(); ) {
+            InternalFactHandle handle = (InternalFactHandle) it.next();
+
+            if ( handle.getLeftTuple() != null ) {
+                stream.writeInt( PersisterEnums.LEFT_TUPLE );
+                int i = 0;
+                for ( LeftTuple leftTuple = handle.getLeftTuple(); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
+                    if ( i != 0 ) {
+                        stream.writeInt( PersisterEnums.REPEAT );
+                    }
+
+                    stream.writeInt( leftTuple.getLeftTupleSink().getId() );
+                    stream.writeInt( leftTuple.getLastHandle().getId() );
+
+                    writeLeftTuple( leftTuple,
+                                    context );
+                }
+                stream.writeInt( PersisterEnums.END );
+            }
+        }
+
+        writePropagationContexts( context );
+
+        writeActivations( context );
+
+        stream.writeInt( PersisterEnums.END );
+    }
+
+    public static void writeRightTuple(RightTuple rightTuple,
+                                       WMSerialisationOutContext context) throws IOException {
+        ObjectOutputStream stream = context.stream;
+        InternalWorkingMemory wm = context.wm;
+        stream.writeInt( rightTuple.getRightTupleSink().getId() );
+    }
+
+    public static void writeLeftTuple(LeftTuple leftTuple,
+                                      WMSerialisationOutContext context) throws IOException {
+        ObjectOutputStream stream = context.stream;
+        InternalRuleBase ruleBase = context.ruleBase;
+        InternalWorkingMemory wm = context.wm;
+
+        LeftTupleSink sink = leftTuple.getLeftTupleSink();
+        stream.writeInt( sink.getId() );
+
+        if ( sink instanceof JoinNode ) {
+            if ( leftTuple.getBetaChildren() != null ) {
+                stream.writeInt( PersisterEnums.RIGHT_TUPLE );
+            }
+            int i = 0;
+            for ( LeftTuple childLeftTuple = leftTuple.getBetaChildren(); leftTuple != null; childLeftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
+                if ( i != 0 ) {
+                    stream.writeInt( PersisterEnums.REPEAT );
+                }
+                stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
+                stream.writeInt( childLeftTuple.getRightParent().getFactHandle().getId() );
+                writeLeftTuple( childLeftTuple,
+                                context );
+            }
+            stream.writeInt( PersisterEnums.END );
+        } else if ( sink instanceof NotNode ) {
+            if ( leftTuple.getBlocker() == null ) {
+                // is blocked so has children
+                stream.writeInt( PersisterEnums.LEFT_TUPLE_NOT_BLOCKED );
+
+                stream.writeInt( PersisterEnums.LEFT_TUPLE );
+                int i = 0;
+                for ( LeftTuple childLeftTuple = leftTuple.getBetaChildren(); leftTuple != null; childLeftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
+                    if ( i != 0 ) {
+                        stream.writeInt( PersisterEnums.REPEAT );
+                    }
+                    stream.writeInt( childLeftTuple.getLeftTupleSink().getId() );
+                    writeLeftTuple( childLeftTuple,
+                                    context );
+                }
+                stream.writeInt( PersisterEnums.END );
+
+            } else {
+                stream.writeInt( PersisterEnums.LEFT_TUPLE_BLOCKED );
+                stream.writeInt( leftTuple.getBlocker().getFactHandle().getId() );
+            }
+        } else if ( sink instanceof RuleTerminalNode ) {
+            int pos = context.terminalTupleMap.size();
+            context.terminalTupleMap.put( leftTuple,
+                                          pos );
+        }
+
+    }
+
+    public static void writeActivations(WMSerialisationOutContext context) throws IOException {
+        ObjectOutputStream stream = context.stream;
+
+        Map<LeftTuple, Integer> tuples = context.terminalTupleMap;
+        if ( !tuples.isEmpty() ) {
+            stream.writeInt( PersisterEnums.ACTIVATION );
+        }
+
+        int i = 0;
+        for ( LeftTuple leftTuple : tuples.keySet() ) {
+            if ( i != 0 ) {
+                stream.writeInt( PersisterEnums.REPEAT );
+            }
+            writeActivation( context,
+                             leftTuple,
+                             (AgendaItem) leftTuple.getActivation(),
+                             (RuleTerminalNode) leftTuple.getLeftTupleSink() );
+            i++;
+        }
+    }
+
+    public static void writeActivation(WMSerialisationOutContext context,
+                                       LeftTuple leftTuple,
+                                       AgendaItem agendaItem,
+                                       RuleTerminalNode ruleTerminalNode) throws IOException {
+        ObjectOutputStream stream = context.stream;
+
+        stream.writeLong( agendaItem.getActivationNumber() );
+
+        stream.writeInt( context.terminalTupleMap.get( leftTuple ) );
+
+        stream.writeInt( agendaItem.getSalience() );
+
+        Rule rule = agendaItem.getRule();
+        stream.writeChars( rule.getPackage() );
+        stream.writeChars( rule.getName() );
+
+        stream.writeLong( agendaItem.getPropagationContext().getPropagationNumber() );
+
+        stream.writeInt( ruleTerminalNode.getId() );
+
+        stream.writeBoolean( agendaItem.isActivated() );
+    }
+
+    public static void writePropagationContexts(WMSerialisationOutContext context) throws IOException {
+        ObjectOutputStream stream = context.stream;
+
+        Map<LeftTuple, Integer> tuples = context.terminalTupleMap;
+        if ( !tuples.isEmpty() ) {
+            stream.writeInt( PersisterEnums.PROPAGATION_CONTEXT );
+        }
+
+        Map<Long, PropagationContext> pcMap = new HashMap<Long, PropagationContext>();
+
+        int i = 0;
+        for ( LeftTuple leftTuple : tuples.keySet() ) {
+            if ( i != 0 ) {
+                stream.writeInt( PersisterEnums.REPEAT );
+            }
+            PropagationContext pc = leftTuple.getActivation().getPropagationContext();
+            if ( !pcMap.containsKey( pc.getPropagationNumber() ) ) {
+                writePropagationContext( context,
+                                         pc );
+                pcMap.put( pc.getPropagationNumber(),
+                           pc );
+            }
+            i++;
+        }
+
+        stream.writeInt( PersisterEnums.END );
+    }
+
+    public static void writePropagationContext(WMSerialisationOutContext context,
+                                               PropagationContext pc) throws IOException {
+        ObjectOutputStream stream = context.stream;
+        Map<LeftTuple, Integer> tuples = context.terminalTupleMap;
+
+        stream.writeInt( pc.getType() );
+
+        Rule ruleOrigin = pc.getRuleOrigin();
+        if ( ruleOrigin != null ) {
+            stream.writeBoolean( true );
+            stream.writeUTF( ruleOrigin.getPackage() );
+            stream.writeUTF( ruleOrigin.getName() );
+        } else {
+            stream.writeBoolean( false );
+        }
+
+        LeftTuple tupleOrigin = pc.getLeftTupleOrigin();
+        if ( tupleOrigin != null ) {
+            stream.writeBoolean( true );
+            stream.writeInt( tuples.get( tupleOrigin ) );
+        } else {
+            stream.writeBoolean( false );
+        }
+
+        stream.writeInt( pc.getFactHandleOrigin().getId() );
+
+        stream.writeInt( pc.getActiveActivations() );
+        stream.writeInt( pc.getDormantActivations() );
+
+        stream.writeUTF( pc.getEntryPoint().getEntryPointId() );
+    }
+
+    //    public void writeParentActivations(Activation[] activations) throws IOException {
+    //        //        // we do these first as we know the parent Activation is null
+    //        //        // first create placeholders for rules
+    //        //        
+    //        //        for ( int i = 0, length = activations.length; i < length; i++ ){                
+    //        //            AgendaItem item = ( AgendaItem ) activations[i];
+    //        //            // this is a parent activation that has had it's resources released, so write first
+    //        //            if ( item.getPropagationContext().getActivationOrigin() == null ) {
+    //        //                writeActivation( item );
+    //        //            }
+    //        //            PlaceholderEntry placeHolder = this.placeholders.assignPlaceholder( item.getRule(), RulePersisterKey.getInstace() );               
+    //        //            RulePersisterKey.getInstace().writeExternal( item.getRule(), placeHolder, this.stream );
+    //        //            
+    //        //            // writeout Activation on PropagationContext
+    //        //            item = ( AgendaItem ) item.getPropagationContext().getActivationOrigin();
+    //        //            Rule rule = item.getPropagationContext().getRuleOrigin();
+    //        //        }           
+    //    }
+    //
+    ////    public void writeActivations(InternalWorkingMemory wm) throws IOException {
+    ////        //        BinaryHeapQueueAgendaGroup[] groups = ( BinaryHeapQueueAgendaGroup[] ) wm.getAgenda().getAgendaGroups();
+    ////        //        for ( int i = 0, iLength = groups.length; i < iLength; i++ ) {
+    ////        //            BinaryHeapQueueAgendaGroup group = groups[i];
+    ////        //            this.stream.writeInt( group.size() );
+    ////        //            this.stream.writeChars( group.getName() );      
+    ////        //            
+    ////        //            writeActivations( groups[i].getActivations() );
+    ////        //        }
+    ////    }
+    //
+    //    public void writeActivation(Activation[] activations) throws IOException {
+    //        //        // first create placeholders for rules, need to count rules first
+    //        //        int count =  0;
+    //        //        RulePersisterKey ruleKey = RulePersisterKey.getInstace() ;
+    //        //        for ( int i = 0, length = activations.length; i < length; i++ ){                
+    //        //            AgendaItem item = ( AgendaItem ) activations[i];    
+    //        //            
+    //        //            Rule rule = item.getRule();
+    //        //            if ( this.placeholders.lookupPlaceholder(  rule, ruleKey) == null ) {
+    //        //                this.placeholders.assignPlaceholder( rule, ruleKey );
+    //        //                count++;
+    //        //            }
+    //        //            
+    //        //            Rule rule = item.getPropagationContext().getRuleOrigin()
+    //        //            
+    //        //            // writeout Activation on PropagationContext
+    //        //            item = ( AgendaItem ) item.getPropagationContext().getActivationOrigin();
+    //        //            Rule rule = item.getPropagationContext().getRuleOrigin();
+    //        //        }   
+    //        //        
+    //        //        // write our activations
+    //        //        for ( int j = 0, jLength = group.size(); j < jLength; j++ ){                
+    //        //            AgendaItem item = ( AgendaItem ) activations[i];                
+    //        //            writeTuple( ( ReteTuple ) item.getTuple() );
+    //        //            this.stream.writeInt( this.placeholders.assignPlaceholder( item.getRule(), RulePersisterKey.getInstace() ).id );
+    //        //            this.stream.write(  item.getSalience()  );
+    //        //        }          
+    //    }
+    //
+    //    public void writeTuple(LeftTuple tuple) throws IOException {
+    //        //        tuple.writeExternal( this.stream );
+    //        //        LeftTuple leftParent = tuple;
+    //        //        LeftTuple child = tuple.getBetaChildren();
+    //        //        RightTuple rightParent = child.getRightParent();
+    //
+    //        //        int size = 0;        
+    //        //        LeftTuple entry = tuple;
+    //        //        while ( entry != null ) {
+    //        //            size++;
+    //        //            entry = entry.getParent();
+    //        //        }
+    //        //        
+    //        //        this.stream.writeInt( size );
+    //        //        while ( entry != null ) {
+    //        //            this.stream.writeLong( entry.getLastHandle().getId() );
+    //        //            entry = entry.getParent();
+    //        //        }        
+    //    }
+
+    //    public OutputPersister(WorkingMemory workingMemory) {
+    //        BinaryHeapQueueAgendaGroup[] groups = ( BinaryHeapQueueAgendaGroup[] ) workingMemory.getAgenda().getAgendaGroups();
+    //        
+    //    }
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PersisterEnums.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PersisterEnums.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PersisterEnums.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,15 @@
+package org.drools.persister;
+
+public class PersisterEnums {
+    public static final int REPEAT                 = 0;
+    public static final int END                    = 1;
+    public static final int FACT_HANDLE            = 2;
+    public static final int LEFT_TUPLE             = 3;
+    public static final int RIGHT_TUPLE            = 4;
+
+    public static final int LEFT_TUPLE_BLOCKED     = 5;
+    public static final int LEFT_TUPLE_NOT_BLOCKED = 6;
+
+    public static final int ACTIVATION             = 7;
+    public static final int PROPAGATION_CONTEXT    = 8;
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PersisterKey.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PersisterKey.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PersisterKey.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,7 @@
+package org.drools.persister;
+
+public interface PersisterKey {
+   public boolean equal(Object object1, Object object2);
+   
+   public int hashCode(Object object);
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PlaceholderResolverStrategy.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PlaceholderResolverStrategy.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PlaceholderResolverStrategy.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,19 @@
+package org.drools.persister;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+
+public interface PlaceholderResolverStrategy {
+
+    public void setId(int id);
+    
+    public int getId();
+
+    public void write(ObjectOutputStream os,
+                      Object object) throws IOException;
+
+    public ObjectPlaceholder read(ObjectInputStream os) throws IOException, ClassNotFoundException;
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PlaceholderResolverStrategyFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PlaceholderResolverStrategyFactory.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/PlaceholderResolverStrategyFactory.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,28 @@
+package org.drools.persister;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class PlaceholderResolverStrategyFactory {
+    List<PlaceholderResolverStrategy> strategiesList;
+    Map<Object, PlaceholderResolverStrategy> strategiesMap = new HashMap<Object, PlaceholderResolverStrategy>();
+    
+    public PlaceholderResolverStrategyFactory() {
+        this.strategiesList = new ArrayList<PlaceholderResolverStrategy>();
+    }
+    
+    public void addPlaceholderResolverStrategy(PlaceholderResolverStrategy strategy) {
+        this.strategiesList.add( strategy );
+    }
+    
+    public PlaceholderResolverStrategy get(int i) {
+        return this.strategiesList.get( i );
+    }
+    
+    public PlaceholderResolverStrategy get(Object object) {
+        return this.strategiesList.get( 0 );
+        //return this.strategiesMap.get( object );
+    }
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/Placeholders.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/Placeholders.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/Placeholders.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,143 @@
+package org.drools.persister;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.util.AbstractHashTable;
+import org.drools.util.Entry;
+
+public class Placeholders extends AbstractHashTable {
+    private List<Object> ids;
+
+    public Placeholders() {
+        super();
+        this.ids = new ArrayList<Object>();
+    }
+    
+    public PlaceholderEntry lookupPlaceholder(Object object, PersisterKey key) {
+        final int hashCode = key.hashCode( object );
+        final int index = indexOf( hashCode,
+                                   this.table.length );
+        
+        PlaceholderEntry current = (PlaceholderEntry) this.table[index];
+        while ( current != null ) {
+            if ( hashCode == current.hashCode && current.key == key && key.equal( object,
+                                                                                  current.object ) ) {
+                return current;
+            }
+            current = (PlaceholderEntry) current.getNext();
+        }
+        return null;
+    }
+
+    public PlaceholderEntry assignPlaceholder(Object object,
+                                              PersisterKey key) {
+        final int hashCode = key.hashCode( object );
+        final int index = indexOf( hashCode,
+                                   this.table.length );
+
+        int id = ids.size();
+        this.ids.add( object );
+        PlaceholderEntry entry = new PlaceholderEntry( object,
+                                                       id,
+                                                       key );
+
+        entry.next = this.table[index];
+        this.table[index] = entry;
+
+        if ( this.size++ >= this.threshold ) {
+            resize( 2 * this.table.length );
+        }
+
+        return entry;
+    }
+
+    public Object lookupObject(int id) {
+        return this.ids.get( id );
+    }
+
+    public static class PlaceholderEntry
+        implements
+        Entry {
+
+        private static final long serialVersionUID = 400L;
+
+        public Object             object;
+
+        public int                id;
+
+        public PersisterKey       key;
+
+        public int                hashCode;
+
+        public Entry              next;
+
+        //        private LinkedList              list;
+
+        public PlaceholderEntry(final Object object,
+                                final int id,
+                                final PersisterKey key) {
+            this.object = object;
+            this.id = id;
+            this.key = key;
+            this.hashCode = key.hashCode( object );
+        }
+
+        //    public PlaceholderEntry(final InternalFactHandle handle,
+        //                            final int hashCode) {
+        //        this.handle = handle;
+        //        this.hashCode = hashCode;
+        //        //            this.list = new LinkedList();
+        //    }
+
+        public Entry getNext() {
+            return this.next;
+        }
+
+        public void setNext(final Entry next) {
+            this.next = next;
+        }
+
+        public int hashCode() {
+            return this.hashCode;
+        }
+
+        public String toString() {
+            return "Placeholder( object=" + this.object + " id = " + this.id + " hashcode=" + this.hashCode + " next=" + this.next + " )";
+        }
+
+        public Object getObject() {
+            return object;
+        }
+
+        public int getId() {
+            return id;
+        }
+
+        public PersisterKey getKey() {
+            return key;
+        }
+
+        public void readExternal(ObjectInput in) throws IOException,
+                                                ClassNotFoundException {
+            // TODO Auto-generated method stub
+            
+        }
+
+        public void writeExternal(ObjectOutput out) throws IOException {
+            // TODO Auto-generated method stub
+            
+        }
+
+    }
+
+    @Override
+    public Entry getBucket(Object object) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/RightTupleKey.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/RightTupleKey.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/RightTupleKey.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,48 @@
+/**
+ * 
+ */
+package org.drools.persister;
+
+import org.drools.reteoo.Sink;
+
+public class RightTupleKey {
+    private final int  id;
+    private final Sink sink;
+
+    public RightTupleKey(int id,
+                         Sink sink) {
+        super();
+        this.id = id;
+        this.sink = sink;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public Sink getSink() {
+        return sink;
+    }
+
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + id;
+        result = prime * result + sink.getId();
+        return result;
+    }
+
+    public boolean equals(Object obj) {
+        if ( this == obj ) return true;
+        if ( obj == null ) return false;
+        if ( getClass() != obj.getClass() ) return false;
+        
+        final RightTupleKey other = (RightTupleKey) obj;
+        if ( id != other.id ) return false;
+        if ( sink == null ) {
+            if ( other.sink != null ) return false;
+        } else if ( sink.getId() != other.sink.getId() ) return false;
+        return true;
+    }
+
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/RuleBaseNodes.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/RuleBaseNodes.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/RuleBaseNodes.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,69 @@
+package org.drools.persister;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.common.BaseNode;
+import org.drools.common.InternalRuleBase;
+import org.drools.reteoo.BetaNode;
+import org.drools.reteoo.LeftTupleSink;
+import org.drools.reteoo.LeftTupleSource;
+import org.drools.reteoo.ObjectSink;
+import org.drools.reteoo.ObjectSource;
+import org.drools.reteoo.ObjectTypeNode;
+import org.drools.reteoo.RuleTerminalNode;
+
+public class RuleBaseNodes {
+    public static Map<Integer, BaseNode> getNodeMap(InternalRuleBase ruleBase) {        
+        Map<Integer, BaseNode> nodes = new HashMap<Integer, BaseNode>();
+        buildNodeMap( ruleBase, nodes );
+        return nodes;
+    }
+    
+    private static void buildNodeMap(InternalRuleBase ruleBase,
+                                     Map<Integer, BaseNode> nodes) {
+        for ( ObjectTypeNode sink : ruleBase.getRete().getObjectTypeNodes() ) {
+            nodes.put( sink.getId(),
+                       sink );
+            addObjectSink( ruleBase,
+                           sink,
+                           nodes );
+        }
+    }
+
+    private static void addObjectSink(InternalRuleBase ruleBase,
+                                     ObjectSink sink,
+                                     Map<Integer, BaseNode> nodes) {
+        // we don't need to store alpha nodes, as they have no state to serialise
+        if ( sink instanceof LeftTupleSource ) {
+            LeftTupleSource node = (LeftTupleSource) sink;
+            for ( LeftTupleSink leftTupleSink : node.getSinkPropagator().getSinks() ) {
+                addLeftTupleSink( ruleBase,
+                                  leftTupleSink,
+                                  nodes );
+            }
+        } else {
+            ObjectSource node = ( ObjectSource ) sink;
+            for ( ObjectSink objectSink : node.getSinkPropagator().getSinks() ) {
+                addObjectSink( ruleBase,
+                               objectSink,
+                               nodes );
+            }
+        }
+    }
+
+    private static void addLeftTupleSink(InternalRuleBase ruleBase,
+                                        LeftTupleSink sink,
+                                        Map<Integer, BaseNode> nodes) {
+        if ( sink instanceof LeftTupleSource ) {
+            for ( LeftTupleSink leftTupleSink : ((LeftTupleSource) sink).getSinkPropagator().getSinks() ) {
+                addLeftTupleSink( ruleBase,
+                                  leftTupleSink,
+                                  nodes );
+            }
+        } else if ( sink instanceof RuleTerminalNode ) {
+            nodes.put( sink.getId(),
+                       (RuleTerminalNode) sink );
+        }
+    }
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/SerializablePlaceholder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/SerializablePlaceholder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/SerializablePlaceholder.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,14 @@
+package org.drools.persister;
+
+public class SerializablePlaceholder implements ObjectPlaceholder {
+    private final Object object;
+    
+    public SerializablePlaceholder(Object object) {
+        this.object = object;
+    }
+    
+    public Object resolveObject() {
+        return object;
+    }
+
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/SerializablePlaceholderResolverStrategy.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/SerializablePlaceholderResolverStrategy.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/SerializablePlaceholderResolverStrategy.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,34 @@
+package org.drools.persister;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+public class SerializablePlaceholderResolverStrategy
+    implements
+    PlaceholderResolverStrategy {
+    private int id;
+
+//    public SerializablePlaceholderResolverStrategy(int id) {
+//        this.id = id;
+//    }
+
+    public void setId(int id) {
+        this.id = id;       
+    }
+    
+    public int getId() {
+        return id;
+    }
+
+    public ObjectPlaceholder read(ObjectInputStream os) throws IOException,
+                                                       ClassNotFoundException {
+        return new SerializablePlaceholder( os.readObject() );
+    }
+
+    public void write(ObjectOutputStream os,
+                      Object object) throws IOException {
+        os.writeObject( object );
+    }
+
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/WMSerialisationInContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/WMSerialisationInContext.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/WMSerialisationInContext.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,50 @@
+/**
+ * 
+ */
+package org.drools.persister;
+
+import java.io.ObjectInputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.common.BaseNode;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.LeftTuple;
+import org.drools.reteoo.RightTuple;
+import org.drools.rule.EntryPoint;
+import org.drools.spi.PropagationContext;
+
+public class WMSerialisationInContext {
+    public final ObjectInputStream                  stream;
+    public final InternalRuleBase                   ruleBase;
+    public InternalWorkingMemory              wm;
+    public final Map<Integer, BaseNode>             sinks;
+
+    public  Map<Integer, InternalFactHandle>        handles;
+    
+    public final Map<RightTupleKey, RightTuple>     rightTuples;
+    public final Map<Integer, LeftTuple>            terminalTupleMap;
+
+    public final PlaceholderResolverStrategyFactory resolverStrategyFactory;
+    public final Map<String, EntryPoint>            entryPoints;
+
+    public final Map<Long, PropagationContext>      propagationContexts;
+
+    public WMSerialisationInContext(ObjectInputStream stream,
+                                    InternalRuleBase ruleBase,
+                                    Map<Integer, BaseNode> sinks,
+                                    PlaceholderResolverStrategyFactory resolverStrategyFactory) {
+        super();
+        this.stream = stream;
+        this.ruleBase = ruleBase;
+        this.sinks = sinks;
+        handles = new HashMap<Integer, InternalFactHandle>();
+        this.rightTuples = new HashMap<RightTupleKey, RightTuple>();
+        this.terminalTupleMap = new HashMap<Integer, LeftTuple>();
+        this.entryPoints = new HashMap<String, EntryPoint>();
+        this.propagationContexts = new HashMap<Long, PropagationContext>();
+        this.resolverStrategyFactory = resolverStrategyFactory;
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/WMSerialisationOutContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/WMSerialisationOutContext.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/persister/WMSerialisationOutContext.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -0,0 +1,43 @@
+/**
+ * 
+ */
+package org.drools.persister;
+
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.common.BaseNode;
+import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.LeftTuple;
+
+public class WMSerialisationOutContext {
+    public final ObjectOutputStream                 stream;
+    public final InternalRuleBase                   ruleBase;
+    public final InternalWorkingMemory              wm;
+    public final Map<Integer, BaseNode>             sinks;
+
+    public final PlaceholderResolverStrategyFactory resolverStrategyFactory;
+//    public final Placeholders                       placeholders;
+
+    public final Map<LeftTuple, Integer>                  terminalTupleMap;
+
+    public WMSerialisationOutContext(ObjectOutputStream stream,
+                                     InternalRuleBase ruleBase,
+                                     InternalWorkingMemory wm,
+                                     Map<Integer, BaseNode> sinks,
+                                     PlaceholderResolverStrategyFactory resolverStrategyFactory) {
+                                     //Placeholders placeholders) {
+        super();
+        this.stream = stream;
+        this.ruleBase = ruleBase;
+        this.wm = wm;
+        this.sinks = sinks;
+
+        this.resolverStrategyFactory = resolverStrategyFactory;
+//        this.placeholders = placeholders;
+        
+        this.terminalTupleMap = new HashMap<LeftTuple, Integer>();
+    }
+}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -129,6 +129,7 @@
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                       PropagationContext.RULE_ADDITION,
                                                                                       null,
+                                                                                      null,
                                                                                       null );
             this.source.updateSink( this,
                                     propagationContext,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -45,7 +45,7 @@
  * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
  * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
  */
-abstract class BetaNode extends LeftTupleSource
+public abstract class BetaNode extends LeftTupleSource
     implements
     LeftTupleSinkNode,
     ObjectSinkNode,
@@ -183,6 +183,7 @@
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                       PropagationContext.RULE_ADDITION,
                                                                                       null,
+                                                                                      null,
                                                                                       null );
             this.rightInput.updateSink( this,
                                         propagationContext,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -75,7 +75,7 @@
         LeftTuple child = leftTuple.getBetaChildren();
         while ( child != null ) {
             LeftTuple temp = child.getLeftParentNext();
-            child.getSink().retractLeftTuple( child,
+            child.getLeftTupleSink().retractLeftTuple( child,
                                               context,
                                               workingMemory );
             child.unlinkFromRightParent();
@@ -90,7 +90,7 @@
         LeftTuple child = leftTuple.getBetaChildren();
         while ( child != null ) {
             LeftTuple temp = child.getLeftParentNext();
-            child.getSink().retractLeftTuple( child,
+            child.getLeftTupleSink().retractLeftTuple( child,
                                               context,
                                               workingMemory );
             workingMemory.getFactHandleFactory().destroyFactHandle( child.getRightParent().getFactHandle() );
@@ -106,7 +106,7 @@
         LeftTuple child = rightTuple.getBetaChildren();
         while ( child != null ) {
             LeftTuple temp = child.getRightParentNext();
-            child.getSink().retractLeftTuple( child,
+            child.getLeftTupleSink().retractLeftTuple( child,
                                               context,
                                               workingMemory );
             child.unlinkFromLeftParent();

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -229,6 +229,7 @@
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                       PropagationContext.RULE_ADDITION,
                                                                                       null,
+                                                                                      null,
                                                                                       null );
             this.source.updateSink( this,
                                     propagationContext,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -131,6 +131,7 @@
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                       PropagationContext.RULE_ADDITION,
                                                                                       null,
+                                                                                      null,
                                                                                       null );
             this.tupleSource.updateSink( this,
                                          propagationContext,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -185,6 +185,7 @@
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                       PropagationContext.RULE_ADDITION,
                                                                                       null,
+                                                                                      null,
                                                                                       null );
             this.tupleSource.updateSink( this,
                                          propagationContext,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactHandle.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/InitialFactHandle.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -88,7 +88,7 @@
         this.delegate.setRecency( recency );
     }
 
-    public long getId() {
+    public int getId() {
         return this.delegate.getId();
     }
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -114,6 +114,7 @@
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                       PropagationContext.RULE_ADDITION,
                                                                                       null,
+                                                                                      null,
                                                                                       null );
             this.objectSource.updateSink( this,
                                           propagationContext,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -70,23 +70,18 @@
         this.handle = factHandle;
         this.recency = factHandle.getRecency();
 
-        int h = handle.hashCode();
-        h += ~(h << 9);
-        h ^= (h >>> 14);
-        h += (h << 4);
-        h ^= (h >>> 10);
-        this.hashCode = h;
+        this.hashCode = handle.hashCode();
 
         if ( leftTupleMemoryEnabled ) {
-            this.sink = sink;
             LeftTuple currentFirst = handle.getLeftTuple();
             if ( currentFirst != null ) {
                 currentFirst.leftParentPrevious = this;
                 this.leftParentNext = currentFirst;
             }
-    
+
             handle.setLeftTuple( this );
         }
+        this.sink = sink;
     }
 
     public LeftTuple(final LeftTuple leftTuple,
@@ -105,8 +100,9 @@
                 this.leftParentNext.leftParentPrevious = this;
             }
             this.leftParent.children = this;
-            this.sink = sink;
         }
+        
+        this.sink = sink;
     }
 
     public LeftTuple(final LeftTuple leftTuple,
@@ -126,15 +122,16 @@
                 this.rightParentNext.rightParentPrevious = this;
             }
             this.rightParent.setBetaChildren( this );
-    
+
             this.leftParent = leftTuple;
             this.leftParentNext = leftTuple.children;
             if ( this.leftParentNext != null ) {
                 this.leftParentNext.leftParentPrevious = this;
             }
             this.leftParent.children = this;
-            this.sink = sink;
         }
+        
+        this.sink = sink;
     }
 
     public void unlinkFromLeftParent() {
@@ -192,8 +189,12 @@
         this.rightParentPrevious = null;
         this.rightParentNext = null;
     }
+    
+    public int getIndex() {
+        return this.index;
+    }
 
-    public LeftTupleSink getSink() {
+    public LeftTupleSink getLeftTupleSink() {
         return sink;
     }
 
@@ -365,19 +366,27 @@
      * @return
      */
     public boolean equals(final LeftTuple other) {
-        // we know the object is never null and always of the  type ReteTuple
+        // we know the object is never null and always of the  type LeftTuple
         if ( other == this ) {
             return true;
         }
 
-        // A ReteTuple is  only the same if it has the same hashCode, factId and parent
-        if ( (other == null) || (this.hashCode != other.hashCode) ) {
+        // A LeftTuple is  only the same if it has the same hashCode, factId and parent
+        if ( this.hashCode != other.hashCode ) {
             return false;
         }
 
         if ( this.handle != other.handle ) {
             return false;
         }
+        
+//        if ( this.sink.getId() != other.sink.getId() ) {
+//            return false;
+//        }
+//        
+//        if ( this.index != other.index ) {
+//            return false;
+//        }
 
         if ( this.parent == null ) {
             return (other.parent == null);

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -211,7 +211,7 @@
         factHandle.setRightTuple( null );
 
         for ( LeftTuple leftTuple = factHandle.getLeftTuple(); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
-            leftTuple.getSink().retractLeftTuple( leftTuple,
+            leftTuple.getLeftTupleSink().retractLeftTuple( leftTuple,
                                                   context,
                                                   workingMemory );
         }
@@ -246,6 +246,7 @@
             final PropagationContextImpl propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                           PropagationContext.RULE_ADDITION,
                                                                                           null,
+                                                                                          null,
                                                                                           null );
             propagationContext.setEntryPoint( ((EntryPointNode) this.source).getEntryPoint() );
             this.source.updateSink( this,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/PropagationQueuingNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -388,7 +388,7 @@
             this.handle.setRightTuple( null );
 
             for ( LeftTuple leftTuple = this.handle.getLeftTuple(); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
-                leftTuple.getSink().retractLeftTuple( leftTuple,
+                leftTuple.getLeftTupleSink().retractLeftTuple( leftTuple,
                                                       context,
                                                       workingMemory );
             }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/QueryTerminalNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -168,6 +168,7 @@
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                       PropagationContext.RULE_ADDITION,
                                                                                       null,
+                                                                                      null,
                                                                                       null );
             this.tupleSource.updateSink( this,
                                          propagationContext,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -41,6 +41,7 @@
 import org.drools.rule.Query;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
+import org.drools.spi.FactHandleFactory;
 import org.drools.spi.PropagationContext;
 
 /**
@@ -77,6 +78,15 @@
         this.agenda = new DefaultAgenda( this );
     }
 
+    public ReteooWorkingMemory(final int id,
+                               final InternalRuleBase ruleBase,
+                               final FactHandleFactory factory) {
+        super( id,
+               ruleBase,
+               factory );
+        this.agenda = new DefaultAgenda( this );
+    }
+
     public QueryResults getQueryResults(final String query) {
         return getQueryResults( query,
                                 null );
@@ -158,7 +168,7 @@
 
         private Rule               ruleOrigin;
 
-        private Activation         activationOrigin;
+        private LeftTuple          leftTuple;
 
         public WorkingMemoryReteAssertAction() {
 
@@ -168,13 +178,12 @@
                                              final boolean removeLogical,
                                              final boolean updateEqualsMap,
                                              final Rule ruleOrigin,
-                                             final Activation activationOrigin) {
-            super();
+                                             final LeftTuple leftTuple) {
             this.factHandle = factHandle;
             this.removeLogical = removeLogical;
             this.updateEqualsMap = updateEqualsMap;
             this.ruleOrigin = ruleOrigin;
-            this.activationOrigin = activationOrigin;
+            this.leftTuple = leftTuple;
         }
 
         public void readExternal(ObjectInput in) throws IOException,
@@ -183,7 +192,7 @@
             removeLogical = in.readBoolean();
             updateEqualsMap = in.readBoolean();
             ruleOrigin = (Rule) in.readObject();
-            activationOrigin = (Activation) in.readObject();
+            leftTuple = (LeftTuple) in.readObject();
         }
 
         public void writeExternal(ObjectOutput out) throws IOException {
@@ -191,7 +200,7 @@
             out.writeBoolean( removeLogical );
             out.writeBoolean( updateEqualsMap );
             out.writeObject( ruleOrigin );
-            out.writeObject( activationOrigin );
+            out.writeObject( leftTuple );
         }
 
         public void execute(InternalWorkingMemory workingMemory) {
@@ -199,7 +208,8 @@
             final PropagationContext context = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                            PropagationContext.ASSERTION,
                                                                            this.ruleOrigin,
-                                                                           this.activationOrigin );
+                                                                           this.leftTuple,
+                                                                           this.factHandle );
             ReteooRuleBase ruleBase = (ReteooRuleBase) workingMemory.getRuleBase();
             ruleBase.assertObject( this.factHandle,
                                    this.factHandle.getObject(),

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -157,7 +157,7 @@
         factHandle.setRightTuple( null );
 
         for ( LeftTuple leftTuple = factHandle.getLeftTuple(); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getLeftParentNext() ) {
-            leftTuple.getSink().retractLeftTuple( leftTuple,
+            leftTuple.getLeftTupleSink().retractLeftTuple( leftTuple,
                                                   context,
                                                   workingMemory );
         }
@@ -179,6 +179,7 @@
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                       PropagationContext.RULE_ADDITION,
                                                                                       null,
+                                                                                      null,
                                                                                       null );
             this.tupleSource.updateSink( this,
                                          propagationContext,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -48,20 +48,6 @@
         handle.setRightTuple( this );
     }
 
-    public RightTuple(RightTuple parent) {
-        this.handle = parent.getFactHandle();
-        this.hashCode = this.handle.hashCode();
-    }
-
-    public RightTuple(RightTuple parent,
-                      RightTupleSink sink) {
-        this.handle = parent.getFactHandle();
-        this.hashCode = this.handle.hashCode();
-
-        this.sink = sink;
-
-    }
-
     public RightTupleSink getRightTupleSink() {
         return this.sink;
     }
@@ -101,7 +87,7 @@
     public RightTupleList getMemory() {
         return memory;
     }
-
+    
     public void setMemory(RightTupleList memory) {
         this.memory = memory;
     }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTupleSink.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -3,7 +3,7 @@
 import org.drools.common.InternalWorkingMemory;
 import org.drools.spi.PropagationContext;
 
-public interface RightTupleSink {
+public interface RightTupleSink extends Sink {
     public void retractRightTuple(final RightTuple rightTuple,
                                   final PropagationContext context,
                                   final InternalWorkingMemory workingMemory);

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -145,6 +145,10 @@
     public Rule getRule() {
         return this.rule;
     }
+    
+    public GroupElement getSubRule() {
+        return this.subrule;
+    }
 
     public void setSequence(int seq) {
         this.sequence = seq;
@@ -189,7 +193,7 @@
 
         // if the current Rule is no-loop and the origin rule is the same and its the same set of facts (tuple) then return
         if ( context.getType() == PropagationContext.MODIFICATION ) {
-            if ( this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() ) && context.getActivationOrigin().getTuple().equals( tuple ) ) {
+            if ( this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() ) && context.getLeftTupleOrigin().equals( tuple ) ) {
                 return;
             }
         } else if ( this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() ) ) {
@@ -450,6 +454,7 @@
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                       PropagationContext.RULE_ADDITION,
                                                                                       null,
+                                                                                      null,
                                                                                       null );
             this.tupleSource.updateSink( this,
                                          propagationContext,
@@ -482,6 +487,7 @@
                 final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
                                                                                           PropagationContext.RULE_REMOVAL,
                                                                                           null,
+                                                                                          null,
                                                                                           null );
                 workingMemory.getTruthMaintenanceSystem().removeLogicalDependencies( activation,
                                                                                      propagationContext,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -52,7 +52,7 @@
         LeftTuple child = leftTuple.getBetaChildren();
         while ( child != null ) {
             LeftTuple temp = child.getLeftParentNext();
-            child.getSink().retractLeftTuple( child,
+            child.getLeftTupleSink().retractLeftTuple( child,
                                               context,
                                               workingMemory );
             child.unlinkFromRightParent();
@@ -67,7 +67,7 @@
         LeftTuple child = leftTuple.getBetaChildren();
         while ( child != null ) {
             LeftTuple temp = child.getLeftParentNext();
-            child.getSink().retractLeftTuple( child,
+            child.getLeftTupleSink().retractLeftTuple( child,
                                               context,
                                               workingMemory );
             workingMemory.getFactHandleFactory().destroyFactHandle( child.getRightParent().getFactHandle() );
@@ -83,7 +83,7 @@
         LeftTuple child = rightTuple.getBetaChildren();
         while ( child != null ) {
             LeftTuple temp = child.getRightParentNext();
-            child.getSink().retractLeftTuple( child,
+            child.getLeftTupleSink().retractLeftTuple( child,
                                               context,
                                               workingMemory );
             child.unlinkFromLeftParent();

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Sink.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Sink.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Sink.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -5,6 +5,6 @@
  * 
  * @author etirelli
  */
-interface Sink {
+public interface Sink {
     public int getId();
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -57,4 +57,8 @@
     public FactHandleFactory newInstance();
 
     public Class getFactHandleType();
+
+    public int getId();
+
+    public long getRecency();
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PropagationContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PropagationContext.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PropagationContext.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -18,6 +18,7 @@
 
 import java.io.Externalizable;
 
+import org.drools.common.InternalFactHandle;
 import org.drools.reteoo.LeftTuple;
 import org.drools.rule.EntryPoint;
 import org.drools.rule.Rule;
@@ -36,7 +37,9 @@
 
     public Rule getRuleOrigin();
 
-    public Activation getActivationOrigin();
+    public LeftTuple getLeftTupleOrigin();
+    
+    public InternalFactHandle getFactHandleOrigin();
 
     public int getType();
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -65,7 +65,8 @@
         this.context = new PropagationContextImpl( 0,
                                                    PropagationContext.ASSERTION,
                                                    null,
-                                                   null );
+                                                   null,
+                                                   null);
 
         ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         BuildContext buildContext = new BuildContext( ruleBase,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -96,6 +96,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule1,
+                                                                        null,
                                                                         null );
 
         // Add consequence. Notice here the context here for the add to ageyunda
@@ -217,6 +218,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        rule,
+                                                                       null,
                                                                        null );
 
         // test agenda is empty
@@ -315,6 +317,7 @@
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule0,
+                                                                        null,
                                                                         null );
 
         final Rule rule1 = new Rule( "test-rule1",
@@ -328,6 +331,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule1,
+                                                                        null,
                                                                         null );
 
         final Rule rule2 = new Rule( "test-rule2",
@@ -341,6 +345,7 @@
         final PropagationContext context2 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule2,
+                                                                        null,
                                                                         null );
 
         final Rule rule3 = new Rule( "test-rule3",
@@ -354,6 +359,7 @@
         final PropagationContext context3 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule3,
+                                                                        null,
                                                                         null );
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
@@ -560,6 +566,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        rule,
+                                                                       null,
                                                                        null );
 
         // first test that autoFocus=false works. Here the rule should not fire
@@ -628,6 +635,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        rule,
+                                                                       null,
                                                                        null );
 
         // When both the rule is lock-on-active and the agenda group is active, activations should be ignored
@@ -706,6 +714,7 @@
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule0,
+                                                                        null,
                                                                         null );
 
         final Rule rule1 = new Rule( "test-rule1" );
@@ -719,6 +728,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule1,
+                                                                        null,
                                                                         null );
 
         final Rule rule2 = new Rule( "test-rule2" );
@@ -731,6 +741,7 @@
         final PropagationContext context2 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule2,
+                                                                        null,
                                                                         null );
 
         final Rule rule3 = new Rule( "test-rule3",
@@ -745,6 +756,7 @@
         final PropagationContext context3 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule3,
+                                                                        null,
                                                                         null );
 
         // Assert the tuple and check it was added to activation-group-0
@@ -925,6 +937,7 @@
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule0,
+                                                                        null,
                                                                         null );
 
         final RuleFlowGroup ruleFlowGroup0 = agenda.getRuleFlowGroup( "rule-flow-group-0" );
@@ -1071,6 +1084,7 @@
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule1,
+                                                                        null,
                                                                         null );
 
         // create rule0
@@ -1192,6 +1206,7 @@
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule1,
+                                                                        null,
                                                                         null );
 
         final LeftTuple tuple1 = new LeftTuple( new DefaultFactHandle( 1,
@@ -1317,6 +1332,7 @@
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule0,
+                                                                        null,
                                                                         null );
 
         // Create two activation for this rule
@@ -1422,6 +1438,7 @@
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule0,
+                                                                        null,
                                                                         null );
 
         // Create an activation for this rule
@@ -1581,6 +1598,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        rule,
+                                                                       null,
                                                                        null );
 
         // When both the rule is lock-on-active and the agenda group is active, activations should be ignored
@@ -1656,6 +1674,7 @@
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule0,
+                                                                        null,
                                                                         null );
 
         final Rule rule1 = new Rule( "test-rule1",
@@ -1670,6 +1689,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule1,
+                                                                        null,
                                                                         null );
 
         final Rule rule2 = new Rule( "test-rule2",
@@ -1684,6 +1704,7 @@
         final PropagationContext context2 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule2,
+                                                                        null,
                                                                         null );
 
         final Rule rule3 = new Rule( "test-rule3",
@@ -1698,6 +1719,7 @@
         final PropagationContext context3 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule3,
+                                                                        null,
                                                                         null );
 
         ruleBase.getAgendaGroupRuleTotals().put( "MAIN",

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -56,6 +56,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
@@ -136,6 +137,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
@@ -205,6 +207,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -65,10 +65,12 @@
         this.contextAssert = new PropagationContextImpl( 0,
                                                          PropagationContext.ASSERTION,
                                                          null,
+                                                         null,
                                                          null );
         this.contextRetract = new PropagationContextImpl( 0,
                                                           PropagationContext.RETRACTION,
                                                           null,
+                                                          null,
                                                           null );
 
         ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/EvalConditionNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/EvalConditionNodeTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/EvalConditionNodeTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -43,6 +43,7 @@
         this.context = new PropagationContextImpl( 0,
                                                    PropagationContext.ASSERTION,
                                                    null,
+                                                   null,
                                                    null );
 
         this.workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ExistsNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ExistsNodeTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ExistsNodeTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -59,6 +59,7 @@
         this.context = new PropagationContextImpl( 0,
                                                    PropagationContext.ASSERTION,
                                                    null,
+                                                   null,
                                                    null );
 
         ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
@@ -134,7 +135,7 @@
                       this.sink.getRetracted() );
 
         assertEquals( new LeftTuple( f0,
-                                     this.node,
+                                     this.sink,
                                      true ),
                       ((Object[]) this.sink.getAsserted().get( 0 ))[0] );
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -45,6 +45,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
         final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
                                                                            (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
@@ -139,6 +140,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
@@ -250,6 +252,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
         final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
                                                                            (ReteooRuleBase) RuleBaseFactory.newRuleBase() );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -56,6 +56,7 @@
         this.context = new PropagationContextImpl( 0,
                                                    PropagationContext.ASSERTION,
                                                    null,
+                                                   null,
                                                    null );
         this.workingMemory = new ReteooWorkingMemory( 1,
                                                       (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
@@ -239,7 +240,7 @@
 
         assertEquals( new LeftTuple( tuple0,
                                      f0.getRightTuple(),
-                                     this.node,
+                                     this.sink,
                                      true ),
                       ((Object[]) this.sink.getAsserted().get( 0 ))[0] );
     }
@@ -309,7 +310,7 @@
 
         assertEquals( new LeftTuple( tuple1,
                                      f0.getRightTuple(),
-                                     this.node,
+                                     this.sink,
                                      true ),
                       ((Object[]) this.sink.getAsserted().get( 0 ))[0] );
 
@@ -326,7 +327,7 @@
                       this.sink.getAsserted().size() );
         assertEquals( new LeftTuple( tuple2,
                                      f0.getRightTuple(),
-                                     this.node,
+                                     this.sink,
                                      true ),
                       ((Object[]) this.sink.getAsserted().get( 1 ))[0] );
 
@@ -344,11 +345,11 @@
 
         assertTrue( tuples.contains( new LeftTuple( tuple1,
                                                     f3.getRightTuple(),
-                                                    this.node,
+                                                    this.sink,
                                                     true ) ) );
         assertTrue( tuples.contains( new LeftTuple( tuple2,
                                                     f3.getRightTuple(),
-                                                    this.node,
+                                                    this.sink,
                                                     true ) ) );
     }
 
@@ -411,11 +412,11 @@
 
         assertTrue( tuples.contains( new LeftTuple( tuple1,
                                                     f0.getRightTuple(),
-                                                    this.node,
+                                                    this.sink,
                                                     true ) ) );
         assertTrue( tuples.contains( new LeftTuple( tuple1,
                                                     f0.getRightTuple(),
-                                                    this.node,
+                                                    this.sink,
                                                     true ) ) );
 
         // Now check the item  is no longer in memory
@@ -433,11 +434,11 @@
 
         assertTrue( tuples.contains( new LeftTuple( tuple2,
                                                     f3.getRightTuple(),
-                                                    this.node,
+                                                    this.sink,
                                                     true ) ) );
         assertTrue( tuples.contains( new LeftTuple( tuple2,
                                                     f4.getRightTuple(),
-                                                    this.node,
+                                                    this.sink,
                                                     true ) ) );
     }
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -93,6 +93,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -111,6 +111,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         null,
+                                                                        null,
                                                                         null );
 
         // Test single activation for a single logical assertions
@@ -230,6 +231,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         null,
+                                                                        null,
                                                                         null );
 
         // Test single activation for a single logical assertions
@@ -331,6 +333,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         null,
+                                                                        null,
                                                                         null );
 
         // Test that a STATED assertion overrides a logical assertion
@@ -490,6 +493,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         null,
+                                                                        null,
                                                                         null );
 
         // Test that a STATED assertion overrides a logical assertion
@@ -591,6 +595,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         node.assertLeftTuple( tuple1,
@@ -707,6 +712,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         null,
+                                                                        null,
                                                                         null );
         // get the activation onto the agenda
         node.assertLeftTuple( tuple1,
@@ -731,6 +737,7 @@
         final PropagationContext context2 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         null,
+                                                                        null,
                                                                         null );
 
         // get the activations onto the agenda
@@ -854,6 +861,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         null,
+                                                                        null,
                                                                         null );
 
         // Assert multiple stated objects
@@ -966,6 +974,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         null,
+                                                                        null,
                                                                         null );
 
         // Test that a STATED assertion overrides a logical assertion

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockRightTupleSink.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockRightTupleSink.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockRightTupleSink.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -21,6 +21,10 @@
     
     public List getRetracted() {
         return this.retracted;
+    }
+
+    public int getId() {
+        return 0;
     }    
 
 }

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -57,6 +57,7 @@
         this.context = new PropagationContextImpl( 0,
                                                    PropagationContext.ASSERTION,
                                                    null,
+                                                   null,
                                                    null );
         this.workingMemory = new ReteooWorkingMemory( 1,
                                                       (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
@@ -116,7 +117,7 @@
                       this.sink.getRetracted() );
 
         assertEquals( new LeftTuple( f0,
-                                     this.node,
+                                     this.sink,
                                      true  ),
                       ((Object[]) this.sink.getAsserted().get( 0 ))[0] );
 
@@ -141,7 +142,7 @@
                       this.sink.getRetracted() );
 
         assertEquals( new LeftTuple( f0,
-                                     this.node,
+                                     this.sink,
                                      true  ),
                       ((Object[]) this.sink.getRetracted().get( 0 ))[0] );
         
@@ -218,7 +219,7 @@
                       this.sink.getRetracted() );
 
         assertEquals( new LeftTuple( f0,
-                                     this.node,
+                                     this.sink,
                                      true  ),
                       ((Object[]) this.sink.getAsserted().get( 0 ))[0] );
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -91,6 +91,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
@@ -140,6 +141,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         RuleBaseConfiguration conf = new RuleBaseConfiguration();
@@ -235,6 +237,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory)ruleBase.newStatefulSession();
@@ -286,6 +289,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();     
         final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
@@ -397,6 +401,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -131,6 +131,7 @@
                            new PropagationContextImpl( 0,
                                                        PropagationContext.ASSERTION,
                                                        null,
+                                                       null,
                                                        null ),
                            workingMemory );
 
@@ -139,8 +140,8 @@
         rete.assertObject( h1,
                            new PropagationContextImpl( 0,
                                                        PropagationContext.ASSERTION,
-        
                                                        null,
+                                                       null,
                                                        null ),
                            workingMemory );               
         
@@ -182,6 +183,7 @@
                            new PropagationContextImpl( 0,
                                                        PropagationContext.ASSERTION,
                                                        null,
+                                                       null,
                                                        null ),
                            workingMemory );
 
@@ -197,6 +199,7 @@
                            new PropagationContextImpl( 0,
                                                        PropagationContext.ASSERTION,
                                                        null,
+                                                       null,
                                                        null ),
                            workingMemory );
 
@@ -324,6 +327,7 @@
                            new PropagationContextImpl( 0,
                                                        PropagationContext.ASSERTION,
                                                        null,
+                                                       null,
                                                        null ),
                            workingMemory );
         assertLength( 0,
@@ -341,6 +345,7 @@
                            new PropagationContextImpl( 0,
                                                        PropagationContext.ASSERTION,
                                                        null,
+                                                       null,
                                                        null ),
                            workingMemory );
 
@@ -348,6 +353,7 @@
                             new PropagationContextImpl( 0,
                                                         PropagationContext.ASSERTION,
                                                         null,
+                                                        null,
                                                         null ),
                             workingMemory );
 
@@ -384,6 +390,7 @@
                            new PropagationContextImpl( 0,
                                                        PropagationContext.ASSERTION,
                                                        null,
+                                                       null,
                                                        null ),
                            workingMemory );
 
@@ -431,6 +438,7 @@
                            new PropagationContextImpl( 0,
                                                        PropagationContext.ASSERTION,
                                                        null,
+                                                       null,
                                                        null ),
                            workingMemory );
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -136,6 +136,7 @@
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule0,
+                                                                        null,
                                                                         null );
 
         // nodes
@@ -415,6 +416,7 @@
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         rule0,
+                                                                        null,
                                                                         null );
 
         // nodes

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java	2008-05-06 01:48:37 UTC (rev 19861)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java	2008-05-06 01:50:21 UTC (rev 19862)
@@ -101,6 +101,7 @@
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
+                                                                       null,
                                                                        null );
 
         final LeftTuple tuple = new LeftTuple( new DefaultFactHandle( 1,
@@ -165,7 +166,8 @@
                     final PropagationContext context2 = new PropagationContextImpl( 0,
                                                                                     0,
                                                                                     rule,
-                                                                                    knowledgeHelper.getActivation() );
+                                                                                    ( LeftTuple ) knowledgeHelper.getTuple(),
+                                                                                    null );
                     final LeftTuple tuple2 = new LeftTuple( new DefaultFactHandle( 2,
                                                                                    "cheese" ), null,
                                                                                    true  );
@@ -187,6 +189,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         null,
+                                                                        null,
                                                                         null );
 
         final LeftTuple tuple1 = new LeftTuple( new DefaultFactHandle( 1,
@@ -255,7 +258,8 @@
                     final PropagationContext context2 = new PropagationContextImpl( 0,
                                                                                     0,
                                                                                     rule,
-                                                                                    knowledgeHelper.getActivation() );
+                                                                                    ( LeftTuple ) knowledgeHelper.getTuple(),
+                                                                                    null );
                     final LeftTuple tuple2 = new LeftTuple( new DefaultFactHandle( 2,
                                                                                    "cheese" ), null,
                                                                                    true  );
@@ -277,6 +281,7 @@
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
                                                                         null,
+                                                                        null,
                                                                         null );
 
         final LeftTuple tuple1 = new LeftTuple( new DefaultFactHandle( 1,




More information about the jboss-svn-commits mailing list