Access metadata of declared drools expert types in Java
by Tobias Neef
Hi,
First I have to say. Drools is a very nice tool with great
documentation. Thats the first time I have to use the ML because I
write a little framework which makes some obscure use of Drools expert
;).
But now my problem: I have a type which I declared like:
declare MyMarker
@Marker
feature : String @Feature
end
When I put an instance of that type into the KB I want to grab those
entries with a given @Marker / annotation. So I tried doing that with
reflection on the MyMarker class which did not work. Also when I try
to get a FactType instance I do not find a way to access those
metadata information. For the class annotation @Marker I see that the
FactType instance contains a private field annotation which includes
the correct type. But I see no way to access this information. The
feature field itself can be accessed but no annotation information is
available:
{feature=FieldDefinition{name='feature', type='java.lang.String',
key=false, inherited=false, index=1, initExpr='null',
annotations=null, accessor=[ClassFieldExtractor class=package.MyMarker
field=feature]}
A second minor problem is the way I access the fact type. Is there a
better way to do this?
for (Object object : result) {
Class c = object.getClass();
Package p = c.getPackage();
String packagename = p.getName();
String classname = c.getSimpleName();
FactType ft = knowledgeBase.getFactType(packagename, classname);
if (ft!=null) {
//stuff
}}}
Best Regards,
Tobias Neef
14 years, 2 months
Rule evaluation logic
by MarcoMojana
I have reduced my problem to a minimal example:
- I use a pseudo clock and stream mode processing
- The events are inserted using a succession of advanceTime(), insert(),
fireAllRules()
- I have three events named: Thief, SwitchOn and SwitchOff
- I have three rules similar to:
rule "detect theft"
when
$t : Thief() from entry-point "thieves" // Line A
$lastSwitchOn : SwitchOn(this before $t) from entry-point "lightsControl"
// Line B
SwitchOff(this before $t, this after $lastSwitchOn) from entry-point
"lightsControl" // Line C
not( SwitchOff(this before $t, this after $lastSwitchOn) from entry-point
"lightsControl" ) // Line D
then
System.out.println($t);
end
The first rule is composed of lines A, B, the second of lines A, B and
C and the third of lines A, B and D. Please note that line D is the negation
of line C.
- Inserting the same sequence of events, only the first rule triggers.
This seems strange to me, because:
1) if the first rule triggers, then "Line A" and "Line B" = true
2) if the second rule doesn't, then "Line A" and "Line B" and "Line C" =
false.
3) from 1) and 2), it follows "Line C" = false
4) from 1) and 3), it follows that "Line A" and "Line B" and not "Line C"
= true, so the third rule should be triggered, but it is not. Why?
--
MM
--
View this message in context: http://drools.46999.n3.nabble.com/Rule-evaluation-logic-tp3620772p3620772...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 2 months
DSL/DSLR question
by Rob Fisher
I have a question given the following code:
Inserted fact setter method:
public void setqrpQualRule6(String qrpQualRule6) {
qrpQualRule6 = qrpQualRule6;
}
DSL
[consequence][]Write {AttributeName} on {objectVarName} as
{customCode}=modify ({objectVarName}) \{{AttributeName}={customCode} \};
DSLR
rule "test rule 1"
dialect "mvel"
when
ThereIsQrpRuleFlagData called QrpFlags
- where $var04 is QrpQualFlagRule6 and is equal to "N"
then
Write QrpQualFlagRule6 on QrpFlags as "Y"
DRL Translation
modify (QrpFlags) {qrpQualRule6="Y" };
Question....Does Drools create the "get" behind the scenes? I'm guessing
yes, because the rule is firing and the qrpQualRule6 attribute is getting
set to "Y".
--
View this message in context: http://drools.46999.n3.nabble.com/DSL-DSLR-question-tp3619216p3619216.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 2 months
Usage of completeMoveTabuSize
by Patrik Dufresne
Hi,
I've try to use the completeMoveTabuSize for my problem and I come to
realize it's not working properly. To make sure, I've check it's usage in
the smart Travelling Tournament. It's look like, the hashCode function it
not well implement.
Here my comprehension of the completeMoveTabuSize functionnality :
When completeMoveTabuSize sets to 7, the last 7 moves are consider Tabu. So
the accept chance of the last 7 moves should be 0.0.
To check the tabu, the acceptor use a HashMap and so the hashCode of the
last 7 moves are used to speed up the comparison. In the smart travelling
tournament, the implementation of hashCode is wrong since it's include the
hashCode of the planning-entity which change over time.
May someone confirm this ??
To figure it out, I add a breakpoint in the equals function of the Move
object (and it's never called).
--
Patrik Dufresne
14 years, 2 months
Flow isn't behaving as I'd expect
by Jamie
I'm having some issues with the interaction between Flow, ruleflow-groups and
AgendaFilters. I've tried it with 5.1.1, 5.2.0 using .rf files and 5.2.0
using .bpmn files, all with the same results, so I'm sure I'm just
misunderstanding something.
I have a flow that looks like this:
http://drools.46999.n3.nabble.com/file/n3200994/fraud_analysis_flow.jpg
Rules 011 and 051 are in ruleflow-group customerAnalysis and rule 018 is in
ruleflow-group customerActivityFilterAndLookup. I added some debugging via
event listeners and if I don't use an agenda filter, I see the following
output:
Executing test Rule018TestCase001
Rules engine initialized
Invoking rules for rule name Rule 018 - Good AVS Buyer
Created activation for [Rule 018 - Good AVS Buyer]
Created activation for [Rule 011 - Bad Zip 9 Address]
Created activation for [Rule 051 - Suspicious Buyer Email]
Triggered node [Order Analysis]
Triggered node [Start Fraud Analysis Flow]
Triggered node [Customer Analysis]
About to fire [Rule 051 - Suspicious Buyer Email]
====> Rule 051 fired for order: 000000022
About to fire [Rule 011 - Bad Zip 9 Address]
====> Rule 011 fired for order: 000000022
Triggered node [Customer Activity Filter And Lookup]
About to fire [Rule 018 - Good AVS Buyer]
Created activation for [Rule 051 - Suspicious Buyer Email]
Created activation for [Rule 011 - Bad Zip 9 Address]
====> Rule 018 fired for order: 210105
Triggered node [Customer Activity Analysis]
Triggered node [Suspect Reason Code Review]
Triggered node [End Fraud Analysis Flow]
Rules executed successfully
The results are roughly what I'd expect, but I have some questions:
- Why do the activations get created for these 3 rules before any flows
have started?
- Why does the [Order Analysis] node get triggered before the [Start Fraud
Analysis Flow] node?
- Why are activations created again for 011 and 051 just prior to 018
firing?
If I introduce an AgendaFilter that only allows a rule with a specific name
to fire, things get stranger to me. If I only allow rule 018, I get the
following output:
Executing test Rule018TestCase001
Invoking rules for rule name Rule 018 - Good AVS Buyer
Created activation for [Rule 018 - Good AVS Buyer]
Created activation for [Rule 011 - Bad Zip 9 Address]
Created activation for [Rule 051 - Suspicious Buyer Email]
Triggered node [Order Analysis]
Triggered node [Start Fraud Analysis Flow]
Triggered node [Customer Analysis]
Rejecting firing of [Rule 051 - Suspicious Buyer Email] because name
doesn't match.
Cancelled activation for [Rule 051 - Suspicious Buyer Email] because FILTER
Rejecting firing of [Rule 011 - Bad Zip 9 Address] because name doesn't
match.
Cancelled activation for [Rule 011 - Bad Zip 9 Address] because FILTER
Rules executed successfully
Ruleflow customerActivityFilterAndLookup doesn't even get triggered, nor do
any nodes after that. Why not?
--
View this message in context: http://drools.46999.n3.nabble.com/Flow-isn-t-behaving-as-I-d-expect-tp320...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 2 months
OSGi version of Drools
by Flavius Vespasianus
Hello,
is there anywhere a OSGi bundle with Drools 4.0.7? I know about
com.springsource.org.drools.* but these had a lot of additional
dependencies and I wasn't able to get them work.
My problem is that I need to have three projects: one is the basic
library which uses Drools very intensively. The second project is editor
- an Eclipse plugin (that's why I need the OSGi bundle) using some
classes from the basic library. It doesn't use Drools, but there is a
dependency. The third project is classic Java application, also using
the basic library.
The basic library was originally created using standard Drools project
wizard (I have downloaded the Eclipse Drools plugin -
org.drools.eclipse). But when I tried to deploy it as an Eclipse plugin,
it couldn't find the Drools classes.
I found a little workaround - I have compiled the binaries (drools-core,
drools-compiler and from libs the mvel, antlr3 and eclipse-jdt-core)
into separate plugin using "Create a plugin from existing jars" wizard.
But if I add this dependency to the basic library, I get a
NullPointerException error on every dslr file and I cannot run the
application properly). At least the second project (editor) can be compiled.
What am I doing wrong? Or can I find somewhere the binaries compiled
correctly into OSGi bundle?
Thanks a lot!
Flavius
14 years, 2 months
Drools Expert 5 OSGi
by jflamy
I want to manage Drools Expert rules with Drools Guvnor. My understanding is
that requires the use of Drools Expert version 5.
I also need to use an OSGi-packaged version of Drools Expert.
I saw a forum posting in 2010 alluding to such a beast, but the springsource
forums only provide 4.0.7.
Is there a ready-made OSGi bundle for drools expert 5, or alternately
specific instructions for building one ?
Jean-François Lamy
--
View this message in context: http://n3.nabble.com/Drools-Expert-5-OSGi-tp681546p681546.html
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 2 months
Possible bug with isA operator
by Mike Melton
I am having trouble getting the isA operator to work with POJO facts.
The problem manifests in the IsAEvaluator.evaluate(...) method, line
163 (5.3.0.Final). This line checks whether the objectValue class is
annotated with @Traitable. For a @Traitable fact fully declared in
DRL, this line correctly evaluates to true. For a POJO fact which is
declared @Traitable in DRL, this line evaluates to false. (I tried
adding @Traitable to the POJO fact itself, which results in the line
evaluating true, but the next line which casts to a TraitableBean
fails.)
I have attached a test demonstrating the problem. There are two DRL
files, one which declares a fact entirely, and another which adds
@Traitable to a POJO fact. The declared fact and the POJO fact have
identical structure, and the rules are also otherwise identical.
However, the declared test passes, while the POJO test fails.
Is this a bug, or am I doing something horribly wrong? Thanks.
Mike
14 years, 2 months
Drools 5 Memory Issues
by drools.user
We are planning on moving from Drools 3.0.5 to Drools 5.2.0. In Load Testing
of Drools 5.2, we faced some issues:
1. KnowledgeBaseImpl Object in Drools 5 is almost 50% bigger than
ReteooRuleBase Object of Drools 3.
2. The server heap memory usage keeps on increasing during Load Testing to
finally give OutOfMemory error and crash.
We are using StatefulKnowledgeSession and calling dispose() after
fireAllRules().
So, the questions we have are:
1. Looking at the heap snapshot, we noticed > 300,000 Objects for some of
Drools Classes (e.g. org.drools.reteoo.LeftTupleImpl) occupying > 25MB in
heap memory. Is that normal?
2. Is there any Memory Leak issues with Drools 5?
3. What is the advantage of using KnowledgeBase vs RuleBase? Is it fine to
use RuleBase in Drools 5?
4. We are using Drools 5.2. Has anything changed significantly in Drools
5.3? Will moving to that help in our memory issues?
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-5-Memory-Issues-tp3615095p361509...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 2 months