/* * (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; }