Fw: Some Querries on Drools
by Sumeet Karawal
Hi Everybody,
I had posted this earlier. It would be very greatful if anybody could help
me on these queries, any suggestions or any document that I can refer to.
Thanks and Regards,
Sumeet Karawal
Mailto: sumeet.karawal(a)tcs.com
From: Sumeet Karawal/MUM/TCS
To: rules-users(a)lists.jboss.org
Date: 04/18/2011 06:58 PM
Subject: Some Querries on Drools
Hello All,
I have some queries regarding use of drools as rule engine for my
Application. It would be very helpful if I get some guidance regarding
these:
1) I have an application in which a user logs in, and according to his
profile he is provided with some benefits, and rule engine check for the
eligibility criteria. But if hundreds of thousands of user will log in at
same time, then what will be the performance accordingly. Like, these
concurrent users hitting the server, and so many threads will be generated
and many number of rules will be fired in the session. Will this hamper the
performance of Rule Engine.
2) Suppose I have an application using drools. I create EAR / WAR file of
that application and deploy it on some other system. Would it be still
possible for me to change the rules on the fly. Or some dependencies might
have to be managed.
3) How can we manage sessions in drools? Suppose we are having different
stateful sessions in our application, but time consumption when we
fireAllRules() exceeds the expected time. So is there a mechanism to kill,
restart the session in drools. Could I get some help/document regarding
session Management on drools.
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
13 years, 8 months
How to use for loop in drools!!!!
by Sumeet Karawal
Hello Everybody,
I am not getting, on how to do for loop functionality in drools.
Like for instance, my functionality has :
for(i = 0; i<10; i++)
{
c.setCustomerCount(c.getCustomerCount() + 1);
}
How to translate this code into rule language (.drl).
It would be helpful if anybody could guide me on this.
Thanks and 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
13 years, 8 months
Trying to compare int and String objects
by Manuel Ortiz
Hello everybody:
I'm trying to write rules in which fact int attributes and fact String
attributes should be compared in condition elements. When I compare them,
let's say from int to String,
rule
when
Fact1($intAttr : attrInt1)
Fact2(attrString == $intAttr)
....
the rule seems to behave OK, whereas when I compare them from String to int,
rule
when
Fact1($stringAttr : attrString1)
Fact2(attrInt == $stringAttr)
....
I get a RuntimeDroolsException( "Conversion to long not supported from
java.lang.String").
I've taken a look at the code which throws the exception,
BaseObjectClassField.getLongValue() and found that it only accepts Number
and Date objects to be converted to long.
...
if ( value instanceof Number ) {
return ((Number) value).longValue();
} else if ( value instanceof Date ) {
return ((Date) value).getTime();
}
...
Is it possible to add String to long conversion via Long.parseLong(str) or
is there any reason not to allow this conversion?.
Thank you again for your time.
Best regards,
Manuel Ortiz.
13 years, 8 months
calling static error function....thread safe?
by marunam
Hello,
I am calling static "error" function in ValidationHelper class from drool
rules. My rules are going to be executed in spring based web application. Is
this call to an "error" function thread safe?
public class ValidationHelper {
public static void error (RuleContext kcontext, Object... context) {
KnowledgeRuntime knowledgeRuntime = drools.getKnowledgeRuntime();
ValidationReport validationReport = (ValidationReport)
knowledgeRuntime
.getGlobal(ValidationConstants.VALIDATION_REPORT_GLOBAL);
ReportFactory reportFactory = (ReportFactory)
knowledgeRuntime
.getGlobal(ValidationConstants.REPORT_FACTORY_GLOBAL);
validationReport.addMessage(reportFactory.createMessage(
Message.Type.ERROR, messageKey, context));
}
}
import org.drools.runtime.rule.RuleContext;
import function ValidationHelper.error;
...
rule test
when
#condition
then
error(drools)
Please advise
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/calling-static-error-function-thread-sa...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months
Can't Get Rules To Modify Object State in Mortgage Example of Drools-5.1.1 + Guvnor
by Jeff Drost
Hello, I'm attempting to use the Drools 5.1.1 Guvnor with the
"mortgage-example" available in the drools downloads. It looks like I get
some, but not all of the rules, to run. I suspect it has something to do
with how I insert the rules, as I can debug and poke around and see the
rules present in the KnowledgeBase object when I debug.
The examples distro on the drools homepage is labeled 5.1.1, however if you
go to the directory
"drools-examples-brms\mortgage-example\mortgage-client\lib" you'll see the
5.0.1 Drools JARs . Therefore using the examples in a pristine fashion,
without modification, was not an option.
I've instead written the class below, and used the XML configuration file
below. In guvnor I've turned the authentication off (not that it makes a
difference when you are requesting a PKG file), imported
"mortgage-sample-repository.xml", and rebuilt the packages.
However, when I run the source code below, it looks as if only one rule
runs, and the state of any of the objects below (i.e. approved or unapproved
mortgage app) fails to change.
Any ideas what I'm doing wrong?
*MyMortgageApplication.java:*
public class MyMortgageApplication {
public static void main(String[] args) throws Throwable {
KnowledgeBase knowledgeBase = createKnowledgeBase();
StatefulKnowledgeSession session =
knowledgeBase.newStatefulKnowledgeSession();
FactType appType =
knowledgeBase.getFactType("mortgages","LoanApplication");
FactType incomeType = knowledgeBase.getFactType("mortgages","IncomeSource");
session.addEventListener(new DebugAgendaEventListener());
session.addEventListener(new DebugWorkingMemoryEventListener());
Object application = appType.newInstance();
Object income = incomeType.newInstance();
appType.set(application, "amount", 25000);
appType.set(application, "deposit", 1500);
appType.set(application, "lengthYears", 20);
incomeType.set(income, "type", "Job");
incomeType.set(income, "amount", 65000);
appType.set(application, "amount", 25000);
appType.set(application, "deposit", 1);
appType.set(application, "lengthYears", 1);
incomeType.set(income, "type", "Job");
incomeType.set(income, "amount", 6);
System.out.println("FactCount: " + session.getFactCount());
session.insert(appType);
session.insert(incomeType);
System.out.println("FireAllRules: " + session.fireAllRules());
System.out.println("FactCount: " + session.getFactCount());
session.dispose();
System.exit(0);
}
private static KnowledgeBase createKnowledgeBase() {
KnowledgeAgentConfiguration kaconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
kaconf.setProperty("drools.agent.scanDirectories", "false");
kaconf.setProperty("drools.agent.newInstance", "true");
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("MortgageAgent", kaconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("my-guvnor.xml"));
return kagent.getKnowledgeBase();
}
}
*my-guvnor.xml:*
<change-set xmlns="http://drools.org/drools-5.0/change-set"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/change-setdrools-change-set-5.0.xsd">
<add>
<resource
source="
http://localhost/drools-guvnor/org.drools.guvnor.Guvnor/package/mortgages...
"
basicAuthentication="enabled" username="admin" password="admin" type="PKG"
/>
</add>
</change-set>
13 years, 8 months
Re: [rules-users] Searching a list - Is Drools the answer?
by Drools User
> Wolfgang, Thanks for the reply. The N threads means I need to be able to
> query/check the list very often. The through put is undetermined, but could
> be as high as several hundred lookups per second. It seems you agree that
> using a stateful session would require me to process each request serially,
> unless I wanted to spin up several copies of my facts. That would seem
> inefficient.
>
> Date: Mon, 18 Apr 2011 10:05:29 +0200
>> From: Wolfgang Laun <wolfgang.laun(a)gmail.com>
>> Subject: Re: [rules-users] Searching a list - Is Drools the answer?
>> To: Rules Users List <rules-users(a)lists.jboss.org>
>>
>> It's possible that putting the "constants" into rules will result in a
>> rule
>> building process that's more complex than what you need to do if this data
>> is in facts. Notice that your Object_1 has to participate in (at least)
>> three different matching scenarios, which is a simple thing for a fact,
>> but
>> may need three rules if FirstName and LastName are literals in rules.
>>
>> A (serially) reusable Stateful Session would need to be set up with the
>> 10k
>> facts. A search request enters an object, produces results, and retracts
>> the
>> request; then the session is ready for the next request. (The N threads
>> you
>> are talking about results from some overall application context?)
>>
>> Regards
>> Wolfgang
>>
>> 2011/4/18 Drools User <drools2030(a)gmail.com>
>>
>> > I have been using Drools for several years, but just with constraints
>> > (rules) on 1 set of objects at a time. Think many rules, few facts in a
>> > stateless session. I have been given a new project at the office which
>> > requires having about 10-100k facts and few rules. These 10k facts would
>> be
>> > basically constants, a list of things I need to search on each request.
>> I
>> > would then need to load a single object, based on a request to see if my
>> > request object matched the list. It is somewhat a simple search, but I
>> need
>> > to be able to inject aliases and search partial matches in addition to
>> exact
>> > matches. A generic example:
>> >
>> > List:
>> > Object 1 (FirstName=John, LastName=Smith)
>> > Object 2 (FirstName=Will, LastName=Smith)
>> > Object 3 (FirstName=Jon, LastName=Smith)
>> >
>> > Request/Use Case:
>> > LastName=Smith, would return all 3 objects, but marked as single match
>> > LastName=Smith, Firstname =John, Would return object 1, as exact double
>> > match, and Object 3 a nickname double match
>> > LastName=Smith, Firstname =J, Would return object 1 and 3, as partial
>> match
>> >
>> > In the second request, I need to run all names through a nickname
>> DB/list
>> > to explode the name into multiple search patterns. Possibly using (
>> > http://code.google.com/p/nickname-and-diminutive-names-lookup/)
>> >
>> > Hopefully that explains a bit about the problem.
>> >
>> > So to the question, there are a few ways to solve this. The simplest is
>> > just SQL from a DB, but this proves to be slow to search all the ways I
>> > need. I need sub second response times. An in memory DB is another
>> possible
>> > solution we are looking at. Not to think of Drools as the golden hammer,
>> but
>> > this smells like something I can use Drools for. My first thought was to
>> > load the "List" as facts into a stateful session. My concern is wouldn't
>> I
>> > need N copies of the list loaded to have N threads? This would be
>> > inefficient if so. I know rules aren't copied per working memory, but is
>> > there a way to create a master working memory for facts to use?
>> >
>> > So my second thought is to convert my List into rules so they would only
>> be
>> > stored once in the system, regardless of number of threads using the
>> engine.
>> >
>> > What do you guys think, am I on the right track with this? Is Drools a
>> good
>> > way to do this or is there something better I have overlooked?
>> >
>> > Thank you for taking the time.
>> > -Drools user
>>
>
>
13 years, 8 months
Re: [rules-users] rules-users Digest, Vol 53, Issue 62
by Drools User
Wolfgang, Thanks for the reply. The N threads means I need to be able to
query/check the list very often. The through put is undetermined, but could
be as high as several hundred lookups per second. It seems you agree that
using a stateful session would require me to process each request serially,
unless I wanted to spin up several copies of my facts. That would seem
inefficient.
Date: Mon, 18 Apr 2011 10:05:29 +0200
> From: Wolfgang Laun <wolfgang.laun(a)gmail.com>
> Subject: Re: [rules-users] Searching a list - Is Drools the answer?
> To: Rules Users List <rules-users(a)lists.jboss.org>
>
> It's possible that putting the "constants" into rules will result in a rule
> building process that's more complex than what you need to do if this data
> is in facts. Notice that your Object_1 has to participate in (at least)
> three different matching scenarios, which is a simple thing for a fact, but
> may need three rules if FirstName and LastName are literals in rules.
>
> A (serially) reusable Stateful Session would need to be set up with the 10k
> facts. A search request enters an object, produces results, and retracts
> the
> request; then the session is ready for the next request. (The N threads you
> are talking about results from some overall application context?)
>
> Regards
> Wolfgang
>
> 2011/4/18 Drools User <drools2030(a)gmail.com>
>
> > I have been using Drools for several years, but just with constraints
> > (rules) on 1 set of objects at a time. Think many rules, few facts in a
> > stateless session. I have been given a new project at the office which
> > requires having about 10-100k facts and few rules. These 10k facts would
> be
> > basically constants, a list of things I need to search on each request. I
> > would then need to load a single object, based on a request to see if my
> > request object matched the list. It is somewhat a simple search, but I
> need
> > to be able to inject aliases and search partial matches in addition to
> exact
> > matches. A generic example:
> >
> > List:
> > Object 1 (FirstName=John, LastName=Smith)
> > Object 2 (FirstName=Will, LastName=Smith)
> > Object 3 (FirstName=Jon, LastName=Smith)
> >
> > Request/Use Case:
> > LastName=Smith, would return all 3 objects, but marked as single match
> > LastName=Smith, Firstname =John, Would return object 1, as exact double
> > match, and Object 3 a nickname double match
> > LastName=Smith, Firstname =J, Would return object 1 and 3, as partial
> match
> >
> > In the second request, I need to run all names through a nickname DB/list
> > to explode the name into multiple search patterns. Possibly using (
> > http://code.google.com/p/nickname-and-diminutive-names-lookup/)
> >
> > Hopefully that explains a bit about the problem.
> >
> > So to the question, there are a few ways to solve this. The simplest is
> > just SQL from a DB, but this proves to be slow to search all the ways I
> > need. I need sub second response times. An in memory DB is another
> possible
> > solution we are looking at. Not to think of Drools as the golden hammer,
> but
> > this smells like something I can use Drools for. My first thought was to
> > load the "List" as facts into a stateful session. My concern is wouldn't
> I
> > need N copies of the list loaded to have N threads? This would be
> > inefficient if so. I know rules aren't copied per working memory, but is
> > there a way to create a master working memory for facts to use?
> >
> > So my second thought is to convert my List into rules so they would only
> be
> > stored once in the system, regardless of number of threads using the
> engine.
> >
> > What do you guys think, am I on the right track with this? Is Drools a
> good
> > way to do this or is there something better I have overlooked?
> >
> > Thank you for taking the time.
> > -Drools user
>
13 years, 8 months
Drools Decision trees
by saihegde
Is there a reference implementation towards Decision Trees (knowing what
Rules that were executed). I know we can have listeners to working memory to
log rule events. But what we have been thinking is that there should be a
better way of knowing why a certain rule failed than writing negative
condition/'s for every positive rule that exists in your BRMS.
Thanks!
Sai
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Decision-trees-tp2834847p2834847...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 8 months