Hi Again,
After some digging I still have a couple of question regarding CEP events and windows in a
testing environment.
Rules:
declare ParameterUpdateEvent
@role(event)
end
rule "Set Parameter Value"
when
ParameterUpdateEvent($name : name, $newParamValue : value)
from entry-point "ParamUpdateStream"
$param : Parameter(name == $name)
then
$param.setValue($newParamValue);
System.out.println("New value = " + $param.getValue());
end
rule "Print Average"
when
ParameterUpdateEvent($paramName : name, $newParamValue : value)
from entry-point "ParamUpdateStream"
$param : Parameter(name == $paramName)
$averageUpdateValue : Number(doubleValue >= 1) from accumulate(
ParameterUpdateEvent(name == $paramName, $value : value)
over window:length( 5 )
from entry-point "ParamUpdateStream", average($value))
#Number($averageUpdateValue : doubleValue)
then
#System.out.println("Here");
System.out.println("Average update value for " + $paramName +
" = " + $averageUpdateValue);
end
* Declare the ParameterUpdateEvent
* Rule to update the parameter in working memory with the value in the event:
"Set Parameter Value"
* Rule to print an average over 5 updates.
As you can see I define the window as a length of 5 so I would expect to have 5 updates
events at any given time, and I do when I don't use a pseudo clock in my test.
Test with no pseudo clock:
* Add 56 - Average output is 56.0
* Add 89 - Average output is 72.5
* Add 3 - Average output is 49.33
* Add 50 - Average output is 49.5
* Add 90 - Average output is 57.6
As I am still learning about Drools and CEP within Drools the next step I took was to
associate a pseudo clock with the session:
KnowledgeSessionConfiguration config =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
config.setOption(ClockTypeOption.get("pseudo"));
mSession = mKnowledgeBase.newStatefulKnowledgeSession(config, null);
mClock = (SessionPseudoClock)mSession.getSessionClock();
And then increment the time before each event insert:
mClock.advanceTime(1, TimeUnit.SECONDS);
I am not sure why that has an effect because my window is still defined as length based so
time should not be a factory at all. What I am seeing is:
* Add 56 - Average output is 56.0
* Add 89 - Average output is 89.0
* Add 3 - Average output is 3.0
* Add 50 - Average output is 50.0
* Add 90 - Average output is 90.0
From the above, and the logging output which states the previous event
is retracted when the next event is inserted, this does not seem to be using the sliding
window. Why does adding the advanceTime call cause this to happen. At the end of the day
these rules do need to be time based and I do need to test them using JUnit.
Thanks
Glenn
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Glenn Macgregor
Sent: 16 February 2010 10:32
To: Rules Users List
Subject: Re: [rules-users] CEP Question
Please ignore my last message, sent by mistake!
Sorry for the confusion.
Glenn
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Edson Tirelli
Sent: 15 February 2010 20:08
To: Rules Users List
Subject: Re: [rules-users] CEP Question
Hi Glen,
The averages are indeed recalculated on event expiration. Example:
You have values for the following events:
e1: 20
e2: 30
e3: 40
So the average is 30. Whenever e1 is expired in your window, the average is
recalculated to 35 (assuming no new event arrived).
What are you seeing there?
Edson
2010/2/15 Glenn Macgregor
<gmacgregor@pocketkings.ie<mailto:gmacgregor@pocketkings.ie>>
Hi All,
I am still working through a CEP use case which is going fairly well. I have a few rules
and it seems they are working as I expect. Is there a way to get called back when events
go out of a time window? My current use case is alerting, I have a stream of events (param
updates) coming in and I create a ParamUpdateEvent for each. I have a rule which averages
the values in the ParamUpdateEvent and tests against a threshold, that is working fine.
The problem is when I don't receive any events for a period of time over the window
size I really want to the rule which calculates the average to fire when anything is moved
out of the window as well as when an update arrives, is this possible?
Thanks
Glenn
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org<mailto:rules-users@lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @
www.jboss.com<http://www.jboss.com>