Title: CARTE DE VISITE
No need to store a explicit timestamp, drools will do that for you.

Your first option is a rule like this :

rule "check_agains_last"
when
     $e1 : EVENT1()
     $e2 : EVENT2(this before $e1)
     not EVENT2(this after $e2)
then
    ...
end

Your second option is to implement a WorkingMemoryEventListener, and implement the objectInserted method to store the last events inserted (a simple 2 sized rolling stack will do the job), and another that return the "previous" inserted Event object (the second element of your stack).
this leads to a rule like this :

rule "check_agains_last"
when
     $e1 : EVENT1()
     eval (PreviousEventListener.getPreviousEvent() instanceof EVENT2)
then
    ...
end

But in this last solution, you may fall into problem if two events are inserted in seom other thread while the rules are processed. In fact, I think you need "the event before another event", and not "the previous of the last one" (the "last one" may be not the one matched in your rule). Mays be your listener can be used to set, in a new event that is inserted, the reference to the last one inserted, something like that:

class PreviousEventListener implements WorkingMemoryEventListener {
    private Object lastInserted;
    public void objectInserted (ObjectInsertedEvent event) {
        event.getObject().setLastEvent( lastInserted ); // check class before of course ...
        lastInserted =       event.getObject();
    }
}

rule "check_agains_last"
when
     $e1 : EVENT1(...)
     $e2 : EVENT2(...) from $e1.getLastEvent()
then
    ...
end


Le 06/10/2011 11:06, tungl a écrit :
So, if I get you right, I have to, for example, store some kind of time stamp
in my event object and compare it? 
My definition of "previous" simply depended on the order, the objects were
inserted into the working memory.

--
View this message in context: http://drools.46999.n3.nabble.com/Get-previous-fact-from-working-memory-tp3399064p3399079.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


--
Vincent LEGENDRE
Consultant Sénior

EURODECISION
9A rue de la Porte de Buc 78000 VERSAILLES
Tél. : +33 (0)1 39 07 12 40
Direct : +33 (0)1 39 07 26 16
www.eurodecision.com

EURODECISION
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to