Search in sources :

Example 1 with SimpleMode

use of org.drools.core.beliefsystem.simple.SimpleMode in project drools by kiegroup.

the class TruthMaintenanceSystem method addLogicalDependency.

public InternalFactHandle addLogicalDependency(final InternalFactHandle handle, final Object object, final Object value, final Activation activation, final PropagationContext context, final RuleImpl rule, final ObjectTypeConf typeConf, final boolean read) {
    BeliefSystem beliefSystem = defaultBeliefSystem;
    if (value != null && value instanceof Mode & !(value instanceof SimpleMode)) {
        Mode mode = (Mode) value;
        beliefSystem = (BeliefSystem) mode.getBeliefSystem();
    }
    BeliefSet beliefSet = handle.getEqualityKey().getBeliefSet();
    if (beliefSet == null) {
        if (context.getType() == PropagationContext.Type.MODIFICATION) {
        // if this was a  update, chances  are its trying  to retract a logical assertion
        }
        beliefSet = beliefSystem.newBeliefSet(handle);
        handle.getEqualityKey().setBeliefSet(beliefSet);
    }
    final LogicalDependency node = beliefSystem.newLogicalDependency(activation, beliefSet, object, value);
    activation.getRule().setHasLogicalDependency(true);
    activation.addLogicalDependency(node);
    if (read) {
        // used when deserialising
        beliefSystem.read(node, beliefSet, context, typeConf);
    } else {
        beliefSet = beliefSystem.insert(node, beliefSet, context, typeConf);
    }
    return beliefSet.getFactHandle();
}
Also used : Mode(org.kie.api.internal.runtime.beliefs.Mode) SimpleMode(org.drools.core.beliefsystem.simple.SimpleMode) BeliefSystem(org.drools.core.beliefsystem.BeliefSystem) BeliefSet(org.drools.core.beliefsystem.BeliefSet) SimpleMode(org.drools.core.beliefsystem.simple.SimpleMode)

Example 2 with SimpleMode

use of org.drools.core.beliefsystem.simple.SimpleMode in project drools by kiegroup.

the class DefaultKnowledgeHelper method blockMatch.

public void blockMatch(Match act) {
    AgendaItem targetMatch = (AgendaItem) 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(activation, targetMatch, mode);
        mode.setObject(dep);
    }
    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 : SimpleLogicalDependency(org.drools.core.beliefsystem.simple.SimpleLogicalDependency) RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) AgendaItem(org.drools.core.common.AgendaItem) InternalRuleFlowGroup(org.drools.core.common.InternalRuleFlowGroup) SimpleMode(org.drools.core.beliefsystem.simple.SimpleMode)

Example 3 with SimpleMode

use of org.drools.core.beliefsystem.simple.SimpleMode in project drools by kiegroup.

the class DefaultKnowledgeHelper method cancelRemainingPreviousLogicalDependencies.

public void cancelRemainingPreviousLogicalDependencies() {
    if (this.previousJustified != null) {
        for (LogicalDependency<T> dep = this.previousJustified.getFirst(); dep != null; dep = dep.getNext()) {
            TruthMaintenanceSystemHelper.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);
            AgendaItem justified = (AgendaItem) dep.getJustified();
            justified.getBlockers().remove((SimpleMode) dep.getMode());
            if (justified.getBlockers().isEmpty()) {
                RuleAgendaItem ruleAgendaItem = justified.getRuleAgendaItem();
                workingMemory.getAgenda().stageLeftTuple(ruleAgendaItem, justified);
            }
            dep = tmp;
        }
    }
}
Also used : RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) AgendaItem(org.drools.core.common.AgendaItem) SimpleMode(org.drools.core.beliefsystem.simple.SimpleMode)

Example 4 with SimpleMode

use of org.drools.core.beliefsystem.simple.SimpleMode in project drools by kiegroup.

the class RuleTerminalNodeLeftTuple method removeAllBlockersAndBlocked.

public void removeAllBlockersAndBlocked(InternalAgenda agenda) {
    if (this.blockers != null) {
        // Iterate and remove this node's logical dependency list from each of it's blockers
        for (SimpleMode node = blockers.getFirst(); node != null; node = node.getNext()) {
            LogicalDependency dep = node.getObject();
            dep.getJustifier().getBlocked().remove(dep);
        }
    }
    this.blockers = null;
    if (this.blocked != null) {
        // Iterate and remove this node's logical dependency list from each of it's blocked
        for (LogicalDependency<SimpleMode> dep = blocked.getFirst(); dep != null; ) {
            LogicalDependency<SimpleMode> tmp = dep.getNext();
            removeBlocked(dep);
            RuleTerminalNodeLeftTuple justified = (RuleTerminalNodeLeftTuple) dep.getJustified();
            if (justified.getBlockers().isEmpty() && justified.isActive()) {
                agenda.stageLeftTuple(ruleAgendaItem, justified);
            }
            dep = tmp;
        }
    }
    this.blocked = null;
}
Also used : LogicalDependency(org.drools.core.common.LogicalDependency) SimpleMode(org.drools.core.beliefsystem.simple.SimpleMode)

Example 5 with SimpleMode

use of org.drools.core.beliefsystem.simple.SimpleMode in project drools by kiegroup.

the class AgendaItemImpl method removeAllBlockersAndBlocked.

@Override
public void removeAllBlockersAndBlocked(InternalAgenda agenda) {
    if (this.blockers != null) {
        // Iterate and remove this node's logical dependency list from each of it's blockers
        for (LinkedListEntry<SimpleMode, LogicalDependency<SimpleMode>> node = blockers.getFirst(); node != null; node = node.getNext()) {
            LogicalDependency dep = node.getObject();
            dep.getJustifier().getBlocked().remove(dep);
        }
    }
    this.blockers = null;
    if (this.blocked != null) {
        // Iterate and remove this node's logical dependency list from each of it's blocked
        for (LogicalDependency<SimpleMode> dep = blocked.getFirst(); dep != null; ) {
            LogicalDependency<SimpleMode> tmp = dep.getNext();
            removeBlocked(dep);
            AgendaItem justified = (AgendaItem) dep.getJustified();
            if (justified.getBlockers().isEmpty()) {
                agenda.stageLeftTuple(null, justified);
            }
            dep = tmp;
        }
    }
    this.blocked = null;
}
Also used : RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) SimpleMode(org.drools.core.beliefsystem.simple.SimpleMode)

Aggregations

SimpleMode (org.drools.core.beliefsystem.simple.SimpleMode)5 RuleAgendaItem (org.drools.core.phreak.RuleAgendaItem)3 AgendaItem (org.drools.core.common.AgendaItem)2 BeliefSet (org.drools.core.beliefsystem.BeliefSet)1 BeliefSystem (org.drools.core.beliefsystem.BeliefSystem)1 SimpleLogicalDependency (org.drools.core.beliefsystem.simple.SimpleLogicalDependency)1 InternalRuleFlowGroup (org.drools.core.common.InternalRuleFlowGroup)1 LogicalDependency (org.drools.core.common.LogicalDependency)1 Mode (org.kie.api.internal.runtime.beliefs.Mode)1