admin管理员组文章数量:1024624
Misterious error occurs when migrating from 5.5.0.Final version of Drools to latest Drools version 9.44.0.Final.
We have a rule that calls a Java method, and then this method calls a Query from Drools. This worked fine in older version, but now in the latest versions doesn't work. The execution hangs.
Debugging it like the current state of KieSessions' Agenda was FIRING and the Query call provokes a new item in this agenda that is blocked permanently and never returns to the code.
Sample code is the following one:
////
// DROOLS
////
query javaToDrools
ves : Data()
end
rule "INSERT: New Item"
when
$data: MyData($id:id)
then
System.out.println("Insert Data: " + $id);
insert(new Data($data));
myJavaClass.droolsToJava();
end
////
// JAVA
////
public void droolsToJava() {
QueryResults results = session.getQueryResults("javaToDrools");
results.forEach(res -> {
res.toString();
});
session.fireUntilHalt();
}
The problem is here:
StatefulKnowledgeSessionImpl.getQueryResults
-> StatefulKnowledgeSessionImpl.internalGetQueryResult
-> StatefulKnowledgeSessionImpl.evalQuery
-> StatefulKnowledgeSessionImpl.addPropagation -> It adds the Propagation
But then in the evalQuery
method, the call to executeQuery.getResult() never retrieves the result. It hangs into an infinite loop.
It's like I can't insert a fact into the KieSession and call to a query at the same time...
Misterious error occurs when migrating from 5.5.0.Final version of Drools to latest Drools version 9.44.0.Final.
We have a rule that calls a Java method, and then this method calls a Query from Drools. This worked fine in older version, but now in the latest versions doesn't work. The execution hangs.
Debugging it like the current state of KieSessions' Agenda was FIRING and the Query call provokes a new item in this agenda that is blocked permanently and never returns to the code.
Sample code is the following one:
////
// DROOLS
////
query javaToDrools
ves : Data()
end
rule "INSERT: New Item"
when
$data: MyData($id:id)
then
System.out.println("Insert Data: " + $id);
insert(new Data($data));
myJavaClass.droolsToJava();
end
////
// JAVA
////
public void droolsToJava() {
QueryResults results = session.getQueryResults("javaToDrools");
results.forEach(res -> {
res.toString();
});
session.fireUntilHalt();
}
The problem is here:
StatefulKnowledgeSessionImpl.getQueryResults
-> StatefulKnowledgeSessionImpl.internalGetQueryResult
-> StatefulKnowledgeSessionImpl.evalQuery
-> StatefulKnowledgeSessionImpl.addPropagation -> It adds the Propagation
But then in the evalQuery
method, the call to executeQuery.getResult() never retrieves the result. It hangs into an infinite loop.
It's like I can't insert a fact into the KieSession and call to a query at the same time...
Share Improve this question edited Nov 18, 2024 at 12:38 Marc Gil Sendra asked Nov 18, 2024 at 11:55 Marc Gil SendraMarc Gil Sendra 9312 gold badges10 silver badges24 bronze badges 2- Which JRE version are you using? – artiomi Commented Nov 18, 2024 at 12:11
- I tried with Java 17 and Java 21 with same result – Marc Gil Sendra Commented Nov 18, 2024 at 12:15
1 Answer
Reset to default 0I found that the problem is that the RuleBaseConfiguration
is set to be executed in SEQUENTIAL
, and I can't set it to FULLY_PARALLEL
due to Queries are not supported. See KnowledgeBaseImpl#checkParallelEvaluation
if (ruleBaseConfig.isParallelEvaluation()) {
if (!rule.isMainAgendaGroup()) {
disableParallelEvaluation( "Agenda-groups are not supported with parallel execution: disabling it" );
} else if (rule.getActivationGroup() != null) {
disableParallelEvaluation( "Activation-groups are not supported with parallel execution: disabling it" );
} else if (!rule.getSalience().isDefault() && ruleBaseConfig.isParallelExecution()) {
disableParallelEvaluation( "Salience is not supported with parallel execution: disabling it" );
} else if (rule.isQuery()) {
disableParallelEvaluation( "Queries are not supported with parallel execution: disabling it" );
}
}
Latest if
force to SEQUENTIAL execution.
Misterious error occurs when migrating from 5.5.0.Final version of Drools to latest Drools version 9.44.0.Final.
We have a rule that calls a Java method, and then this method calls a Query from Drools. This worked fine in older version, but now in the latest versions doesn't work. The execution hangs.
Debugging it like the current state of KieSessions' Agenda was FIRING and the Query call provokes a new item in this agenda that is blocked permanently and never returns to the code.
Sample code is the following one:
////
// DROOLS
////
query javaToDrools
ves : Data()
end
rule "INSERT: New Item"
when
$data: MyData($id:id)
then
System.out.println("Insert Data: " + $id);
insert(new Data($data));
myJavaClass.droolsToJava();
end
////
// JAVA
////
public void droolsToJava() {
QueryResults results = session.getQueryResults("javaToDrools");
results.forEach(res -> {
res.toString();
});
session.fireUntilHalt();
}
The problem is here:
StatefulKnowledgeSessionImpl.getQueryResults
-> StatefulKnowledgeSessionImpl.internalGetQueryResult
-> StatefulKnowledgeSessionImpl.evalQuery
-> StatefulKnowledgeSessionImpl.addPropagation -> It adds the Propagation
But then in the evalQuery
method, the call to executeQuery.getResult() never retrieves the result. It hangs into an infinite loop.
It's like I can't insert a fact into the KieSession and call to a query at the same time...
Misterious error occurs when migrating from 5.5.0.Final version of Drools to latest Drools version 9.44.0.Final.
We have a rule that calls a Java method, and then this method calls a Query from Drools. This worked fine in older version, but now in the latest versions doesn't work. The execution hangs.
Debugging it like the current state of KieSessions' Agenda was FIRING and the Query call provokes a new item in this agenda that is blocked permanently and never returns to the code.
Sample code is the following one:
////
// DROOLS
////
query javaToDrools
ves : Data()
end
rule "INSERT: New Item"
when
$data: MyData($id:id)
then
System.out.println("Insert Data: " + $id);
insert(new Data($data));
myJavaClass.droolsToJava();
end
////
// JAVA
////
public void droolsToJava() {
QueryResults results = session.getQueryResults("javaToDrools");
results.forEach(res -> {
res.toString();
});
session.fireUntilHalt();
}
The problem is here:
StatefulKnowledgeSessionImpl.getQueryResults
-> StatefulKnowledgeSessionImpl.internalGetQueryResult
-> StatefulKnowledgeSessionImpl.evalQuery
-> StatefulKnowledgeSessionImpl.addPropagation -> It adds the Propagation
But then in the evalQuery
method, the call to executeQuery.getResult() never retrieves the result. It hangs into an infinite loop.
It's like I can't insert a fact into the KieSession and call to a query at the same time...
Share Improve this question edited Nov 18, 2024 at 12:38 Marc Gil Sendra asked Nov 18, 2024 at 11:55 Marc Gil SendraMarc Gil Sendra 9312 gold badges10 silver badges24 bronze badges 2- Which JRE version are you using? – artiomi Commented Nov 18, 2024 at 12:11
- I tried with Java 17 and Java 21 with same result – Marc Gil Sendra Commented Nov 18, 2024 at 12:15
1 Answer
Reset to default 0I found that the problem is that the RuleBaseConfiguration
is set to be executed in SEQUENTIAL
, and I can't set it to FULLY_PARALLEL
due to Queries are not supported. See KnowledgeBaseImpl#checkParallelEvaluation
if (ruleBaseConfig.isParallelEvaluation()) {
if (!rule.isMainAgendaGroup()) {
disableParallelEvaluation( "Agenda-groups are not supported with parallel execution: disabling it" );
} else if (rule.getActivationGroup() != null) {
disableParallelEvaluation( "Activation-groups are not supported with parallel execution: disabling it" );
} else if (!rule.getSalience().isDefault() && ruleBaseConfig.isParallelExecution()) {
disableParallelEvaluation( "Salience is not supported with parallel execution: disabling it" );
} else if (rule.isQuery()) {
disableParallelEvaluation( "Queries are not supported with parallel execution: disabling it" );
}
}
Latest if
force to SEQUENTIAL execution.
本文标签: Call from Drools Rule to Java and call to QueryStack Overflow
版权声明:本文标题:Call from Drools Rule to Java and call to Query - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745619732a2159501.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论