[jboss-svn-commits] JBL Code SVN: r16869 - in labs/jbossrules/branches/temporal_rete: drools-compiler/src/test/resources/org/drools/integrationtests and 9 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Nov 27 18:50:42 EST 2007


Author: tirelli
Date: 2007-11-27 18:50:41 -0500 (Tue, 27 Nov 2007)
New Revision: 16869

Added:
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java
Removed:
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/PseudoSessionClock.java
Modified:
   labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
   labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_SimpleTimeWindow.drl
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/WorkingMemory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EventFactHandle.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
   labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java
   labs/jbossrules/branches/temporal_rete/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java
   labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94EventFactHandle.java
   labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java
Log:
JBRULES-1332: quick and dirty hack of the session clock into the working memory instance. Not happy with the implementation, but it is a start.

Modified: labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -9,17 +9,21 @@
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
+import org.drools.FactHandle;
+import org.drools.OrderEvent;
 import org.drools.RuleBase;
 import org.drools.RuleBaseConfiguration;
 import org.drools.RuleBaseFactory;
 import org.drools.StockTick;
 import org.drools.WorkingMemory;
+import org.drools.common.EventFactHandle;
 import org.drools.common.InternalFactHandle;
 import org.drools.compiler.DrlParser;
 import org.drools.compiler.DroolsParserException;
 import org.drools.compiler.PackageBuilder;
 import org.drools.lang.descr.PackageDescr;
 import org.drools.rule.Package;
+import org.drools.temporal.SessionPseudoClock;
 
 public class CepEspTest extends TestCase {
     protected RuleBase getRuleBase() throws Exception {
@@ -82,22 +86,22 @@
                                          "DROO",
                                          50,
                                          System.currentTimeMillis() );
-        
+
         InternalFactHandle handle1 = (InternalFactHandle) wm.insert( tick1 );
         InternalFactHandle handle2 = (InternalFactHandle) wm.insert( tick2 );
         InternalFactHandle handle3 = (InternalFactHandle) wm.insert( tick3 );
         InternalFactHandle handle4 = (InternalFactHandle) wm.insert( tick4 );
-        
+
         assertNotNull( handle1 );
         assertNotNull( handle2 );
         assertNotNull( handle3 );
         assertNotNull( handle4 );
-        
+
         assertTrue( handle1.isEvent() );
         assertTrue( handle2.isEvent() );
         assertTrue( handle3.isEvent() );
         assertTrue( handle4.isEvent() );
-        
+
         wm.fireAllRules();
 
         assertEquals( 2,
@@ -105,7 +109,7 @@
 
     }
 
-    public void FIXME_testSimpleTimeWindow() throws Exception {
+    public void testSimpleTimeWindow() throws Exception {
         // read in the source
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_CEP_SimpleTimeWindow.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
@@ -118,32 +122,74 @@
 
         // how to initialize the clock?
         // how to configure the clock?
-        //        PseudoSessionClock clock = wm.getSessionClock();
-        //        
-        //        clock.advanceTime( 10000 ); // 10 seconds
-        //        wm.insert( new OrderEvent("1", "customer A", 70) );
-        //        wm.fireAllRules();
-        //
-        //        clock.advanceTime( 10000 ); // 10 seconds
-        //        wm.insert( new OrderEvent("2", "customer A", 60) );
-        //        wm.fireAllRules();
-        //
-        //        clock.advanceTime( 10000 ); // 10 seconds
-        //        wm.insert( new OrderEvent("3", "customer A", 50) );
-        //        wm.fireAllRules();
-        //
-        //        clock.advanceTime( 10000 ); // 10 seconds
-        //        wm.insert( new OrderEvent("4", "customer A", 30) );
-        //        wm.fireAllRules();
-        //
-        //        clock.advanceTime( 10000 ); // 10 seconds
-        //        wm.insert( new OrderEvent("5", "customer A", 70) );
-        //        wm.fireAllRules();
-        //        
-        //        clock.advanceTime( 10000 ); // 10 seconds
-        //        wm.insert( new OrderEvent("6", "customer A", 80) );
-        //        wm.fireAllRules();
+        SessionPseudoClock clock = (SessionPseudoClock) wm.getSessionClock();
 
+        clock.advanceTime( 10000 ); // 10 seconds
+        EventFactHandle handle1 = (EventFactHandle) wm.insert( new OrderEvent( "1",
+                                                                               "customer A",
+                                                                               70 ) );
+        assertEquals( 10000,
+                      handle1.getStartTimestamp() );
+        assertEquals( 0,
+                      handle1.getDuration() );
+
+        wm.fireAllRules();
+
+        clock.advanceTime( 10000 ); // 10 seconds
+        EventFactHandle handle2 = (EventFactHandle) wm.insert( new OrderEvent( "2",
+                                                                               "customer A",
+                                                                               60 ) );
+        assertEquals( 20000,
+                      handle2.getStartTimestamp() );
+        assertEquals( 0,
+                      handle2.getDuration() );
+
+        wm.fireAllRules();
+
+        clock.advanceTime( 10000 ); // 10 seconds
+        EventFactHandle handle3 = (EventFactHandle) wm.insert( new OrderEvent( "3",
+                                                                               "customer A",
+                                                                               50 ) );
+        assertEquals( 30000,
+                      handle3.getStartTimestamp() );
+        assertEquals( 0,
+                      handle3.getDuration() );
+
+        wm.fireAllRules();
+
+        clock.advanceTime( 10000 ); // 10 seconds
+        EventFactHandle handle4 = (EventFactHandle) wm.insert( new OrderEvent( "4",
+                                                                               "customer A",
+                                                                               30 ) );
+        assertEquals( 40000,
+                      handle4.getStartTimestamp() );
+        assertEquals( 0,
+                      handle4.getDuration() );
+
+        wm.fireAllRules();
+
+        clock.advanceTime( 10000 ); // 10 seconds
+        EventFactHandle handle5 = (EventFactHandle) wm.insert( new OrderEvent( "5",
+                                                                               "customer A",
+                                                                               70 ) );
+        assertEquals( 50000,
+                      handle5.getStartTimestamp() );
+        assertEquals( 0,
+                      handle5.getDuration() );
+
+        wm.fireAllRules();
+
+        clock.advanceTime( 10000 ); // 10 seconds
+        EventFactHandle handle6 = (EventFactHandle) wm.insert( new OrderEvent( "6",
+                                                                               "customer A",
+                                                                               80 ) );
+        assertEquals( 60000,
+                      handle6.getStartTimestamp() );
+        assertEquals( 0,
+                      handle6.getDuration() );
+
+        wm.fireAllRules();
+
     }
 
     //    public void testTransactionCorrelation() throws Exception {

Modified: labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_SimpleTimeWindow.drl
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_SimpleTimeWindow.drl	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_SimpleTimeWindow.drl	2007-11-27 23:50:41 UTC (rev 16869)
@@ -5,13 +5,13 @@
 global java.util.List results;
 
 rule "average over threshold"
-    time-window 30 seconds
+    //time-window 30 seconds
 when
     Number( $avg : intValue >= 50 ) from accumulate(
-              OrderEvent( $amt : amount ),
+              OrderEvent( $amt : total ),
               average( $amt ) )
 then
     System.out.println( "Over threshold: "+$avg );
-    results.add( $amt )
+    results.add( $avg );
 end
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -29,7 +29,8 @@
 import org.drools.concurrent.ExecutorService;
 import org.drools.spi.ConflictResolver;
 import org.drools.spi.ConsequenceExceptionHandler;
-import org.drools.spi.RuleBaseUpdateListener;
+import org.drools.temporal.SessionClock;
+import org.drools.temporal.SessionPseudoClock;
 import org.drools.util.ChainedProperties;
 
 /**
@@ -67,42 +68,44 @@
  * drools.conflictResolver = <qualified class name>
  * drools.consequenceExceptionHandler = <qualified class name>
  * drools.ruleBaseUpdateHandler = <qualified class name>
+ * drools.sessionClock = <qualified class name>
  * 
  */
 public class RuleBaseConfiguration
     implements
     Serializable {
-    private static final long           serialVersionUID = 400L;
+    private static final long              serialVersionUID = 400L;
 
-    private ChainedProperties           chainedProperties;
+    private ChainedProperties              chainedProperties;
 
-    private boolean                     immutable;
+    private boolean                        immutable;
 
-    private boolean                     sequential;
-    private SequentialAgenda            sequentialAgenda;
+    private boolean                        sequential;
+    private SequentialAgenda               sequentialAgenda;
 
-    private boolean                     maintainTms;
-    private boolean                     removeIdentities;
-    private boolean                     shareAlphaNodes;
-    private boolean                     shareBetaNodes;
-    private boolean                     alphaMemory;
-    private int                         alphaNodeHashingThreshold;
-    private int                         compositeKeyDepth;
-    private boolean                     indexLeftBetaMemory;
-    private boolean                     indexRightBetaMemory;
-    private AssertBehaviour             assertBehaviour;
-    private LogicalOverride             logicalOverride;
-    private ExecutorService             executorService;
-    private ConsequenceExceptionHandler consequenceExceptionHandler;
-    private String                      ruleBaseUpdateHandler;
+    private boolean                        maintainTms;
+    private boolean                        removeIdentities;
+    private boolean                        shareAlphaNodes;
+    private boolean                        shareBetaNodes;
+    private boolean                        alphaMemory;
+    private int                            alphaNodeHashingThreshold;
+    private int                            compositeKeyDepth;
+    private boolean                        indexLeftBetaMemory;
+    private boolean                        indexRightBetaMemory;
+    private AssertBehaviour                assertBehaviour;
+    private LogicalOverride                logicalOverride;
+    private ExecutorService                executorService;
+    private ConsequenceExceptionHandler    consequenceExceptionHandler;
+    private String                         ruleBaseUpdateHandler;
+    private Class< ? extends SessionClock> sessionClockClass;
 
-    private ConflictResolver            conflictResolver;
+    private ConflictResolver               conflictResolver;
 
-    private boolean                     shadowProxy;
-    private Map                         shadowProxyExcludes;
-    private static final String         STAR             = "*";
+    private boolean                        shadowProxy;
+    private Map                            shadowProxyExcludes;
+    private static final String            STAR             = "*";
 
-    private transient ClassLoader       classLoader;
+    private transient ClassLoader          classLoader;
 
     /**
      * Creates a new rulebase configuration using the provided properties
@@ -218,9 +221,9 @@
 
         setConsequenceExceptionHandler( RuleBaseConfiguration.determineConsequenceExceptionHandler( this.chainedProperties.getProperty( "drools.consequenceExceptionHandler",
                                                                                                                                         "org.drools.base.DefaultConsequenceExceptionHandler" ) ) );
-        
+
         setRuleBaseUpdateHandler( this.chainedProperties.getProperty( "drools.ruleBaseUpdateHandler",
-                                                                      "org.drools.base.FireAllRulesRuleBaseUpdateListener" ) );        
+                                                                      "org.drools.base.FireAllRulesRuleBaseUpdateListener" ) );
 
         setConflictResolver( RuleBaseConfiguration.determineConflictResolver( this.chainedProperties.getProperty( "drools.conflictResolver",
                                                                                                                   "org.drools.conflict.DepthConflictResolver" ) ) );
@@ -231,6 +234,10 @@
 
         setShadowProxyExcludes( this.chainedProperties.getProperty( "drools.shadowProxyExcludes",
                                                                     "" ) );
+
+        setSessionClockClass( this.chainedProperties.getProperty( "drools.sessionClock",
+                                                                  SessionPseudoClock.class.getName() ) );
+    
     }
 
     /**
@@ -386,7 +393,7 @@
         checkCanChange(); // throws an exception if a change isn't possible;        
         this.consequenceExceptionHandler = consequenceExceptionHandler;
     }
-    
+
     public String getRuleBaseUpdateHandler() {
         return ruleBaseUpdateHandler;
     }
@@ -394,8 +401,52 @@
     public void setRuleBaseUpdateHandler(String ruleBaseUpdateHandler) {
         checkCanChange(); // throws an exception if a change isn't possible;        
         this.ruleBaseUpdateHandler = ruleBaseUpdateHandler;
-    }    
+    }
 
+    /**
+     * Returns the actual class that is set to be used as the session clock
+     * for sessions of this rulebase
+     *  
+     * @return
+     */
+    public Class< ? extends SessionClock> getSessionClockClass() {
+        return sessionClockClass;
+    }
+
+    /**
+     * Sets the class whose instance is to be used as the session clock 
+     * for sessions of this rulebase
+     * 
+     * @param sessionClockClass
+     */
+    public void setSessionClockClass(Class< ? extends SessionClock> sessionClockClass) {
+        checkCanChange(); // throws an exception if a change isn't possible;        
+        this.sessionClockClass = sessionClockClass;
+    }
+
+    /**
+     * Sets the class name whose instance is to be used as the session clock
+     * for sessions of this rulebase
+     * 
+     * @param className
+     */
+    public void setSessionClockClass(String className) {
+        Class<? extends SessionClock> sessionClock;
+        try {
+            ClassLoader cl = this.getClassLoader();
+            if( cl == null ) {
+                cl = Thread.currentThread().getContextClassLoader();
+                if( cl == null ) {
+                    cl = this.getClass().getClassLoader();
+                }
+            }
+            sessionClock = (Class< ? extends SessionClock>) cl.loadClass( className );
+        } catch( Exception ex ) {
+            throw new RuntimeDroolsException("Not possible to load the session clock class: "+className, ex);
+        } 
+        setSessionClockClass( sessionClock );
+    }
+
     public AgendaGroupFactory getAgendaGroupFactory() {
         if ( isSequential() ) {
             if ( this.sequentialAgenda == SequentialAgenda.SEQUENTIAL ) {
@@ -422,7 +473,7 @@
             // sequential never needs shadowing, so always override
             return false;
         }
-        
+
         if ( userValue != null ) {
             return Boolean.valueOf( userValue ).booleanValue();
         } else {
@@ -551,7 +602,7 @@
     private static ConsequenceExceptionHandler determineConsequenceExceptionHandler(String className) {
         return (ConsequenceExceptionHandler) instantiateClass( "ConsequenceExceptionHandler",
                                                                className );
-    }   
+    }
 
     private static Object instantiateClass(String type,
                                            String className) {

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/WorkingMemory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/WorkingMemory.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/WorkingMemory.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -23,6 +23,7 @@
 import org.drools.spi.AgendaGroup;
 import org.drools.spi.AsyncExceptionHandler;
 import org.drools.spi.GlobalResolver;
+import org.drools.temporal.SessionClock;
 
 /**
  * A knowledge session for a <code>RuleBase</code>.
@@ -343,4 +344,13 @@
      */
     public void halt();
     
+    /**
+     * Returns the session clock instance for this session.
+     * 
+     * The actual session clock implementation is defined by the
+     * RuleBaseConfiguration.setSessionClockImpl() call or by
+     * setting the corresponding system property.
+     */
+    public SessionClock getSessionClock();
+    
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractFactHandleFactory.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import org.drools.WorkingMemory;
 import org.drools.spi.FactHandleFactory;
 import org.drools.util.PrimitiveLongStack;
 
@@ -39,16 +40,18 @@
     /* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#newFactHandle()
      */
-    public final InternalFactHandle newFactHandle( final Object object, final boolean isEvent ) {
+    public final InternalFactHandle newFactHandle( final Object object, final boolean isEvent, final WorkingMemory workingMemory ) {
         if ( !this.factHandlePool.isEmpty() ) {
             return newFactHandle( this.factHandlePool.pop(),
                                   object, 
-                                  isEvent );
+                                  isEvent,
+                                  workingMemory );
         }
 
         return newFactHandle( this.id++,
                               object,
-                              isEvent );
+                              isEvent,
+                              workingMemory );
     }
 
     /* (non-Javadoc)
@@ -56,11 +59,13 @@
      */
     protected final InternalFactHandle newFactHandle(final long id,
                                                      final Object object,
-                                                     final boolean isEvent ) {
+                                                     final boolean isEvent, 
+                                                     final WorkingMemory workingMemory ) {
         return newFactHandle( id,
                               object,
                               this.counter++,
-                              isEvent );
+                              isEvent,
+                              workingMemory );
     }
 
     /* (non-Javadoc)
@@ -69,7 +74,8 @@
     protected abstract InternalFactHandle newFactHandle(final long id,
                                                         final Object object,
                                                         final long recency,
-                                                        final boolean isEvent );
+                                                        final boolean isEvent, 
+                                                        final WorkingMemory workingMemory );
 
     /* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#increaseFactHandleRecency(org.drools.FactHandle)

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -69,6 +69,7 @@
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.GlobalResolver;
 import org.drools.spi.PropagationContext;
+import org.drools.temporal.SessionClock;
 import org.drools.util.JavaIteratorAdapter;
 import org.drools.util.ObjectHashMap;
 import org.drools.util.PrimitiveLongMap;
@@ -157,6 +158,8 @@
 
     private Map<Object, ObjectTypeConf>    typeConfMap;
 
+    private SessionClock                   sessionClock;
+
     // ------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------
@@ -715,7 +718,7 @@
         InternalFactHandle handle = null;
 
         if ( isSequential() ) {
-            handle = this.handleFactory.newFactHandle( object, typeConf.isEvent() );
+            handle = this.handleFactory.newFactHandle( object, typeConf.isEvent(), this );
             addHandleToMaps( handle );
             insert( handle,
                     object,
@@ -767,7 +770,7 @@
                 if ( key == null ) {
                     // key is also null, so treat as a totally new stated/logical
                     // assert
-                    handle = this.handleFactory.newFactHandle( object, typeConf.isEvent() );
+                    handle = this.handleFactory.newFactHandle( object, typeConf.isEvent(), this );
                     addHandleToMaps( handle );
 
                     key = new EqualityKey( handle );
@@ -821,7 +824,7 @@
                         } else {
                             // override, then instantiate new handle for assertion
                             key.setStatus( EqualityKey.STATED );
-                            handle = this.handleFactory.newFactHandle( object, typeConf.isEvent() );
+                            handle = this.handleFactory.newFactHandle( object, typeConf.isEvent(), this );
                             handle.setEqualityKey( key );
                             key.addFactHandle( handle );
                             addHandleToMaps( handle );
@@ -829,7 +832,7 @@
                         }
 
                     } else {
-                        handle = this.handleFactory.newFactHandle( object, typeConf.isEvent() );
+                        handle = this.handleFactory.newFactHandle( object, typeConf.isEvent(), this );
                         addHandleToMaps( handle );
                         key.addFactHandle( handle );
                         handle.setEqualityKey( key );
@@ -856,7 +859,7 @@
                 if ( handle != null ) {
                     return handle;
                 }
-                handle = this.handleFactory.newFactHandle( object, typeConf.isEvent() );
+                handle = this.handleFactory.newFactHandle( object, typeConf.isEvent(), this );
                 addHandleToMaps( handle );
 
             }
@@ -1359,6 +1362,19 @@
     public RuleFlowEventSupport getRuleFlowEventSupport() {
         return this.ruleFlowEventSupport;
     }
+    
+    public SessionClock getSessionClock() {
+        if( this.sessionClock == null ) {
+            try {
+                this.sessionClock = this.ruleBase.getConfiguration().getSessionClockClass().newInstance();
+            } catch ( InstantiationException e ) {
+                throw new RuntimeDroolsException("Not possible to create a session clock instance for class: "+this.ruleBase.getConfiguration().getSessionClockClass().getName(), e);
+            } catch ( IllegalAccessException e ) {
+                throw new RuntimeDroolsException("Not possible to create a session clock instance for class: "+this.ruleBase.getConfiguration().getSessionClockClass().getName(), e);
+            }
+        }
+        return this.sessionClock;
+    }
 
     /**
      * Sets the AsyncExceptionHandler to handle exceptions thrown by the Agenda

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EventFactHandle.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EventFactHandle.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/common/EventFactHandle.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -6,8 +6,8 @@
 
     private static final long serialVersionUID = 5997141759543399455L;
     
-    private long startTimestamp;
-    private long duration;
+    private final long startTimestamp;
+    private final long duration;
 
     // ----------------------------------------------------------------------
     // Constructors
@@ -15,12 +15,16 @@
 
     public EventFactHandle() {
         super();
+        this.startTimestamp = 0;
+        this.duration = 0;
     }
 
     public EventFactHandle(final long id,
                            final Object object) {
         super( id,
                object );
+        this.startTimestamp = 0;
+        this.duration = 0;
     }
 
     /**
@@ -35,6 +39,8 @@
         super( id,
                object,
                recency );
+        this.startTimestamp = 0;
+        this.duration = 0;
     }
     
     /**

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -161,7 +161,7 @@
             this.resultBinder.updateFromTuple( workingMemory,
                                                leftTuple );
             if ( this.resultBinder.isAllowedCachedLeft( result ) ) {
-                final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result, false ); // so far, result is not an event
+                final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result, false, workingMemory ); // so far, result is not an event
                 accresult.handle = handle;
 
                 this.sink.propagateAssertTuple( leftTuple,
@@ -379,7 +379,7 @@
             this.resultBinder.updateFromTuple( workingMemory,
                                                leftTuple );
             if ( this.resultBinder.isAllowedCachedLeft( result ) ) {
-                final InternalFactHandle createdHandle = workingMemory.getFactHandleFactory().newFactHandle( result, false ); // so far, result is not an event
+                final InternalFactHandle createdHandle = workingMemory.getFactHandleFactory().newFactHandle( result, false, workingMemory ); // so far, result is not an event
                 accresult.handle = createdHandle;
 
                 this.sink.propagateAssertTuple( leftTuple,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -107,7 +107,7 @@
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
 
         final Collection result = this.collect.instantiateResultObject();
-        final InternalFactHandle resultHandle = workingMemory.getFactHandleFactory().newFactHandle( result, false );
+        final InternalFactHandle resultHandle = workingMemory.getFactHandleFactory().newFactHandle( result, false, workingMemory );
         CollectResult colresult = new CollectResult();
         colresult.handle = resultHandle;
         colresult.propagated = false;

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/FromNode.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -83,7 +83,7 @@
             }
 
             if ( this.betaConstraints.isAllowedCachedLeft( object ) ) {
-                final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( object, false );
+                final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( object, false, workingMemory );
 
                 list.add( new LinkedListEntry( handle ) );
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -16,11 +16,13 @@
  * limitations under the License.
  */
 
+import org.drools.WorkingMemory;
 import org.drools.common.AbstractFactHandleFactory;
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.EventFactHandle;
 import org.drools.common.InternalFactHandle;
 import org.drools.spi.FactHandleFactory;
+import org.drools.temporal.SessionClock;
 
 public class ReteooFactHandleFactory extends AbstractFactHandleFactory {
 
@@ -32,11 +34,15 @@
     protected final InternalFactHandle newFactHandle(final long id,
                                                      final Object object,
                                                      final long recency,
-                                                     final boolean isEvent) {
+                                                     final boolean isEvent,
+                                                     final WorkingMemory workingMemory ) {
         if ( isEvent ) {
+            SessionClock clock = workingMemory.getSessionClock(); 
             return new EventFactHandle( id,
                                         object,
-                                        recency );
+                                        recency,
+                                        clock.getCurrentTime(),
+                                        0 );  // primitive events have 0 duration
         } else {
             return new DefaultFactHandle( id,
                                           object,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -235,7 +235,7 @@
                 super.addStatefulSession( session );
             }
 
-            final InitialFactHandle handle = new InitialFactHandle( session.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(), false ) );
+            final InitialFactHandle handle = new InitialFactHandle( session.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(), false, session ) );
 
             session.queueWorkingMemoryAction( new WorkingMemoryReteAssertAction( handle,
                                                                                  false,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -59,7 +59,7 @@
             wm.setAgendaEventSupport( this.agendaEventSupport );
             wm.setRuleFlowEventSupport( ruleFlowEventSupport );
 
-            final InitialFactHandle handle = new InitialFactHandle( wm.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(), false ) );
+            final InitialFactHandle handle = new InitialFactHandle( wm.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject(), false, wm ) );
 
             wm.queueWorkingMemoryAction( new WorkingMemoryReteAssertAction( handle,
                                                                             false,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -87,7 +87,7 @@
     public QueryResults getQueryResults(final String query, final Object[] arguments) {
 
         Object object = new DroolsQuery( query, arguments );
-        InternalFactHandle handle = this.handleFactory.newFactHandle( object, false );
+        InternalFactHandle handle = this.handleFactory.newFactHandle( object, false, this );
         
         insert( handle,
                 object,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/reteoo/RightInputAdapterNode.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -92,7 +92,7 @@
                             final InternalWorkingMemory workingMemory) {
 
         // creating a dummy fact handle to wrap the tuple
-        final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( tuple, false );
+        final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( tuple, false, workingMemory );
         
         if ( this.tupleMemoryEnabled ) {
             final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/spi/FactHandleFactory.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -19,6 +19,7 @@
 import java.io.Serializable;
 
 import org.drools.FactHandle;
+import org.drools.WorkingMemory;
 import org.drools.common.InternalFactHandle;
 
 /**
@@ -37,7 +38,7 @@
      * 
      * @return The handle.
      */
-    InternalFactHandle newFactHandle(Object object, boolean isEvent);
+    InternalFactHandle newFactHandle(Object object, boolean isEvent, WorkingMemory workingMemory );
 
     /**
      * Increases the recency of the FactHandle

Deleted: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/PseudoSessionClock.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/PseudoSessionClock.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/PseudoSessionClock.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -1,49 +0,0 @@
-/*
- * Copyright 2007 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Created on Oct 17, 2007
- */
-package org.drools.temporal;
-
-/**
- * A PseudoSessionClock is a clock that allows the user to explicitly 
- * control current time.
- * 
- * @author etirelli
- *
- */
-public class PseudoSessionClock
-    implements
-    SessionClock {
-    
-    private long timer;
-
-    public PseudoSessionClock() {
-        this.timer = 0;
-    }
-    
-    /* (non-Javadoc)
-     * @see org.drools.temporal.SessionClock#getCurrentTime()
-     */
-    public long getCurrentTime() {
-        return this.timer;
-    }
-    
-    public long advanceTime( long millisecs ) {
-        this.timer += millisecs;
-        return this.timer;
-    }
-
-}

Copied: labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java (from rev 16752, labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/PseudoSessionClock.java)
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java	                        (rev 0)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/main/java/org/drools/temporal/SessionPseudoClock.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2007 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Created on Oct 17, 2007
+ */
+package org.drools.temporal;
+
+/**
+ * A SessionPseudoClock is a clock that allows the user to explicitly 
+ * control current time.
+ * 
+ * @author etirelli
+ *
+ */
+public class SessionPseudoClock
+    implements
+    SessionClock {
+    
+    private long timer;
+
+    public SessionPseudoClock() {
+        this.timer = 0;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.drools.temporal.SessionClock#getCurrentTime()
+     */
+    public long getCurrentTime() {
+        return this.timer;
+    }
+    
+    public long advanceTime( long millisecs ) {
+        this.timer += millisecs;
+        return this.timer;
+    }
+
+}

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/common/EqualityKeyTest.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -10,13 +10,13 @@
     public void test1() {
         ReteooFactHandleFactory factory = new ReteooFactHandleFactory();
         
-        InternalFactHandle ch1 = factory.newFactHandle( new Cheese ("c", 10), false );
+        InternalFactHandle ch1 = factory.newFactHandle( new Cheese ("c", 10), false, null );
         EqualityKey key = new EqualityKey( ch1 );
         
         assertSame( ch1, key.getFactHandle() );
         assertNull( key.getOtherFactHandle() );
         
-        InternalFactHandle ch2 = factory.newFactHandle( new Cheese ("c", 10), false );
+        InternalFactHandle ch2 = factory.newFactHandle( new Cheese ("c", 10), false, null );
         key.addFactHandle( ch2 );
         
         assertEquals( 1, key.getOtherFactHandle().size() );

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -128,10 +128,10 @@
                              0,
                              this.sink.getAsserted().size() );
 
-        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false ) ),
+        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null ) ),
                                this.context,
                                this.workingMemory );
-        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false ) ),
+        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null ) ),
                                this.context,
                                this.workingMemory );
 
@@ -155,7 +155,7 @@
      * Test method for {@link org.drools.reteoo.AccumulateNode#assertTuple(org.drools.reteoo.ReteTuple, org.drools.spi.PropagationContext, org.drools.reteoo.ReteooWorkingMemory)}.
      */
     public void testAssertTuple() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
         // assert tuple, should add one to left memory
@@ -171,7 +171,7 @@
                            this.accumulator.getMatchingObjects().isEmpty() );
 
         // assert tuple, should add left memory 
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null );
 
         final ReteTuple tuple1 = new ReteTuple( f1 );
         this.node.assertTuple( tuple1,
@@ -195,8 +195,8 @@
      * Test method for {@link org.drools.reteoo.AccumulateNode#assertTuple(org.drools.reteoo.ReteTuple, org.drools.spi.PropagationContext, org.drools.reteoo.ReteooWorkingMemory)}.
      */
     public void testAssertTupleWithObjects() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -244,7 +244,7 @@
      * Test method for {@link org.drools.reteoo.AccumulateNode#retractTuple(org.drools.reteoo.ReteTuple, org.drools.spi.PropagationContext, org.drools.reteoo.ReteooWorkingMemory)}.
      */
     public void testRetractTuple() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -275,8 +275,8 @@
      * Test method for {@link org.drools.reteoo.AccumulateNode#assertObject(InternalFactHandle, org.drools.spi.PropagationContext, InternalWorkingMemory)}.
      */
     public void testAssertObject() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -320,8 +320,8 @@
      * Test method for {@link org.drools.reteoo.AccumulateNode#retractObject(InternalFactHandle, org.drools.spi.PropagationContext, InternalWorkingMemory)}.
      */
     public void testRetractObject() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -431,8 +431,8 @@
         
         this.memory = ((AccumulateMemory) this.workingMemory.getNodeMemory( this.node )).betaMemory;
 
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -125,10 +125,10 @@
                              0,
                              this.sink.getAsserted().size() );
 
-        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false ) ),
+        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null ) ),
                                this.contextAssert,
                                this.workingMemory );
-        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false ) ),
+        this.node.assertTuple( new ReteTuple( this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null ) ),
                                this.contextAssert,
                                this.workingMemory );
 
@@ -149,7 +149,7 @@
     }
 
     public void testAssertTuple() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
         // assert tuple, should add one to left memory
@@ -165,7 +165,7 @@
                            ((Collection) ((DefaultFactHandle) ((Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
 
         // assert tuple, should add left memory 
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null );
 
         final ReteTuple tuple1 = new ReteTuple( f1 );
         this.node.assertTuple( tuple1,
@@ -185,8 +185,8 @@
     }
 
     public void testAssertTupleWithObjects() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -230,7 +230,7 @@
     }
 
     public void testRetractTuple() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -258,8 +258,8 @@
     }
 
     public void testAssertObject() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -302,8 +302,8 @@
     }
 
     public void testRetractObject() {
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 
@@ -395,8 +395,8 @@
         this.memory = (BetaMemory) this.workingMemory.getNodeMemory( this.node );
         this.node.setTupleMemoryEnabled( false );
 
-        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false );
-        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false );
+        final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese", false, null );
+        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese", false, null );
 
         final ReteTuple tuple0 = new ReteTuple( f0 );
 

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -257,7 +257,7 @@
         ad.addObjectSink( al2 );
         ad.addObjectSink( al3 );
 
-        InternalFactHandle handle = new ReteooFactHandleFactory().newFactHandle( new Cheese(), false );
+        InternalFactHandle handle = new ReteooFactHandleFactory().newFactHandle( new Cheese(), false, null );
         try {
             ad.propagateAssertObject( handle,
                                       null,

Modified: labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-core/src/test/java/org/drools/reteoo/DefaultFactHandleFactoryTest.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -27,21 +27,21 @@
      */
     public void testNewFactHandle() {
         final ReteooFactHandleFactory factory = new ReteooFactHandleFactory();
-        DefaultFactHandle handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
+        DefaultFactHandle handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false, null );
         assertEquals( 0,
                       handle.getId() );
         assertEquals( 0,
                       handle.getRecency() );
 
         // issue  new handle
-        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
+        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false, null );
         assertEquals( 1,
                       handle.getId() );
         assertEquals( 1,
                       handle.getRecency() );
 
         // issue  new handle, under a different reference so we  can destroy later        
-        final DefaultFactHandle handle2 = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
+        final DefaultFactHandle handle2 = (DefaultFactHandle) factory.newFactHandle( "cheese", false, null );
         assertEquals( 2,
                       handle2.getId() );
         assertEquals( 2,
@@ -53,7 +53,7 @@
                       handle.getRecency() );
 
         // issue new handle and make sure  recency is still inline
-        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
+        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false, null );
         assertEquals( 3,
                       handle.getId() );
         assertEquals( 4,
@@ -63,14 +63,14 @@
         factory.destroyFactHandle( handle2 );
 
         // issue  new  fact handle and  make sure it  recycled the  id=2
-        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
+        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false, null );
         assertEquals( 2,
                       handle.getId() );
         assertEquals( 5,
                       handle.getRecency() );
 
         // issue new  handle  making  sure it correctly resumes  ids  and recency
-        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false );
+        handle = (DefaultFactHandle) factory.newFactHandle( "cheese", false, null );
         assertEquals( 4,
                       handle.getId() );
         assertEquals( 6,

Modified: labs/jbossrules/branches/temporal_rete/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -28,6 +28,7 @@
 import org.drools.spi.AgendaGroup;
 import org.drools.spi.AsyncExceptionHandler;
 import org.drools.spi.GlobalResolver;
+import org.drools.temporal.SessionClock;
 
 public class ExternalSheetListenerTest extends TestCase {
 
@@ -382,6 +383,11 @@
                     // TODO Auto-generated method stub
                     
                 }
+
+                public SessionClock getSessionClock() {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 			};
 		}
 	}

Modified: labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94EventFactHandle.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94EventFactHandle.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94EventFactHandle.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -75,10 +75,32 @@
      * @see org.drools.conflict.RecencyConflictResolver
      */
     Jsr94EventFactHandle(final long id,
-                    final Object object,
-                    final long recency) {
+                         final Object object,
+                         final long recency) {
         super( id,
                object,
                recency );
     }
+
+    /**
+     * Creates a new event fact handle.
+     * 
+     * @param id this event fact handle ID
+     * @param object the event object encapsulated in this event fact handle
+     * @param recency the recency of this event fact handle
+     * @param timestamp the timestamp of the occurence of this event
+     * @param duration the duration of this event. May be 0 (zero) in case this is a primitive event.
+     */
+    public Jsr94EventFactHandle(final long id,
+                                final Object object,
+                                final long recency,
+                                final long timestamp,
+                                final long duration) {
+        super( id,
+               object,
+               recency,
+               timestamp,
+               duration );
+    }
+
 }

Modified: labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java	2007-11-27 23:27:58 UTC (rev 16868)
+++ labs/jbossrules/branches/temporal_rete/drools-jsr94/src/main/java/org/drools/jsr94/rules/Jsr94FactHandleFactory.java	2007-11-27 23:50:41 UTC (rev 16869)
@@ -16,9 +16,11 @@
  * limitations under the License.
  */
 
+import org.drools.WorkingMemory;
 import org.drools.common.AbstractFactHandleFactory;
 import org.drools.common.InternalFactHandle;
 import org.drools.spi.FactHandleFactory;
+import org.drools.temporal.SessionClock;
 
 /**
  * A factory for creating <code>Handle</code>s.
@@ -35,11 +37,15 @@
     protected final InternalFactHandle newFactHandle(final long id,
                                                      final Object object,
                                                      final long recency,
-                                                     final boolean isEvent) {
+                                                     final boolean isEvent,
+                                                     final WorkingMemory workingMemory ) {
         if ( isEvent ) {
+            SessionClock clock = workingMemory.getSessionClock(); 
             return new Jsr94EventFactHandle( id,
                                              object,
-                                             recency );
+                                             recency,
+                                             clock.getCurrentTime(),
+                                             0 ); // for now, we are only handling primitive events
         } else {
             return new Jsr94FactHandle( id,
                                         object,




More information about the jboss-svn-commits mailing list