private DefeasibilityStatus resolveStatus(LogicalDependency node) { List<? extends FactHandle> premise = node.getJustifier().getFactHandles(); DefeasibilityStatus status = DefeasibilityStatus.resolve(node.getValue()); if (status == null) { DefeasibleRuleNature defeasibleType = DefeasibleRuleNature.STRICT; if (node.getJustifier() .getRule() .getMetaData() .containsKey(DefeasibleRuleNature.DEFEASIBLE.getLabel())) { defeasibleType = DefeasibleRuleNature.DEFEASIBLE; } else if (node.getJustifier() .getRule() .getMetaData() .containsKey(DefeasibleRuleNature.DEFEATER.getLabel())) { defeasibleType = DefeasibleRuleNature.DEFEATER; } switch (defeasibleType) { case DEFEASIBLE: status = checkDefeasible(premise); break; case DEFEATER: status = checkDefeater(premise); break; case STRICT: default: status = checkStrict(premise); break; } } return status; }
public static ProtobufMessages.Activation writeActivation( MarshallerWriteContext context, AgendaItem 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.getFactHandle() != null) { _activation.setHandleId(agendaItem.getFactHandle().getId()); } org.drools.core.util.LinkedList<LogicalDependency> 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(); }
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.intValue()); _logicalDependency.setObject( ByteString.copyFrom( strategy.marshal( context.strategyContext.get(strategy), context, belief.getObject()))); } if (belief.getValue() != null) { ObjectMarshallingStrategy strategy = objectMarshallingStrategyStore.getStrategyObject(belief.getValue()); Integer index = context.getStrategyIndex(strategy); _logicalDependency.setValueStrategyIndex(index.intValue()); _logicalDependency.setValue( ByteString.copyFrom( strategy.marshal( context.strategyContext.get(strategy), context, belief.getValue()))); } _beliefSet.addLogicalDependency(_logicalDependency.build()); } _key.setBeliefSet(_beliefSet); }
public void cancel(PropagationContext propagationContext) { // 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 FastIterator it = iterator(); for (LinkedListEntry<DefeasibleLogicalDependency> node = getFirst(); node != tailUndefeated; ) { LinkedListEntry<DefeasibleLogicalDependency> temp = (LinkedListEntry<DefeasibleLogicalDependency>) it.next(node); // get next, as we are about to remove it final DefeasibleLogicalDependency dep = node.getObject(); dep.getJustifier().getLogicalDependencies().remove(dep); remove(dep); node = temp; } LinkedListEntry last = (LinkedListEntry) getFirst(); final LogicalDependency node = (LogicalDependency) last.getObject(); node.getJustifier().getLogicalDependencies().remove(node); // beliefSystem.delete( node, this, context ); positiveFactHandle = null; negativeFactHandle = null; }