-
1. Re: Difficulties Invoking Rule Task
salaboy21 Sep 19, 2011 7:45 AM (in response to tob1as)Hi Tobias,
Yes you are right, when you use Rule Tasks now you need to call fireAllRules. The behavior of the Rule Tasks Nodes in the current version works as follow:
The rule task node will activate the ruleflow group that contains your rules. At that point all the activated rules inside that group are elegible to fire. For that reason you need to call fire all rules in order to fire the active rules. I'm trying to change that behavior to call it automatically.
Cheers
-
2. Re: Difficulties Invoking Rule Task
eaa Sep 19, 2011 11:41 AM (in response to tob1as)The behavior of Rule Task is the one defined by Mauricio.
You have 2 options:
- execute fireAllRules() manually. This could be very tricky because maybe you don't know when or where you need to invoke it
- have a separate thread running fireUntilHalt() in the ksession. For this, you need to manually start a thread invoking fileUntilRun() in its run() method.
But the question is, why does the first example work but the second doesn't?
And the "problem" is because of the inclusion of an asynchornous node in your process: the Human Task.
So, when you start your process, the execution reaches the Human Task, the task is created in the HT Server and the execution control gets back to your code. At that point you are executing the fireAllRules(). This fireAllRules() is not doing anything because there is nothing to be fired. The Rule Task was never executed yet.
When you complete the HT, the process continues its execution and the Rule Task gets invoked. Here you need to call fireAllRules() to continue with the execution of the process.
Best Regards,
-
3. Re: Difficulties Invoking Rule Task
tob1as Sep 25, 2011 3:40 AM (in response to eaa)Thanks Esteban and Mauricio,
is there a simple example for case 2 somewhere? Since the rule engine is a key selling point for jBPM, I would like to be able to present a working business rule task in my scenario. This invocation of a rule task within a process flow however seems a bit awkward.
I would expect the process to just simply run in a rule task, do something and go on with the process.
Another thing - not that I am trying to do it - but could the rules engine theoretically be exchanged / how tightly coupled is jBPM with the rules engine?
Best regards,
Tobias
-
4. Re: Difficulties Invoking Rule Task
tsurdilovic Sep 25, 2011 11:44 AM (in response to tob1as)Hi Tobias, there is a third options which is to attach an AgendaEventListener to your ksession and fire the rules upon an RuleFlowGroupActivatedEvent. Here is an example:
final org.drools.event.AgendaEventListener agendaEventListener = new org.drools.event.AgendaEventListener() {
public void activationCreated(ActivationCreatedEvent event,
WorkingMemory workingMemory){
}
public void activationCancelled(ActivationCancelledEvent event,
WorkingMemory workingMemory){
}
public void beforeActivationFired(BeforeActivationFiredEvent event,
WorkingMemory workingMemory) {
}
public void afterActivationFired(AfterActivationFiredEvent event,
WorkingMemory workingMemory) {
}
public void agendaGroupPopped(AgendaGroupPoppedEvent event,
WorkingMemory workingMemory) {
}
public void agendaGroupPushed(AgendaGroupPushedEvent event,
WorkingMemory workingMemory) {
}
public void beforeRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event,
WorkingMemory workingMemory) {
}
public void afterRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event,
WorkingMemory workingMemory) {
workingMemory.fireAllRules();
}
public void beforeRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event,
WorkingMemory workingMemory) {
}
public void afterRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event,
WorkingMemory workingMemory) {
}
};
((StatefulKnowledgeSessionImpl) ((KnowledgeCommandContext) ((CommandBasedStatefulKnowledgeSession) ksession)
.getCommandService().getContext()).getStatefulKnowledgesession() )
.session.addEventListener(agendaEventListener);
Regarding >> but could the rules engine theoretically be exchanged / how tightly coupled is jBPM with the rules engine? <<
This is where the beauty of custom work items comes in You could write your work item to interact with any rule engine or service.
Hope this helps.
-
5. Re: Difficulties Invoking Rule Task
tob1as Sep 25, 2011 6:24 PM (in response to tsurdilovic)Thanks, that looks a lot more convenient.
-
6. Re: Difficulties Invoking Rule Task
ashu_akg21 Jun 29, 2012 9:57 AM (in response to tsurdilovic)Hi Tihomir,
We are using JBPM 5.3 and we are facing the same problem [getting Rule task to fire after Human Task]. When we tried to follow the method suggested, we are getting only the following events within AgendaEventListener:
AgendaEventListener a=new AgendaEventListener() {
@Override
public void beforeActivationFired(
org.drools.event.rule.BeforeActivationFiredEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void agendaGroupPushed(
org.drools.event.rule.AgendaGroupPushedEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void agendaGroupPopped(
org.drools.event.rule.AgendaGroupPoppedEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void afterActivationFired(
org.drools.event.rule.AfterActivationFiredEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void activationCreated(
org.drools.event.rule.ActivationCreatedEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void activationCancelled(
org.drools.event.rule.ActivationCancelledEvent arg0) {
// TODO Auto-generated method stub
}
};
We cant find afterRuleFlowGroupActivated event here. Could you please advise how we can move forward?
-
7. Re: Difficulties Invoking Rule Task
cold_gin Apr 29, 2013 2:36 PM (in response to tob1as)Here is my solution to this problem in case it helps someone:
https://community.jboss.org/thread/224241