[rules-users] Define global varibales to several drl files

2010-01-26 Thread orchid

Hi,

I would like to ask if it possible to define a global variables which can be
accessed from rules which are defined in several drl files? 

My idea behind this is to hold some structure (array for example) which will
hold the results of all rules. The rules are defined in several files. All
RHS of the rules should update this structure.

Thanks in advance...
-- 
View this message in context: 
http://n3.nabble.com/Define-global-varibales-to-several-drl-files-tp138974p138974.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


[rules-users] KnowledgeAgent and Guvnor restart

2010-01-26 Thread Gerret Hansper
Hello,

I have got an issue with the KnowledgeAgent that seems not to survive a Guvnor 
restart. The scenario is as follows:

* We use Drools 5.0 
* On our application server we create a KnowledgeAgent 
applying a ChangeSet that points to a package binary on a separate Guvnor 
server 
like so:

SystemEventListenerFactory.setSystemEventListener(new 
SystemEventLogger()); 
ResourceFactory.getResourceChangeNotifierService().start(); 
ResourceFactory.getResourceChangeScannerService().start(); 
KnowledgeAgent agent = 
KnowledgeAgentFactory.newKnowledgeAgent(workflowName); 
agent.applyChangeSet(changeSet);

* Creating the kbase, registering globals and running sessions works fine. 
* We shut down Guvnor (or the connection goes down, this was how we spotted the 
problem) and restart it after a minute 
* We then try to run sessions from the 
same agent as above via 
kagent.getKnowledgeBase().newStatefulKnowledgeSession(); 
which returns a ksession, but then setting a global we get

  java.lang.RuntimeException: Unexpected global [log]   
  at 
  org.drools.common.AbstractWorkingMemory.setGlobal(AbstractWorkingMemory.java:5
  50) 
  at 
  org.drools.impl.StatefulKnowledgeSessionImpl.setGlobal(StatefulKnowledgeSessio
  nImpl.java:284)

From the debugger I can see that indeed the ruleBase's globals map is empty. 
The 
SystemEventLogger indicates that the KnowledgeAgent unsubscribes from its 
resource when Guvnor is down and rebuilds its kbase. Also, it stops scanning 
the 
resource and does not find it once Guvnor is up again. (See log snippet below).
 
Wouldn't it be better in these cases to keep the resource as is in memory and 
try to rescan? I figure that as long as the resource is specified in the 
changeSet it should be considered part of the kbase and not be removed if it 
cannot be found. 

For the time being, does anyone have a suggestion how to avoid these problems? 
We could catch the RuntimeException and recreate the KnowledgeAgent, but 
perhaps 
there is a better way?

Thanks, Gerret


-- SystemEventLog -- 
# Guvnor is up here 
07:58:01,881 ResourceChangeScanner attempt to scan 1 resources 
07:58:02,209 ResourceChangeScanner thread is waiting for 60 
07:58:15,067 ResourceChangeScanner attempt to scan 1 resources 
# Guvnor goes down here 
07:58:16,738 ResourceChangeScanner removed resource=[UrlResource 
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] 
07:58:16,738 ResourceChangeNotification received ChangeSet notification 
07:58:16,738 ResourceChangeScanner thread is waiting for 60 
07:58:16,738  ResourceChangeNotification processing ChangeSet 
07:58:16,738 ResourceChangeNotification ChangeSet removed resource=[UrlResource 
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] for 
listener=org.drools.agent.impl.knowledgeagenti...@1053d6d 
07:58:16,738 ResourceChangeNotification ChangeSet removed resource=[UrlResource 
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] for 
listener=org.drools.agent.impl.knowledgeagenti...@b71c17 
07:58:16,738 KnowledgeAgent received ChangeSet changed notification 
07:58:16,738 KnowledgeAgent received ChangeSet changed notification 
07:58:16,738 KnowledgAgent applying ChangeSet 
07:58:16,738 ResourceChangeNotification thread is waiting for queue update 
07:58:16,738 KnowledgAgent applying ChangeSet 
07:58:16,738 KnowledgeAgent unsubscribing from resource=[UrlResource 
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] 
07:58:16,738 ResourceChangeNotification unsubscribing 
listener=org.drools.agent.impl.knowledgeagenti...@1053d6d to 
resource=[UrlResource path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] 
07:58:16,738 KnowledgeAgent rebuilding KnowledgeBase using ChangeSet 
07:58:16,738 KnowledgeAgent unsubscribing from resource=[UrlResource 
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] 
07:58:16,738 ResourceChangeNotification unsubscribing 
listener=org.drools.agent.impl.knowledgeagenti...@b71c17 to 
resource=[UrlResource path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] 
07:58:16,738 
KnowledgeAgent rebuilding KnowledgeBase using ChangeSet 
07:58:16,738 KnowledgeAgent new KnowledgeBase now built and in use 
07:58:16,738 KnowledgeAgent new KnowledgeBase now built and in use 
07:59:02,202 ResourceChangeScanner attempt to scan 0 resources 
07:59:02,202 ResourceChangeScanner thread is waiting for 60 
# Guvnor back up here 
07:59:16,731 ResourceChangeScanner attempt to scan 0 resources 
07:59:16,731 ResourceChangeScanner thread is waiting for 60


___
rules-users mailing list
rules-users@lists.jboss.org

Re: [rules-users] infinite loop in decision table

2010-01-26 Thread djb

Hi Thomas,

I implemented the latch system as you suggested, but came to a problem when
running batches of data.

Since the latch is set when the rule fires, you can't have that rule fire
for more than one piece of data.

So, with this method, for batch processing, you need to include a UUID into
each latch.

Are there any other patterns?  All this UUID and Latch/Flag functionality
seems really a lot more complicated than it should be.

I suppose I can write it to only process one piece of data at a time, but
that might end up slower.


Regards,
Daniel
-- 
View this message in context: 
http://n3.nabble.com/infinite-loop-in-decision-table-tp129933p139034.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


[rules-users] Is it possible to restore StatefulKnowledgeSession?

2010-01-26 Thread Grigoriev, Grigoriy
Hi everyone,

I have a ruleflow that calls a ruleflow group.

In rhs of one of the rules in the ruleflow group an Exception is thrown. After 
that, when I insert a new fact into the working memory, the activations for the 
new fact are not created. To make the session work again, I call 
.getAgenda().clear(). However, session works incorrectly after that.

Is there any other way to 'restore' the StatefulKnowledgeSession, after it has 
thrown an Exception or should I always create a new session in this case?

With best regards,
Grigoriy.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] infinite loop in decision table

2010-01-26 Thread Swindells, Thomas
As I see it you have a number of options,

As you have said you could scope your latches so that they only apply to a 
particular object, rather than generating a UUID you can probably get away with 
using the object reference itself; however you will also need to watch out for 
memory leaks, this can probably be solved by having a rule which removes 
latches when the object they refer to is no longer in the knowledge base.

You may also be able to use drools flow to fire the pieces in one at a time but 
not need to recreate the entire state again.

Your best bet (if possible) is to restructure your model so that your actions 
don't modify the objects that your conditions are based upon.  For instance 
rather than actually performing any changes you populate result objects and use 
a query after the rules have finished firing to retrieve them all.  This does 
have the downside however that it removes one of the advantages of a rules 
engine that the actions can cause other rules to activate and deactivate.

Hope this helps, if not hopefully someone else will have some better insights 
than me,

Thomas

 -Original Message-
 From: rules-users-boun...@lists.jboss.org [mailto:rules-users-
 boun...@lists.jboss.org] On Behalf Of djb
 Sent: 26 January 2010 09:07
 To: rules-users@lists.jboss.org
 Subject: Re: [rules-users] infinite loop in decision table


 Hi Thomas,

 I implemented the latch system as you suggested, but came to a problem when
 running batches of data.

 Since the latch is set when the rule fires, you can't have that rule fire
 for more than one piece of data.

 So, with this method, for batch processing, you need to include a UUID into
 each latch.

 Are there any other patterns?  All this UUID and Latch/Flag functionality
 seems really a lot more complicated than it should be.

 I suppose I can write it to only process one piece of data at a time, but
 that might end up slower.


 Regards,
 Daniel
 --
 View this message in context: http://n3.nabble.com/infinite-loop-in-decision-
 table-tp129933p139034.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

This message is confidential and intended only for the addressee. If you have 
received this message in error, please immediately notify the 
postmas...@nds.com and delete it from your system as well as any copies. The 
content of e-mails as well as traffic data may be monitored by NDS for 
employment and security purposes.
To protect the environment please do not print this e-mail unless necessary.

An NDS Group Limited company. www.nds.com

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


Re: [rules-users] ConsequenceException when retract from entry point

2010-01-26 Thread jschmied

solved:

rule test 3
when
$t : My_Type() from  entry-point NM
then
retract($t)  // -- now without referencing the entry-point
end   
-- 
View this message in context: 
http://n3.nabble.com/ConsequenceException-when-retract-from-entry-point-tp136290p139191.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] Define global varibales to several drl files

2010-01-26 Thread orchid

Can someone help me please with this question?
-- 
View this message in context: 
http://n3.nabble.com/Define-global-varibales-to-several-drl-files-tp138974p139254.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


[rules-users] KnowledgeAgent and Guvnor restart

2010-01-26 Thread Gerret Hansper
Hello,

I have got an issue with the KnowledgeAgent that seems not to survive a Guvnor 
restart. The scenario is as follows:

* We use Drools 5.0 
* On our application server we create a KnowledgeAgent 
applying a ChangeSet that points to a package binary on a separate Guvnor 
server 
like so:

SystemEventListenerFactory.setSystemEventListener(new 
SystemEventLogger()); 
ResourceFactory.getResourceChangeNotifierService().start(); 
ResourceFactory.getResourceChangeScannerService().start(); 
KnowledgeAgent agent = 
KnowledgeAgentFactory.newKnowledgeAgent(workflowName); 
agent.applyChangeSet(changeSet);

* Creating the kbase, registering globals and running sessions works fine. 
* We shut down Guvnor (or the connection goes down, this was how we spotted the 
problem) and restart it after a minute 
* We then try to run sessions from the 
same agent as above via 
kagent.getKnowledgeBase().newStatefulKnowledgeSession(); 
which returns a ksession, but then setting a global we get

  java.lang.RuntimeException: Unexpected global [log]   
  at 
  org.drools.common.AbstractWorkingMemory.setGlobal(AbstractWorkingMemory.java:5
  50) 
  at 
  org.drools.impl.StatefulKnowledgeSessionImpl.setGlobal(StatefulKnowledgeSessio
  nImpl.java:284)

From the debugger I can see that indeed the ruleBase's globals map is empty. 
The 
SystemEventLogger indicates that the KnowledgeAgent unsubscribes from its 
resource when Guvnor is down and rebuilds its kbase. Also, it stops scanning 
the 
resource and does not find it once Guvnor is up again. (See log snippet below).
 
Wouldn't it be better in these cases to keep the resource as is in memory and 
try to rescan? I figure that as long as the resource is specified in the 
changeSet it should be considered part of the kbase and not be removed if it 
cannot be found. 

For the time being, does anyone have a suggestion how to avoid these problems? 
We could catch the RuntimeException and recreate the KnowledgeAgent, but 
perhaps 
there is a better way?

Thanks, Gerret


-- SystemEventLog -- 
# Guvnor is up here 
07:58:01,881 ResourceChangeScanner attempt to scan 1 resources 
07:58:02,209 ResourceChangeScanner thread is waiting for 60 
07:58:15,067 ResourceChangeScanner attempt to scan 1 resources 
# Guvnor goes down here 
07:58:16,738 ResourceChangeScanner removed resource=[UrlResource 
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] 
07:58:16,738 ResourceChangeNotification received ChangeSet notification 
07:58:16,738 ResourceChangeScanner thread is waiting for 60 
07:58:16,738  ResourceChangeNotification processing ChangeSet 
07:58:16,738 ResourceChangeNotification ChangeSet removed resource=[UrlResource 
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] for 
listener=org.drools.agent.impl.knowledgeagenti...@1053d6d 
07:58:16,738 ResourceChangeNotification ChangeSet removed resource=[UrlResource 
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] for 
listener=org.drools.agent.impl.knowledgeagenti...@b71c17 
07:58:16,738 KnowledgeAgent received ChangeSet changed notification 
07:58:16,738 KnowledgeAgent received ChangeSet changed notification 
07:58:16,738 KnowledgAgent applying ChangeSet 
07:58:16,738 ResourceChangeNotification thread is waiting for queue update 
07:58:16,738 KnowledgAgent applying ChangeSet 
07:58:16,738 KnowledgeAgent unsubscribing from resource=[UrlResource 
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] 
07:58:16,738 ResourceChangeNotification unsubscribing 
listener=org.drools.agent.impl.knowledgeagenti...@1053d6d to 
resource=[UrlResource path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] 
07:58:16,738 KnowledgeAgent rebuilding KnowledgeBase using ChangeSet 
07:58:16,738 KnowledgeAgent unsubscribing from resource=[UrlResource 
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] 
07:58:16,738 ResourceChangeNotification unsubscribing 
listener=org.drools.agent.impl.knowledgeagenti...@b71c17 to 
resource=[UrlResource path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] 
07:58:16,738 
KnowledgeAgent rebuilding KnowledgeBase using ChangeSet 
07:58:16,738 KnowledgeAgent new KnowledgeBase now built and in use 
07:58:16,738 KnowledgeAgent new KnowledgeBase now built and in use 
07:59:02,202 ResourceChangeScanner attempt to scan 0 resources 
07:59:02,202 ResourceChangeScanner thread is waiting for 60 
# Guvnor back up here 
07:59:16,731 ResourceChangeScanner attempt to scan 0 resources 
07:59:16,731 ResourceChangeScanner thread is waiting for 60

-- 
Nur noch bis 31.01.2010: DSL-Komplettpaket für 16,99 Euro/mtl.!*
http://portal.gmx.net/de/go/dsl02

[rules-users] KnowledgeAgent doesn't load dsl files and dslr file from a change-set correctly

2010-01-26 Thread Pritham

I have a folder in classpath:

dsl/global.dsl
rules/section-A.dslr
rules/section-A/page-1.dslr

I create a knowledge base like this:

public KnowledgeBase createKnowledgeBase() throws DroolsParserException,
IOException {

KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();

knowledgeBuilder.add(ResourceFactory
.newClassPathResource(dsl/global.dsl),
ResourceType.DSL);
knowledgeBuilder.add(ResourceFactory
.newClassPathResource(rules/section-A.dslr),
ResourceType.DSLR);
knowledgeBuilder.add(ResourceFactory
.newClassPathResource(rules/section-A/page-1.dslr),
ResourceType.DSLR);   

if (knowledgeBuilder.hasErrors()) {
throw new RuntimeException(knowledgeBuilder.getErrors().toString());
}

KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
   
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());

return knowledgeBase;
}

// code
knowledgeBase = createKnowledgeBase();
session = knowledgeBase.newStatefulKnowledgeSession();
// insert facts
session.fireAllRules();
session.dispose();  

The above code works and I can get a unit test to work that processes rules
accordingly. I can see my dslr converting to a drl using the drl viewer
correctly (provided I temporarily place the dsl file in the same location
since expander doesn't accept a relative path).

The problem, however is when I use a change-set.xml and a KnowledgeAgent,
things don't work 

code for loading via knowledgeAgent

public static KnowledgeBase loadKnowledgeBase() throws
DroolsParserException, IOException {
agent = KnowledgeAgentFactory.newKnowledgeAgent(msll agent);
   
agent.applyChangeSet(ResourceFactory.newClassPathResource(change-set.xml));

return agent.getKnowledgeBase();
}   


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-set.xsd'

   add
   resource source='classpath:dsl/' type='DSL' /  
   resource source='classpath:rules/' type='DSLR' /
   resource source='classpath:rules/section-A/' type='DSLR' /
/add
/change-set


I get the following generic drools errors:
ERR 103] Line 4:0 rule 'rule_key' failed predicate:
{(validateIdentifierKey(DroolsSoftKeywords.RULE))}? in rule[7,0]: [ERR 101]
Line 7:0 no viable alternative at input 'import' in rule Con in rule
attribute
...
...

The rules are same, folder location is the same. I believe that drools has a
problem resolving path (expander global.dsl) from the dslr file when using a
KnowlegeAgent since in the earlier strategy, one could build a dsl into the
knowledgeBuilder directly from the classpath.

Pl suggest.
-- 
View this message in context: 
http://n3.nabble.com/KnowledgeAgent-doesn-t-load-dsl-files-and-dslr-file-from-a-change-set-correctly-tp139702p139702.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] KnowledgeAgent doesn't load dsl files and dslr file from a change-set correctly

2010-01-26 Thread Steve Ronderos
Pritham,

I've experienced this issue before as well.  It has to do with the way 
that the KnowledgeAgent subscribes to resources.  I believe behind the 
scenes the resources are loaded in an arbitrary order.  There is a JIRA 
bug report already filed:

https://jira.jboss.org/jira/browse/JBRULES-2377

Hope this helps,

Steve

rules-users-boun...@lists.jboss.org wrote on 01/26/2010 01:07:29 PM:

 [image removed] 
 
 [rules-users] KnowledgeAgent doesn't load dsl files and dslr file 
 from a change-set correctly
 
 Pritham 
 
 to:
 
 rules-users
 
 01/26/2010 01:10 PM
 
 Sent by:
 
 rules-users-boun...@lists.jboss.org
 
 Please respond to Rules Users List
 
 
 I have a folder in classpath:
 
 dsl/global.dsl
 rules/section-A.dslr
 rules/section-A/page-1.dslr
 
 I create a knowledge base like this:
 
 public KnowledgeBase createKnowledgeBase() throws DroolsParserException,
 IOException {
 
 KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory
 .newKnowledgeBuilder();
 
 knowledgeBuilder.add(ResourceFactory
 .newClassPathResource(dsl/global.dsl),
 ResourceType.DSL);
 knowledgeBuilder.add(ResourceFactory
 .newClassPathResource(rules/section-A.dslr),
 ResourceType.DSLR);
 knowledgeBuilder.add(ResourceFactory
 .newClassPathResource(rules/section-A/page-1.dslr),
 ResourceType.DSLR); 
 
 if (knowledgeBuilder.hasErrors()) {
 throw new 
RuntimeException(knowledgeBuilder.getErrors().toString());
 }
 
 KnowledgeBase knowledgeBase = 
KnowledgeBaseFactory.newKnowledgeBase();
 
 
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
 
 return knowledgeBase;
 }
 
 // code
 knowledgeBase = createKnowledgeBase();
 session = knowledgeBase.newStatefulKnowledgeSession();
 // insert facts
 session.fireAllRules();
 session.dispose(); 
 
 The above code works and I can get a unit test to work that processes 
rules
 accordingly. I can see my dslr converting to a drl using the drl 
viewer
 correctly (provided I temporarily place the dsl file in the same 
location
 since expander doesn't accept a relative path).
 
 The problem, however is when I use a change-set.xml and a 
KnowledgeAgent,
 things don't work 
 
 code for loading via knowledgeAgent
 
 public static KnowledgeBase loadKnowledgeBase() throws
 DroolsParserException, IOException {
 agent = KnowledgeAgentFactory.newKnowledgeAgent(msll agent);
 
 
agent.applyChangeSet(ResourceFactory.newClassPathResource(change-set.xml));
 
 return agent.getKnowledgeBase();
 } 
 
 
 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-set.xsd'
 
add
resource source='classpath:dsl/' type='DSL' / 
resource source='classpath:rules/' type='DSLR' / 
resource source='classpath:rules/section-A/' type='DSLR' /
 /add
 /change-set
 
 
 I get the following generic drools errors:
 ERR 103] Line 4:0 rule 'rule_key' failed predicate:
 {(validateIdentifierKey(DroolsSoftKeywords.RULE))}? in rule[7,0]: [ERR 
101]
 Line 7:0 no viable alternative at input 'import' in rule Con in rule
 attribute
 ...
 ...
 
 The rules are same, folder location is the same. I believe that drools 
has a
 problem resolving path (expander global.dsl) from the dslr file when 
using a
 KnowlegeAgent since in the earlier strategy, one could build a dsl into 
the
 knowledgeBuilder directly from the classpath.
 
 Pl suggest.
 -- 
 View this message in context: http://n3.nabble.com/KnowledgeAgent-
 doesn-t-load-dsl-files-and-dslr-file-from-a-change-set-correctly-
 tp139702p139702.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
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] KnowledgeAgent doesn't load dsl files and dslr file from a change-set correctly

2010-01-26 Thread Pegram, Macon
That's actually my ticket, and I've been hoping to get it resolved for
awhile now.  I've posted to this mailing list as well as the actual
ticket but haven't heard responses from anyone.

 

I've recently done more research into the issue, and have some updated
information that needs to be attached to the ticket (I'll try to get it
in shortly) but what it boils down to is a collision of two problems...

 

Problem 1: DSL and DSLR need to be in the same folder, but if you don't
explicitly list the resources for each item in the changeset, you can't
define an independent resource type.This is kind of silly and in my
mind defeats the benefits of the change-set.  The benefit in my mind of
a change set is being able to point it at a folder and have it scan for
new rule additions as well as changes. 

 

Problem 2: Internally the identified resources in the change set are
held in a hashmap.  Since there's no ordering to a hashmap, when they're
pulled out and added to the knowledgebuilder they could be added in any
order.  In order for a DSL and DSLR to work, they have to be added to
the KnowledgeBuilder in the proper order (DSL first then DSLR).  It does
not matter what order you list them in the change set, the rebuild code
in the KnowledgeAgent framework does not enforce any concept of ordering
or priority to resource types.

 

The documentation (since 5.0.1) has suggested that at some point they
plan to have autodetection of file types which would solve for problem
#1, but problem #2 would remain without some priority given to how the
KnowledgeBuilder is being instructed to construct rule sets.  This
problem is present even in the latest 5.1 milestone.

 

Unfortunately this has driven us to choose between having a DSL or
having hot deployment of rules (we've chosen the later)

 

Macon

 



From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Steve Ronderos
Sent: Tuesday, January 26, 2010 2:58 PM
To: Rules Users List
Subject: Re: [rules-users] KnowledgeAgent doesn't load dsl files and
dslr file from a change-set correctly

 


Pritham, 

I've experienced this issue before as well.  It has to do with the way
that the KnowledgeAgent subscribes to resources.  I believe behind the
scenes the resources are loaded in an arbitrary order.  There is a JIRA
bug report already filed: 

https://jira.jboss.org/jira/browse/JBRULES-2377
https://jira.jboss.org/jira/browse/JBRULES-2377  

Hope this helps, 

Steve 

rules-users-boun...@lists.jboss.org wrote on 01/26/2010 01:07:29 PM:

 [image removed] 
 
 [rules-users] KnowledgeAgent doesn't load dsl files and dslr file 
 from a change-set correctly 
 
 Pritham 
 
 to: 
 
 rules-users 
 
 01/26/2010 01:10 PM 
 
 Sent by: 
 
 rules-users-boun...@lists.jboss.org 
 
 Please respond to Rules Users List 
 
 
 I have a folder in classpath:
 
 dsl/global.dsl
 rules/section-A.dslr
 rules/section-A/page-1.dslr
 
 I create a knowledge base like this:
 
 public KnowledgeBase createKnowledgeBase() throws
DroolsParserException,
 IOException {
 
 KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory
 .newKnowledgeBuilder();
 
 knowledgeBuilder.add(ResourceFactory
 .newClassPathResource(dsl/global.dsl),
 ResourceType.DSL);
 knowledgeBuilder.add(ResourceFactory
 .newClassPathResource(rules/section-A.dslr),
 ResourceType.DSLR);
 knowledgeBuilder.add(ResourceFactory
 .newClassPathResource(rules/section-A/page-1.dslr),
 ResourceType.DSLR);   
 
 if (knowledgeBuilder.hasErrors()) {
 throw new
RuntimeException(knowledgeBuilder.getErrors().toString());
 }
 
 KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase();


knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages
());
 
 return knowledgeBase;
 }
 
 // code
 knowledgeBase = createKnowledgeBase();
 session = knowledgeBase.newStatefulKnowledgeSession();
 // insert facts
 session.fireAllRules();
 session.dispose();   
 
 The above code works and I can get a unit test to work that processes
rules
 accordingly. I can see my dslr converting to a drl using the drl
viewer
 correctly (provided I temporarily place the dsl file in the same
location
 since expander doesn't accept a relative path).
 
 The problem, however is when I use a change-set.xml and a
KnowledgeAgent,
 things don't work 
 
 code for loading via knowledgeAgent
 
 public static KnowledgeBase loadKnowledgeBase() throws
 DroolsParserException, IOException {
 agent = KnowledgeAgentFactory.newKnowledgeAgent(msll agent);


agent.applyChangeSet(ResourceFactory.newClassPathResource(change-set.xm
l));
 
 return agent.getKnowledgeBase();
 }   
 
 
 change-set xmlns='http://drools.org/drools-5.0/change-set'
  xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'


Re: [rules-users] KnowledgeAgent doesn't load dsl files and dslr file from a change-set correctly

2010-01-26 Thread Pritham

Thanks for the heads up. I can even load the same change-set.xml via kbuilder
and get the rules to fire and work, turns out that KnowledgeAgent has an
issue.

On a larger note, looking at 5.1M1, KnowledgeAgentImpl has changed a lot
(Mark Proctor) and a lot of todos and comments were uncommented in the
newer one. Is it recommended to try the class in an older distribution?
-- 
View this message in context: 
http://n3.nabble.com/KnowledgeAgent-doesn-t-load-dsl-files-and-dslr-file-from-a-change-set-correctly-tp139702p139849.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] Stateless Vs Stateful Sessions in Webtier

2010-01-26 Thread Pritham

I'm planning to use the following approach in my webtier:

High level design: Each http request for a page on our site has an average
of 5 separate requests to process rules before finally rendering. Each time,
servlet handler calls runRule(some context object). Essentially, rules is
serving as a filtering process and while Stateless ksession would have done
the trick, I needed to control the execution of rules based on agenda-order
and salience, hence the stateful ksession. The rules themselves are pretty
st forward and I don't see the need to insert facts dynamically during a
long web conversation (at least for now). 

protected void runRule(MyContect context) {

try {
KnowledgeBase kbase = loadKnowledgeBase(context);

StatefulKnowledgeSession kSession =
kbase.newStatefulKnowledgeSession();
   
// set some globals here 

// pop groups into agenda's stack for controlling execution order
kSession.getAgenda().getAgendaGroup(page-id).setFocus();
kSession.getAgenda().getAgendaGroup(section-id).setFocus();
kSession.getAgenda().getAgendaGroup(site-global).setFocus();  

kSession.insert(context);

kSession.fireAllRules();

// at this point context is updated by rules for the servlet to
handle after the call;

kSession.dispose();

} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(Error occured in processing Drools
rules, e);
}   
}

public KnowledgeBase loadKnowledgeBase() throws DroolsParserException,
IOException {

 if(kbase != null) { // singleton instance
return kbase;
 }  

KnowledgeBuilder knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();

   
knowledgeBuilder.add(ResourceFactory.newClassPathResource(dsl/global.dsl),
ResourceType.DSL);
knowledgeBuilder.add(ResourceFactory.newClassPathResource(rules/),
ResourceType.DSLR);
  
if (knowledgeBuilder.hasErrors()) {
throw new RuntimeException(knowledgeBuilder.getErrors().toString());
}

kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase .addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());

return kbase ;
}


Michael Bali's book has an entire chapter on Stateful Session in which it
recommended to create a 
StatefulSession Service with a dedicated writeObject and readObject and
warns about thread safety. 

I'm still not clear about the unsafe threading issues with using a stateful
ksession inside a webtier. 

And would the approach 1 in the above work, assuming multiple users are
executing the same rules at the same time?

Thanks



public class DroolsService implements Serializable {

private static final long serialVersionUID = 6623448115053519253L;
private transient KnowledgeBase knowledgeBase;
private transient StatefulKnowledgeSession statefulSession;

public DroolsService(KnowledgeBase knowledgeBase) {
this.knowledgeBase = knowledgeBase;
statefulSession = createKnowledgeSession();
}

private StatefulKnowledgeSession createKnowledgeSession() {
StatefulKnowledgeSession session = knowledgeBase
.newStatefulKnowledgeSession();
return session;
}

public void insertOrUpdate(Object fact) {
if (fact == null) {
return;
}

FactHandle factHandle = statefulSession.getFactHandle(fact);

if (factHandle == null) {
statefulSession.insert(fact);
} else {
statefulSession.update(factHandle, fact);
}
}

public void executeRules() {
statefulSession.fireAllRules();
}

public void terminate() {
statefulSession.dispose();
}

private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
DroolsObjectOutputStream droolsOut = new 
DroolsObjectOutputStream(
(OutputStream) out);
droolsOut.writeObject(knowledgeBase);
Marshaller marshaller = 
createSerializableMarshaller(knowledgeBase);
marshaller.marshall(droolsOut, statefulSession);
}

private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
in.defaultReadObject();
DroolsObjectInputStream droolsIn = new DroolsObjectInputStream(
(InputStream) in);
this.knowledgeBase = (KnowledgeBase) droolsIn.readObject();
Marshaller marshaller = 
createSerializableMarshaller(knowledgeBase);
statefulSession = 

Re: [rules-users] Drools Roadmap - Planned Release 5.1 release date

2010-01-26 Thread Pritham

It's been 6 months since this post and only Milestone 1 has been released.
Any idea when 5.1 final is being panned for? The noteworthyfeatures,
fixes, spring integration and others look interesting.
-- 
View this message in context: 
http://n3.nabble.com/Drools-Roadmap-Planned-Release-5-1-release-date-tp60252p139939.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


[rules-users] Does rule execution block when the Knowlege Agent is rebuild KnowlegeBase???

2010-01-26 Thread Wing

Hello Drools User,

I am using Knowlege Agent to monitor changes in the repository.  I have
started the following services:

ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();

I was able to change the rules in the repository and the changes did get
pick up in my application and everything is working fine as expected.

However, I have a question regarding rule execution when the Knowlege Base
is in the middle of being build by the Knowlege Agent.   What happen when I
execute the rules using:

ksessionStateless = knowledgeAgent.newStatelessKnowledgeSession();
ksessionStateless.execute(ObjList);

Will the method ksessionStateless.execute(ObjList) block and wait until the
Knowlege Base is finish being build by the knowledge agent or the method
won't block and just pick up the old Knowlege Base and then switch to the
new knowlege base when the knowlege agent is finish building it?  Will the
method ksessionStateless.execute(ObjList) block or not block?

thanks very much in advace for any help on this!

Wing Tang





-- 
View this message in context: 
http://n3.nabble.com/Does-rule-execution-block-when-the-Knowlege-Agent-is-rebuild-KnowlegeBase-tp139987p139987.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] KnowledgeAgent doesn't load dsl files and dslr file from a change-set correctly

2010-01-26 Thread Pegram, Macon
I did my trace (which led to the comments below) on 5.1M1, but the I
noticed the problem originally on 5.0.1 so I don't believe there's any
version that will work for you at this time.

Macon

-Original Message-
From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Pritham
Sent: Tuesday, January 26, 2010 4:29 PM
To: rules-users@lists.jboss.org
Subject: Re: [rules-users] KnowledgeAgent doesn't load dsl files and
dslr file from a change-set correctly


Thanks for the heads up. I can even load the same change-set.xml via
kbuilder
and get the rules to fire and work, turns out that KnowledgeAgent has an
issue.

On a larger note, looking at 5.1M1, KnowledgeAgentImpl has changed a lot
(Mark Proctor) and a lot of todos and comments were uncommented in the
newer one. Is it recommended to try the class in an older distribution?
-- 
View this message in context:
http://n3.nabble.com/KnowledgeAgent-doesn-t-load-dsl-files-and-dslr-file
-from-a-change-set-correctly-tp139702p139849.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

CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for 
the sole use of the intended recipient(s) and may contain confidential and 
privileged information or otherwise protected by law.  Any unauthorized review, 
use, disclosure or distribution is prohibited.  If you are not the intended 
recipient, please contact the sender by reply e-mail and destroy all copies of 
the original message.



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


Re: [rules-users] KnowledgeAgent doesn't load dsl files and dslr file from a change-set correctly - JIRA:JBRULES-2377 updated

2010-01-26 Thread Pegram, Macon

I have updated the JIRA ticket with more detailed information.   If this
issue is important to you, please vote up its importance so that we can
hopefully capture the attention of the development team.

You can find the JIRA ticket at:
https://jira.jboss.org/jira/browse/JBRULES-2377

Thanks!
Macon

-Original Message-
From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Pritham
Sent: Tuesday, January 26, 2010 4:29 PM
To: rules-users@lists.jboss.org
Subject: Re: [rules-users] KnowledgeAgent doesn't load dsl files and
dslr file from a change-set correctly


Thanks for the heads up. I can even load the same change-set.xml via
kbuilder
and get the rules to fire and work, turns out that KnowledgeAgent has an
issue.

On a larger note, looking at 5.1M1, KnowledgeAgentImpl has changed a lot
(Mark Proctor) and a lot of todos and comments were uncommented in the
newer one. Is it recommended to try the class in an older distribution?
-- 
View this message in context:
http://n3.nabble.com/KnowledgeAgent-doesn-t-load-dsl-files-and-dslr-file
-from-a-change-set-correctly-tp139702p139849.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

CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for 
the sole use of the intended recipient(s) and may contain confidential and 
privileged information or otherwise protected by law.  Any unauthorized review, 
use, disclosure or distribution is prohibited.  If you are not the intended 
recipient, please contact the sender by reply e-mail and destroy all copies of 
the original message.



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