[rules-users] StatefulKnowledgeSession construction executes sequentially (no multithread)

2011-10-11 Thread Juan Carlos Fernández
Hi all,

Try to execute many threads with the next source code (simple simple code).
You will see that only one CPU-thread is used in a mutithreaded CPU system.
It seems to be a system lock inside newStatefulKnowledgeSession().

This is a big disappoint because we can't use StatefulKnowledgeSession in
multithreaded environment. All is executing sequentially because of this
problem. Yes, we can asure newStatefulKnowledgeSession() is multithread (no
error is returned) but we can't asure newStatefulKnowledgeSession() executes
in parallel.

Do you know any problem about this?

Thank's in advance

PROBLEMATIC SOURCE CODE:

public class KnowledgeSessionThread extends Thread {
private static final int ITERATIONS = 100;
private KnowledgeBase kbase;
   
public KnowledgeSessionThread() throws Exception {
kbase = readKnowledgeBase();
}

public void run() {
try {
for( int i = 0; i  ITERATIONS; i++ ) { 
StatefulKnowledgeSession session = 
kbase.newStatefulKnowledgeSession(); 
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/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412107.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] StatefulKnowledgeSession construction executes sequentially (no multithread)

2011-10-11 Thread Wolfgang Laun
Why should newStatefulKnowledgeSession, which merely *creates* a
StatefulKnowledgeSession object from a KnowledgeBase, be able to run in
parallel with calls to the same method? It's a lightweight operation, not
taking long, and the KnowledgeBase must be protected for a short time to
avoid confusion in its internal data structures.

-W


2011/10/11 Juan Carlos Fernández juancarlos.fernan...@safelayer.com

 Hi all,

 Try to execute many threads with the next source code (simple simple code).
 You will see that only one CPU-thread is used in a mutithreaded CPU system.
 It seems to be a system lock inside newStatefulKnowledgeSession().

 This is a big disappoint because we can't use StatefulKnowledgeSession in
 multithreaded environment. All is executing sequentially because of this
 problem. Yes, we can asure newStatefulKnowledgeSession() is multithread (no
 error is returned) but we can't asure newStatefulKnowledgeSession()
 executes
 in parallel.

 Do you know any problem about this?

 Thank's in advance

 PROBLEMATIC SOURCE CODE:

 public class KnowledgeSessionThread extends Thread {
private static final int ITERATIONS = 100;
private KnowledgeBase kbase;

public KnowledgeSessionThread() throws Exception {
kbase = readKnowledgeBase();
}

public void run() {
try {
for( int i = 0; i  ITERATIONS; i++ ) {
StatefulKnowledgeSession session =
 kbase.newStatefulKnowledgeSession();
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/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412107.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] How to convert .drl file to XML ...

2011-10-11 Thread Manohar Kokkula
Hi All! 

I'm trying to convert a .drl file to xml
But im not sure how to approach for this,
Please help me regarding the same.
Here is my drl file:

package com.rules
import com.model.Bank;

rule Your First Rule
 
when
$b1:Bank(name==Manohar, accntno==533)
then 
 
$b1.setBalance(5000);
$b1.setDeposit($b1.getBalance()+1000);
 
end

rule Your Second Rule
 
when
$b1:Bank(name==Ajay, accntno==536)
then 
 
 
$b1.setBalance(6000);
$b1.setDeposit($b1.getBalance()+2000);
 
end





Thanks and Regards
Manohar Kokkula
Mailto: manohar.kokk...@tcs.com
=-=-=
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you


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


Re: [rules-users] How to convert .drl file to XML ...

2011-10-11 Thread Michael Anstis
Any particular XML schema?

The simplest answer would be to wrap your package DRL into an XML element:-

package
package com.rules
import com.model.Bank;

rule Your First Rule

when
$b1:Bank(name==Manohar, accntno==533)
then

$b1.setBalance(5000);
$b1.setDeposit($b1.getBalance()+1000);

end

rule Your Second Rule

when
$b1:Bank(name==Ajay, accntno==536)
then


$b1.setBalance(6000);
$b1.setDeposit($b1.getBalance()+2000);

end
/package

I suspect however you are after a little more?

With kind regards,

Mike

2011/10/11 Manohar Kokkula manohar.kokk...@tcs.com

 Hi All!

 I'm trying to convert a .drl file to xml
 But im not sure how to approach for this,
 Please help me regarding the same.
 *Here is my drl file:*

 package com.rules
 import com.model.Bank;

 rule Your First Rule

 when
 $b1:Bank(name==Manohar, accntno==533)
 then

 $b1.setBalance(5000);
 $b1.setDeposit($b1.getBalance()+1000);

 end

 rule Your Second Rule

 when
 $b1:Bank(name==Ajay, accntno==536)
 then


 $b1.setBalance(6000);
 $b1.setDeposit($b1.getBalance()+2000);

 end





 Thanks and Regards
 Manohar Kokkula
 Mailto: manohar.kokk...@tcs.com

 =-=-=
 Notice: The information contained in this e-mail
 message and/or attachments to it may contain
 confidential or privileged information. If you are
 not the intended recipient, any dissemination, use,
 review, distribution, printing or copying of the
 information contained in this e-mail message
 and/or attachments to it are strictly prohibited. If
 you have received this communication in error,
 please notify us by reply e-mail or telephone and
 immediately and permanently delete the message
 and any attachments. Thank you



 ___
 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] StatefulKnowledgeSession construction executes sequentially (no multithread)

2011-10-11 Thread Juan Carlos Fernández
We create one StatefulKnowledgeSession for every client (if 20 clients at
same time, 20 StatefulKnowledgeSession are created) because every client has
different environment for rule evaluation. Facts for one client does not
have to collide with facts of other clients so this is the reason why we
create multiple sessions.

Let me explain all this in greater detail. When a client executes a SOAP
operation, one StatefulKnowledgeSession is created and associated to the
transaction. Every log generated by the transaction is inserted as a Fact.
When transaction finishes, we fire all rules for the current transaction
knowledge session in order to correlate all transaction logs. This
transaction logs do not have to collide with other transaction logs so every
thread (transaction) has its own StatefulKnowledgeSession.

Our app locks and begin to use only one CPU thread because of
newStatefulKnowledgeSession().

Do you think entry-points would be the solution? Is there any other
solution?

One solution is to use StatefulKnowledgeSession pool who creates instances
but we have to retract all facts when returning session to pool.

Concurrent executions and throughput is a key feature of our SOAP
application.

Thank you very much

--
View this message in context: 
http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p341.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] StatefulKnowledgeSession construction executes sequentially (no multithread)

2011-10-11 Thread Swindells, Thomas
The problem is your test isn't calling fire all rules. You are testing just the 
creation of the sessions,
this is expected to be fast and low cost  and requires some synchronization for 
safety*.
The process that is expected to take a significant amount of time is the 
inserting of the facts,
firing the rules and getting the results, this should run in parallel correctly 
- but your test
isn't testing this.

Can you make a realistic test case then feed back the results.

Thomas

*I don't know the code, and it is possible that it could benefit from using a 
more sophisticated
read/write lock but that is only worth implementing if session creation really 
does take up a
significant amount of time.



 -Original Message-
 From: rules-users-boun...@lists.jboss.org [mailto:rules-users-
 boun...@lists.jboss.org] On Behalf Of Juan Carlos Fernández
 Sent: 11 October 2011 11:49
 To: rules-users@lists.jboss.org
 Subject: Re: [rules-users] StatefulKnowledgeSession construction executes
 sequentially (no multithread)

 We create one StatefulKnowledgeSession for every client (if 20 clients at
 same time, 20 StatefulKnowledgeSession are created) because every client
 has different environment for rule evaluation. Facts for one client does not
 have to collide with facts of other clients so this is the reason why we 
 create
 multiple sessions.

 Let me explain all this in greater detail. When a client executes a SOAP
 operation, one StatefulKnowledgeSession is created and associated to the
 transaction. Every log generated by the transaction is inserted as a Fact.
 When transaction finishes, we fire all rules for the current transaction
 knowledge session in order to correlate all transaction logs. This transaction
 logs do not have to collide with other transaction logs so every thread
 (transaction) has its own StatefulKnowledgeSession.

 Our app locks and begin to use only one CPU thread because of
 newStatefulKnowledgeSession().

 Do you think entry-points would be the solution? Is there any other solution?

 One solution is to use StatefulKnowledgeSession pool who creates instances
 but we have to retract all facts when returning session to pool.

 Concurrent executions and throughput is a key feature of our SOAP
 application.

 Thank you very much

 --
 View this message in context:
 http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-
 executes-sequentially-no-multithread-tp3412107p341.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


**
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.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, 
United Kingdom. A company registered in England and Wales. Registered no. 
3080780. VAT no. GB 603 8808 40-00
**

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


Re: [rules-users] StatefulKnowledgeSession construction executes sequentially (no multithread)

2011-10-11 Thread Wolfgang Laun
The code you have posted just calls newStatefulKnowledgeSession, which does
lock and unlock. But this should not prevent the insertion of facts and the
firing of rules executing in parallel. It's pointless to execute
newStatefulKnowledgeSession a million times in a single thread and to do
nothing else, because this won't be a meaningful use case.

Don't run the million-times-loop. Just waste some cycles between session
creation and dispose and see how many of these you can have in parallel.

-W


2011/10/11 Juan Carlos Fernández juancarlos.fernan...@safelayer.com

 We create one StatefulKnowledgeSession for every client (if 20 clients at
 same time, 20 StatefulKnowledgeSession are created) because every client
 has
 different environment for rule evaluation. Facts for one client does not
 have to collide with facts of other clients so this is the reason why we
 create multiple sessions.

 Let me explain all this in greater detail. When a client executes a SOAP
 operation, one StatefulKnowledgeSession is created and associated to the
 transaction. Every log generated by the transaction is inserted as a Fact.
 When transaction finishes, we fire all rules for the current transaction
 knowledge session in order to correlate all transaction logs. This
 transaction logs do not have to collide with other transaction logs so
 every
 thread (transaction) has its own StatefulKnowledgeSession.

 Our app locks and begin to use only one CPU thread because of
 newStatefulKnowledgeSession().

 Do you think entry-points would be the solution? Is there any other
 solution?

 One solution is to use StatefulKnowledgeSession pool who creates instances
 but we have to retract all facts when returning session to pool.

 Concurrent executions and throughput is a key feature of our SOAP
 application.

 Thank you very much

 --
 View this message in context:
 http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p341.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] StatefulKnowledgeSession construction executes sequentially (no multithread)

2011-10-11 Thread Juan Carlos Fernández
Thank you for your responses,

Have a look to the 
http://drools.46999.n3.nabble.com/ksession-insert-executes-sequentially-in-multithreaded-StatefulKnowledgeSessions-td3399339.html
post  I wrote some days ago. You will see a complete test (no responses in
the forum). After I wrote the post, I looked inside drools source code and
tested that executing thousands internal ObjectHashMap::put() when calling
session.insert(fact) reached the same result (JMV memory management blocked
parallel execution and no more than one CPU thread was used).

I have tested lots of possibilities. This is the test source code you
request. Same result (one CPU thread used)... after creating some sessions,
I insert some facts. When I implement the test solution inside my SOAP
application, same result again (drools lock).

Ideas? I'm testing session pooling...

public class KnowledgeSessionThread extends Thread {

private static final int iterations = 500;
private static final int numberFacts = 1000;
private KnowledgeBase base;

public KnowledgeSessionThread(KnowledgeBase base) throws Exception {
this.base = base;
}

public void run() {
try { 
for( int i = 0; i  iterations; i++ ) {
StatefulKnowledgeSession session =
base.newStatefulKnowledgeSession();
for( int j = 0; j  numberFacts; j++ ) {
Message msg = new Message();
msg.setMessage(Hello world);
msg.setStatus(Message.HELLO);
session.insert(msg);
}
session.fireAllRules();
session.dispose();
}
System.out.println(Thread finished  +
this.currentThread().getName());
} catch( Exception e ) {
e.printStackTrace();
}
}
}

--
View this message in context: 
http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412305.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] StatefulKnowledgeSession construction executes sequentially (no multithread)

2011-10-11 Thread Juan Carlos Fernández
Here you have my pooling solution. Testing this source code reaches 100% CPU
usage!! Used apache commons pooling. borrowObject() creates stateful session
and pool it. returnObject() retracts all facts.

Can we extract a conclusion with my tests? I'm going to implement pooling
solution inside my SOAP app and do performance tests (throughput).

public class KnowledgeSessionThread extends Thread {

int iterations = 500;
int numberFacts = 1000;
private ObjectPool pool;

public KnowledgeSessionThread(ObjectPool pool) throws Exception {
this.pool = pool;
}

public void run() {
try { 
for( int i = 0; i  iterations; i++ ) {
StatefulKnowledgeSession session =
(StatefulKnowledgeSession)pool.borrowObject();
for( int j = 0; j  numberFacts; j++ ) {
Message msg = new Message();
msg.setMessage(Hello world);
msg.setStatus(Message.HELLO);
session.insert(msg);
}
session.fireAllRules();
pool.returnObject(session);
}
System.out.println(Thread finished  +
this.currentThread().getName());
} catch( Exception e ) {
e.printStackTrace();
}
}
}

@Override
public Object makeObject() throws Exception {
System.out.println(Thread.currentThread().getName() +  - 
makeObject()
called );
return kbase.newStatefulKnowledgeSession();
}

@Override
public void destroyObject( Object obj ) {
StatefulKnowledgeSession session = 
(StatefulKnowledgeSession)obj;
session.dispose();

}

@Override
public void passivateObject(Object obj) { 
StatefulKnowledgeSession session = 
(StatefulKnowledgeSession)obj;
for( FactHandle handle : session.getFactHandles() ) {
session.retract(handle);
}
} 

--
View this message in context: 
http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412338.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] StatefulKnowledgeSession construction executes sequentially (no multithread)

2011-10-11 Thread Wolfgang Laun
Its just a hunch, but try your original code (not the pooling one) but pass
the newStatefulKnowledgeSession to the constructor of the Thread sublass.
-W


2011/10/11 Juan Carlos Fernández juancarlos.fernan...@safelayer.com

 Here you have my pooling solution. Testing this source code reaches 100%
 CPU
 usage!! Used apache commons pooling. borrowObject() creates stateful
 session
 and pool it. returnObject() retracts all facts.

 Can we extract a conclusion with my tests? I'm going to implement pooling
 solution inside my SOAP app and do performance tests (throughput).

 public class KnowledgeSessionThread extends Thread {

 int iterations = 500;
int numberFacts = 1000;
private ObjectPool pool;

public KnowledgeSessionThread(ObjectPool pool) throws Exception {
this.pool = pool;
 }

public void run() {
try {
for( int i = 0; i  iterations; i++ ) {
StatefulKnowledgeSession session =
 (StatefulKnowledgeSession)pool.borrowObject();
 for( int j = 0; j  numberFacts; j++ ) {
Message msg = new Message();
msg.setMessage(Hello world);
msg.setStatus(Message.HELLO);
session.insert(msg);
}
session.fireAllRules();
 pool.returnObject(session);
 }
System.out.println(Thread finished  +
 this.currentThread().getName());
} catch( Exception e ) {
e.printStackTrace();
}
}
 }

 @Override
public Object makeObject() throws Exception {
System.out.println(Thread.currentThread().getName() +  -
 makeObject()
 called );
return kbase.newStatefulKnowledgeSession();
}

@Override
public void destroyObject( Object obj ) {
StatefulKnowledgeSession session =
 (StatefulKnowledgeSession)obj;
session.dispose();

}

@Override
public void passivateObject(Object obj) {
StatefulKnowledgeSession session =
 (StatefulKnowledgeSession)obj;
for( FactHandle handle : session.getFactHandles() ) {
session.retract(handle);
}
}

 --
 View this message in context:
 http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412338.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] [planner] Problem setting configuration file

2011-10-11 Thread Guilherme Kunigami
Hi,

I'm trying to load a configuration file (namely SolverConf.xml) into
XmlSolver with the code below:

XmlSolverConfigurer configurer = new XmlSolverConfigurer();
configurer.configure(SOLVER_CONFIG);
Solver solver = configurer.buildSolver();

If I bundle SolverConf.xml file with the application .jar file, then using
SOLVER_CONFIG as /path/to/xml/file/SolverConf.xml works fine.

But I want to use SolverConf.xml outside the .jar, so I can easiliy edit it,
but I don't know what path should I pass to it.

I know it's a Java related question, but I was wondering if anyone had a
similar problem when configuring drools planner. (I've asked on
stackoverflow, but none of the answers worked for me:
http://stackoverflow.com/questions/7718807/can-getresourceasstream-find-files-outside-the-jar-file
)

(Supposing my .jar is in /some/path and the SolverConf.xml will be on
/some/path/conf for example)

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


[rules-users] Typecasting problem

2011-10-11 Thread hsherlock
I have a following scenario in which a complex logic (distributed over
multiple .DRL files) need to process incoming jobs as fast as possible. A
job definition looks something like describing what to do (type), what to
process (item) with some additional data supplied (args).

enum JobType
{
VALIDATE,
SEND
}

class Job
{
String type; 
Object item;
Object[] args;
}

In order to implement the processing I need to put the business logic into
rules which fire depending on the kind of processing requested and type of
the item passed:

rule process [VALIDATION] on [Document]
when
$job: Job(type==JobType.VALIDATE)
$doc: Document(issued==true) from $job.item
then
insert(new DocumentAlreadyIssuedFact());
end

rule process [SENDING] on [Message]
when
$job: Job(type==JobType.SEND)
$msg: Message() from $job.item
then
//do the sending
end

Unfortunately this does not work and results in ClassCastException being
thrown, because it looks that Drools tries to cast any passed item to the
class expected by the particular rule. In my opinion behaviour one can
expect from Drools here is to first match the item class to the one expected
by the rule and on success to perform the type casting.
Is it a Drools bug or a missing feature?

So after stidying the documention and example code I found only one way to
workaround this – by using eval and instanceof which should have its
performance implications due to extensive use of the eval.

rule process [VALIDATION] on [Message]
when
$job: Job(type==”validate”)
$msg: Message() from $job.item
then
//do the validation
end

rule process [SENDING] on [Message]
when
$job: Job(type==”send”)
$msg: Message() from $job.item
then
//do the sending
end

Such an implementation works, but I see it as some form of workaround as my
feeling is that it will not allow the optimizations of Drools to shine. 

Please recommend more effective and elegant way of implementing this.

Thank you in advance

--
View this message in context: 
http://drools.46999.n3.nabble.com/Typecasting-problem-tp3412494p3412494.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] Typecasting problem

2011-10-11 Thread hsherlock
I have a following scenario in which a complex logic (distributed over
multiple .DRL files) need to process incoming jobs as fast as possible. A
job definition looks something like describing what to do (type), what to
process (item) with some additional data supplied (args).

enum JobType
{
VALIDATE,
SEND
}

class Job
{
String type; 
Object item;
Object[] args;
}

In order to implement the processing I need to put the business logic into
rules which fire depending on the kind of processing requested and type of
the item passed:

rule process [VALIDATION] on [Document]
when
$job: Job(type==JobType.VALIDATE)
$doc: Document(issued==true) from $job.item
then
insert(new DocumentAlreadyIssuedFact());
end

rule process [SENDING] on [Message]
when
$job: Job(type==JobType.SEND)
$msg: Message() from $job.item
then
//do the sending
end

Unfortunately this does not work and results in ClassCastException being
thrown, because it looks that Drools tries to cast any passed item to the
class expected by the particular rule. In my opinion behaviour one can
expect from Drools here is to first match the item class to the one expected
by the rule and on success to perform the type casting.
Is it a Drools bug or a missing feature?

So after stidying the documention and example code I found only one way to
workaround this – by using eval and instanceof which should have its
performance implications due to extensive use of the eval.

rule process [VALIDATION] on [Document]
when
$job: Job(type==JobType.VALIDATE)
eval(($job.item instanceof Document))
$doc: Document(issued==true) from $job.item
then
insert(new DocumentAlreadyIssuedFact());
end

rule process [SENDING] on [Message]
when
$job: Job(type==JobType.SEND)
eval(($job.item instanceof Message))
$msg: Message() from $job.item
then
//do the sending
end

Such an implementation works, but I see it as some form of workaround as my
feeling is that it will not allow the optimizations of Drools to shine. 

Please recommend more effective and elegant way of implementing this.

Thank you in advance

--
View this message in context: 
http://drools.46999.n3.nabble.com/Typecasting-problem-tp3412518p3412518.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] StatefulKnowledgeSession construction executes sequentially (no multithread)

2011-10-11 Thread Juan Carlos Fernández
Same result. This is the source code.

This test tells us that insert() locks too (too many internal resize and
system memory operations).

I tested passing to thread class the session, the knowledge base and create
session at thread construction time, at thread execution time. I obtain the
same result for all tests.

Oh, yes, if I insert double a = Math.sqrt(1919) * Math.sqrt(1919); in the
thread execution without drools code, I can see 100% CPU usage :-)

The only solution that increases CPU usage is the pooling one.

Oh my god!

public class KnowledgeSessionThread extends Thread { 

private static final int iterations = 500; 
private static final int numberFacts = 1000; 
private StatefulKnowledgeSession session; 

public KnowledgeSessionThread(StatefulKnowledgeSession sess) throws
Exception { 
this.session = sess; 
} 

public void run() { 
try { 
for( int i = 0; i  iterations; i++ ) { 
for( int j = 0; j  numberFacts; j++ ) { 
Message msg = new Message(); 
msg.setMessage(Hello world); 
msg.setStatus(Message.HELLO); 
session.insert(msg); 
}
}
session.fireAllRules();
session.dispose();
System.out.println(Thread finished  + 
this.currentThread().getName()); 
} catch( Exception e ) { 
e.printStackTrace(); 
} 
} 
} 

--
View this message in context: 
http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-construction-executes-sequentially-no-multithread-tp3412107p3412530.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] Typecasting problem

2011-10-11 Thread Wolfgang Laun
The best option might very well be to insert the item objects as well and to
write

   $doc: Document(issued==true)
   $job: Job(type==JobType.VALIDATE, item == $doc)

-W


On 11 October 2011 15:10, hsherlock citad...@gmail.com wrote:

 I have a following scenario in which a complex logic (distributed over
 multiple .DRL files) need to process incoming jobs as fast as possible. A
 job definition looks something like describing what to do (type), what to
 process (item) with some additional data supplied (args).

 enum JobType
 {
VALIDATE,
SEND
 }

 class Job
 {
String type;
Object item;
Object[] args;
 }

 In order to implement the processing I need to put the business logic into
 rules which fire depending on the kind of processing requested and type of
 the item passed:

 rule process [VALIDATION] on [Document]
when
$job: Job(type==JobType.VALIDATE)
$doc: Document(issued==true) from $job.item
then
insert(new DocumentAlreadyIssuedFact());
 end

 rule process [SENDING] on [Message]
when
$job: Job(type==JobType.SEND)
$msg: Message() from $job.item
then
//do the sending
 end

 Unfortunately this does not work and results in ClassCastException being
 thrown, because it looks that Drools tries to cast any passed item to the
 class expected by the particular rule. In my opinion behaviour one can
 expect from Drools here is to first match the item class to the one
 expected
 by the rule and on success to perform the type casting.
 Is it a Drools bug or a missing feature?

 So after stidying the documention and example code I found only one way to
 workaround this – by using eval and instanceof which should have its
 performance implications due to extensive use of the eval.

 rule process [VALIDATION] on [Document]
when
$job: Job(type==JobType.VALIDATE)
eval(($job.item instanceof Document))
 $doc: Document(issued==true) from $job.item
then
insert(new DocumentAlreadyIssuedFact());
 end

 rule process [SENDING] on [Message]
when
$job: Job(type==JobType.SEND)
 eval(($job.item instanceof Message))
 $msg: Message() from $job.item
then
//do the sending
 end

 Such an implementation works, but I see it as some form of workaround as my
 feeling is that it will not allow the optimizations of Drools to shine.

 Please recommend more effective and elegant way of implementing this.

 Thank you in advance

 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Typecasting-problem-tp3412518p3412518.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] [planner] Problem setting configuration file

2011-10-11 Thread Geoffrey De Smet

Hi Guilharme,

There's an overloaded method called configure(InputStream in) and 
configure(Reader reader)  too, use either of those instead:


try {
  InputStream in = new FileInputStream(/path/to/xml/file/SolverConf.xml);
  configurer.configure(in);
} finally {
  IOUtils.closeSilently(in);
}

Op 11-10-11 15:01, Guilherme Kunigami schreef:

Hi,

I'm trying to load a configuration file (namely SolverConf.xml) into 
XmlSolver with the code below:


XmlSolverConfigurer configurer = new XmlSolverConfigurer();
configurer.configure(SOLVER_CONFIG);
Solver solver = configurer.buildSolver();

If I bundle SolverConf.xml file with the application .jar file, then 
using SOLVER_CONFIGas /path/to/xml/file/SolverConf.xmlworks fine.


But I want to use SolverConf.xml outside the .jar, so I can easiliy 
edit it, but I don't know what path should I pass to it.


I know it's a Java related question, but I was wondering if anyone had 
a similar problem when configuring drools planner. (I've asked on 
stackoverflow, but none of the answers worked for me: 
http://stackoverflow.com/questions/7718807/can-getresourceasstream-find-files-outside-the-jar-file)


(Supposing my .jar is in /some/path and the SolverConf.xml will be on 
/some/path/conf for example)


Thanks,



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


--
With kind regards,
Geoffrey De Smet

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


Re: [rules-users] How to convert .drl file to XML ...

2011-10-11 Thread FrankVhh
Hi,

You could also use the following functions as described in the Drools Expert
documentation.

XmlDumper - for exporting XML.
DrlDumper - for exporting DRL.
DrlParser - reading DRL.
XmlPackageReader - reading XML

Of course, this will imply that you agree to work with the Drools xml format
:-)

Regards,
Frank

--
View this message in context: 
http://drools.46999.n3.nabble.com/rules-users-How-to-convert-drl-file-to-XML-tp3412206p3412906.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] Typecasting problem

2011-10-11 Thread Edson Tirelli
   Which version of Drools are you using?

   Latest Drools versions changed the behavior of from to deal with it as
you mentioned. So it will not raise ClassCastException. Instead:

$doc: Document(...) from $job.item  // only matches if the returned item is
a Document

$msg: Message(...) from $job.item // only matches if the returned item is a
Message

   I think 5.2 was the first version released with this change, but need to
double check. For sure 5.3 works like that.

   Edson


2011/10/11 hsherlock citad...@gmail.com

 I have a following scenario in which a complex logic (distributed over
 multiple .DRL files) need to process incoming jobs as fast as possible. A
 job definition looks something like describing what to do (type), what to
 process (item) with some additional data supplied (args).

 enum JobType
 {
VALIDATE,
SEND
 }

 class Job
 {
String type;
Object item;
Object[] args;
 }

 In order to implement the processing I need to put the business logic into
 rules which fire depending on the kind of processing requested and type of
 the item passed:

 rule process [VALIDATION] on [Document]
when
$job: Job(type==JobType.VALIDATE)
$doc: Document(issued==true) from $job.item
then
insert(new DocumentAlreadyIssuedFact());
 end

 rule process [SENDING] on [Message]
when
$job: Job(type==JobType.SEND)
$msg: Message() from $job.item
then
//do the sending
 end

 Unfortunately this does not work and results in ClassCastException being
 thrown, because it looks that Drools tries to cast any passed item to the
 class expected by the particular rule. In my opinion behaviour one can
 expect from Drools here is to first match the item class to the one
 expected
 by the rule and on success to perform the type casting.
 Is it a Drools bug or a missing feature?

 So after stidying the documention and example code I found only one way to
 workaround this – by using eval and instanceof which should have its
 performance implications due to extensive use of the eval.

 rule process [VALIDATION] on [Message]
when
$job: Job(type==”validate”)
$msg: Message() from $job.item
then
//do the validation
 end

 rule process [SENDING] on [Message]
when
$job: Job(type==”send”)
$msg: Message() from $job.item
then
//do the sending
 end

 Such an implementation works, but I see it as some form of workaround as my
 feeling is that it will not allow the optimizations of Drools to shine.

 Please recommend more effective and elegant way of implementing this.

 Thank you in advance

 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Typecasting-problem-tp3412494p3412494.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] Temporal operators fail on persisted SKS

2011-10-11 Thread Melton, Michael P CTR SPAWARSYSCEN-ATLANTIC, 01200
Hello,

I have a SKS that is persisted using JPAKnowledgeService. I am using events and 
have multiple rules that match on those events using the after and before 
temporal operators. When I have a fresh session, I can insert events and fire 
rules till the cows come home with no issue. However, if I load a persisted 
session containing event facts and try to insert a new event, when rule 
conditions attempt to evaluate on the *persisted* events in working memory, I 
get org.drools.common.DefaultFactHandle cannot be cast to 
org.drools.common.EventFactHandle.

I have googled extensively on this issue and, though it seems to be relatively 
common, none of the resolutions I've seen apply to me. I've doublechecked that 
my events are declared as such. I've debugged into Drools code and verified 
that the FactHandle returned upon insertion is an EventFactHandle. However, it 
seems as if the engine forgets that these facts are events when the session 
is persisted or rehydrated.

I do not currently have a simple example to share, and I can work on one if 
required, but I wanted to get my question out ahead of that in case anyone in 
the community has an answer for me off the top of their head. Any assistance is 
appreciated.

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


[rules-users] Temporal operators fail on persisted SKS

2011-10-11 Thread Melton, Michael P CTR SPAWARSYSCEN-ATLANTIC, 01200
Hello,

I have a SKS that is persisted using JPAKnowledgeService. I am using events and 
have multiple rules that match on those events using the after and before 
temporal operators. When I have a fresh session, I can insert events and fire 
rules till the cows come home with no issue. However, if I load a persisted 
session containing event facts and try to insert a new event, when rule 
conditions attempt to evaluate on the *persisted* events in working memory, I 
get org.drools.common.DefaultFactHandle cannot be cast to 
org.drools.common.EventFactHandle.

I have googled extensively on this issue and, though it seems to be relatively 
common, none of the resolutions I've seen apply to me. I've doublechecked that 
my events are declared as such. I've debugged into Drools code and verified 
that the FactHandle returned upon insertion is an EventFactHandle. However, it 
seems as if the engine forgets that these facts are events when the session 
is persisted or rehydrated.

I do not currently have a simple example to share, and I can work on one if 
required, but I wanted to get my question out ahead of that in case anyone in 
the community has an answer for me off the top of their head. Any assistance is 
appreciated.

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


Re: [rules-users] Temporal operators fail on persisted SKS

2011-10-11 Thread Mark Proctor

Please don't reply to an existing thread to start a new thread.

The 5.3 release toing out today/tomorrow adds the temperal facilities to 
persistence. Try it and get back to us with issues.


Mark
On 11/10/2011 18:51, Melton, Michael P CTR SPAWARSYSCEN-ATLANTIC, 01200 
wrote:

Hello,
I have a SKS that is persisted using JPAKnowledgeService. I am using 
events and have multiple rules that match on those events using the 
after and before temporal operators. When I have a fresh session, 
I can insert events and fire rules till the cows come home with no 
issue. However, if I load a persisted session containing event facts 
and try to insert a new event, when rule conditions attempt to 
evaluate on the *persisted* events in working memory, I get 
org.drools.common.DefaultFactHandle cannot be cast to 
org.drools.common.EventFactHandle.
I have googled extensively on this issue and, though it seems to be 
relatively common, none of the resolutions I've seen apply to me. I've 
doublechecked that my events are declared as such. I've debugged into 
Drools code and verified that the FactHandle returned upon insertion 
is an EventFactHandle. However, it seems as if the engine forgets 
that these facts are events when the session is persisted or rehydrated.
I do not currently have a simple example to share, and I can work on 
one if required, but I wanted to get my question out ahead of that in 
case anyone in the community has an answer for me off the top of their 
head. Any assistance is appreciated.

Mike


___
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] Map errors and quirks

2011-10-11 Thread zstlaw
Ok finished doing some in depth testing on 5.4.  I was wrong on a few
accounts above the internal variable access to a hash still fails only in a
different way.

First off I added a few new methods to my Mailbox object just for testing :

// returns an statically defined inner enum
public FolderType getDefaultFolderType() {
return FolderType.INBOX;
}

// returns an external enum
public MailType getMailType() {
return MailType.WORK;
}

// takes a statically defined inner enum and returns an external enum
public MailType getMailTypeForFolderType(FolderType pType) {
return MailType.WORK;
}

Test I found that generally enums work much better but internal defined
instances still cause problems.  Also there was some asymmetry where
FolderType.INBOX != $folderType was legal but $folderType !=
FolderType.INBOX was not.

I will start opening issues in JIRA but expect I may need to open one or two
large issues and a lot of sub issues to keep clarity.  In particular the
issue with having an assignments and a variable in the same row continues to
be vexing (i.e. $myvar : getFoo($otherVar) always has problems evaluating
$otherVar since it wants to check it as a inner field of the return type and
not a local variable passed to the procedure call.)

Hope some of this can get in the next build.  I have some huge projects
coming up where we really want to use drools but I am having to really
simplify our data to work around some of these issues.

Thanks,
Zack

--
View this message in context: 
http://drools.46999.n3.nabble.com/Map-errors-and-quirks-tp3404106p3413546.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] Map errors and quirks

2011-10-11 Thread Edson Tirelli
   Zack,

   Thanks for the update and please, do open JIRAs for everything you found
that is not working and ping me after.

   I am working on the binding with extra variables issue at the moment.
E.g.:

$x : someMap[$y]

   The problem here is that Drools always used a fly weight pattern with no
additional inputs for variable bindings. This means it is not possible as of
Drools 5.3 to support that kind of variable binding. What I am doing at the
moment is implementing a more friendly error message for 5.3. For 5.4 I am
discussing it with Mark, but I think we should add support for it.

   Please note that as a work around, in 5.3, you can still bind the
variable to the map ($x : someMap) and then on usage apply the key:

foo == $x[$y]

Edson

2011/10/11 zstlaw zstla...@akamai.com

 Ok finished doing some in depth testing on 5.4.  I was wrong on a few
 accounts above the internal variable access to a hash still fails only in a
 different way.

 First off I added a few new methods to my Mailbox object just for testing :

 // returns an statically defined inner enum
 public FolderType getDefaultFolderType() {
return FolderType.INBOX;
 }

 // returns an external enum
 public MailType getMailType() {
return MailType.WORK;
 }

 // takes a statically defined inner enum and returns an external enum
 public MailType getMailTypeForFolderType(FolderType pType) {
return MailType.WORK;
 }

 Test I found that generally enums work much better but internal defined
 instances still cause problems.  Also there was some asymmetry where
 FolderType.INBOX != $folderType was legal but $folderType !=
 FolderType.INBOX was not.

 I will start opening issues in JIRA but expect I may need to open one or
 two
 large issues and a lot of sub issues to keep clarity.  In particular the
 issue with having an assignments and a variable in the same row continues
 to
 be vexing (i.e. $myvar : getFoo($otherVar) always has problems evaluating
 $otherVar since it wants to check it as a inner field of the return type
 and
 not a local variable passed to the procedure call.)

 Hope some of this can get in the next build.  I have some huge projects
 coming up where we really want to use drools but I am having to really
 simplify our data to work around some of these issues.

 Thanks,
 Zack

 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Map-errors-and-quirks-tp3404106p3413546.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


Re: [rules-users] Map errors and quirks

2011-10-11 Thread zstlaw
I wound up entering the issue as a single JIRA item
https://issues.jboss.org/browse/JBRULES-3241 I figured if sub-components
were right to break out it was better that someone more knowledgeable break
them up in a way that facilitates development.  (At the time I didn't
realize that variable binding was such a distinct sub-entity and had no good
way to describe it myself)

Thank you for your speedy responses and also the attention to the variable
binding problem as they have been particularly troublesome for me.  

Your workaround allows me to continue from where I left off.  Thank you.  I
will eagerly await the next build.
Zack

--
View this message in context: 
http://drools.46999.n3.nabble.com/Map-errors-and-quirks-tp3404106p3413926.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] Guvnor - Loading enums programatically using rule metadata

2011-10-11 Thread GPatel
I realize that drools is a runtime variable, available only during rule 
execution, but the question still stands. Is it possible to somehow pass 
in rule attributes as arguments to Data loaders for enums?

Any help would be appreciated

Thanks
G. Patel



From:   Ghanshyam Patel/Tempe/TotalSystem
To: rules-users@lists.jboss.org
Date:   10/10/2011 03:35 PM
Subject:Guvnor - Loading enums programatically using rule metadata


The Guvnor manual specifies how to load enum data programtically but it 
seems like only other fields on the same Fact can be used to filter the 
values that can show up in the drop-down fields, as shown below:

'Fact.field[dependentField1, dependentField2]' : '(new 
com.yourco.DataHelper()).getListOfAges(@{dependentField1}, 
@{dependentField2})'

Is it possible to somehow use other rule attributes, like package name or 
rule metadata to filter the list? Something like the following:

'Fact.field[dependentField1]' : '(new 
com.yourco.DataHelper()).getListOfAges(@{dependentField1}, 
drools.getRule().getMetaData().get(ID))'

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


Re: [rules-users] Setting category tags programmatically

2011-10-11 Thread Jervis Liu
On 2011/10/12 1:10, gab wrote:
 Hi all,
 my application needs several hundreds rules to implement its business logic.
 We generated such rules from a legacy database using a few sql scripts,
 since the relevant tables contained the business configuration constraints
 for the app, and then added them to Guvnor by means of the eclipse plugin.

 Is it possible to set category tags programmatically for that rules
 artifacts in Guvnor? Possibly a script or some java api?
You can do this through REST service: 
https://hudson.jboss.org/jenkins/job/guvnor/lastSuccessfulBuild/artifact/guvnor-docs/target/docbook/publish/en-US/html_single/index.html#d0e1856

Basically what you need to do is to send a HTTP GET request to retrieve 
asset metadata (in which the category info is not set yet), then send a 
PUT request to update asset metadata with category set to the value you 
want. Please take a look at this test:
https://github.com/droolsjbpm/guvnor/blob/master/guvnor-webapp/src/test/java/org/drools/guvnor/server/jaxrs/AssetPackageResourceTest.java

Cheers,
Jervis
 Thanks in advance,
 Gab


 --
 View this message in context: 
 http://drools.46999.n3.nabble.com/Setting-category-tags-programmatically-tp3413214p3413214.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