<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
No need to store a explicit timestamp, drools will do that for you.<br>
<br>
Your first option is a rule like this :<br>
<br>
rule "check_agains_last"<br>
when<br>
$e1 : EVENT1()<br>
$e2 : EVENT2(this before $e1)<br>
not EVENT2(this after $e2)<br>
then<br>
...<br>
end<br>
<br>
Your second option is to implement a <a
href="http://docs.jboss.org/jbpm/v5.1/javadocs/org/drools/event/rule/WorkingMemoryEventListener.html">WorkingMemoryEventListener</a>,
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). <br>
this leads to a rule like this :<br>
<br>
rule "check_agains_last"<br>
when<br>
$e1 : EVENT1()<br>
eval (PreviousEventListener.getPreviousEvent() instanceof
EVENT2)<br>
then<br>
...<br>
end<br>
<br>
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: <br>
<br>
class PreviousEventListener implements <a
href="http://docs.jboss.org/jbpm/v5.1/javadocs/org/drools/event/rule/WorkingMemoryEventListener.html">WorkingMemoryEventListener</a>
{<br>
private Object lastInserted;<br>
public void objectInserted (<code><a
href="http://docs.jboss.org/jbpm/v5.1/javadocs/org/drools/event/rule/ObjectInsertedEvent.html"
title="interface in org.drools.event.rule">ObjectInsertedEvent</a> event)</code>
{<br>
event.getObject().setLastEvent( lastInserted ); // check
class before of course ...<br>
lastInserted = event.getObject();<br>
}<br>
}<br>
<br>
rule "check_agains_last"<br>
when<br>
$e1 : EVENT1(...)<br>
$e2 : EVENT2(...) from $e1.getLastEvent()<br>
then<br>
...<br>
end<br>
<br>
<br>
Le 06/10/2011 11:06, tungl a écrit :
<blockquote cite="mid:1317891978095-3399079.post@n3.nabble.com"
type="cite">
<pre wrap="">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: <a class="moz-txt-link-freetext" href="http://drools.46999.n3.nabble.com/Get-previous-fact-from-working-memory-tp3399064p3399079.html">http://drools.46999.n3.nabble.com/Get-previous-fact-from-working-memory-tp3399064p3399079.html</a>
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
<br>
<div class="moz-signature">-- <br>
<!-- @author Hadrien HUGOT -->
<!-- Modèle signature thunderbird et autres -->
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>CARTE DE VISITE</title>
<span
style="font-size:13.5pt;font-family:"Arial","sans-serif";color:#15185A">Vincent
LEGENDRE</span><br>
<i><span style="font-size:8.5pt;
font-family:"Arial","sans-serif";color:#15185A">Consultant
Sénior</span></i><br>
<span style="font-size:4.5pt"> <br>
</span>
<span
style="font-size:9.0pt;font-family:"Arial","sans-serif";color:#15185A">EURODECISION<o:p></o:p></span><br>
<span
style="font-size:9.0pt;font-family:"Arial","sans-serif";color:#15185A">9A
rue de la Porte de Buc 78000 VERSAILLES<br>
Tél. : +33 (0)1 39 07 12 40<br>
Direct : +33 (0)1 39 07 26 16<br>
<a href="www.eurodecision.com">www.eurodecision.com</a></span><br>
<a href="http://www.eurodecision.com/"><span style="font-size:
12pt; font-family: "Times New
Roman","serif"; color: windowtext;
text-decoration: none;"> <img
src="cid:part1.07050102.00020907@eurodecision.com"
alt="EURODECISION" border="no"></span></a><a
href="http://www.eurodecision.com/"><span
style="font-size:12.0pt;font-family:"Times New
Roman","serif";color:windowtext;
text-decoration:none;text-underline:none"> </span></a>
</div>
</body>
</html>