Drools Rule Evaluations are Inconsistent
by bdolbeare
Drools is not producing consistent results in the following example. If you
run the DRL shown below, you will see that rules 2 and 3 activate and log a
message. If you then comment out rule 3 in the DRL (you must put the entire
rule inside /* */ characters rather than simply disabling it), and rerun
it, you'll notice that rules 1 and 2 fire. How is it that the presence of
rule 3 affects whether or not rule 1 activates? These two rules are not
dependent in their DRL.
It appears to be related to the fact that rule 1 uses single quotes instead
of double quotes. If you change that, then Drools starts behaving
consistently. This makes me believe that the problem is somehow related to
how Drools is building the Rete tree with the single quotes.
With all three rules active I get:
[main]::INFO ::DroolsTest::test 3 hit on RecordA( id=100 ) - RecordB(
id=100, role=2 )
[main]::INFO ::DroolsTest::test 2 hit on RecordA( id=100 ) - RecordB(
id=100, role=1 )
With rule 3 commented out I get:
[main]::INFO ::DroolsTest::test 2 hit on RecordA( id=100 ) - RecordB(
id=100, role=1 )
[main]::INFO ::DroolsTest::test 1 hit on RecordA( id=100 ) - RecordB(
id=100, role=1 )
Interestingly, if you comment out rule 2 so only rules 1 and 3 are active,
rule 1 fires again:
[main]::INFO ::DroolsTest::test 3 hit on RecordA( id=100 ) - RecordB(
id=100, role=2 )
[main]::INFO ::DroolsTest::test 1 hit on RecordA( id=100 ) - RecordB(
id=100, role=1 )
*Environment: Drools 5.4.0*
package tests
import org.apache.log4j.Logger;
global Logger log
declare RecordA
id : long
end
declare RecordB
id : long
role : String
end
rule "insert data 1"
salience 99999
when
then
insert (new RecordA(100));
insert (new RecordB(100, "1"));
insert (new RecordB(100, "2"));
end
rule "test 1"
when
a : RecordA( )
b : RecordB( id == b.id, role == '1' )
then
log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(),
a, b));
end
rule "test 2"
when
a : RecordA( )
b : RecordB( id == b.id, role == "1" )
then
log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(),
a, b));
end
rule "test 3"
when
a : RecordA( )
b : RecordB( id == b.id, role == "2" )
then
log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(),
a, b));
end
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Rule-Evaluations-are-Inconsisten...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 5 months
how is Integer converted when comparing with primitive?
by mpgong
Hello
I have a rule that looks something like this
when
$mydate : TaskRowDate(0 < currentLateCount < 100)
then
doSomething();
My problem is that currentLateCount is an Integer type because i want to be
able to store null. 0 means something different in my app.
The problem is when a fact that is inserted with the currentLateCount =
null, the above rule matches and is fired.
Is this suppose to be the case and what value does currentLateCount take
that makes it match?
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/how-is-Integer-converted-when-comparing...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 5 months
Drools 5.4 final and jbpm: problem in acces process variable
by Manasi
Hi all,
I am newbie in drools and jbpm. I am getting problem in retrieving the
updated process variable value.
Here is the code:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(flowName),
ResourceType.BPMN2);
KnowledgeBase knowledgeBase= kbuilder.newKnowledgeBase();
StatefulKnowledgeSession ksession = knowledgeBase
.newStatefulKnowledgeSession();
// Retrieving request parameters
Map<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put("screenId",screenId);
parameterMap.put("hello","abc");
ksession.startProcess("com.yousee.drools.services.DroolsAuthorizationService",
parameterMap);
ksession.fireAllRules();
I am passing parameter to the jbpm while starting the process for the
execution of flow.
Now if my process chnages this value. say process variable hello value to
"abcd".
How to get the updated variable value in java? wahts the api?
Plz help asap.
Regards
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-5-4-final-and-jbpm-problem-in-ac...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 5 months
Reloading knowledge base from another thread
by gkalabin
Hi everybody!
I'm using Drools 5.4.0.Final.
I'm checking changes in knowledge repository and if there is any - update
knowledge base.
The changes listening I perform like described in article:
https://community.jboss.org/wiki/PublishDroolsArtifactsFromAProductionEnv....
Updating knowledge base code:
private static final Environment JBPM_ENVIRONMENT =
KnowledgeBaseFactory.newEnvironment();
private static final KnowledgeSessionConfiguration JBPM_CONFIG;
static {
JBPM_ENVIRONMENT.set(EnvironmentName.ENTITY_MANAGER_FACTORY,
Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa"));
JBPM_ENVIRONMENT.set(EnvironmentName.TRANSACTION_MANAGER,
TransactionManagerServices.getTransactionManager());
JBPM_ENVIRONMENT.set(EnvironmentName.GLOBALS, new
MapGlobalResolver());
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory",
"org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory",
"org.jbpm.persistence.processinstance.JPASignalManagerFactory");
JBPM_CONFIG =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
}
....
private static StatefulKnowledgeSession createSession() {
StatefulKnowledgeSession session =
JPAKnowledgeService.newStatefulKnowledgeSession(readKnowledgeBase(),
JBPM_CONFIG, JBPM_ENVIRONMENT);
session.getWorkItemManager().registerWorkItemHandler("Human Task",
new CommandBasedWSHumanTaskHandler(session));
return session;
}
When I load changes from main thread (on startup, for example) everything is
fine, but when I try to reload knowledge base from another thread it falls
with exception ( full stacktrace
<http://drools.46999.n3.nabble.com/file/n4020008/error_log.txt> ):
15:00:56,420 ERROR [org.drools.persistence.SingleSessionCommandService]
(Timer-14) Could not commit session: java.lang.NullPointerException
at
org.drools.persistence.jta.JtaTransactionManager.getStatus(JtaTransactionManager.java:205)
[drools-persistence-jpa-5.4.0.Final.jar:5.4.0.Final]
How can I solve it?
Thank you for your attention. Have a good day!
--
View this message in context: http://drools.46999.n3.nabble.com/Reloading-knowledge-base-from-another-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 5 months
How to integrate Drools application with Servlet
by zeeshan
Hi All !
I have an existing web application "Bonus Calculation Management System"
which has been developed in servlet and Hibernate which is interacting with
DB. I have developed a product in Drools using Struts. Now the task is I
have to integrate this drools product in the Existing Servlet application. I
have integrating it converting Struts to Servlet. But it is giving this
exception about my Rule File :
*
com.drools.action.PolicyAction
hurrrrrrrrrrrrrr
java.io.FileNotFoundException: Cannot find rule file:Sample.drl
at com.drools.facts.RuleRunner.loadRuleFile(RuleRunner.java:89)
at com.drools.facts.RuleRunner.loadRules(RuleRunner.java:67)
at com.drools.facts.RuleRunner.getStatefulSession(RuleRunner.java:227)
at com.drools.facts.RuleMain.main(RuleMain.java:46)*
*In my Servlet class I have written like this :* public int
calculate(HttpServletRequest req, String schId,String schStepID, Date
clcFrDate, Date clcToDate,String runNo)
{
System.out.println("hurrrrrrrrrrrrrr");
InputFormBean inputFormBean=new InputFormBean();
inputFormBean.setFromDate(clcFrDate.toString());
inputFormBean.setToDate(clcToDate.toString());
String fromDateArray[]=inputFormBean.getFromDate().trim().split("/");
String toDateArray[]=inputFormBean.getToDate().trim().split("/");
inputFormBean.setFromDateArray(fromDateArray);
inputFormBean.setToDateArray(toDateArray);
RuleMain ruleMain=new RuleMain();
try {
ruleMain.main(inputFormBean);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
*In the RuleMain.java* : public class RuleMain extends HttpServlet {
private final String[] RULES_FILES8 = new String[] {"Sample.drl"}; // *I
also tried : com.drools.rules/Sample.drl but dint work*
static HashMap<Integer, Double>agntAPEMap=new HashMap<Integer, Double>();
public void main(InputFormBean inputFormBean) throws Exception {
HashMap<String, Object> globals = new HashMap<String, Object>();
//globals.put("index", new Index(0));
StatefulSession statefulSession=new
RuleRunner().getStatefulSession(RULES_FILES8,null,null, globals, null);
......
........
Thanks !!!
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-integrate-Drools-application-wit...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 5 months
Planner: Vehicle Routing, but with return to home after last delivery
by jimirn
Hi all,
I have changed the Vehicle Routing example to suit my domain model.
My domain is:
- Consultant (the person that will drive to a DeliveryPlace and spent some
time there, each Consultant has a max total time available, implements
Appearance)
- DeliveryPlace (the place where a Consultant will drive to and spent some
time making a delivery, implements Appearance)
- Location (a Consultant has a home and a DeliveryPlace has a location)
I need the soft constraints to take into account returning from last
DeliveryPlace to the home location of the Consultant.
But how do I know if a DeliveryPlace is the last one so I can add that to
the rule ?
Right now I have a rule that just takes each DeliveryPlace and calculates
minutes to previousAppearance:
rule "minutesToPreviousAppearance"
when
$deliveryPlace : DeliveryPlace(previousAppearance != null,
$minutesToPreviousAppearance : minutesToPreviousAppearance)
then
insertLogical(new
IntConstraintOccurrence("minutesToPreviousAppearance",
ConstraintType.NEGATIVE_SOFT,
$minutesToPreviousAppearance,
$deliveryPlace));
end
--
View this message in context: http://drools.46999.n3.nabble.com/Planner-Vehicle-Routing-but-with-return...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 5 months
adding de-serialized packages to the rulebase takes 7 minutes time.
by subba
Hi,
I am using drools 5.0.0 CR1 on sun sparc machine with JRE 1.6.0_12. The JVM
has 2GB heap and 256 permGen settings.
Recently I have noticed that the adding the deserialized package to the
rulebase takes almost 7 minutes time.
The serialized cache files contains 4000 rules and the file size is 40MB.
The de-serialization is pretty quick but adding this package to the rulebase
is taking lot of time.
Other observations:
=============
1. The the task on windows PC takes lesser time.
2. During addpackage method execution, I had observed lots of Garbage
collection happening though there is plenty of heap available.
Can you please suggest a way to improve this task timing ?
Regards.
Subba.
--
View this message in context: http://drools.46999.n3.nabble.com/adding-de-serialized-packages-to-the-ru...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 5 months