/* * (non-Javadoc) * * @see org.kie.common.AgendaI#clearAgendaGroup(org.kie.common.AgendaGroupImpl) */ public void clearAndCancelAgendaGroup(final AgendaGroup agendaGroup) { final EventSupport eventsupport = (EventSupport) this.workingMemory; ((InternalAgendaGroup) agendaGroup) .setClearedForRecency(this.workingMemory.getFactHandleFactory().getRecency()); // this is thread safe for BinaryHeapQueue // Binary Heap locks while it returns the array and reset's it's own internal array. Lock is // released afer getAndClear() for (Activation aQueueable : ((InternalAgendaGroup) agendaGroup).getAndClear()) { final AgendaItem item = (AgendaItem) aQueueable; if (item == null) { continue; } // this must be set false before removal from the activationGroup. // Otherwise the activationGroup will also try to cancel the Actvation // Also modify won't work properly item.setQueued(false); if (item.getActivationGroupNode() != null) { item.getActivationGroupNode().getActivationGroup().removeActivation(item); } eventsupport .getAgendaEventSupport() .fireActivationCancelled(item, this.workingMemory, MatchCancelledCause.CLEAR); } }
public static ProtobufMessages.Activation writeActivation( MarshallerWriteContext context, AgendaItem agendaItem) { ProtobufMessages.Activation.Builder _activation = ProtobufMessages.Activation.newBuilder(); RuleImpl rule = agendaItem.getRule(); _activation.setPackageName(rule.getPackage()); _activation.setRuleName(rule.getName()); _activation.setTuple(writeTuple(agendaItem.getTuple())); _activation.setSalience(agendaItem.getSalience()); _activation.setIsActivated(agendaItem.isQueued()); _activation.setEvaluated(agendaItem.isRuleAgendaItem()); if (agendaItem.getActivationGroupNode() != null) { _activation.setActivationGroup( agendaItem.getActivationGroupNode().getActivationGroup().getName()); } if (agendaItem.getFactHandle() != null) { _activation.setHandleId(agendaItem.getFactHandle().getId()); } org.drools.core.util.LinkedList<LogicalDependency> list = agendaItem.getLogicalDependencies(); if (list != null && !list.isEmpty()) { for (LogicalDependency node = list.getFirst(); node != null; node = node.getNext()) { _activation.addLogicalDependency(((BeliefSet) node.getJustified()).getFactHandle().getId()); } } return _activation.build(); }
public void removeActivation(final AgendaItem activation) { if (declarativeAgenda) { workingMemory .getEntryPointNode() .retractActivation( activation.getFactHandle(), activation.getPropagationContext(), workingMemory); if (activation.getActivationGroupNode() != null) { activation.getActivationGroupNode().getActivationGroup().removeActivation(activation); } } if (activation instanceof ScheduledAgendaItem) { removeScheduleItem((ScheduledAgendaItem) activation); } }
public void modifyActivation(final AgendaItem activation, boolean previouslyActive) { if (declarativeAgenda) { InternalFactHandle factHandle = activation.getFactHandle(); workingMemory .getEntryPointNode() .modifyActivation(factHandle, activation.getPropagationContext(), workingMemory); if (previouslyActive) { // already activated return; } if (activation.isCanceled() || (activation.getBlockers() != null && activation.getBlockers().size() > 0)) { // it's blocked so do nothing return; } // All activations started off staged, they are unstaged if they are blocked or // allowed to move onto the actual agenda for firing. InternalActivationGroup activationGroup = getStageActivationsGroup(); if (activation.getActivationGroupNode() != null && activation.getActivationGroupNode().getActivationGroup() == activationGroup) { // already staged, so return return; } activationGroup.addActivation(activation); } else { if (!previouslyActive) { addActivation(activation, true); } else { Timer timer = activation.getRule().getTimer(); if (timer != null && timer instanceof ExpressionIntervalTimer) { ScheduledAgendaItem schItem = (ScheduledAgendaItem) activation; removeScheduleItem(schItem); scheduleItem(schItem, workingMemory); } } } }