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);
}
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);
}
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;
}
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();
}
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);
}
}
Aggregations