public boolean createPostponedActivation( final LeftTuple tuple, final PropagationContext context, final InternalWorkingMemory workingMemory, final TerminalNode rtn) { final RuleImpl rule = rtn.getRule(); AgendaItem item; 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) getAgendaGroup(rule.getAgendaGroup()); // 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; } item = createAgendaItem(tuple, 0, context, rtn, null, agendaGroup); item.setSalience( rule.getSalience() .getValue(new DefaultKnowledgeHelper(item, workingMemory), rule, workingMemory)); if (activationsFilter != null && !activationsFilter.accept(item, workingMemory, rtn)) { return false; } item.setQueued(true); tuple.increaseActivationCountForEvents(); ((EventSupport) workingMemory) .getAgendaEventSupport() .fireActivationCreated(item, workingMemory); return true; }
/* * (non-Javadoc) * * @see org.kie.common.AgendaI#getNextFocus() */ public InternalAgendaGroup getNextFocus() { InternalAgendaGroup agendaGroup; // Iterate until we find a populate AgendaModule or we reach the MAIN, // default, AgendaGroup while (true) { agendaGroup = (InternalAgendaGroup) this.focusStack.getLast(); if (!agendaGroup.isAutoDeactivate()) { // does not automatically pop, when empty, so always return, even if empty break; } final boolean empty = agendaGroup.isEmpty(); // No populated queues found so pop the focusStack and repeat if (empty && (this.focusStack.size() > 1)) { agendaGroup.setActive(false); this.focusStack.removeLast(); if (agendaGroup.isAutoDeactivate() && !agendaGroup.getNodeInstances().isEmpty()) { innerDeactiveRuleFlowGroup((InternalRuleFlowGroup) agendaGroup); } final EventSupport eventsupport = (EventSupport) this.workingMemory; eventsupport.getAgendaEventSupport().fireAgendaGroupPopped(agendaGroup, this.workingMemory); } else { agendaGroup = (empty) ? null : agendaGroup; break; } } if (agendaGroup != null && !agendaGroup.isActive()) { // only update recency, if not already active. It may be active already if the use called // setFocus agendaGroup.setActivatedForRecency(this.workingMemory.getFactHandleFactory().getRecency()); agendaGroup.setActive(true); } return agendaGroup; }
public boolean createActivation( final LeftTuple tuple, final PropagationContext context, final InternalWorkingMemory workingMemory, final TerminalNode rtn) { // 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 (rtn.isFireDirect()) { // Fire RunLevel == 0 straight away. agenda-groups, rule-flow groups, salience are ignored AgendaItem item = createAgendaItem(tuple, 0, context, rtn, null, null); tuple.setObject(item); if (activationsFilter != null && !activationsFilter.accept(item, workingMemory, rtn)) { return false; } item.setQueued(true); tuple.increaseActivationCountForEvents(); fireActivation(item); // Control rules fire straight away. return true; } final RuleImpl rule = rtn.getRule(); AgendaItem item; final Timer timer = rule.getTimer(); InternalAgendaGroup agendaGroup = (InternalAgendaGroup) getAgendaGroup(rule.getAgendaGroup()); if (timer != null) { item = createScheduledAgendaItem(tuple, context, rtn, agendaGroup); } 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; } } } if (rule.isLockOnActive() && agendaGroup.isActive() && agendaGroup.getAutoFocusActivator() != context) { // do not add the activation if the rule is "lock-on-active" and the AgendaGroup is active 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; } item = createAgendaItem(tuple, 0, context, rtn, null, agendaGroup); item.setSalience( rule.getSalience() .getValue(new DefaultKnowledgeHelper(item, workingMemory), rule, workingMemory)); } if (activationsFilter != null && !activationsFilter.accept(item, workingMemory, rtn)) { return false; } item.setQueued(true); tuple.increaseActivationCountForEvents(); ((EventSupport) workingMemory) .getAgendaEventSupport() .fireActivationCreated(item, workingMemory); return true; }