Advice on varying rule behavior based on object tested?
by zstlaw
Each item I am testing MAY have overridden the default thresholds or disable
the rule entirely. I would prefer to have this data related to the item I
am testing rather than have each rule manage customized behavior for
thousands of different types of objects.
The object could have a map of rule thresholds it overrides, but for
simplicity I assume there is a method to return the current threshold for
the current object. is there a better way to perform this kind of logic?
Example of my current code:
declare TestedEntity
temp : Double
end
declare AlertThreshold
maxAllowed : Double
end
rule "Check temperature"
when
$entity : TestedEntity( )
// would prefer to use drools.getRule().getName() on next line
AlertThreshold($entity.temp > maxAllowed) from
$entity.getAlertThresholdForRule("Check temperature")
then
// raise alert
end
I dislike hard-coding the rule name as it leads to copy paste errors. I
can't insert thresholds easily unless I define different ones for each rule
and I want to be able to fall back to defaults easily. This is a type of
problem I have come up against several times now so I feel like others must
have dealt with it before. The idea of writing copies of rules tailored to
each Entity appeals less than a generalized way of doing this. By doing
this I want to contain complexity. Dozens of slightly different
implementations of the same rule would be much harder to test and support.
I am dealing with hundreds of thousands of facts today and will need to
scale to millions before I can deploy fully. But with that large number I
need to have ways to manage exceptions to the general case just to keep
complexity manageable.
Thanks,
Zack
--
View this message in context: http://drools.46999.n3.nabble.com/Advice-on-varying-rule-behavior-based-o...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 4 months
WorkingMemoryLogger + statelessSessions = memory leak?
by Swindells, Thomas
Hi everyone,
I believe that there is a memory leak when using WorkingMemoryLoggers with statelessSessions. This was raised against 5.1.1 but I think it will still exist in the latest as well.
Our code basically has the following pattern:
KnowledgeBase kb ==;
while(nextEvent()) {
StatelessKnowledgeSession session = kb.newStatelessKnowledgeSession();
auditor = new WorkingMemoryInMemoryLogger(session);
session.execute(getEvent());
dumpAuditLog(auditor);
session = null; //no dispose it's stateless
}
We were getting Out of Memory Exception on site and the stack dump showed a high number of MemoryLoggers on the heap.
Having a look at the code I think the problem is in the WorkingMemoryLogger constructor:
} else if (session instanceof StatelessKnowledgeSessionImpl) {
((StatelessKnowledgeSessionImpl) session).workingMemoryEventSupport.addEventListener( this );
((StatelessKnowledgeSessionImpl) session).agendaEventSupport.addEventListener( this );
((StatelessKnowledgeSessionImpl) session).ruleFlowEventSupport.addEventListener( this );
((StatelessKnowledgeSessionImpl) session).getRuleBase().addEventListener( this );
}
The last statement gets the knowledge base and attaches the event listener to it.
As far as I can see there is no way to dispose of the WorkingMemoryLogger and you don't dispose stateless sessions (and it doesn't know about the listener anyway). This means that even after the session is gone the rule base still has a reference to the logger.
The work around is to make the logger a singleton and clear it in each loop rather than creating a new one each time, however this obviously doesn't scale to multiple threads.
Have I missed some fundamental in the api or should I raise a Jira for this?
Thomas
________________________________
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster(a)nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************
14 years, 4 months
Rule, import with wildcards and variable / patternBinding
by Per Sterner
Hello,
Yesterday I wanted to upgrade my drools version to 5.3 (from 5.1). I got
the exception "java.lang.NoClassDefFoundError:
de/pelle7/testpackage/event/myEvent (wrong name:
de/pelle7/testpackage/event/MyEvent)" while adding my resources.
I removed the import wildcards and the error disappeard.
Finally I found the problem:
I used the patternBinding 'myEvent' and there is a class called
'MyEvent' and I used an wildcard import where the class 'MyEvent' is
located.
Example code:
"
package de.pelle7.testrules.impl.drools
import de.pelle7.testpackage.event.*
rule "Test rule 1"
dialect "java"
salience 50
when
myEvent : MyEvent( )
myEvent2 : MyEvent( data == myEvent.data ) <-- here the Exception
is thrown
then
System.err.println("Output");
end
"
My solution is that I replaced all my pattern bindings with the suffix
'$' which is more convenient.
Perhaps it would be nice to produce an rule-compilation error. with a
line notice.
Regard,
Per Sterner
14 years, 4 months
Why this rule fires immediately ?
by eskomk
Hi all,
Here is the rule:
CLIP -->
rule "ZZZOver30" dialect "mvel"
when
$tsb : ZZZBean($prof : profileID)
$avg : Number( doubleValue > 30 ) from accumulate(
ZZZBean( $tempr : temperature, profileID == $prof) over
window:length( 3 ),
average( $tempr ) )
then
// do something
end
CLIP <--
The intention as you can see is that the rule fires if the average
temperature rises above 30 degrees (of Celsius) in some measuring period.
For testing purposes the rule takes a specific number of temperatures
(window:length), in production environment the window will be time
(window:time(Xm)).
My question is, why this rule fires immediately after drools-expert is
started ?
Is there something wrong in syntax ?
In startup there are obviously no objects of this kind (ZZZBean) in Working
Set's memory, so it really shouldn't fire.
We are running Drools ver. 5.1.1 as a web service on top of apache, and the
facts (events) are fed to Drools via REST interface as XML.
thanks and regards,
Esko
-----
Esko Hujanen
www.ebsolut.fi
--
View this message in context: http://drools.46999.n3.nabble.com/Why-this-rule-fires-immediately-tp34304...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 4 months
Validation flow - defer expression evaluation
by peters
Hi,
I was wondering which is the proper way to do sanity checks (not null
etc...) on a fact before starting the actual business rules.
I have created a a ruleflow with a validation node (VALRFG) and a business
rule node (BRRFG) to determine execution order.
If in the validation node a not null constraint is violated, the session is
aborted (drools.halt()).
Problem with this approach is that assertions defined in rules of the
ruleflow-group "BRRFG" are validated before the validation rules execute.
The engine throws exception at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:298)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:130).
...
at
org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.java:101)
at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:291)
How can I make sure that the validation rules are executed before the mvel
expressions in the business rules are being evaluated?
Thanks for feedback,
--
View this message in context: http://drools.46999.n3.nabble.com/Validation-flow-defer-expression-evalua...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 4 months
5.3.0.Final resource change scanner bug
by lhorton
I tried loading up 5.3.0 this weekend but have run into this bug:
https://bugzilla.redhat.com/show_bug.cgi?id=733008
my server log says:
Exception in thread "Thread-38" java.lang.IllegalStateException: reader does
have a modified date
at
org.drools.io.impl.ReaderResource.getLastModified(ReaderResource.java:64)
at
org.drools.io.impl.ResourceChangeScannerImpl.scan(ResourceChangeScannerImpl.java:166)
at
org.drools.io.impl.ResourceChangeScannerImpl$ProcessChangeSet.run(ResourceChangeScannerImpl.java:311)
at java.lang.Thread.run(Thread.java:662)
some rules files loaded, but some failed (silently, except for the above
message). Is there a workaround for this problem? we cannot migrate to
5.3.0 unless this is fixed or there is a way to work around the problem.
thanks for any help.
--
View this message in context: http://drools.46999.n3.nabble.com/5-3-0-Final-resource-change-scanner-bug...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 4 months
Printing rule content when a rule is fired
by GPatel@tsys.com
Is is possible to get textual rule content from
org.drools.definition.rule.Rule? What I am looking to do is get the rule
definition (the when/then part) when a rule fires (i.e on
AfterActivationFiredEvent)
Thanks
G. Patel
-----------------------------------------
The information contained in this communication (including any
attachments hereto) is confidential and is intended solely for the
personal and confidential use of the individual or entity to whom
it is addressed. If the reader of this message is not the intended
recipient or an agent responsible for delivering it to the intended
recipient, you are hereby notified that you have received this
communication in error and that any review, dissemination, copying,
or unauthorized use of this information, or the taking of any
action in reliance on the contents of this information is strictly
prohibited. If you have received this communication in error,
please notify us immediately by e-mail, and delete the original
message. Thank you
14 years, 4 months
Regarding BPEL
by Sumeet Karawal
Hi,
I required some information whether jBPM supports BPEL. I searched and
found something regarding its use in jBPM v3.x. But got nothing regarding
BPEL for versions 4.x and 5.x. Is jBPM compatible with BPEL or is there
anyway to have BPEL functionality with jBPM.
jBPM creates the process using JPDL. Is it better in someway or the other
than BPEL ? Could anybody please help me on this.
Thanks & Regards,
Sumeet Karawal
Mailto: sumeet.karawal(a)tcs.com
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
14 years, 4 months
How to use lists in RHS when using MVEL?
by zstlaw
I want to make an array and pass it to a method in the RHS but can't when I
use mvel. If I use mvel then java new Object[3] causes compile errors. If
I use the mvel syntax the object is not an real array, only a string in
mvel's special array notation which is not useful for the functions I am
trying to call. Working example:
rule "Array bug"
dialect "java" // explicit java or mvel barfs on new Object[];
when
Message( )
then
Object[] logArgs = new Object[3];
logArgs[0] = "Sample string";
logArgs[1] = "Another string";
logArgs[2] = "And done";
System.out.println( "Array was "+$m );
end
If you change dialect above to mvel the code no longer compiles. If you
change it to mvel and use the mvel list syntax ["Sample string", "Another
string", "And done"] you don't have an array so methods requiring an array
do not work. Concrete example: I want to log 3 values using a logging
framework. Many logging frameworks (like sl4j) support a notation like
Logger.warn("My name is {} and you killed my {}", array); where array has
"Inigo Montonya" and "father" for values.
Thanks for any advice!
Zack
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-use-lists-in-RHS-when-using-MVEL...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 4 months