Re: [rules-users] ksession.insert() executes sequentially in multithreaded StatefulKnowledgeSessions

2011-10-27 Thread Marco Rietveld
Hi Juan Carlos,

Sorry for the late reply.

Would you mind sending me the Sample.drl en .bpmn files as well?

I happen to have a bit of code that I can use to look into this.

Thanks,
Marco

10/06/2011 01:28 PM, juancarlos.fernandezj:
 Hello,

 I'm having trouble when trying to insert() facts inside parallel
 StatefulKnowledgeSessions. From a main() java program I start multiple
 threads. Every thread creates new KnowledgeBase and every KnowledgeBase
 creates new StatefulKnowledgeSession so I have one StatefulKnowledgeSession
 in every thread. Once StatefulKnowledgeSession has been created, I insert
 lots of facts in each StatefulKnowledgeSession.

 What was expected? I expected to run insert() in parallel, each insert
 inside its thread StatefulKnowledgeSession. 4 threads inserting lots of
 facts inside its own StatefulKnowledgeSession is expected to run in parallel
 and see how CPU usage increases.

 What have I seen? when all threads are inserting facts in its own
 StatefulKnowledgeSession I can see that only one CPU is being used so there
 is no parallel insertion in different StatefulKnowledgeSession.

 Is there a synchronization inside insert() code? It's so strange. Even if i
 try with 12 threads, I can't see a CPU usage increase when executing
 parallel insert() inside different StatefulKnowledgeSession (threads).

 Help please.

 This is my thread code (no static objects):

 public class KnowledgeSessionThread extends Thread {
   
   private StatefulKnowledgeSession session;
   private Message[] facts;
   
  public KnowledgeSessionThread(Message[] facts) throws Exception {
   session = readKnowledgeBase().newStatefulKnowledgeSession();
   this.facts = facts;
  }

  public void run() {
   try {
   for( int i = 0; i  facts.length; i++ ) {
   session.insert(facts[i]);
   }
   session.startProcess(flowId);
   session.fireAllRules();
   session.dispose();
   System.out.println(Thread finished);
   } catch( Exception e ) {
   e.printStackTrace();
   }
  }

  private KnowledgeBase readKnowledgeBase() throws Exception {
  KnowledgeBuilder kbuilder =
 KnowledgeBuilderFactory.newKnowledgeBuilder();
  kbuilder.add(ResourceFactory.newClassPathResource(Sample.drl),
 ResourceType.DRL);
  kbuilder.add(ResourceFactory.newClassPathResource(Sample.bpmn),
 ResourceType.BPMN2);
  KnowledgeBuilderErrors errors = kbuilder.getErrors();
  if (errors.size()  0) {
  for (KnowledgeBuilderError error: errors) {
  System.err.println(error);
  }
  throw new IllegalArgumentException(Could not parse
 knowledge.);
  }
  KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
  kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
  return kbase;
  }
 }

 --
 View this message in 
 context:http://drools.46999.n3.nabble.com/ksession-insert-executes-sequentially-in-multithreaded-StatefulKnowledgeSessions-tp3399339p3399339.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users


-- 
jBPM/Drools developer
Utrecht, the Netherlands

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


[rules-users] inserting multiple facts in RHS

2011-10-27 Thread RK
I want to insert multiple facts sourced by a 'from' clause to a service
method.
For Ex:

when
...
then
 insert( mycustomobject() from globalService.getCustomObjects())

getCustomObjects() method will return several instances of custom objects
based on a sql query and i want to insert them into the knowledge session.
I'll be using these custom objects in other subsequent rules.

Is it possible to do something like this ?

Thanks


--
View this message in context: 
http://drools.46999.n3.nabble.com/inserting-multiple-facts-in-RHS-tp3459071p3459071.html
Sent from the Drools: User forum 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] inserting multiple facts in RHS

2011-10-27 Thread Michael Anstis
Why not get get List using from in the LHS and iterate this in the RHS
adding individual facts?

On 27 October 2011 21:39, RK rmeiap...@datacert.com wrote:

 I want to insert multiple facts sourced by a 'from' clause to a service
 method.
 For Ex:

 when
 ...
 then
  insert( mycustomobject() from globalService.getCustomObjects())

 getCustomObjects() method will return several instances of custom objects
 based on a sql query and i want to insert them into the knowledge session.
 I'll be using these custom objects in other subsequent rules.

 Is it possible to do something like this ?

 Thanks


 --
 View this message in context:
 http://drools.46999.n3.nabble.com/inserting-multiple-facts-in-RHS-tp3459071p3459071.html
 Sent from the Drools: User forum 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] inserting multiple facts in RHS

2011-10-27 Thread Wolfgang Laun
If globalService.getCustomObjects() returns a collection then there is no
point in doing a from/collect to iterate and collect (again) what was a
collection to start with.

Simply use
   for (Object obj: globalService.getCustomObjects()) insert(obj);

-W


2011/10/27 Michael Anstis michael.ans...@gmail.com

 Why not get get List using from in the LHS and iterate this in the RHS
 adding individual facts?


 On 27 October 2011 21:39, RK rmeiap...@datacert.com wrote:

 I want to insert multiple facts sourced by a 'from' clause to a service
 method.
 For Ex:

 when
 ...
 then
  insert( mycustomobject() from globalService.getCustomObjects())

 getCustomObjects() method will return several instances of custom objects
 based on a sql query and i want to insert them into the knowledge session.
 I'll be using these custom objects in other subsequent rules.

 Is it possible to do something like this ?

 Thanks


 --
 View this message in context:
 http://drools.46999.n3.nabble.com/inserting-multiple-facts-in-RHS-tp3459071p3459071.html
 Sent from the Drools: User forum 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


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


Re: [rules-users] confusing behaviour of enum comparison

2011-10-27 Thread Edson Tirelli
   Make sure you try with Drools 5.3 and the proper mvel version.

   Edson

2011/10/27 lhorton lhor...@abclegal.com

 thank you for taking the time to test this, Wolf.I have other tests
 with
 the same syntax that have tested ok as well.  It is puzzling.  I will test
 tomorrow with the mvel jar that I'm using.  I went to the beta 6 mvel
 because it compiles a lot faster for 5.2 but perhaps there are side
 effects.

 --
 View this message in context:
 http://drools.46999.n3.nabble.com/confusing-behaviour-of-enum-comparison-tp3455245p3456711.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users




-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Guvnor data enumeration issue

2011-10-27 Thread GPatel
I am trying to use data enumerations and running into a problem. Following 
the Vehicle engineType/fuelType data enumeration example in the Guvnor 
manual, I created the following enumeration list and it works:

'Vehicle.engineType' : (new test.VehicleHelper()).getEngineTypes()
'Vehicle.fuelType[engineType]' : '(new 
test.VehicleHelper()).getFuelTypes(@{engineType})'

VehicleHelper:


public class VehicleHelper {
 
public ListString getEngineTypes(){
ListString engineTypes = new ArrayListString();
engineTypes.add(Petrol);
engineTypes.add(Diesel);
return engineTypes;
}
 
public ListString getFuelTypes(String engineType){
ListString fuelTypes = new ArrayListString();
if(Petrol.equalsIgnoreCase(engineType)){
fuelTypes.add(ULP);
fuelTypes.add(PULP);
}
else if(Diesel.equalsIgnoreCase(engineType)){
fuelTypes.add(BIO);
fuelTypes.add(NORMAL);
}
else{
fuelTypes.add(Default Fuel 1);
fuelTypes.add(Default Fuel 2);
}
return fuelTypes;
}

}

Above works as expected.

Problem:

I want to only have an enumeration on Vehicle.fuelType that depends on the 
value of engineType, without specifying an enumeration on engineType. So, 
I took out the first line in my enumeration list so that it is now: 

'Vehicle.fuelType[engineType]' : '(new 
test.VehicleHelper()).getFuelTypes(@{engineType})'

But that does not work. When I create a rule, VehicleHelper.getFuelTypes 
does not get called and the dropdown for fuelType is not a list.

How do I get this working?

Thanks
G. Patel

-
The information contained in this communication (including any
attachments hereto) is confidential and is intended solely for the
personal and confidential use of the individual or entity to whom
it is addressed. If the reader of this message is not the intended
recipient or an agent responsible for delivering it to the intended
recipient, you are hereby notified that you have received this
communication in error and that any review, dissemination, copying,
or unauthorized use of this information, or the taking of any
action in reliance on the contents of this information is strictly
prohibited. If you have received this communication in error,
please notify us immediately by e-mail, and delete the original
message. Thank you ___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users