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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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