Fire Rule in Stateless Knowledge Session

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Fire Rule in Stateless Knowledge Session

snehils
Hi,

I am new in Drools. I am using Drools version 5.1.0

My requirement is kind of request response, where I have to perform some checks for the request and respond the result. Hence, I decided to go with stateless knowledge session.

I have prepared .DRL file and it contains set of rules. When some request receives I have to identify the rule(s) belongs to that request and then fire the rule(s).

I am not able to figure out how to categories the rules request wise in DRL file? Also, how to fire only those rules which belongs to the category.

For example, there are three kinds of requests Rq1, Rq2 and Rq3. There are rules in DRL file: R1, R2, R3, R4 and R5. R1, R2 belongs to Rq1, R3 belongs to Rq2 and R4, R5 belongs to Rq3.

When some request receives only its belonging rules should be fired. For example, on receiving of Rq2 only R3 should be fired.

Please provide me some code snipped or link.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

laune
Basically you could do

rule RL1
when
   Request( type == "Rq1",... )

which limits the rule to Requests of this type.

-W

On 8 August 2011 10:23, snehils <[hidden email]> wrote:
Hi,

I am new in Drools. I am using Drools version 5.1.0

My requirement is kind of request response, where I have to perform some
checks for the request and respond the result. Hence, I decided to go with
stateless knowledge session.

I have prepared .DRL file and it contains set of rules. When some request
receives I have to identify the rule(s) belongs to that request and then
fire the rule(s).

I am not able to figure out how to categories the rules request wise in DRL
file? Also, how to fire only those rules which belongs to the category.

For example, there are three kinds of requests Rq1, Rq2 and Rq3. There are
rules in DRL file: R1, R2, R3, R4 and R5. R1, R2 belongs to Rq1, R3 belongs
to Rq2 and R4, R5 belongs to Rq3.

When some request receives only its belonging rules should be fired. For
example, on receiving of Rq2 only R3 should be fired.

Please provide me some code snipped or link.

Thanks


--
View this message in context: http://drools.46999.n3.nabble.com/Fire-Rule-in-Stateless-Knowledge-Session-tp3234893p3234893.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

Esteban
In reply to this post by snehils
You can have a map of kbases containing the specific rules. When a request arrives, you get the proper kbase from the map and create a ksession from it. 

Another way could be to use Control Objects in your rules.

Best Regards, 

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


On Mon, Aug 8, 2011 at 10:23 AM, snehils <[hidden email]> wrote:
Hi,

I am new in Drools. I am using Drools version 5.1.0

My requirement is kind of request response, where I have to perform some
checks for the request and respond the result. Hence, I decided to go with
stateless knowledge session.

I have prepared .DRL file and it contains set of rules. When some request
receives I have to identify the rule(s) belongs to that request and then
fire the rule(s).

I am not able to figure out how to categories the rules request wise in DRL
file? Also, how to fire only those rules which belongs to the category.

For example, there are three kinds of requests Rq1, Rq2 and Rq3. There are
rules in DRL file: R1, R2, R3, R4 and R5. R1, R2 belongs to Rq1, R3 belongs
to Rq2 and R4, R5 belongs to Rq3.

When some request receives only its belonging rules should be fired. For
example, on receiving of Rq2 only R3 should be fired.

Please provide me some code snipped or link.

Thanks


--
View this message in context: http://drools.46999.n3.nabble.com/Fire-Rule-in-Stateless-Knowledge-Session-tp3234893p3234893.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

snehils
In reply to this post by laune
I thought of doing same but this will become slow when number of rules are more (100 or 200 rules). The given condition will be checked in each rule.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

Mattias Nilsson Grip
In reply to this post by snehils

snehils wrote:

>
> Hi,
>
> I am new in Drools. I am using Drools version 5.1.0
>
> My requirement is kind of request response, where I have to perform some
> checks for the request and respond the result. Hence, I decided to go with
> stateless knowledge session.
>
> I have prepared .DRL file and it contains set of rules. When some request
> receives I have to identify the rule(s) belongs to that request and then
> fire the rule(s).
>
> I am not able to figure out how to categories the rules request wise in
> DRL file? Also, how to fire only those rules which belongs to the
> category.
>
> For example, there are three kinds of requests Rq1, Rq2 and Rq3. There are
> rules in DRL file: R1, R2, R3, R4 and R5. R1, R2 belongs to Rq1, R3
> belongs to Rq2 and R4, R5 belongs to Rq3.
>
> When some request receives only its belonging rules should be fired. For
> example, on receiving of Rq2 only R3 should be fired.
>
> Please provide me some code snipped or link.
>
> Thanks
>
One way could be to have conditions in your rules that check what kind of
request it is. Without knowing your problem in detail it's hard to know if
this is feasible. E.g. you could insert a request object as a fact into the
session and let rules in R3 have condition:

when
   Request(type = "Rq2")
   ...

If you switch to stateful session instead of stateless you could use agenda
groups to achieve something similar. See Drools Expert user guide for
details on how to use agenda groups.

/Mattias

--
View this message in context: http://drools.46999.n3.nabble.com/Fire-Rule-in-Stateless-Knowledge-Session-tp3234893p3234944.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

Esteban
In reply to this post by snehils
Because of node sharing, it shouldn't be that bad if you use the Request() constraint as the first conditional element of your rules. You must also use always the same order when checking for more than 1 request. 

For example:

rule "Rule1"
when
   Request ( type == "Rq1" || type == "Rq2")
   ...
then
  ....
end

rule "Rule2"
when
   Request ( type == "Rq1" || type == "Rq2")  <--- Constraints are in the same order
   ...
then
  ....
end

Wolfgang, please correct me if I'm wrong :)

Best Regards,

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


On Mon, Aug 8, 2011 at 10:41 AM, snehils <[hidden email]> wrote:
I thought of doing same but this will become slow when number of rules are
more (100 or 200 rules). The given condition will be checked in each rule.

--
View this message in context: http://drools.46999.n3.nabble.com/Fire-Rule-in-Stateless-Knowledge-Session-tp3234893p3234939.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

Mattias Nilsson Grip
In reply to this post by snehils
snehils wrote
I thought of doing same but this will become slow when number of rules are more (100 or 200 rules). The given condition will be checked in each rule.
The Rete algorithm will make sure that this does not become slow when number of rules increases. Multiple rules with the same condition will only result in one node in the Rete tree. I.e. each unique condition will only be checked once.

/Mattias
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

snehils
Thanks Mattias...
Now Wolfgang's solution will work

Mattias Nilsson Grip wrote
The Rete algorithm will make sure that this does not become slow when number of rules increases. Multiple rules with the same condition will only result in one node in the Rete tree. I.e. each unique condition will only be checked once.

/Mattias
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

snehils
In reply to this post by Esteban
Can you give some reference link ot code snippet? that would be helpful :)

Esteban wrote
You can have a map of kbases containing the specific rules. When a request
arrives, you get the proper kbase from the map and create a ksession from
it.

Another way could be to use Control Objects in your rules.

Best Regards,

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

snehils
In reply to this post by Mattias Nilsson Grip
Is there any disadvantage switching in stateful session?

Mattias Nilsson Grip wrote
If you switch to stateful session instead of stateless you could use agenda
groups to achieve something similar. See Drools Expert user guide for
details on how to use agenda groups.

/Mattias
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

Mattias Nilsson Grip
snehils wrote
Is there any disadvantage switching in stateful session?
If you switch to stateful sessions you have to ensure that you call the dispose-method on your session when you are done with it. Otherwise you could get a memory leak. Other than that I can't think of any disadvantage.

/Mattias
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Fire Rule in Stateless Knowledge Session

kashif10
I am facing memory leak while using StatefulKnowledgeSession

I found that after dispose call the global objects still intact.
ksession.dispose()

See print statementd.;

 [STDOUT] %%%%% reading before dispose:p1.Readings@49fff2ef

 [STDOUT] %%%%% reading after dispose:p1.Readings@49fff2ef

Any idea how to clear globals from memory?