boolean tryagain;
int localFireCount = 0;
try {
do {
while ( !eager.isEmpty() ) {
RuleAgendaItem item = eager.removeFirst();
log.trace("Eager Evaluating rule {}.", item.getRule().getName() );
item.getRuleExecutor().evaluateNetwork(this.workingMemory);
}
this.workingMemory.prepareToFireActivation();
tryagain = false;
final InternalAgendaGroup group = (InternalAgendaGroup) getNextFocus();
// if there is a group with focus
if ( group != null ) {
if ( this.unlinkingEnabled ) {
final RuleAgendaItem item = (RuleAgendaItem) group.peekNext();
localFireCount = item.getRuleExecutor().evaluateNetworkAndFire(this.workingMemory, filter,
fireCount, fireLimit);
if ( localFireCount == 0 ) {
// nothing matched
tryagain = true; // will force the next Activation of the agenda, without going to outer loop which checks halt
this.workingMemory.executeQueuedActions(); // There may actions to process, which create new rule matches
}
} else {
final AgendaItem item = (AgendaItem) group.getNext();
// if there is an item to fire from that group
if ( item != null ) {
// if that item is allowed to fire
// The routine bellow cleans up ruleflow activations
InternalRuleFlowGroup ruleFlowGroup = null;
if ( item.getActivationNode() != null ) {
ruleFlowGroup = (InternalRuleFlowGroup) item.getActivationNode().getParentContainer();
// it is possible that the ruleflow group is no longer active if it was
// cleared during execution of this activation
ruleFlowGroup.removeActivation( item );
}