tuple.increaseActivationCountForEvents();
fireActivation( item ); // Control rules fire straight away.
return true;
}
final Rule rule = rtn.getRule();
AgendaItem item;
final Timer timer = rule.getTimer();
if ( timer != null ) {
if ( reuseActivation ) {
item = ( AgendaItem ) tuple.getObject();
item.setPropagationContext( context );
} else {
item = createScheduledAgendaItem( tuple,
context,
rtn );
}
} 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;
}
}
}
long handleRecency = this.unlinkingEnabled ? ((InternalFactHandle) context.getFactHandle()).getRecency() : 0; // this is needed as on sink updates context fh may not be sets
InternalAgendaGroup agendaGroup = (InternalAgendaGroup) 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() &&
( !this.unlinkingEnabled || agendaGroup.getActivatedForRecency() < handleRecency ) &&
agendaGroup.getAutoFocusActivator() != context) {
if ( tuple.getObject() == null ) {
tuple.setObject( Boolean.TRUE ); // this is so we can do a check with a bit more intent than a null check on modify
}
return false;
} else if ( this.unlinkingEnabled && agendaGroup.getClearedForRecency() != -1 && agendaGroup.getClearedForRecency() >= handleRecency ) {
return false;
}
} else {
// There is a RuleFlowNode so add it there, instead of the Agenda
InternalRuleFlowGroup rfg = (InternalRuleFlowGroup) 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() &&
( !this.unlinkingEnabled || rfg.getActivatedForRecency() < handleRecency ) &&
agendaGroup.getAutoFocusActivator() != context) {
if ( tuple.getObject() == null ) {
tuple.setObject( Boolean.TRUE ); // this is so we can do a check with a bit more intent than a null check on modify
}
return false;
} else if ( this.unlinkingEnabled && rfg.getClearedForRecency() != -1 && rfg.getClearedForRecency() >= handleRecency ) {
return false;
}
}
if ( reuseActivation ) {
item = ( AgendaItem ) tuple.getObject();
item.setSalience( rule.getSalience().getValue( new DefaultKnowledgeHelper( item, workingMemory ),
rule,
workingMemory ) );
item.setPropagationContext( context );
} else {
item = createAgendaItem( tuple,
0,
context,
rtn);
item.setSalience( rule.getSalience().getValue( new DefaultKnowledgeHelper( item, workingMemory ),
rule,
workingMemory ) );
}
item.setAgendaGroup( agendaGroup );