[rules-users] Get previous fact from working memory.
Vincent Legendre
vincent.legendre at eurodecision.com
Thu Oct 6 05:34:13 EDT 2011
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
<http://docs.jboss.org/jbpm/v5.1/javadocs/org/drools/event/rule/WorkingMemoryEventListener.html>,
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
<http://docs.jboss.org/jbpm/v5.1/javadocs/org/drools/event/rule/WorkingMemoryEventListener.html>
{
private Object lastInserted;
public void objectInserted (|ObjectInsertedEvent
<http://docs.jboss.org/jbpm/v5.1/javadocs/org/drools/event/rule/ObjectInsertedEvent.html> 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 at 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 <http://www.eurodecision.com/><http://www.eurodecision.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111006/7c092a43/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logoED.gif
Type: image/gif
Size: 3345 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20111006/7c092a43/attachment.gif
More information about the rules-users
mailing list