Search in sources :

Example 1 with TruthMaintenanceSystemAgendaItem

use of org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem in project drools by kiegroup.

the class TruthMaintenanceSystemKnowledgeHelper method blockMatch.

@Override
public void blockMatch(Match act) {
    TruthMaintenanceSystemAgendaItem targetMatch = (TruthMaintenanceSystemAgendaItem) act;
    // iterate to find previous equal logical insertion
    LogicalDependency<SimpleMode> dep = null;
    if (this.previousBlocked != null) {
        for (dep = this.previousBlocked.getFirst(); dep != null; dep = dep.getNext()) {
            if (targetMatch == dep.getJustified()) {
                this.previousBlocked.remove(dep);
                break;
            }
        }
    }
    if (dep == null) {
        SimpleMode mode = new SimpleMode();
        dep = new SimpleLogicalDependency((TruthMaintenanceSystemActivation) this.activation, targetMatch, mode);
        mode.setObject(dep);
    }
    ((TruthMaintenanceSystemActivation) this.activation).addBlocked(dep);
    if (targetMatch.getBlockers().size() == 1 && targetMatch.isQueued()) {
        if (targetMatch.getRuleAgendaItem() == null) {
            // it wasn't blocked before, but is now, so we must remove it from all groups, so it cannot be executed.
            targetMatch.remove();
        } else {
            targetMatch.getRuleAgendaItem().getRuleExecutor().removeLeftTuple(targetMatch.getTuple());
        }
        if (targetMatch.getActivationGroupNode() != null) {
            targetMatch.getActivationGroupNode().getActivationGroup().removeActivation(targetMatch);
        }
        if (targetMatch.getActivationNode() != null) {
            final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) targetMatch.getActivationNode().getParentContainer();
            ruleFlowGroup.remove(targetMatch);
        }
    }
}
Also used : TruthMaintenanceSystemActivation(org.drools.tms.agenda.TruthMaintenanceSystemActivation) TruthMaintenanceSystemAgendaItem(org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem) SimpleLogicalDependency(org.drools.tms.beliefsystem.simple.SimpleLogicalDependency) InternalRuleFlowGroup(org.drools.core.common.InternalRuleFlowGroup)

Example 2 with TruthMaintenanceSystemAgendaItem

use of org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem in project drools by kiegroup.

the class TruthMaintenanceSystemKnowledgeHelper method cancelRemainingPreviousLogicalDependencies.

public void cancelRemainingPreviousLogicalDependencies() {
    if (this.previousJustified != null) {
        for (LogicalDependency<T> dep = this.previousJustified.getFirst(); dep != null; dep = dep.getNext()) {
            TruthMaintenanceSystemImpl.removeLogicalDependency(dep, activation.getPropagationContext());
        }
    }
    if (this.previousBlocked != null) {
        for (LogicalDependency<SimpleMode> dep = this.previousBlocked.getFirst(); dep != null; ) {
            LogicalDependency<SimpleMode> tmp = dep.getNext();
            this.previousBlocked.remove(dep);
            TruthMaintenanceSystemAgendaItem justified = (TruthMaintenanceSystemAgendaItem) dep.getJustified();
            justified.getBlockers().remove(dep.getMode());
            if (justified.getBlockers().isEmpty()) {
                RuleAgendaItem ruleAgendaItem = justified.getRuleAgendaItem();
                toStatefulKnowledgeSession().getAgenda().stageLeftTuple(ruleAgendaItem, justified);
            }
            dep = tmp;
        }
    }
}
Also used : RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) TruthMaintenanceSystemAgendaItem(org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem)

Example 3 with TruthMaintenanceSystemAgendaItem

use of org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem in project drools by kiegroup.

the class TruthMaintenanceSystemKnowledgeHelper method unblockAllMatches.

@Override
public void unblockAllMatches(Match act) {
    TruthMaintenanceSystemAgendaItem targetMatch = (TruthMaintenanceSystemAgendaItem) act;
    boolean wasBlocked = (targetMatch.getBlockers() != null && !targetMatch.getBlockers().isEmpty());
    for (LinkedListEntry entry = (LinkedListEntry) targetMatch.getBlockers().getFirst(); entry != null; ) {
        LinkedListEntry tmp = (LinkedListEntry) entry.getNext();
        LogicalDependency dep = (LogicalDependency) entry.getObject();
        ((TruthMaintenanceSystemAgendaItem) dep.getJustifier()).removeBlocked(dep);
        entry = tmp;
    }
    if (wasBlocked) {
        RuleAgendaItem ruleAgendaItem = targetMatch.getRuleAgendaItem();
        InternalAgenda agenda = toStatefulKnowledgeSession().getAgenda();
        agenda.stageLeftTuple(ruleAgendaItem, targetMatch);
    }
}
Also used : InternalAgenda(org.drools.core.common.InternalAgenda) RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) LinkedListEntry(org.drools.core.util.LinkedListEntry) TruthMaintenanceSystemAgendaItem(org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem) SimpleLogicalDependency(org.drools.tms.beliefsystem.simple.SimpleLogicalDependency)

Example 4 with TruthMaintenanceSystemAgendaItem

use of org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem in project drools by kiegroup.

the class ProtobufOutputMarshaller method writeActivation.

public static <M extends ModedAssertion<M>> ProtobufMessages.Activation writeActivation(MarshallerWriteContext context, AgendaItem agendaItem, boolean isDormient) {
    ProtobufMessages.Activation.Builder _activation = ProtobufMessages.Activation.newBuilder();
    RuleImpl rule = agendaItem.getRule();
    _activation.setPackageName(rule.getPackage());
    _activation.setRuleName(rule.getName());
    _activation.setTuple(writeTuple(context, agendaItem, isDormient));
    _activation.setSalience(agendaItem.getSalience());
    _activation.setIsActivated(agendaItem.isQueued());
    _activation.setEvaluated(agendaItem.isRuleAgendaItem());
    if (agendaItem.getActivationGroupNode() != null) {
        _activation.setActivationGroup(agendaItem.getActivationGroupNode().getActivationGroup().getName());
    }
    if (agendaItem.getActivationFactHandle() != null) {
        _activation.setHandleId(agendaItem.getActivationFactHandle().getId());
    }
    if (agendaItem instanceof TruthMaintenanceSystemAgendaItem) {
        org.drools.core.util.LinkedList<LogicalDependency<M>> list = ((TruthMaintenanceSystemAgendaItem) 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();
}
Also used : TruthMaintenanceSystemAgendaItem(org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem) LogicalDependency(org.drools.tms.LogicalDependency) BeliefSet(org.drools.tms.beliefsystem.BeliefSet) Activation(org.drools.core.spi.Activation) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl)

Aggregations

TruthMaintenanceSystemAgendaItem (org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem)4 RuleAgendaItem (org.drools.core.phreak.RuleAgendaItem)2 SimpleLogicalDependency (org.drools.tms.beliefsystem.simple.SimpleLogicalDependency)2 InternalAgenda (org.drools.core.common.InternalAgenda)1 InternalRuleFlowGroup (org.drools.core.common.InternalRuleFlowGroup)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 Activation (org.drools.core.spi.Activation)1 LinkedListEntry (org.drools.core.util.LinkedListEntry)1 LogicalDependency (org.drools.tms.LogicalDependency)1 TruthMaintenanceSystemActivation (org.drools.tms.agenda.TruthMaintenanceSystemActivation)1 BeliefSet (org.drools.tms.beliefsystem.BeliefSet)1