Search in sources :

Example 1 with LogicalDependency

use of org.drools.tms.LogicalDependency in project drools by kiegroup.

the class JTMSBeliefSetImpl method cancel.

public void cancel(PropagationContext context) {
    // get all but last, as that we'll do via the BeliefSystem, for cleanup
    // note we don't update negative, conflict counters. It's needed for the last cleanup operation
    JTMSMode<M> entry = getFirst();
    while (entry != getLast()) {
        // get next, as we are about to remove it
        JTMSMode<M> temp = entry.getNext();
        final LogicalDependency<M> node = entry.getLogicalDependency();
        node.getJustifier().getLogicalDependencies().remove(node);
        remove((M) entry);
        entry = temp;
    }
    JTMSMode<M> last = getFirst();
    final LogicalDependency node = last.getLogicalDependency();
    node.getJustifier().getLogicalDependencies().remove(node);
    beliefSystem.delete(node, this, context);
}
Also used : LogicalDependency(org.drools.tms.LogicalDependency)

Example 2 with LogicalDependency

use of org.drools.tms.LogicalDependency in project drools by kiegroup.

the class SimpleBeliefSet method cancel.

public void cancel(PropagationContext context) {
    // get all but last, as that we'll do via the BeliefSystem, for cleanup
    SimpleMode entry = getFirst();
    while (entry != getLast()) {
        // get next, as we are about to remove it
        SimpleMode temp = entry.getNext();
        final LogicalDependency<SimpleMode> node = entry.getObject();
        node.getJustifier().getLogicalDependencies().remove(node);
        remove(entry);
        entry = temp;
    }
    LinkedListEntry last = getFirst();
    final LogicalDependency<SimpleMode> node = (LogicalDependency) last.getObject();
    node.getJustifier().getLogicalDependencies().remove(node);
    beliefSystem.delete(node, this, context);
}
Also used : LinkedListEntry(org.drools.core.util.LinkedListEntry) LogicalDependency(org.drools.tms.LogicalDependency) SimpleMode(org.drools.tms.SimpleMode)

Example 3 with LogicalDependency

use of org.drools.tms.LogicalDependency in project drools by kiegroup.

the class ProtobufOutputMarshaller method writeBeliefSet.

private static void writeBeliefSet(MarshallerWriteContext context, BeliefSet beliefSet, ProtobufMessages.EqualityKey.Builder _key) throws IOException {
    ProtobufMessages.BeliefSet.Builder _beliefSet = ProtobufMessages.BeliefSet.newBuilder();
    _beliefSet.setHandleId(beliefSet.getFactHandle().getId());
    ObjectMarshallingStrategyStore objectMarshallingStrategyStore = context.getObjectMarshallingStrategyStore();
    // for ( LinkedListEntry node = (LinkedListEntry) beliefSet.getFirst(); node != null; node = (LinkedListEntry) node.getNext() ) {
    FastIterator it = beliefSet.iterator();
    for (LinkedListEntry node = (LinkedListEntry) beliefSet.getFirst(); node != null; node = (LinkedListEntry) it.next(node)) {
        LogicalDependency belief = (LogicalDependency) node.getObject();
        ProtobufMessages.LogicalDependency.Builder _logicalDependency = ProtobufMessages.LogicalDependency.newBuilder();
        // _belief.setActivation( value )
        LogicalDependency dependency = (LogicalDependency) node.getObject();
        org.drools.core.spi.Activation activation = dependency.getJustifier();
        ProtobufMessages.Activation _activation = ProtobufMessages.Activation.newBuilder().setPackageName(activation.getRule().getPackage()).setRuleName(activation.getRule().getName()).setTuple(writeTuple(context, activation, true)).build();
        _logicalDependency.setActivation(_activation);
        if (belief.getObject() != null) {
            ObjectMarshallingStrategy strategy = objectMarshallingStrategyStore.getStrategyObject(belief.getObject());
            Integer index = context.getStrategyIndex(strategy);
            _logicalDependency.setObjectStrategyIndex(index);
            _logicalDependency.setObject(ByteString.copyFrom(strategy.marshal(context.getStrategyContext().get(strategy), (ObjectOutputStream) context, belief.getObject())));
        }
        if (belief.getMode() != null) {
            ObjectMarshallingStrategy strategy = objectMarshallingStrategyStore.getStrategyObject(belief.getMode());
            Integer index = context.getStrategyIndex(strategy);
            _logicalDependency.setValueStrategyIndex(index);
            _logicalDependency.setValue(ByteString.copyFrom(strategy.marshal(context.getStrategyContext().get(strategy), (ObjectOutputStream) context, belief.getMode())));
        }
        _beliefSet.addLogicalDependency(_logicalDependency.build());
    }
    _key.setBeliefSet(_beliefSet);
}
Also used : ObjectMarshallingStrategyStore(org.kie.api.marshalling.ObjectMarshallingStrategyStore) LinkedListEntry(org.drools.core.util.LinkedListEntry) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) Activation(org.drools.core.spi.Activation) BeliefSet(org.drools.tms.beliefsystem.BeliefSet) LogicalDependency(org.drools.tms.LogicalDependency) FastIterator(org.drools.core.util.FastIterator)

Example 4 with LogicalDependency

use of org.drools.tms.LogicalDependency in project drools by kiegroup.

the class TruthMaintenanceSystemRuleTerminalNodeLeftTuple method removeAllBlockersAndBlocked.

@Override
public void removeAllBlockersAndBlocked(ActivationsManager activationsManager) {
    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);
            TruthMaintenanceSystemRuleTerminalNodeLeftTuple justified = (TruthMaintenanceSystemRuleTerminalNodeLeftTuple) dep.getJustified();
            if (justified.getBlockers().isEmpty() && justified.isActive()) {
                activationsManager.stageLeftTuple(ruleAgendaItem, justified);
            }
            dep = tmp;
        }
    }
    this.blocked = null;
}
Also used : LogicalDependency(org.drools.tms.LogicalDependency) SimpleMode(org.drools.tms.SimpleMode)

Example 5 with LogicalDependency

use of org.drools.tms.LogicalDependency in project drools by kiegroup.

the class TruthMaintenanceSystemAgendaItemImpl method removeAllBlockersAndBlocked.

@Override
public void removeAllBlockersAndBlocked(ActivationsManager activationsManager) {
    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);
            TruthMaintenanceSystemAgendaItemImpl justified = (TruthMaintenanceSystemAgendaItemImpl) dep.getJustified();
            if (justified.getBlockers().isEmpty()) {
                activationsManager.stageLeftTuple(null, justified);
            }
            dep = tmp;
        }
    }
    this.blocked = null;
}
Also used : LogicalDependency(org.drools.tms.LogicalDependency) SimpleMode(org.drools.tms.SimpleMode)

Aggregations

LogicalDependency (org.drools.tms.LogicalDependency)6 SimpleMode (org.drools.tms.SimpleMode)3 Activation (org.drools.core.spi.Activation)2 LinkedListEntry (org.drools.core.util.LinkedListEntry)2 BeliefSet (org.drools.tms.beliefsystem.BeliefSet)2 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 FastIterator (org.drools.core.util.FastIterator)1 TruthMaintenanceSystemAgendaItem (org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem)1 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)1 ObjectMarshallingStrategyStore (org.kie.api.marshalling.ObjectMarshallingStrategyStore)1