Intermediate conclusions using strings
by David Boaz
Hi all,
I have an idea and I want to get the community feedback.
Many times there are many ways to reach an intermediate conclusion. This
conclusion can be used to derive higher level conclusions or actions.
For example, assuming a credit application has several (or) options to
conclude whether a parson is classified as gold member. Then, other rules
need this information to determine the credit limit for that member. To
note, the Person java class doesn't have a specialized attribute for the
classification. The classification is only an internal means to simplify the
application logic.
To solve that problem, I thought to insert a string conclusion to the WM.
Something like:
rule "gold member if revenue per month > 1000"
when ...
then insert("gold member")
end
rule "gold member if total amount > 1000000"
when ...
then insert("gold member")
end
...
rule r100
when String(value=="gold member")
then...
end
* Is it an appropriate approach?
* I know it ugly to use the same string literal in various rules. Can we
avoid that?
* Is there a known mechanism to handle these cases?
Thanks, David
--
View this message in context: http://www.nabble.com/Intermediate-conclusions-using-strings-tp19141834p1...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 4 months
TypeCasting in BusinessRule
by Vinoth Kumar Somasundaram
Hi All,
I have used drools-jbrms.war and drools-guvnor.war. I facing a Problem
in both.
I have a package called Rating which has the following source.
'Rule 1' is Business-Rule; 'Rule 2' is a Technical-Rule(DRL).
------------------------------------------------------------------------
--------------------------------
package rating
import com.esspl.ic.dom.CallDetail;
import com.esspl.ic.dom.ICConstants;
import com.esspl.ic.dom.RateDetail;
import java.util.Map;
import java.lang.String;
global Map rateCache;
rule "Rule 1"
dialect "mvel"
when
cd : CallDetail( callType == "VOICE" )
then
cd.setRate( cd.getCallDuration() * ((RateDetail)
rateCache.get("VOICE")).getRate() );
end
rule "Rule 2"
when
cd : CallDetail( callType == "SMS")
then
cd.setRate(cd.getCallDuration() * ((RateDetail)
rateCache.get("SMS")).getRate() );
End
------------------------------------------------------------------------
---------------------------------
Rule 2 Compiles fine but Rule 1 does not.
It seems there is a Problem in compiling a BusinessRule. The Business
Rule Compiler doesn't support Typecasting. Whereas the Technical rule
compiler supports type casting.
I have to make all my rules as Business Rules. But it doesn't get
compiled.
Can anyone help me get rid of this problem.
Thanks in Advance,
Vinoth
16 years, 4 months
Re: [rules-users] firing rules again?
by David Cracauer
Marcin Krol-3 wrote:
>
> 1. When I call session.fireAllRules(), I find I can no longer add new
> facts using this session. Strictly speaking, I can do that, but they
> there doesn't seem to be any effect re firing rules.
>
You shouldn't need to do anything to the existing session. I have a
situation where I add facts in a loop, calling session.fireAllRules() during
each iteration.
Have you tried using a working memory logger and the eclipse plugin to see
what happens after you add the next set of facts? Its fairly easy to see if
there are any activations created by the facts that are inserted.
--
View this message in context: http://www.nabble.com/firing-rules-again--tp19114453p19118169.html
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 4 months
how do RuleBase.lock()/unlock() functions work?
by Marina
Hello!
I am researching how to do thread safe update of packages/rules in a rulebase. I noticed that there are lock() and unlock() methods on the RuleBase object, but could not find much documentation on how they could be used.
I am trying to implement the following scenario and was wondering if someone could verify that I am using the lock functionality correctly in this case:
Thread1:
1. rulebase.getStatelessSession()
1.1 rulebase.lock()
1.2 rulebase.removeRule(rule1)
1.3 rulebase.removePackage(somePackage)
1.4 rulebase.addPackage(someCompiledNewPackage)
1.5 rulebase.unlock()
Thread2
2. rulebase.getStatelessSession()
Threads 1 and 2 use the same rulebase object.
Quesion 1: What does it mean having the rulebase be locked in Thread1? Does it mean, that if Thread2 is trying to get the session , say, between steps1.2 and 1.3 of the Thread1 , then it will wait until Thread1 released the lock on the rulebase?
If that's true, that's exactly what I need.
Question 2: I also see methods rulebase.getAdditionsSinceLock() and getRemovalsSinceLock(). Who will see anything when calling these functions - Thread1 after operation 1.5? before 1.5?
Or Thread2? But, which lock would it mean to Thread2? - it woudl probably not even be aware of any locks being place by other threads??
Thanks!
Marina
16 years, 4 months
firing rules again?
by Marcin Krol
Hello everyone,
I have a session to rule base:
RuleBase rb = RuleBaseFactory.newRuleBase();
rb.addPackage( pb.getPackage() );
StatefulSession session = rb.newStatefulSession();
Two questions:
1. When I call session.fireAllRules(), I find I can no longer add new
facts using this session. Strictly speaking, I can do that, but they
there doesn't seem to be any effect re firing rules.
Do I have to declare the new session? Is there some way to add the new
facts and rules to the session after fireAllRules has been called?
2. Is there an equivalent of (refresh rule-name) that is implemented in
CLIPS?
Regards,
Marcin
16 years, 4 months
Fire rule only when all the fact objects sent during a specific period match the WHEN part
by ganesh.p
I need to create a rule with following requirements:
There is a fact class called SystemInfo which contains idle information of a
sytem
public class SystemInfo {
private double idle; //System idle percentage
public void setIdle(double idle) {
this.idle = idle;
}
public double getIdle() {
return this.idle;
}
}
The SystemInfo objects are continuously sent to DROOLS (StatelessSession)
with 5 second delay.
I need to create a rule
rule "Start_New_Process_If_System_is_70%_Idle_Continuously_for_60_Seconds"
when SystemInfo (idle >= 70) //Idle continuously for 60 seconds
then
// start new process
end
I need to fire this rule only if all the 12 SystemInfo objects which are
sent with 5 seconds delay for 60 seconds, match the condition "idle >= 70".
Even if a single SystemInfo doesn't match this condition then this rule
shouldn't be fired.
I am using DROOLS 4.0. Please help me in implementing the WHEN condition.
Thanks
-Ganesh
--
View this message in context: http://www.nabble.com/Fire-rule-only-when-all-the-fact-objects-sent-durin...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 4 months
Re: [rules-users] strategy for rulebase updates in a cluster?
by Marina
Edson,
Thanks for the quick reply.
I'll go for the approach #1. I am also thinking of using Stateless sessions rather than Stateful to basically always ensure that the engine does one full run over a static set of rules. I am not going to maintain long-running sessions at all.
One small question: when I create a StatelessSession from the rulebase, will it also maintain a reference to the rulebase? In which case, when the session is done, is it going to release the reference? I'm trying to see if I am going to have some dangling references to old rulebases (R1) laying around even after the ruleBase variable in the singleton class points to the new R2 rulebase instance already. Just to make sure that old references are GC-ed properly, since, as I understand, rulebases are pretty big objects.
Thanks,
Marina
----- Original Message ----
From: Edson Tirelli <tirelli(a)post.com>
To: Rules Users List <rules-users(a)lists.jboss.org>
Sent: Wednesday, August 20, 2008 1:55:15 PM
Subject: Re: [rules-users] strategy for rulebase updates in a cluster?
Marina,
Operations over an existing rulebase (add/remove rules/packages) will lock existing stateful sessions in order to be executed making them thread safe. But having said that, for a JEE environment I would design it as in scenario #1.
I.e., requests are arriving and being handled by sessions created against a rulebase R1. When an update is made, the application will simply create a new rulebase (R2) and your singleton will now reference R2. Working memories have an internal reference to the rulebase used to create them, so existing sessions will work with the old rulebase until disposed, but any new request will create sessions against R2 (since your singleton now holds a reference for R2).
I like this solution because it provides, IMO, the safest and more consistent way of handling existing sessions, since you ensure a complete reasoning cycle (session) is made with an immutable set of rules, that can be easily tracked by whatever audit mechanisms you use. Only new requests will use the new rulebase, and are ensured to also complete the reasoning with immutable rules.
If you have long running sessions, though, the problem is a bit different and there is no other option IMO, except using solution #2.
Hope it helps,
Edson
2008/8/20 Marina <ppine7(a)yahoo.com>
Hello,
I'm integrating DRools into a J2EE application and need to understand how it behaves in a multi-threaded distributed environment. I have many questions about thread safety but for now I'll ask about clustering only and post other questions separately.
So, as I understand, Drools per se is not cluster-aware. In my current design I have a singleton class, RuleEngineMAnager, that holds a reference to a RuleBase. Hence, there will be one instance of a rulebase per JVM per machine in a cluster. Rules can be added/modified from any node in the cluster, and the modifications have to me made visible in all rulebases.
The way I handle it now is by using a DB as the shared unit and setting up a flag when modifications are made in any JVM. Next time a request comes in for the rule engine to run all rule , the flag is checked and the RuleBase is updated.
So, my question is about how to handle the rulebase updates most efficiently.
I see two possibilities:
1. ditch the rulebase completely, build a new Package of rules , create a new rulebase and add the package to it
2. Use the same rulebase - just remove the old package of rules and load in the new one.
The issues here are:
-- what if there are operations going on in the rule engine, invoked from other threads, at the time I want to do either 1 or 2?
Say, in the scenario #2, the rule engine is running all rules in one thread. At the same time I'm asking it to drop the rule package from another thread and add the new one. Is it going to finish running all rules with the old package, return results, and only then do the update of the package?
And in the scenario #1, if the rule engine is running the rules, and I try to destroy the old rule base - are those operations sequential?
Any suggestions as to how to design this functionality in the most efficient and safe way?
thank you!
Marina Popova
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
JBoss, a division of Red Hat @ www.jboss.com
16 years, 4 months
object creation
by thomas kukofka
Hello
the created OutputObjects should be used by the GUI to be displayed
and only reasonable filled OutputObjects should be displayed.
Furthermore an OutputObject of one type can be input for another rule
to create output of another type.
I'm not sure what's better and easier to handle in my case, lazy
initialisation or insert from outside.
Is there anything more to consider using lazy initialisation?
Regards
Thomas
Any reason you can't assert the OutputObject from outside? (i.e.
before rules fire) You're essentially doing lazy initialization, and
that's always a bit more complex.
--- On Thu, 8/21/08, thomas kukofka <thomaskukofka at web.de> wrote:
> From: thomas kukofka <thomaskukofka at web.de>
> Subject: [rules-users] object creation
> To: "Rules Users List" <rules-users at lists.jboss.org>
> Date: Thursday, August 21, 2008, 9:03 AM
> Hello,
>
> I have a rule which creates an object in the consequence
> part and updates
> this object each time teh rule is executed. So the object
> has to be created
> only the first time.
> So I always need two rules, one init rule which creates the
> object if it
> doesn't exist yet and one if it already exists and it
> should only be
> updated:
>
> rule "init rule"
> when
> "condition"
> AND
> not OutputObject()
> then
> OutputObject oo = new OutputObject();
> insert(oo);
>
> rule "update rule"
> when
> "condition"
> AND
> oo: OutputObject()
> then
> #do something with the object
> update(oo);
>
> But is it really neccessary to write an extra rule only to
> create the
> output-fact initially? Is it possible/good style to make
> this in one single
> rule?
>
> Appreciate your help.
>
> Regards
> Thomas
**
16 years, 4 months