Search in sources :

Example 1 with LogicalDependency

use of org.drools.core.common.LogicalDependency in project drools by kiegroup.

the class ProtobufOutputMarshaller method writeBeliefSet.

private static void writeBeliefSet(MarshallerWriteContext context, BeliefSet beliefSet, org.drools.core.marshalling.impl.ProtobufMessages.EqualityKey.Builder _key) throws IOException {
    ProtobufMessages.BeliefSet.Builder _beliefSet = ProtobufMessages.BeliefSet.newBuilder();
    _beliefSet.setHandleId(beliefSet.getFactHandle().getId());
    ObjectMarshallingStrategyStore objectMarshallingStrategyStore = context.objectMarshallingStrategyStore;
    // 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(PersisterHelper.createTuple(activation.getTuple())).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.strategyContext.get(strategy), 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.strategyContext.get(strategy), 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.core.beliefsystem.BeliefSet) LogicalDependency(org.drools.core.common.LogicalDependency) FastIterator(org.drools.core.util.FastIterator)

Example 2 with LogicalDependency

use of org.drools.core.common.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
    for (SimpleMode entry = getFirst(); 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.core.common.LogicalDependency)

Example 3 with LogicalDependency

use of org.drools.core.common.LogicalDependency 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 4 with LogicalDependency

use of org.drools.core.common.LogicalDependency in project drools by kiegroup.

the class ProtobufOutputMarshaller method writeActivation.

public static <M extends ModedAssertion<M>> ProtobufMessages.Activation writeActivation(MarshallerWriteContext context, AgendaItem<M> 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.getActivationFactHandle() != null) {
        _activation.setHandleId(agendaItem.getActivationFactHandle().getId());
    }
    org.drools.core.util.LinkedList<LogicalDependency<M>> 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();
}
Also used : LogicalDependency(org.drools.core.common.LogicalDependency) BeliefSet(org.drools.core.beliefsystem.BeliefSet) Activation(org.drools.core.spi.Activation) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl)

Example 5 with LogicalDependency

use of org.drools.core.common.LogicalDependency in project drools by kiegroup.

the class DefaultKnowledgeHelper method unblockAllMatches.

public void unblockAllMatches(Match act) {
    AgendaItem targetMatch = (AgendaItem) 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();
        ((AgendaItem) dep.getJustifier()).removeBlocked(dep);
        entry = tmp;
    }
    if (wasBlocked) {
        RuleAgendaItem ruleAgendaItem = targetMatch.getRuleAgendaItem();
        InternalAgenda agenda = workingMemory.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) LogicalDependency(org.drools.core.common.LogicalDependency) SimpleLogicalDependency(org.drools.core.beliefsystem.simple.SimpleLogicalDependency) RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) AgendaItem(org.drools.core.common.AgendaItem)

Aggregations

LogicalDependency (org.drools.core.common.LogicalDependency)6 LinkedListEntry (org.drools.core.util.LinkedListEntry)3 BeliefSet (org.drools.core.beliefsystem.BeliefSet)2 Activation (org.drools.core.spi.Activation)2 SimpleLogicalDependency (org.drools.core.beliefsystem.simple.SimpleLogicalDependency)1 SimpleMode (org.drools.core.beliefsystem.simple.SimpleMode)1 AgendaItem (org.drools.core.common.AgendaItem)1 InternalAgenda (org.drools.core.common.InternalAgenda)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 RuleAgendaItem (org.drools.core.phreak.RuleAgendaItem)1 FastIterator (org.drools.core.util.FastIterator)1 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)1 ObjectMarshallingStrategyStore (org.kie.api.marshalling.ObjectMarshallingStrategyStore)1