Java Client for Drools
by Dwarka
Hello All,
I am new to JBoss Drools and i am finding out a way to deploy drools and
invoke or fire rules from a java program. By reading some books and surfing
tro internet i learnt that there are two types of deployment model i.e. push
and pull type. I understood everything in both the models expect for one
thing in common,
"The Creation of a KnowledgeBase from a
resource"
In the Drools environment we say a resource lives inside a repository. In my
case i used Drools Guvnor to author the drl file and used the default
configuration JCR storage(jackrabbit file store). But i am not able to find
any of my drl's in the file store. Now i need to write a java client which
can load this drl file and fire the rules as required. I am very clear that
i am missing a very important part, but i was not lucky enough find an
answer for this.
In this case i need to know how to retrieve a resource from the jackrabbit
repository and use the same in my java program.
Thanks in advance,
Dwarka
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Java-Client-for-Drool...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 1 month
Problem in Concurrent execution of Rules
by Nikhil S. Kulkarni
Hi All,
I am using JBOSS Drools 5.0. The problem which I am currently facing is concurrent execution of Rules.
I am using RuleBase to get Session object
i.e.
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
StatelessSession session = ruleBase.newStatelessSession();
Session.execute(ArrayList of Facts);
In the application I am creating separate RuleBase and session object for each request of process.
Now the Problem is as follows :-
There are currently two users logged in the System.
Suppose User 1 clicks a button to process 100 members of Data using Rules and User 2 clicks same button to process same 100 members of Data,
When request of User 1 comes to Rule Engine, it starts processing its data but as User 2 comes to Rule Engine, The engine stops processing the request
of User 1 and continues processing Request of User 2 because of which I am not getting same output in both the cases though the Input to Rules is same.
If I do the process one after the another then I am getting correct values but it is not working for Concurrent execution.
Thanks & Regards,
Nikhil S. Kulkarni
MASTEK LTD.
In the US, we're called MAJESCOMASTEK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 years, 1 month
About for and inheritance
by Chris Woodrow
Hi,
I recently find out a few issues using for, and I wanted to share it with
you. I made a simple exemple to illustrate my purpose.
My classes are (I did not represent accessors & constructors):
public class Cheese {
protected String name;
}
public class FrenchCheese extends Cheese{
private String smell;
}
public class Person {
private Cheese likes;
}
Here is my rule set :
package rules
rule "likes cheese"
when
$person : Person ()
Cheese( ) from $person.getLikes()
then
System.out.println("likes cheese");
end
rule "likes french cheese"
when
$person : Person ()
FrenchCheese( ) from $person.getLikes()
then
System.out.println("likes french cheese");
end
First test :
Cheese cheese = new FrenchCheese("good", "camembert");
Person person = new Person();
person.setLikes(cheese);
Output :
likes french cheese
likes cheese
Wich is expected...
Second test :
Cheese cheese = new Cheese();
Person person = new Person();
person.setLikes(cheese);
Output :
likes french cheese
likes cheese
That's the first strange thing. As far as I am concerned, rule "likes french
cheese" should not match (since a Cheese is not a FrenchCheese).
I made a change to the second rule :
rule "likes french cheese"
when
$person : Person ()
FrenchCheese( smell == "good" ) from $person.getLikes()
then
System.out.println("likes french cheese");
end
Third test :
Cheese cheese = new Cheese();
Person person = new Person();
person.setLikes(cheese);
output :
It throwed an exception : Exception in thread "main"
java.lang.ClassCastException: rules.Cheese
I am not saying the ClassCastException is not to expect in such a case but I
think I would simply expect it not to match (as far as a Cheese is not a
FrenchCheese).
Chris
15 years, 1 month
Drools Planner, when/how is a cloned solution used?
by aliquip
I’ve known about drools planner for quite some time and always wanted to play
with it, but now that I finally found something to solve with it, I’m afraid
that I don’t fully understand drools planner, or I’m simply using it wrong.
The problem I try to solve/optimize is optimizing a sequence of events,
where each event can be influence by the previous events.
Background info (not essential for my main question):
-----------------------------------------------------------------------
More specifically I try to optimize a series of “attacks” for the webgame
utopia, so that they do most damage, each attack changes the targets. To put
it simply:
We have the following attackers and targets
1. Attacker A: [offense :55, nw:100, attacks_made: 0]
2. Attacker B: [offense :75, nw:150, attacks_made: 0]
3. Attacker C: [offense :40, nw:80, attacks_made: 0]
1. Target A: [defense :30, nw:50, land:500]
2. Target B: [defense :21, nw:50, land: 500]
3. Target C: [defense :60, nw:80, land: 800]
Particularities: each attacker can, at max make 4 attacks, but each attack
uses offense. Each attack destroys defense, nw and land. Attacks take 10% of
land or less (less when nw attacker is largetly different from that of the
target).
So for example the following sequence is possible
• Attacker B: [offense :80, nw:150, attacks_made: 0] attacks Target C:
[defense :60, nw:80, land: 800]
• -> new status Attacker B: [offense :20, nw:150, attacks_made: 1]
• -> new status Target C: [defense :54, nw:70, land: 720]
• Attacker A: [offense :55, nw:100, attacks_made: 0] attacks Target C:
[defense :54, nw:70, land: 720]
• -> new status Attacker A: [offense 1, nw:100, attacks_made: 1]
• -> new status Target C: [defense :49, nw:65, land: 620]
• Attacker C: [offense :40, nw:80, attacks_made: 0] attacks Target B:
[defense :21, nw:50, land: 500]
• new status Attacker C xxxx
• new status Target B: [defense :19, nw:45, land: 450] >Now Attacker B can
attack this target<
• Attacker B: [offense :20, nw:150, attacks_made: 1] attacks Target B:
[defense :19, nw:45, land: 450
• etc
• etc
In my implementation, the solver has a sequence of attack. The possible
moves are attacks and undo attacks. Undo attacks are nasty, because when
there are, for example 20 attacks, and the 15th is undo, attacks 16 is
invalid if it’s on the same target as attack 15, or is by the same attacker,
attack 17 is invalid if it’s by the same attacker or on the same target as
15 OR attacks 16 was invalid and 17 has same attacker or target, etc. This
is taken care of by removing all invalidated attacks.
This has 1 large problem: removing an attack that invalidates multiple
attacks has an enormous impact on
the score.
-----------------------------------------------------------------------
Anyway, my problem is that I don’t fully understand what is going on, or I
have a bug in my logic, I suppose the last.
What I expected the solver to do:
• clone the solution to clone[1]
• clone clone[1] to clone[1.1], do some semi random moves on clone[1.1]
• clone clone[1] to clone[1.2], do some semi random moves on clone[1.2]
• clone clone[1] to clone[1.3], do some semi random moves on clone[1.3]
• get the solution with the best score, for example clone[1.3]
• clone clone[1.3] to clone[1.3.1], do some semi random moves on
clone[1.3.1]
• clone clone[1.3] to clone[1.3.2], do some semi random moves on
clone[1.3.2]
• etc
• get the solution with the best score, for example clone[1.3.1]
• clone clone[1.3.1] to clone[1.3.1.1], do some semi random moves on
clone[1.3.1.1]
• etc
• etc
But what appears to happen is:
• clone the solution to clone[1]
• do move on clone[1], if result is better than previous result, clone
clone[1] to clone[1.1]
• do move on clone[1], if result is better than previous result, clone
clone[1] to clone[1.2]
• do move on clone[1], if result is better than previous result, clone
clone[1] to clone[1.3]
• etc
• etc
Thus effectively for every move the same, initial, solution is used. And all
the clones are used for is to remember the best solution.
This is important for my problem because a solution has a sequence of
events, a move either adds an event, or removes one or multiple events. It
turns out that, even though the solution is cloned, my moves always affect
the sequence in the original solution. This seems strange to me.
Any insights that could help me understand whether or t what I’m doing makes
sense?
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Planner-when-h...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 1 month
No activations created for condition with two checks for collection size
by Tina Vießmann
Hi,
I'm trying to check the following condition:
when
$currentLowLimit : LimitViolationEvent ( limitTypes.size == 1
&& limitTypes contains LimitTypes.ACTIVE_LOWER_LIMIT
&& parameterNames.size == 1 )
limitType and parameterNames are both Sets. I know events exists which
satisfy the condition. But why are there no activation created at all?
Thank you,
Tina
15 years, 1 month
Knowledge Base and Guvnor
by Dean Whisnant
Hi all, thank you for all the help in the past.
I'm to a point in my project of implementing Guvnor built packages into my java code that calls drools.
In the past I used the simple solution of building the knowledge agent on a .drl file as follows:
//Setup the knowledge session for drools
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Standard837P.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
A little background before the question. My project includes one set of rules that are standard business logic, we'll call that STANDARD for now and one set of rules that any one of my 45 customers could have created, we'll call CUSTOMER, on our common guvnor server. My java code knows which customer is running the app, so determining which two packages I want to fire is simple. The part that is not as straight forward for me is how I then I migrate using the guvnor urls in my above code.
I thought it would be as easy as to replace "Standard837P.drl" above with the STANDARD url and create a second add that would use the CUSTOMER url.
I also want all of my STANDARD rules applied before my CUSTOMER rules are applied. This got me thinking that I need to have two independent knowledge bases running so that I fire all in the first and then fire all in the second.
Backing up a bit again, my application looks through an incoming file inserting facts into the knowledge base for one medical claim line item, fires rules, writes out results to a database, and then moves on to the next claim line item in the file.
1) What would the syntax need to be to implement the STANDARD and CUSTOMER urls?
2) Would I need to create two independent knowledge bases?
3) DO you see any performance issues in this arrangement?
Thank you!
Dean
15 years, 1 month
Drools 5.1: What happens when an incremental KA rebuild fails?
by ljnelson
Seeing some strange things on a production system.
I have Drools set up to use a KnowledgeAgent.
I have the KnowledgeAgent set up to scan resources and directories.
The agent is pointed at--let's say--C:\LEAD\rules, where "LEAD" is the name
of the project in question and "rules" is a directory underneath which I
would like to have several .drl files.
I begin by placing one well-known, valid .drl file under there. That
obviously loads up fine and the rules go into effect.
If I deliberately introduce a syntax error, I hear about it in the
logs--that's fine too.
But if I then remove the syntax error, it's as though scanning stops. The
KnowledgeAgent appears as though it is never rebuilt again, so it appears
simply to be broken.
I will obviously supply more details as needed, but thought I'd fire this
quick flare to see if anyone knows of any simple cause here.
Best,
Laird
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-5-1-What-happe...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 1 month