global as link to DB: different results
by elsdestickere
Hi,
I read docs about global and Hibernate to access your DB from the rules.
I tried something simular for in memory DAO's.
But some rules fire ("WM" in RHS) as the DAO has 3 items, but others ("dao"
in LHS) don't, how is that possible?
global RepositoryFactory repFact;
rule "dao"
when
k : Customer( ) from repFact.getCustomerRepository().findAll();
then
System.out.println( "Drools "+drools.getRule().getName()+": "
+k.getName());
end
rule "WM"
when
k : Customer( ) ;
then
System.out.println( "Drools "+drools.getRule().getName()+": "
+k.getName()+" + size: "+repFact.getCustomerRepository().findAll().size());
end
...
RepositoryFactory repFact = Registry.getRepositoryFactory();
ksession.setGlobal("repFact", repFact);
...
CustomerRepository customerRepo = Registry.getRepositoryFactory()
.getCustomerRepository();
customerRepo.add(tom);
customerRepo.add(elise);
customerRepo.add(bert);
ksession.insert(bert);
ksession.fireAllRules();
...
Output:
Drools WM: Bert + size: 3
br,
Els
--
View this message in context: http://drools.46999.n3.nabble.com/global-as-link-to-DB-different-results-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 1 month
Sliding Length Windows
by diana-mendes
Hello,
I'm having trouble using sliding length windows. Either I'm implementing
them wrong or I have misunderstood how they're supposed to work.
I have a class named Notif:
*public class Notif implements Serializable{
...
private String specificProblem;
...
public String getSpecificProblem() {
return specificProblem;
}
public void setSpecificProblem(String specificProblem) {
this.specificProblem = specificProblem;
}
}*
These Notif's represent my events. I want to know how many Notifs with
specificProblem "New ONT" are there in the last 2 received events.
My .drl file looks like this:
*declare Notif
@role( event )
end
rule "Rule1"
when
$event : Notif()
$nNewONT : Number() from accumulate (
Notif( specificProblem == "New ONT" ) over window:length(2), count() )
then
System.out.println("In the last 2 events there were "+$nNewONT+" events
'New ONT'");
end*
My test file:
*...
session.insert(ONTIsInactive1);
session.insert(newONT1);
session.insert(ONTIsInactive2);
session.insert(newONT2);
session.insert(LOKS1);
session.insert(LOKS2);
session.insert(LOKS3);
session.insert(newONT3);
session.fireAllRules(); *
As you probably can tell by the names, the events I'm looking for are the
2nd, the 4th and the last one.
But the output I get is:
In the last 2 events there were 2 events 'New ONT'
In the last 2 events there were 2 events 'New ONT'
In the last 2 events there were 2 events 'New ONT'
In the last 2 events there were 2 events 'New ONT'
In the last 2 events there were 2 events 'New ONT'
In the last 2 events there were 2 events 'New ONT'
In the last 2 events there were 2 events 'New ONT'
In the last 2 events there were 2 events 'New ONT'
The output I'm looking for is:
In the last 2 events there were 0 events 'New ONT' (because the received
event is "ONTIsInactive")
In the last 2 events there were 1 events 'New ONT' (because the last 2
received events are "ONTIsInactive" and "New ONT")
In the last 2 events there were 1 events 'New ONT' (because the last 2
received events are "New ONT" and "ONTIsInactive")
...
and so on...
What am I doing wrong? Any help would be appreciated!
Thanks in advance,
Diana
--
View this message in context: http://drools.46999.n3.nabble.com/Sliding-Length-Windows-tp3438408p343840...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 1 month
Time Window
by diana-mendes
Hello,
I want to implement a simple scenario using Drools, but I can't find the
right functions to do so.
I have a class named Notif that represents my events.
When I receive a Notif with a certain attribute (for example, type == "A") I
want to get a list of all the events I receive in the next 10 seconds.
If I receive a second event of type "A" during those 10 seconds, I don't
want to start another count. It should only restart the count after the 10
seconds have expired.
Example:
1s: Notif (type=="A") should start the 10 second count
2s: Notif (type=="B")
3s: Notif (type=="C")
4s: Notif (type=="A")
5s: Notif (type=="D")
12s: Notif(type=="E")
10 seconds after the first Notif(type=="A") I would like to receive the
following list:
Notif (type=="A")
Notif (type=="B")
Notif (type=="C")
Notif (type=="A")
Notif (type=="D")
Note that Notif(type=="E") (at 12 seconds) should not be in the list because
it's outside of the 10 seconds interval. Also, note that the second
Notif(type=="A") (at 4 seconds) should not start a new count because it's
included in the 10 seconds interval.
Thanks in advance,
Diana
--
View this message in context: http://drools.46999.n3.nabble.com/Time-Window-tp3468566p3468566.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 1 month
Turning off strict mode
by Alexander
Hello.
Is it possible to turn off strict mode in Drools 5.2 or 5.3 like in 5.1? How
can i do it?
We use Drools 5.1 and we use lots of maps so we turned off strict mode. I
tried to switch to Drools 5.2 or 5.3 but setting
System.setProperty("drools.dialect.mvel.strict", "false") doesn't work with
those versions. Our domain model is basicaly a hierarchy of Maps without
generics so using strict mode will force us to write alot of casts. This is
not acceptable cause we want our non technical guys to write some rules. One
of our goals was to make it possible to update our application without
recompiling and redeploying any java code only rules and flows, thats why we
have such "domain model".
--
View this message in context: http://drools.46999.n3.nabble.com/Turning-off-strict-mode-tp3468094p34680...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 1 month
Does window:length work in Drools version 5.1.1 ?
by eskomk
Drools-expert 5.1.1
Does window:length work in Drools version 5.1.1 ?
It seems that "over window:length( 5 )" in rule "PossibleFFF_launch_level1"
does not work.
It seems that it returns only the last MMMBean added in trackers in rules
"PossibleFFF_Level1_update_tracker_count" and
"PossibleFFF_Level2_update_tracker_count".
The idea here is that trackers keep count of how many MMMBeans have entered
the system, after incoming BBBBean with bbbEmpty == true have initiated the
tracking (PossibleFFF).
App domain specific operations are launched if there is no active counts
(actCount) in a series of MMMBeans ("PossibleFFF_launch_level1" and
"PossibleFFF_launch_level2").
actCount is an integer but accumulate function sum apparently returns a
floating point number, hence the check "doubleValue < 0.5".
Rules "PossibleFFF_kill_tracker_with_bbb" and
"PossibleFFF_kill_tracker_with_count" are to retract the trackers from
memory, so ending the tracking.
Rule "PossibleFFF_kill_tracker_with_bbb" kills this profileID's tracker if
bbbEmpty == false.
Rule "PossibleFFF_kill_tracker_with_count" kills tracker if count > 5, count
indicating that no operations were launched ("PossibleFFF_launch_level1" and
"PossibleFFF_launch_level2").
Problem is, that the condition
$theSum : Number(doubleValue < 0.5) from accumulate(
// MMMBean( $actCount : activeCount) over window:length( 5 ) from
$tracker.mdsBeanList,
MMMBean( $actCount : activeCount) over window:length( 5 ) from
$tracker.getMdsBeanList(),
sum( $actCount ) )
in rules
"PossibleFFF_launch_level1" and "PossibleFFF_launch_level2"
does not seem to work as expected.
I expected that the sum would be calculated from field MMMBean.actCount over
all MMMBean members of list $tracker.mdsBeanList.
It seems that sum returns only the actCount of last MMMBean which was
inserted in $tracker.mdsBeanList.
Is there something wrong with the rules ?
Rules are like these:
// RULES -->
rule "PossibleFFF" dialect "mvel"
when
$bsb : BBBBean(bbbEmpty == true)
not FFFTracker(profileID == $bsb.profileID)
then
FFFTracker $tracker = new FFFTracker();
$tracker.level = 1;
$tracker.count = 0;
$tracker.profileID = $bsb.profileID;
$tracker.location = $bsb.location;
retract($bsb);
$tracker.sensorBean = $bsb;
insert($tracker);
end
rule "PossibleFFF_Level1_update_tracker_count" dialect "mvel"
when
$tracker : FFFTracker(level == 1)
$mds : MMMBean(profileID == $tracker.profileID, this after $tracker)
then
drools.retract($mds);
$tracker.addMdsBean($mds);
$tracker.count = $tracker.count + 1;
drools.update($tracker);
end
rule "PossibleFFF_launch_level1" dialect "mvel"
when
$tracker : FFFTracker(level == 1, count == 5, $prof : profileID)
$theSum : Number(doubleValue < 0.5) from accumulate(
// MMMBean( $actCount : activeCount) over window:length( 5 ) from
$tracker.mdsBeanList,
MMMBean( $actCount : activeCount) over window:length( 5 ) from
$tracker.getMdsBeanList(),
sum( $actCount ) )
then
retract($tracker);
FFFTracker $tracker2 = new FFFTracker();
$tracker2.level = 2;
$tracker2.profileID = $tracker.profileID;
$tracker2.location = $tracker.location;
$tracker2.sensorBean = $tracker.sensorBean;
$tracker2.count = 0;
// Tracker2 is set to track further conditions
insert($tracker2);
// launch the app domain specific things
end
rule "PossibleFFF_Level2_update_tracker_count" dialect "mvel"
when
$tracker : FFFTracker(level == 2)
$mds : MMMBean(profileID == $tracker.profileID, this after $tracker)
then
drools.retract($mds);
$tracker.addMdsBean($mds);
$tracker.count = $tracker.count + 1;
drools.update($tracker);
end
rule "PossibleFFF_launch_level2" dialect "mvel"
when
$tracker : FFFTracker(level == 2, count == 5, $prof : profileID)
$theSum : Number(doubleValue < 0.5) from accumulate(
// MMMBean( $actCount : activeCount, profileID == $prof) over
window:length( 5 ) from $tracker.mdsBeanList,
MMMBean( $actCount : activeCount, profileID == $prof) over
window:length( 5 ) from $tracker.getMdsBeanList(),
sum( $actCount ) )
then
retract($tracker);
// launch the app domain specific things
end
rule "PossibleFFF_kill_tracker_with_bbb" dialect "mvel"
when
$tracker : FFFTracker($prof : profileID, $loc : location)
$bsb : BBBBean(profileID == $prof, location == $loc, bbbEmpty == false,
this after $tracker)
then
retract($tracker);
end
rule "PossibleFFF_kill_tracker_with_count" dialect "mvel"
when
$tracker : FFFTracker(count > 5, $prof : profileID)
then
retract($tracker);
end
// <-- RULES
BBBBean, MMMBean, FFFTracker are declared as events.
class FFFTracker:
public class FFFTracker extends Tracker
{
private ArrayList<MMMMBean> mdsBeanList = new ArrayList<MMMMBean>();
public ArrayList<MMMBean> getMdsBeanList()
{
return mdsBeanList;
}
public void setMdsBeanList(ArrayList<MMMBean> pmdsbeanlist)
{
this.mdsBeanList = pmdsbeanlist;
}
public void addMdsBean(MMMBean pbean)
{
this.mdsBeanList.add(pbean);
}
}
class Tracker:
public class Tracker
{
private long profileID = 0;
private short location = 0;
private int level = 0;
private int count = 0;
private ASensorBean sensorBean = null; // AsensorBean is an abstract
class from which BBBBean and MMMBean are derived
// getters and setters goes here
}
Best Regards,
Esko
------
Esko Hujanen
www.ebsolut.fi
--
View this message in context: http://drools.46999.n3.nabble.com/Does-window-length-work-in-Drools-versi...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 1 month
Drools session reuse question
by arrehman
Is creation of StatefulKnowledgeSession expensive? Is there a guideline or
best practice regarding this?
Currently I am creating a new session /kbase.newStatefulKnowledgeSession()/
each time I want to call /session.fireAllRules()/. I do this for each of the
200,000 data records that I have. So it creates and destroys 200 drools
sessions (monitored via drools JMX bean)
I was trying to reuse the same drools session for each of those 200,000 data
records to see if it improves the performance (don't know if this is frowned
upon or recommended). However this was failing my rules left and right, not
sure why, possibly because I am not cleaning up the session cleanly. I have
been calling /session.dispose() /after every /fireAllRules() /though.
Any thoughts?
Thanks,
Abdul
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-session-reuse-question-tp3466635...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 1 month
Drools Performance /Memory Leak Issue
by arrehman
Hi,
I am not much of an expert on Drools. I got a DRL file (very small rule set
of less than 10 rules, that checks few conditions, also includes DB calls).
I use Drools 5.2 inside a grails application. I am using stateful session. I
call this rules 100,000 times for each for each of the 100,000 records that
I want to validate. However the performance gradually deteriorates. What
could be going on here? General advice on how to approach solving this,
improving performance. Should I be using stateless drools session? How do I
configure the Drools MBeans so I can monitor Drools better?
PS: I can provide more details as you needed. I can paste the general gist
of the code and DRL file. Any help is greatly appreciated. I spent two days
on this with no results.
Thanks,
Abdul
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Performance-Memory-Leak-Issue-tp...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 1 month
Drools 5.3.0 Dependencies
by arrehman
Hi,
I was using drools 5.2.0 in my grails 2.0.0.M2 application. I use Drools
expert to execute a .drl file I have. The three dependencies that I have set
up for this to work was:
runtime 'org.drools:drools-core:5.2.0.Final'
runtime 'org.drools:drools-compiler:5.2.0.Final'
runtime 'com.sun.xml.bind:jaxb-xjc:2.2.4'
However when I switched to drools 5.3.0. The rules are not getting executed
or there are some problems. There is no stacktrace or log. I have no idea
what is going on. My guess is that some of the dependency jars or classes
are missing. Any insight into this?
Thanks,
Abdul
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-5-3-0-Dependencies-tp3452346p345...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 1 month
Drools command line tools?
by arrehman
Hi,
I am using Drools 5.2 (direclty, not via grails plugins) in a grails
2.0.0.M2 web application. I use IntelliJ IDEA for development which does not
support Drools inherently. (I know eclipse has better support) I am
struggling with the compilations, syntax erros of .DRL file I have in my
app. Are there any command line tools that will help me point out the exact
syntax errors of the DRL file? Currently I am struggling, and doing a adhoc
approach. I know there must be a better way.
Thanks,
Abdul
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-command-line-tools-tp3465973p346...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 1 month