Re: [rules-users] Unable to create restriction '[QualifiedIndentifierRestr: != $nissan.pos ]' for field 'pos' , in the rule 'Racing order'

2008-08-20 Thread Maxim Veksler
On Wed, Aug 20, 2008 at 8:57 PM, Edson Tirelli <[EMAIL PROTECTED]> wrote:

>
>You are using variables (like $nissan) before binding them. Remember you
> can only use a variable "after" binding it.
>
>[]s
>Edson
>

Please allow me to a related question, regarding drools 3.0.x

In this LHS example, mentioned in this thread :

"""
   $fred : Golfer( name == "Fred")
   $bob : Golfer( name == "Bob",
   position != $fred.position,
   color == "plaid",
   color != $fred.color)
"""

$fred is a bind variable, but how is it possible to use a data member from
this variable inside another node's ruling ?

Judging from Drools 3, this should have failed with compilation errors,
assuming that it's a new feature of Drools 4, is there a possibility to
implement this behavior in drools3? as it would be great help for me in my
rules.

// Just for reference, the way I would implement the above logic in Drools 3
is :

"""
   $fred : Golfer( name == "Fred", $fredPosition : position, $fredColor
: color)
   $bob : Golfer( name == "Bob",
   position != $fredPosition,
   color == "plaid",
   color != $fredColor)
"""


Thank you,
Maxim.

>
>
> 2008/8/20 Marcin Krol <[EMAIL PROTECTED]>
>
> Hello everyone,
>>
>> I managed to produce my first example of Drools rules. However, I am
>> having problems with some field restrictions:
>>
>> Racing order:Unable to create restriction '[QualifiedIndentifierRestr: !=
>> $nissan.pos ]' for field 'pos' in the rule 'Racing order'
>>
>> The problem is only SOME field restrictions produce this error. Other
>> field restrictions don't!
>>
>> If anybody has a hint or knows why this is not working, please let me
>> know, I would greatly appreciate it.
>>
>>
>>
>> The rules are:
>>
>>
>> #created on: 2008-08-20
>> package com.sample
>>
>> #list any import classes here.
>>
>> #declare any global variables here
>>
>> dialect "mvel"
>>
>> import com.sample.Car;
>>
>> rule "Racing order"
>>when
>>
>>// Porsche was not red
>>$porsche : Car( manufacturer == "Porsche",
>>pos != $nissan.pos,
>>pos != $subaru.pos,
>>color != "red"
>>//color != "blue",
>>//color != $nissan.color,
>>//color != $subaru.color
>>)
>>
>>
>>// First car was Nissan
>>$nissan : Car( manufacturer == "Nissan",
>> pos == 1,
>> color != $subaru.color,
>> color != $porsche.color )
>>
>>// Subaru was blue
>>$subaru : Car( manufacturer == "Subaru",
>>//pos == 2,
>>pos != $nissan.pos,
>>pos != $porsche.pos,
>>color == "blue" )
>>
>>// 2nd car was silver
>>Car( pos == 2,
>>  color == "silver",
>>  this in ( $nissan, $subaru, $porsche ) )
>>
>>then
>>System.out.println( "Nissan " + $nissan.getPos() + " " +
>> $nissan.getColor() );
>>System.out.println( "Subaru " + $subaru.getPos() + " " +
>> $subaru.getColor() );
>>System.out.println( "Porsche " + $porsche.getPos() + " " +
>> $porsche.getColor() );
>>
>> end
>>
>>
>>
>>
>>
>> The Car.java file:
>>
>>
>> package com.sample;
>>
>>public class Car {
>>private String manufacturer;
>>private String color;
>>private int pos;
>>
>>public Car() {
>>
>>}
>>
>>public Car(String manufacturer, String color, int pos) {
>>super();
>>this.color = color;
>>this.pos = pos;
>>this.manufacturer = manufacturer;
>>}
>>
>>public String getManufacturer() {
>>return this.manufacturer;
>>}
>>
>>public float getPos() {
>>return this.pos;
>>}
>>
>>public String getColor() {
>>return this.color;
>>}
>>}
>>
>>
>>
>>
>> The CarExample.java file, which is the main app:
>>
>>
>>
>> package com.sample;
>>
>> import java.io.InputStreamReader;
>>
>> import org.drools.RuleBase;
>> import org.drools.RuleBaseFactory;
>> import org.drools.StatefulSession;
>> import org.drools.compiler.PackageBuilder;
>> import com.sample.Car;
>>
>> public class CarExample {
>>
>>public static void main(String[] args) throws Exception {
>>
>>final PackageBuilder builder = new PackageBuilder();
>>builder.addPackageFromDrl( new InputStreamReader(
>> CarExample.class.getResourceAsStream( "CarExample.drl" ) ) );
>>
>>final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
>>ruleBase.addPackage( builder.getPackage() );
>>
>>final StatefulSession session = ruleBase.newStatefulSession();
>>
>>String[] names = new String[] { "Nissan", "Subaru", "Porsche"};
>>String[] colors = new String[] { "red", "blue", "silver"};
>>int[] pos

Re: [rules-users] Problem using RuleFlows .

2008-08-20 Thread Amninder

Hi Harsh
I need help in the beginning stage of drools. could you guide me in how to
deploy a full Drools Project in my java application(local host)? also i am
unable to operate JBRMS i am finding a lot of problems uploading my project
also where actually the reposirory is made when a rule is created through
JBRMS

Thanks 
Amninder Kaur

Harsh Jetly wrote:
> 
> 
> 
> Hi ,
> The version of Drools that I have used is 4.0.4
> 
> I have used ruleflow groups to create my rule file.
> It has a split node (XOR) in which I specify a constraint on which a
> ruleflow-group is to be selected .
> 
> Insert arraylists as facts in the working memory one by one.
> 
> The problem I face is that when I insert these arraylists in the same
> session , it doesn't evaluate every constraint in the split node .
> 
> 
> The work around I am using , it that I create a new session for every
> arraylist , this works just fine . But creating a new session always is an
> overhead .
> 
> Can you please assist me with this situation .
> 
> Thank You
> 
> Harsh Jetly
> 
> 
> 
> 
> Larsen & Toubro Infotech Ltd.
> www.Lntinfotech.com
> 
> This Document is classified as:
> 
> |--|
> | [X]  |
> |--|L&T Infotech Proprietary   |--|
>| [ ]  |
>|--|L&T Infotech Confidential  
> |--|
>| [
> ]  |
>   
> |--|
> L&T Infotech Internal Use Only   |--|
>  | [ ]  |
>  |--|L&T Infotech General Business
> 
> This Email may contain confidential or privileged information for the
> intended recipient (s) If you are not the intended recipient, please do
> not
> use or disseminate the information, notify the sender and delete it from
> your system.
> 
> 
> __
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Problem-using-RuleFlows-.-tp18866433p19082394.html
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] strategy for rulebase updates in a cluster?

2008-08-20 Thread Edson Tirelli
   Marina,

   Yes, stateless sessions have a reference to the rulebase, so that they
can execute, but they automatically release all resources after executing.
The difference to stateful sessions is that you must call dispose() manually
for stateful sessions to release their resources. So you are fine.

   []s
   Edson

2008/8/20 Marina <[EMAIL PROTECTED]>

> 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 <[EMAIL PROTECTED]>
> To: Rules Users List 
> 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 <[EMAIL PROTECTED]>
>
>> 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@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
>
>
> --
> Edson Tirelli
> J

[rules-users] Re: Cause(LHS) of rule an query brings different results.

2008-08-20 Thread Tomasz Krzywicki
Answering to myself but maybe somebody is interested ;)
Based on my experiments query should be rewritten to
encapsulate first order logic operations within one type brackets.

 query "my query"
i:  Item(  ( x == "A" && q > 0)  ||  ( x == "B"  && q > 1 )  )

//   Lets forget about this part ;)
// $x: Ref( name=="Exp" ) and
// Item( x == "A", quantity > 0 ) from $x.items
 end

I still can not find a way to point to items directly inserted
into working memory or referenced as property ( Set of Items )
of other type - at the same time.

So far I am using rule to contribute to some temporary fact
and then retrieving and querying this fact. Not my preferable
solution but works :)

tk.


On Mon, Aug 18, 2008 at 5:15 PM, Tomasz Krzywicki <[EMAIL PROTECTED]> wrote:
> I have query and rule which have identical LHS or "cause"
> for some unknown for me reason my query returns only one Item
> while rule is fired multiple times showing multiple occurences of my
> desired facts.
>
> query "my query"
>i:  Item( x == "A", q > 0 ) or
>Item( x == "B", q > 1 ) or
>
> $x: Ref( name=="Exp" ) and
> Item( x == "A", quantity > 0 ) from $x.items
> end
>
>
> rule "my query test"
>  when
>i:  Item( x == "A", q > 0 ) or
>Item( x == "B", q > 1 ) or
>
> $x: Ref( name=="Exp" ) and
>Item( x == "A", quantity > 0 ) from $x.items
>  then
>System.out.println ("FOUND: "+i);
> end
>
> There must be something fundamentally wrong in the approach I am
> taking ;)
>
> I am using drools 4.0.7
>
> Thanks in advance
>
> tk
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] Drools job opportunity

2008-08-20 Thread Jim Bury
Any idea where the position is located or if it can be remote?



Jim B.



From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of arina he
Sent: Wednesday, August 20, 2008 2:12 PM
To: Rules Users List
Subject: [rules-users] Drools job opportunity



Hi experts, here is an excellent (good pay too) job, check it out.

http://jobs.athico.com/job/e6096e40842d5299272736ee75fb5aba/?d=1&source=
jobroll

No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.138 / Virus Database: 270.6.6/1623 - Release Date:
8/20/2008 8:12 AM

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] strategy for rulebase updates in a cluster?

2008-08-20 Thread 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 <[EMAIL PROTECTED]>
To: Rules Users List 
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 <[EMAIL PROTECTED]>

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@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
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Drools job opportunity

2008-08-20 Thread arina he
Hi experts, here is an excellent (good pay too) job, check it out.
http://jobs.athico.com/job/e6096e40842d5299272736ee75fb5aba/?d=1&source=jobroll
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Re: ClassCastException using RuleAgent

2008-08-20 Thread Vinicius Carvalho
Never mind, upgraded to 4.0.7 and forgot to upgrade mvel...

[]s

On Wed, Aug 20, 2008 at 2:33 PM, Vinicius Carvalho <
[EMAIL PROTECTED]> wrote:

> Hello there! I'm getting an classcastexception when I try to insert facts
> on my RuleAgent:
>
> Properties props = new Properties();
> props.put("url", "
> http://localhost:8080/drools-jbrms/org.drools.brms.JBRMS/package/com.acme.rules/latest
> ");
> props.put("newInstance", "true");
> props.put("name","testagent");
> RuleAgent agent = RuleAgent.newRuleAgent(props);
> StatefulSession session = agent.getRuleBase().newStatefulSession();
> session.insert(fact);
>
> The error happens on the session.insert method. It also happens inside my
> Seam application When I try to insert the facts on the working memory. My
> drools package contains the model that I've extracted from my seam
> application.
> If I run it using a local drl file, it works fine. This problem only
> happens with the rule agent
>
> Could someone give me a hand on this?
>
> Regards
>
> --
> "In a world without fences and walls, who needs Gates and Windows?"
>



-- 
"In a world without fences and walls, who needs Gates and Windows?"
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Unable to create restriction '[QualifiedIndentifierRestr: != $nissan.pos ]' for field 'pos' , in the rule 'Racing order'

2008-08-20 Thread Edson Tirelli
   You are using variables (like $nissan) before binding them. Remember you
can only use a variable "after" binding it.

   []s
   Edson

2008/8/20 Marcin Krol <[EMAIL PROTECTED]>

> Hello everyone,
>
> I managed to produce my first example of Drools rules. However, I am having
> problems with some field restrictions:
>
> Racing order:Unable to create restriction '[QualifiedIndentifierRestr: !=
> $nissan.pos ]' for field 'pos' in the rule 'Racing order'
>
> The problem is only SOME field restrictions produce this error. Other field
> restrictions don't!
>
> If anybody has a hint or knows why this is not working, please let me know,
> I would greatly appreciate it.
>
>
>
> The rules are:
>
>
> #created on: 2008-08-20
> package com.sample
>
> #list any import classes here.
>
> #declare any global variables here
>
> dialect "mvel"
>
> import com.sample.Car;
>
> rule "Racing order"
>when
>
>// Porsche was not red
>$porsche : Car( manufacturer == "Porsche",
>pos != $nissan.pos,
>pos != $subaru.pos,
>color != "red"
>//color != "blue",
>//color != $nissan.color,
>//color != $subaru.color
>)
>
>
>// First car was Nissan
>$nissan : Car( manufacturer == "Nissan",
> pos == 1,
> color != $subaru.color,
> color != $porsche.color )
>
>// Subaru was blue
>$subaru : Car( manufacturer == "Subaru",
>//pos == 2,
>pos != $nissan.pos,
>pos != $porsche.pos,
>color == "blue" )
>
>// 2nd car was silver
>Car( pos == 2,
>  color == "silver",
>  this in ( $nissan, $subaru, $porsche ) )
>
>then
>System.out.println( "Nissan " + $nissan.getPos() + " " +
> $nissan.getColor() );
>System.out.println( "Subaru " + $subaru.getPos() + " " +
> $subaru.getColor() );
>System.out.println( "Porsche " + $porsche.getPos() + " " +
> $porsche.getColor() );
>
> end
>
>
>
>
>
> The Car.java file:
>
>
> package com.sample;
>
>public class Car {
>private String manufacturer;
>private String color;
>private int pos;
>
>public Car() {
>
>}
>
>public Car(String manufacturer, String color, int pos) {
>super();
>this.color = color;
>this.pos = pos;
>this.manufacturer = manufacturer;
>}
>
>public String getManufacturer() {
>return this.manufacturer;
>}
>
>public float getPos() {
>return this.pos;
>}
>
>public String getColor() {
>return this.color;
>}
>}
>
>
>
>
> The CarExample.java file, which is the main app:
>
>
>
> package com.sample;
>
> import java.io.InputStreamReader;
>
> import org.drools.RuleBase;
> import org.drools.RuleBaseFactory;
> import org.drools.StatefulSession;
> import org.drools.compiler.PackageBuilder;
> import com.sample.Car;
>
> public class CarExample {
>
>public static void main(String[] args) throws Exception {
>
>final PackageBuilder builder = new PackageBuilder();
>builder.addPackageFromDrl( new InputStreamReader(
> CarExample.class.getResourceAsStream( "CarExample.drl" ) ) );
>
>final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
>ruleBase.addPackage( builder.getPackage() );
>
>final StatefulSession session = ruleBase.newStatefulSession();
>
>String[] names = new String[] { "Nissan", "Subaru", "Porsche"};
>String[] colors = new String[] { "red", "blue", "silver"};
>int[] positions = new int[] { 1, 2, 3 };
>
>for ( int n = 0; n < names.length; n++ ) {
>for ( int c = 0; c < colors.length; c++ ) {
>for ( int p = 0; p < positions.length; p++ ) {
>session.insert( new Car( names[n], colors[c],
> positions[p]) );
>}
>}
>}
>
>session.fireAllRules();
>session.dispose();
>}
>
>
>
> }
>
> ___
> rules-users mailing list
> rules-users@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
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] strategy for rulebase updates in a cluster?

2008-08-20 Thread Edson Tirelli
   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 <[EMAIL PROTECTED]>

> 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@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
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] ClassCastException using RuleAgent

2008-08-20 Thread Vinicius Carvalho
Hello there! I'm getting an classcastexception when I try to insert facts on
my RuleAgent:

Properties props = new Properties();
props.put("url", "
http://localhost:8080/drools-jbrms/org.drools.brms.JBRMS/package/com.acme.rules/latest
");
props.put("newInstance", "true");
props.put("name","testagent");
RuleAgent agent = RuleAgent.newRuleAgent(props);
StatefulSession session = agent.getRuleBase().newStatefulSession();
session.insert(fact);

The error happens on the session.insert method. It also happens inside my
Seam application When I try to insert the facts on the working memory. My
drools package contains the model that I've extracted from my seam
application.
If I run it using a local drl file, it works fine. This problem only happens
with the rule agent

Could someone give me a hand on this?

Regards

-- 
"In a world without fences and walls, who needs Gates and Windows?"
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Unable to create restriction '[QualifiedIndentifierRestr: != $nissan.pos ]' for field 'pos' , in the rule 'Racing order'

2008-08-20 Thread Marcin Krol

Hello everyone,

The same problem regards the "golfing example" from examples project. 
Adding nearly any restrictions, e.g. this one:


position != $tom.position,


in rules for Bob:

// Bob is wearing plaid pants
$bob : Golfer( name == "Bob",
position != $fred.position,
position != $joe.position,
position != $tom.position,
color == "plaid",
color != $fred.color,
color != $joe.color )


produces an error:

find solution:Unable to create restriction '[QualifiedIndentifierRestr: 
!= $tom.position ]' for field 'position' in the rule 'find solution'



How to resolve this?

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Unable to create restriction '[QualifiedIndentifierRestr: != $nissan.pos ]' for field 'pos' , in the rule 'Racing order'

2008-08-20 Thread Marcin Krol

Hello everyone,

I managed to produce my first example of Drools rules. However, I am 
having problems with some field restrictions:


Racing order:Unable to create restriction '[QualifiedIndentifierRestr: 
!= $nissan.pos ]' for field 'pos' in the rule 'Racing order'


The problem is only SOME field restrictions produce this error. Other 
field restrictions don't!


If anybody has a hint or knows why this is not working, please let me 
know, I would greatly appreciate it.




The rules are:


#created on: 2008-08-20
package com.sample

#list any import classes here.

#declare any global variables here

dialect "mvel"

import com.sample.Car;

rule "Racing order"
when

// Porsche was not red
$porsche : Car( manufacturer == "Porsche",
pos != $nissan.pos,
pos != $subaru.pos,
color != "red"
//color != "blue",
//color != $nissan.color,
//color != $subaru.color
)


// First car was Nissan
$nissan : Car( manufacturer == "Nissan",
 pos == 1,
 color != $subaru.color,
 color != $porsche.color )

// Subaru was blue
$subaru : Car( manufacturer == "Subaru",
//pos == 2,
pos != $nissan.pos,
pos != $porsche.pos,
color == "blue" )

// 2nd car was silver
Car( pos == 2,
  color == "silver",
  this in ( $nissan, $subaru, $porsche ) )

then
System.out.println( "Nissan " + $nissan.getPos() + " " + 
$nissan.getColor() );
System.out.println( "Subaru " + $subaru.getPos() + " " + 
$subaru.getColor() );
System.out.println( "Porsche " + $porsche.getPos() + " " + 
$porsche.getColor() );


end





The Car.java file:


package com.sample;

public class Car {
private String manufacturer;
private String color;
private int pos;

public Car() {

}

public Car(String manufacturer, String color, int pos) {
super();
this.color = color;
this.pos = pos;
this.manufacturer = manufacturer;
}

public String getManufacturer() {
return this.manufacturer;
}

public float getPos() {
return this.pos;
}

public String getColor() {
return this.color;
}
}




The CarExample.java file, which is the main app:



package com.sample;

import java.io.InputStreamReader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.compiler.PackageBuilder;
import com.sample.Car;

public class CarExample {

public static void main(String[] args) throws Exception {

final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( 
CarExample.class.getResourceAsStream( "CarExample.drl" ) ) );


final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( builder.getPackage() );

final StatefulSession session = ruleBase.newStatefulSession();

String[] names = new String[] { "Nissan", "Subaru", "Porsche"};
String[] colors = new String[] { "red", "blue", "silver"};
int[] positions = new int[] { 1, 2, 3 };

for ( int n = 0; n < names.length; n++ ) {
for ( int c = 0; c < colors.length; c++ ) {
for ( int p = 0; p < positions.length; p++ ) {
session.insert( new Car( names[n], colors[c], 
positions[p]) );

}
}
}

session.fireAllRules();
session.dispose();
}



}

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Where is WorkingMemoryFactoryBean?

2008-08-20 Thread Ray Pendergraph
I am trying create my RuleBase and WorkingMemory via a Spring configuration. 
This older post http://forum.springframework.org/archive/index.php/t-16289.html 
sort of looks like what I am trying to do with WorkingMemoryFactoryBean. It 
seems the org.drools.spring. package does not seem to be a part of recent 
Drools implementations. I could probably implement the Spring widgets myself 
but I am wondering why these Spring artifacts were removed. Is there a more 
preferred or better way of doing this now?

thanks,

ray



  ___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] strategy for rulebase updates in a cluster?

2008-08-20 Thread Marina
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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] new user - running examples

2008-08-20 Thread Marcin Krol

Paul Sentosa wrote:

I experienced some problems too when I tried to import the examples for 
the first time.
I can't remember what I exactly did to solve them, but I end up deleting 
the project dependencies, and instead I put them(drools compiler, core, 
and other required plugins - listed in maven, but unfortunately didn't 
work for me as well)  as referenced libraries. Try to clean and re-build 
your project and it should work


Thanks for reply.

I ended up re-creating packages and examples in the sample project 
(created using the Drools button), this works too.


Regards,
Marcin




- Original Message 
From: Marcin Krol <[EMAIL PROTECTED]>
To: rules-users@lists.jboss.org
Sent: Tuesday, August 19, 2008 8:52:56 PM
Subject: [rules-users] new user - running examples

Hello everyone,

I am totally new to Drools (I have basic exposure to Java, nothing
more), hope that someone helps me with the following problem:

I have successfully imported Eclipse plugin and ran the DroolTest.java
example in Eclipse Europa (it worked OK). Then I imported Eclipse
example (4.0.7) project into Eclipse workspace.


But most of .drl files show error markers with messages like:

Rule 01:Unable to resolve ObjectType 'Cashflow'  (example4.drl)

Now when I try to run Example4.java, I get the error:

The project: drools-compiler which is referenced by the classpath,
does not exist.


In Eclipse: menu Project | Properties | Java Build Path | Projects tab
shows drools-core and drools-compiler with yellow warning icons. Button
Edit is grayed out, there's nothing I can do to fix those items.

I have added drools-core-4.0.7.jar and drools-compiler-4.0.7.jar in Add
External JARs on Libraries tab, but this does nothing to resolve the
problem.

How do I fix those problems so I can run examples?

Regards,
Marcin


___
rules-users mailing list
rules-users@lists.jboss.org 
https://lists.jboss.org/mailman/listinfo/rules-users




___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] new user - running examples

2008-08-20 Thread Paul Sentosa
I experienced some problems too when I tried to import the examples for the 
first time.
I can't remember what I exactly did to solve them, but I end up deleting the 
project dependencies, and instead I put them(drools compiler, core, and other 
required plugins - listed in maven, but unfortunately didn't work for me as 
well)  as referenced libraries. Try to clean and re-build your project and it 
should work



- Original Message 
From: Marcin Krol <[EMAIL PROTECTED]>
To: rules-users@lists.jboss.org
Sent: Tuesday, August 19, 2008 8:52:56 PM
Subject: [rules-users] new user - running examples

Hello everyone,

I am totally new to Drools (I have basic exposure to Java, nothing 
more), hope that someone helps me with the following problem:

I have successfully imported Eclipse plugin and ran the DroolTest.java 
example in Eclipse Europa (it worked OK). Then I imported Eclipse 
example (4.0.7) project into Eclipse workspace.


But most of .drl files show error markers with messages like:

 Rule 01:Unable to resolve ObjectType 'Cashflow'  (example4.drl)

Now when I try to run Example4.java, I get the error:

 The project: drools-compiler which is referenced by the classpath, 
does not exist.


In Eclipse: menu Project | Properties | Java Build Path | Projects tab 
shows drools-core and drools-compiler with yellow warning icons. Button 
Edit is grayed out, there's nothing I can do to fix those items.

I have added drools-core-4.0.7.jar and drools-compiler-4.0.7.jar in Add 
External JARs on Libraries tab, but this does nothing to resolve the 
problem.

How do I fix those problems so I can run examples?

Regards,
Marcin


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



  ___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] some basic questions to grouping

2008-08-20 Thread psentosa

Edson, thanks a lot for your very enlightening explanation.
Wouldn't it be nice if the official DROOL documentation also include this
information? It would help people to create more effective rules, I think :)

Regards



Edson Tirelli-3 wrote:
> 
> 1. Rete network is built at rulebase "compile" time, i.e., when you add
> packages to the Rulebase:
> 
> ruleBase.addPackageFromDrl( ... ); // and similar API calls
> 
>At assert time, the facts are propagated and when you call
> fireAllRules(), active rules are fired.
> 
> 2. These are part of the internal optimization algorithms. Let me try to
> simplify things, but talking about 2 optimizations we have:
> 
> * node sharing: every time you have the same condition (even among
> different
> rules), the engine will try to share them, so that you have it executed
> only
> once. Writing conditions in the same order helps to achieve this. So, for
> the first example, when you have the Gender constraints, it will share the
> Gender.FEMALE constraints among the 1000 rules and will execute it only
> once. The Gender.MALE constraint is also executed once, and then you have
> 2
> executions in total.
> 
> * alpha hashing: this is a bit more complicate, but when you have mutually
> exclusive constraints on the same field, you know that only one of them is
> correct. So, if you have 100 different constraints like this:
> 
> Person( countryOfBirth == Country.CANADA...
> Person( countryOfBirth == Country.BRAZIL...
> 
> You know that only one of them will be true. The engine detects that and
> instead of evaluating every constraint, where 99 of them will fail, it
> will
> hash all the constraints.
> Then, when a fact is asserted (lets say contryOfBirth is BRAZIL), instead
> of
> going through all the constraints, it applies the hash function on the
> attribute value (BRAZIL) and knows where the constraint is. So it will
> only
> evaluate that constraint and forget about the others, since they will fail
> anyway.
> 
> Having said that, the first example (gender) is also mutually exclusive,
> but
> there are only 2 possible values. What happens is that there is a cost to
> calculate the hash value on the alpha hashing optimization and the cost
> does
> not pay off if you have only 2 possible values. In fact, after doing some
> research we found that the ideal cardinality to activate the alpha hashing
> optimization is 3, but that is a parameter you can configure using
> RuleBaseConfiguration (either by API or by a system property). So, by
> default, that optimization only kicks in when you have 3 or more possible
> values (like the country of birth) and not with 2 or less (like gender).
> 
> 3. Sorry, I don't see your attachement. But anyway, rule-flow,
> agenda-groups
> and etc are used to control rule "firing" order, not rule evaluation. Rete
> will evaluate your rules eagerly, even if your group is not active. In
> your
> case, with mutually exclusive constraints in your patterns, you should not
> worry about that. Let the engine optimize the matching for you. If you
> find
> performance problems, then come back and we can see if there is any
> sub-optimal rules in your rule set. Until then, don't worry with it.
> 
> []s
> Edson
> 
> 2008/8/19 psentosa <[EMAIL PROTECTED]>
> 
>>
>> Jakob, Edson, thanks a lot for your replies especially on agenda vs
>> activation-group :)
>>
>> But please allow me to ask some further questions:
>> 1. The LHS of the rules is evaluated at "assert time".
>> When is actually the RETE network built? On assertion, will a fact then
>> be
>> propagated over the network?
>>
>> 2. The example with Gender and countryOfBirth:
>>For the gender example, you said the condition will be executed only
>> twice. So I assumed it's because there are 2 possibilities of gender. But
>> the example with countryOfBirth with 100 possibilities, why only once?
>>
>> 3. Back to my problem I described before:
>>   Before I read your reply (Edson's), I try to follow the suggestion from
>> Jakob, namely using the ruleflow-group. So I came up with a the
>> ruleflow-graph I attached (please have a look if you don't mind)
>> http://www.nabble.com/file/p19053522/regulation-check.rfm
>> regulation-check.rfm.
>> I try to describe the following hierarchy:
>> There are certain rules only for young people; if they are older, than it
>> will be checked, whether he/she is a male/female. Another group of rules
>> is
>> only valid for females, the rest of the rules are valid for both male and
>> female. does the graph correspond correctly to the problem I describe? Is
>> it
>> better to use such grouping or like you said, just write my patterns and
>> constraints as much as possible (without the grouping)?
>> Again thanks in advance!
>>
>> Regards
>>
>>
>>
>>
>> Edson Tirelli-3 wrote:
>> >
>> > 1. when you are saying "rules fire", does this mean: matching/checking
>> the
>> > LHS of rule, or executin