Search in sources :

Example 1 with TruthMaintenanceSystemActivation

use of org.drools.tms.agenda.TruthMaintenanceSystemActivation 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 TruthMaintenanceSystemActivation

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

the class TruthMaintenanceSystemKnowledgeHelper method bolster.

@Override
public InternalFactHandle bolster(final Object object, final Object value) {
    if (object == null || !activation.isMatched()) {
        return null;
    }
    InternalFactHandle handle = getFactHandleFromWM(object);
    NamedEntryPoint ep = (NamedEntryPoint) reteEvaluator.getEntryPoint(EntryPointId.DEFAULT.getEntryPointId());
    ObjectTypeConf otc = ep.getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(ep.getEntryPoint(), object);
    BeliefSet beliefSet = null;
    if (handle == null) {
        handle = RuntimeComponentFactory.get().getFactHandleFactoryService().newFactHandle(object, otc, reteEvaluator, ep);
    }
    if (handle.getEqualityKey() == null) {
        handle.setEqualityKey(new TruthMaintenanceSystemEqualityKey(handle, EqualityKey.STATED));
    } else {
        beliefSet = ((TruthMaintenanceSystemEqualityKey) handle.getEqualityKey()).getBeliefSet();
    }
    BeliefSystem beliefSystem = value instanceof BeliefSystemMode ? ((BeliefSystemMode) value).getBeliefSystem() : ((TruthMaintenanceSystemImpl) TruthMaintenanceSystemFactory.get().getOrCreateTruthMaintenanceSystem(toStatefulKnowledgeSession())).getBeliefSystem();
    if (beliefSet == null) {
        beliefSet = beliefSystem.newBeliefSet(handle);
        ((TruthMaintenanceSystemEqualityKey) handle.getEqualityKey()).setBeliefSet(beliefSet);
    }
    return beliefSystem.insert(beliefSystem.asMode(value), activation.getRule(), (TruthMaintenanceSystemActivation) activation, object, beliefSet, activation.getPropagationContext(), otc).getFactHandle();
}
Also used : TruthMaintenanceSystemActivation(org.drools.tms.agenda.TruthMaintenanceSystemActivation) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) BeliefSystemMode(org.drools.tms.beliefsystem.BeliefSystemMode) NamedEntryPoint(org.drools.kiesession.entrypoints.NamedEntryPoint) BeliefSystem(org.drools.tms.beliefsystem.BeliefSystem) BeliefSet(org.drools.tms.beliefsystem.BeliefSet) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 3 with TruthMaintenanceSystemActivation

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

the class TruthMaintenanceSystemKnowledgeHelper method setActivation.

@Override
public void setActivation(final Activation agendaItem) {
    TruthMaintenanceSystemActivation tmsActivation = (TruthMaintenanceSystemActivation) agendaItem;
    this.previousJustified = tmsActivation.getLogicalDependencies();
    this.previousBlocked = tmsActivation.getBlocked();
    super.setActivation(agendaItem);
    tmsActivation.setLogicalDependencies(null);
    tmsActivation.setBlocked(null);
}
Also used : TruthMaintenanceSystemActivation(org.drools.tms.agenda.TruthMaintenanceSystemActivation)

Aggregations

TruthMaintenanceSystemActivation (org.drools.tms.agenda.TruthMaintenanceSystemActivation)3 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 InternalRuleFlowGroup (org.drools.core.common.InternalRuleFlowGroup)1 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)1 NamedEntryPoint (org.drools.kiesession.entrypoints.NamedEntryPoint)1 TruthMaintenanceSystemAgendaItem (org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem)1 BeliefSet (org.drools.tms.beliefsystem.BeliefSet)1 BeliefSystem (org.drools.tms.beliefsystem.BeliefSystem)1 BeliefSystemMode (org.drools.tms.beliefsystem.BeliefSystemMode)1 SimpleLogicalDependency (org.drools.tms.beliefsystem.simple.SimpleLogicalDependency)1