use of org.drools.core.beliefsystem.BeliefSet 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.beliefsystem.BeliefSet in project drools by kiegroup.
the class DefaultKnowledgeHelper method bolster.
public InternalFactHandle bolster(final Object object, final Object value) {
if (object == null || !activation.isMatched()) {
return null;
}
InternalFactHandle handle = getFactHandleFromWM(object);
NamedEntryPoint ep = (NamedEntryPoint) workingMemory.getEntryPoint(EntryPointId.DEFAULT.getEntryPointId());
ObjectTypeConf otc = ep.getObjectTypeConfigurationRegistry().getObjectTypeConf(ep.getEntryPoint(), object);
BeliefSystem beliefSystem;
if (value == null) {
beliefSystem = workingMemory.getTruthMaintenanceSystem().getBeliefSystem();
} else {
if (value instanceof Mode) {
Mode m = (Mode) value;
beliefSystem = (BeliefSystem) m.getBeliefSystem();
} else {
beliefSystem = workingMemory.getTruthMaintenanceSystem().getBeliefSystem();
}
}
BeliefSet beliefSet = null;
if (handle == null) {
handle = workingMemory.getKnowledgeBase().getConfiguration().getComponentFactory().getFactHandleFactoryService().newFactHandle(object, otc, workingMemory, ep);
}
if (handle.getEqualityKey() == null) {
handle.setEqualityKey(new EqualityKey(handle, EqualityKey.STATED));
} else {
beliefSet = handle.getEqualityKey().getBeliefSet();
}
if (beliefSet == null) {
beliefSet = beliefSystem.newBeliefSet(handle);
handle.getEqualityKey().setBeliefSet(beliefSet);
}
return beliefSystem.insert(beliefSystem.asMode(value), activation.getRule(), activation, object, beliefSet, activation.getPropagationContext(), otc).getFactHandle();
}
use of org.drools.core.beliefsystem.BeliefSet in project drools by kiegroup.
the class BeliefSystemLogicalCallback method execute.
public void execute(InternalWorkingMemory workingMemory) {
NamedEntryPoint nep = (NamedEntryPoint) handle.getEntryPoint();
BeliefSet bs = handle.getEqualityKey().getBeliefSet();
bs.setWorkingMemoryAction(null);
if (update) {
if (!bs.isEmpty()) {
// We need the isEmpty check, in case the BeliefSet was made empty (due to retract) after this was scheduled
((NamedEntryPoint) handle.getEntryPoint()).update(handle, handle.getObject(), allSetButTraitBitMask(), Object.class, null);
}
} else {
if (fullyRetract) {
((NamedEntryPoint) handle.getEntryPoint()).delete(this.handle, context.getRuleOrigin(), this.activation.getTuple().getTupleSink());
} else {
final ObjectTypeConf typeConf = nep.getObjectTypeConfigurationRegistry().getObjectTypeConf(nep.getEntryPoint(), handle.getObject());
((NamedEntryPoint) handle.getEntryPoint()).getEntryPointNode().retractObject(handle, context, typeConf, workingMemory);
}
}
}
Aggregations