There is a fundamental misunderstanding on your side.
An event's timestamp and duration are used for reasoning, relating
events by means of temporal operators, e.g., A before B, A meets B,
and so on.
Your condition
Event()
is just a test for a fact of type Event() being in WM, and it doesn't
care for its timestamp and duration.
For relating (real or psudo) with your events' times, look at
window:time, timer() and the aforementioned temporal ops.
Cheers
Wolfgang
On 16/04/2012, RobinMacharg <robin.macharg(a)gmail.com> wrote:
Hi,
I'm new to Drools (this is my first post) and am running into problems
understanding the temporal aspects of it.
I am trying to create a simple test case, using the pseudo-clock to control
time. I declare and add a number of events with different start times
(@timestamp) and durations (@duration). I'd then like to advance the
pseudo-clock by hand, calling fireAllRules() between clock-ticks. I have a
single rule that I would hope would fire on events that are 'valid', i.e.
their (start_time < clock) and their (start_time + duration > clock). I'm
seeing ALL events being picked up the first time I fireAllRules(). I'd
really appreciate an explanation of what I'm missing here.
Some code:
I have a POJO Event class:
public class Event {
public String name;
public long start;
public long dur;
//... constructor, getters, setters omitted for brevity
}
I have a .drl file with an event declaration and a single rule in it:
package myPackage.Event
import myPackage.Event
declare Event
@role( event )
@timestamp ( start )
@duration ( dur )
end
rule "events"
when
e : Event()
then
System.out.println(e.name);
end
My scaffolding creates a STREAM based, pseudo-clock configured stateful
KnowledgeSession, and reads the .drl rules using the standard code from the
examples. I create a number of Events:
Event e1 = new Event("myEvent1", 0, 1000);
Event e2 = new Event("myEvent1", 10000, 20000);
ksession.insert(e1)
... etc.
Then I fireAllRules(), advance the clock and fire them again. I'm seeing
the second event being matched on the first fireAllRules(). I'd not have
expected it to fire until the clock > 10000. I'm sure Drools is doing the
right thing, and I'm not, but I can't work out what. The examples of the
temporal operators all refer to a second event to be compared to. Also, I
can't find an example of referencing the drools system clock value (in this
case the pseudo-clock) from within a rule match section.
So, what am I doing wrong? If I can make my example clearer please let me
know.
Thanks in advance,
Robin
--
View this message in context:
http://drools.46999.n3.nabble.com/Problem-with-simple-Fusion-test-case-tp...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users