if ( item != null && item.isActivated() ) {
// already activated, do nothing
return;
}
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() ) ) {
agenda.increaseDormantActivations();
return;
}
final Timer timer = this.rule.getTimer();
if ( timer != null ) {
if ( item == null ) {
item = agenda.createScheduledAgendaItem( leftTuple,
context,
this.rule,
this.subrule );
}
agenda.scheduleItem( (ScheduledAgendaItem) item,
workingMemory );
item.setActivated( true );
// workingMemory.removeLogicalDependencies( item,
// context,
// this.rule );
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
workingMemory );
} else {
if ( this.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 : this.rule.getCalendars() ) {
if ( !workingMemory.getCalendars().get( cal ).isTimeIncluded( timestamp ) ) {
return;
}
}
}
if ( item == null ) {
// -----------------
// Lazy instantiation and addition to the Agenda of AgendGroup
// implementations
// ----------------
item = agenda.createAgendaItem( leftTuple,
rule.getSalience().getValue( leftTuple,
workingMemory ),
context,
this.rule,
this.subrule );
item.setSequenence( this.sequence );
} else {
item.setSalience( rule.getSalience().getValue( leftTuple,
workingMemory ) ); // need to re-evaluate salience, as used fields may have changed
item.setPropagationContext( context ); // update the Propagation Context
}
boolean added = agenda.addActivation( item );
item.setActivated( added );
if ( added ) {
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
workingMemory );
}
}
agenda.increaseActiveActivations();
}