Hi Tobias, there is a third options which IMO is some better than the other two which is to attach an AgendaEventListener to your ksession and fire the rules upon an RuleFlowGroupActivatedEvent. Here is an example which is a paste from CommandDelegate.java in the jBPM console:
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.