if ( !this.rule.isEffective( tuple,
workingMemory ) ) {
return false;
}
final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
// if the current Rule is no-loop and the origin rule is the same then return
if ( this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() ) ) {
return false;
}
// First process control rules
// Control rules do increase ActivationCountForEvent and agenda ActivateActivations, they do not currently fire events
// ControlRules for now re-use the same PropagationContext
if ( fireDirect ) {
// Fire RunLevel == 0 straight away. agenda-groups, rule-flow groups, salience are ignored
AgendaItem item = null;
if ( reuseActivation ) {
item = ( AgendaItem ) tuple.getObject();
} else {
item = agenda.createAgendaItem( tuple,
0,
context,
this);
}
tuple.setObject( item );
item.setActivated( true );
tuple.increaseActivationCountForEvents();
agenda.increaseActiveActivations();
agenda.fireActivation( item ); // Control rules fire straight away.
return true;
}
AgendaItem item = null;
final Timer timer = this.rule.getTimer();
if ( timer != null ) {
if ( reuseActivation ) {
item = ( AgendaItem ) tuple.getObject();
} else {
item = agenda.createScheduledAgendaItem( tuple,
context,
this );
}
} else {
if ( rule.getCalendars() != null ) {
// for normal activations check for Calendar inclusion here, scheduled activations check on each trigger point
long timestamp = workingMemory.getSessionClock().getCurrentTime();
for ( String cal : rule.getCalendars() ) {
if ( !workingMemory.getCalendars().get( cal ).isTimeIncluded( timestamp ) ) {
return false;
}
}
}
InternalAgendaGroup agendaGroup = (InternalAgendaGroup) agenda.getAgendaGroup( rule.getAgendaGroup() );
if ( rule.getRuleFlowGroup() == null ) {
// No RuleFlowNode so add it directly to the Agenda
// do not add the activation if the rule is "lock-on-active" and the
// AgendaGroup is active
if ( rule.isLockOnActive() && agendaGroup.isActive() && agendaGroup.getAutoFocusActivator() != context) {
return false;
}
} else {
// There is a RuleFlowNode so add it there, instead of the Agenda
InternalRuleFlowGroup rfg = (InternalRuleFlowGroup) agenda.getRuleFlowGroup( rule.getRuleFlowGroup() );
// do not add the activation if the rule is "lock-on-active" and the
// RuleFlowGroup is active
if ( rule.isLockOnActive() && rfg.isActive() && agendaGroup.getAutoFocusActivator() != context) {
return false;
}
}
if ( reuseActivation ) {
item = ( AgendaItem ) tuple.getObject();
item.setSalience( rule.getSalience().getValue( tuple,
this.rule,
workingMemory ) );
item.setPropagationContext( context );
} else {
item = agenda.createAgendaItem( tuple,
rule.getSalience().getValue( tuple,
this.rule,
workingMemory ),
context,
this);
}
item.setAgendaGroup( agendaGroup );
}
tuple.setObject( item );
item.setActivated( true );
tuple.increaseActivationCountForEvents();
agenda.increaseActiveActivations();
item.setSequenence( this.sequence );
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
workingMemory );
return true;